Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit a1da59a

Browse files
committed
helper/schema: provisioner allows for nil state
1 parent b2891bc commit a1da59a

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

helper/schema/provisioner.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ func (p *Provisioner) Apply(
130130
// easily build a ResourceData structure. We do this by simply treating
131131
// the conn info as configuration input.
132132
raw := make(map[string]interface{})
133-
for k, v := range s.Ephemeral.ConnInfo {
134-
raw[k] = v
133+
if s != nil {
134+
for k, v := range s.Ephemeral.ConnInfo {
135+
raw[k] = v
136+
}
135137
}
136138

137139
c, err := config.NewRawConfig(raw)

helper/schema/provisioner_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,42 @@ func TestProvisionerApply(t *testing.T) {
137137
}
138138
}
139139

140+
func TestProvisionerApply_nilState(t *testing.T) {
141+
p := &Provisioner{
142+
ConnSchema: map[string]*Schema{
143+
"foo": &Schema{
144+
Type: TypeString,
145+
Optional: true,
146+
},
147+
},
148+
149+
Schema: map[string]*Schema{
150+
"foo": &Schema{
151+
Type: TypeInt,
152+
Optional: true,
153+
},
154+
},
155+
156+
ApplyFunc: func(ctx context.Context) error {
157+
return nil
158+
},
159+
}
160+
161+
conf := map[string]interface{}{
162+
"foo": 42,
163+
}
164+
165+
c, err := config.NewRawConfig(conf)
166+
if err != nil {
167+
t.Fatalf("err: %s", err)
168+
}
169+
170+
err = p.Apply(nil, nil, terraform.NewResourceConfig(c))
171+
if err != nil {
172+
t.Fatalf("err: %s", err)
173+
}
174+
}
175+
140176
func TestProvisionerStop(t *testing.T) {
141177
var p Provisioner
142178

0 commit comments

Comments
 (0)