helper/diff: if attribute is set and also computed, don't mark computed
This commit is contained in:
parent
f93c9c23d5
commit
4f798fdec6
|
@ -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,
|
||||
|
|
|
@ -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"
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue