diff --git a/helper/schema/provisioner.go b/helper/schema/provisioner.go index c6d21c1995..d73aaa95e1 100644 --- a/helper/schema/provisioner.go +++ b/helper/schema/provisioner.go @@ -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) diff --git a/helper/schema/provisioner_test.go b/helper/schema/provisioner_test.go index 827685e8f9..d8448acef9 100644 --- a/helper/schema/provisioner_test.go +++ b/helper/schema/provisioner_test.go @@ -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