helper/schema: provisioner allows for nil state

This commit is contained in:
Mitchell Hashimoto 2016-12-22 14:11:28 -08:00
parent b2891bc9ef
commit a1da59a73e
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 40 additions and 2 deletions

View File

@ -130,8 +130,10 @@ func (p *Provisioner) Apply(
// easily build a ResourceData structure. We do this by simply treating
// the conn info as configuration input.
raw := make(map[string]interface{})
for k, v := range s.Ephemeral.ConnInfo {
raw[k] = v
if s != nil {
for k, v := range s.Ephemeral.ConnInfo {
raw[k] = v
}
}
c, err := config.NewRawConfig(raw)

View File

@ -137,6 +137,42 @@ func TestProvisionerApply(t *testing.T) {
}
}
func TestProvisionerApply_nilState(t *testing.T) {
p := &Provisioner{
ConnSchema: map[string]*Schema{
"foo": &Schema{
Type: TypeString,
Optional: true,
},
},
Schema: map[string]*Schema{
"foo": &Schema{
Type: TypeInt,
Optional: true,
},
},
ApplyFunc: func(ctx context.Context) error {
return nil
},
}
conf := map[string]interface{}{
"foo": 42,
}
c, err := config.NewRawConfig(conf)
if err != nil {
t.Fatalf("err: %s", err)
}
err = p.Apply(nil, nil, terraform.NewResourceConfig(c))
if err != nil {
t.Fatalf("err: %s", err)
}
}
func TestProvisionerStop(t *testing.T) {
var p Provisioner