diff --git a/helper/diff/resource_builder.go b/helper/diff/resource_builder.go index c388d56a3..e365bd806 100644 --- a/helper/diff/resource_builder.go +++ b/helper/diff/resource_builder.go @@ -146,6 +146,10 @@ func (b *ResourceBuilder) Diff( // that will be changing due to the creation of the resource. if requiresNew { for _, k := range b.ComputedAttrs { + if _, ok := attrs[k]; ok { + continue + } + old := s.Attributes[k] attrs[k] = &terraform.ResourceAttrDiff{ Old: old, diff --git a/helper/diff/resource_builder_test.go b/helper/diff/resource_builder_test.go index 6a318a716..b9e3b3509 100644 --- a/helper/diff/resource_builder_test.go +++ b/helper/diff/resource_builder_test.go @@ -7,6 +7,36 @@ import ( "github.com/hashicorp/terraform/terraform" ) +func TestResourceBuilder_attrSetComputed(t *testing.T) { + rb := &ResourceBuilder{ + Attrs: map[string]AttrType{ + "foo": AttrTypeCreate, + }, + ComputedAttrs: []string{ + "foo", + }, + } + + state := &terraform.ResourceState{} + c := testConfig(t, map[string]interface{}{ + "foo": "bar", + }, nil) + + diff, err := rb.Diff(state, c) + if err != nil { + t.Fatalf("err: %s", err) + } + if diff == nil { + t.Fatal("diff shold not be nil") + } + + actual := testResourceDiffStr(diff) + expected := testRBAttrSetComputedDiff + if actual != expected { + t.Fatalf("bad: %s", actual) + } +} + func TestResourceBuilder_replaceComputed(t *testing.T) { rb := &ResourceBuilder{ Attrs: map[string]AttrType{ @@ -262,6 +292,10 @@ func TestResourceBuilder_vars(t *testing.T) { } } +const testRBAttrSetComputedDiff = `CREATE + IN foo: "" => "bar" (forces new resource) +` + const testRBComplexDiff = `UPDATE IN listener.0.port: "80" => "3000" `