Merge pull request #9699 from hashicorp/b-removed-forcenew

helper/schema: removed optional items force new
This commit is contained in:
Mitchell Hashimoto 2016-10-31 13:24:36 -07:00 committed by GitHub
commit 2d84582881
2 changed files with 44 additions and 11 deletions

View File

@ -285,6 +285,11 @@ func (s *Schema) finalizeDiff(
d.New = normalizeBoolString(d.New)
}
if s.ForceNew {
// Force new, set it to true in the diff
d.RequiresNew = true
}
if d.NewRemoved {
return d
}
@ -302,11 +307,6 @@ func (s *Schema) finalizeDiff(
}
}
if s.ForceNew {
// Force new, set it to true in the diff
d.RequiresNew = true
}
if s.Sensitive {
// Set the Sensitive flag so output is hidden in the UI
d.Sensitive = true

View File

@ -2024,6 +2024,7 @@ func TestSchemaMap_Diff(t *testing.T) {
Old: "foo",
New: "",
NewRemoved: true,
RequiresNew: true,
},
},
},
@ -2336,6 +2337,7 @@ func TestSchemaMap_Diff(t *testing.T) {
Old: "22",
New: "",
NewRemoved: true,
RequiresNew: true,
},
"instances.3": &terraform.ResourceAttrDiff{
Old: "333",
@ -2422,6 +2424,37 @@ func TestSchemaMap_Diff(t *testing.T) {
Err: false,
},
"removed optional items should trigger ForceNew": {
Schema: map[string]*Schema{
"description": &Schema{
Type: TypeString,
ForceNew: true,
Optional: true,
},
},
State: &terraform.InstanceState{
Attributes: map[string]string{
"description": "foo",
},
},
Config: map[string]interface{}{},
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"description": &terraform.ResourceAttrDiff{
Old: "foo",
New: "",
RequiresNew: true,
NewRemoved: true,
},
},
},
Err: false,
},
}
for tn, tc := range cases {