helper/diff: if attribute is set and also computed, don't mark computed

This commit is contained in:
Mitchell Hashimoto 2014-07-11 11:46:21 -07:00
parent f93c9c23d5
commit 4f798fdec6
2 changed files with 38 additions and 0 deletions

View File

@ -146,6 +146,10 @@ func (b *ResourceBuilder) Diff(
// that will be changing due to the creation of the resource. // that will be changing due to the creation of the resource.
if requiresNew { if requiresNew {
for _, k := range b.ComputedAttrs { for _, k := range b.ComputedAttrs {
if _, ok := attrs[k]; ok {
continue
}
old := s.Attributes[k] old := s.Attributes[k]
attrs[k] = &terraform.ResourceAttrDiff{ attrs[k] = &terraform.ResourceAttrDiff{
Old: old, Old: old,

View File

@ -7,6 +7,36 @@ import (
"github.com/hashicorp/terraform/terraform" "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) { func TestResourceBuilder_replaceComputed(t *testing.T) {
rb := &ResourceBuilder{ rb := &ResourceBuilder{
Attrs: map[string]AttrType{ 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 const testRBComplexDiff = `UPDATE
IN listener.0.port: "80" => "3000" IN listener.0.port: "80" => "3000"
` `