Merge pull request #9699 from hashicorp/b-removed-forcenew
helper/schema: removed optional items force new
This commit is contained in:
commit
2d84582881
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue