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

Don't crash when populating NewExtra. #686

Merged
merged 3 commits into from
Jan 27, 2021
Merged
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
40 changes: 33 additions & 7 deletions helper/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ func (s *Schema) finalizeDiff(d *terraform.ResourceAttrDiff, customized bool) *t
if d.Old != "" && d.New == "" {
// This is a computed value with an old value set already,
// just let it go.
log.Println("[DEBUG] A computed value with the empty string as the new value and a non-empty old value was found. Interpreting the empty string as \"unset\" to align with legacy behavior.")
return nil
}
}
Expand Down Expand Up @@ -1061,13 +1062,18 @@ func (m schemaMap) diffList(
oldStr = ""
}

diff.Attributes[k+".#"] = countSchema.finalizeDiff(
finalizedAttr := countSchema.finalizeDiff(
&terraform.ResourceAttrDiff{
Old: oldStr,
New: newStr,
},
customized,
)
if finalizedAttr != nil {
diff.Attributes[k+".#"] = finalizedAttr
} else {
delete(diff.Attributes, k+".#")
}
}

// Figure out the maximum
Expand Down Expand Up @@ -1167,13 +1173,18 @@ func (m schemaMap) diffMap(
oldStr = ""
}

diff.Attributes[k+".%"] = countSchema.finalizeDiff(
finalizedAttr := countSchema.finalizeDiff(
&terraform.ResourceAttrDiff{
Old: oldStr,
New: newStr,
},
customized,
)
if finalizedAttr != nil {
diff.Attributes[k+".%"] = finalizedAttr
} else {
delete(diff.Attributes, k+".%")
}
}

// If the new map is nil and we're computed, then ignore it.
Expand All @@ -1190,22 +1201,28 @@ func (m schemaMap) diffMap(
continue
}

diff.Attributes[prefix+k] = schema.finalizeDiff(
finalizedAttr := schema.finalizeDiff(
&terraform.ResourceAttrDiff{
Old: old,
New: v,
},
customized,
)
if finalizedAttr != nil {
diff.Attributes[prefix+k] = finalizedAttr
}
}
for k, v := range stateMap {
diff.Attributes[prefix+k] = schema.finalizeDiff(
finalizedAttr := schema.finalizeDiff(
&terraform.ResourceAttrDiff{
Old: v,
NewRemoved: true,
},
customized,
)
if finalizedAttr != nil {
diff.Attributes[prefix+k] = finalizedAttr
}
}

return nil
Expand Down Expand Up @@ -1277,26 +1294,32 @@ func (m schemaMap) diffSet(
countStr = ""
}

diff.Attributes[k+".#"] = countSchema.finalizeDiff(
finalizedAttr := countSchema.finalizeDiff(
&terraform.ResourceAttrDiff{
Old: countStr,
NewComputed: true,
},
customized,
)
if finalizedAttr != nil {
diff.Attributes[k+".#"] = finalizedAttr
}
return nil
}

// If the counts are not the same, then record that diff
changed := oldLen != newLen
if changed || all {
diff.Attributes[k+".#"] = countSchema.finalizeDiff(
finalizedAttr := countSchema.finalizeDiff(
&terraform.ResourceAttrDiff{
Old: oldStr,
New: newStr,
},
customized,
)
if finalizedAttr != nil {
diff.Attributes[k+".#"] = finalizedAttr
}
}

// Build the list of codes that will make up our set. This is the
Expand Down Expand Up @@ -1383,7 +1406,7 @@ func (m schemaMap) diffString(
return nil
}

diff.Attributes[k] = schema.finalizeDiff(
finalizedAttr := schema.finalizeDiff(
&terraform.ResourceAttrDiff{
Old: os,
New: ns,
Expand All @@ -1393,6 +1416,9 @@ func (m schemaMap) diffString(
},
customized,
)
if finalizedAttr != nil {
diff.Attributes[k] = finalizedAttr
}

return nil
}
Expand Down