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

@ -2021,9 +2021,10 @@ func TestSchemaMap_Diff(t *testing.T) {
RequiresNew: true,
},
"instances.3": &terraform.ResourceAttrDiff{
Old: "foo",
New: "",
NewRemoved: true,
Old: "foo",
New: "",
NewRemoved: true,
RequiresNew: true,
},
},
},
@ -2333,9 +2334,10 @@ func TestSchemaMap_Diff(t *testing.T) {
New: "2",
},
"instances.2": &terraform.ResourceAttrDiff{
Old: "22",
New: "",
NewRemoved: true,
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 {