Fixing a small logic bug in diffList
It’s not enough to only check if no new value is set. It can also be that a new value is set, but contains a variable that cannot be interpolated until a depending resource is created during the apply fase. I actually found this one as one of the acceptance tests for the AWS ELB resource was failing. It failed with the following error: ``` --- FAIL: TestAccAWSELB_InstanceAttaching (177.83 seconds) testing.go:121: Step 1 error: Error applying: aws_elb.bar: diffs didn't match during apply. This is a bug with the resource provider, please report a bug. FAIL exit status 1 FAIL github.com/hashicorp/terraform/builtin/providers/aws 177.882s ``` After a quick look I noticed it was actually a bug in core TF so added the test and made sure all unit tests and AWS acceptance tests are now running successfully.
This commit is contained in:
parent
afe2cf8580
commit
54db46ef1b
|
@ -459,9 +459,10 @@ func (m schemaMap) diffList(
|
||||||
o, n, _, computedList := d.diffChange(k)
|
o, n, _, computedList := d.diffChange(k)
|
||||||
nSet := n != nil
|
nSet := n != nil
|
||||||
|
|
||||||
// If we have an old value, but no new value set but we're computed,
|
// If we have an old value and no new value is set or will be
|
||||||
// then nothing has changed.
|
// computed once all variables can be interpolated and we're
|
||||||
if o != nil && n == nil && schema.Computed {
|
// computed, then nothing has changed.
|
||||||
|
if o != nil && n == nil && !computedList && schema.Computed {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1466,6 +1466,57 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||||
|
|
||||||
Err: false,
|
Err: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
Schema: map[string]*Schema{
|
||||||
|
"internal": &Schema{
|
||||||
|
Type: TypeBool,
|
||||||
|
Required: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
"instances": &Schema{
|
||||||
|
Type: TypeSet,
|
||||||
|
Elem: &Schema{Type: TypeString},
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
Set: func(v interface{}) int {
|
||||||
|
return len(v)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
State: &terraform.InstanceState{
|
||||||
|
Attributes: map[string]string{
|
||||||
|
"internal": "false",
|
||||||
|
"instances.#": "0",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
Config: map[string]interface{}{
|
||||||
|
"internal": true,
|
||||||
|
"instances": []interface{}{"${var.foo}"},
|
||||||
|
},
|
||||||
|
|
||||||
|
ConfigVariables: map[string]string{
|
||||||
|
"var.foo": config.UnknownVariableValue,
|
||||||
|
},
|
||||||
|
|
||||||
|
Diff: &terraform.InstanceDiff{
|
||||||
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
||||||
|
"internal": &terraform.ResourceAttrDiff{
|
||||||
|
Old: "0",
|
||||||
|
New: "1",
|
||||||
|
},
|
||||||
|
|
||||||
|
"instances.#": &terraform.ResourceAttrDiff{
|
||||||
|
Old: "0",
|
||||||
|
NewComputed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
Err: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range cases {
|
for i, tc := range cases {
|
||||||
|
|
Loading…
Reference in New Issue