From a1da59a73e4697d0ada1b5be15f8a8803200844b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 22 Dec 2016 14:11:28 -0800 Subject: [PATCH] helper/schema: provisioner allows for nil state --- helper/schema/provisioner.go | 6 ++++-- helper/schema/provisioner_test.go | 36 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/helper/schema/provisioner.go b/helper/schema/provisioner.go index c6d21c199..d73aaa95e 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 827685e8f..d8448acef 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