Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper/schema: removed optional items force new #9699

Merged
merged 1 commit into from
Oct 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions helper/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
45 changes: 39 additions & 6 deletions helper/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2019,9 +2019,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,
},
},
},
Expand Down Expand Up @@ -2331,9 +2332,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",
Expand Down Expand Up @@ -2420,6 +2422,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 {
Expand Down