Skip to content

Commit 787f1a1

Browse files
committed
WIP: Some changes to the ReadMany() logic
1 parent 49493dd commit 787f1a1

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

pkg/translate/terraform_provider/template.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -977,9 +977,26 @@ for _, elt := range existing {
977977
processedElementsByName[elt.Name] = processedElement
978978
}
979979
980-
objects := make([]{{ $resourceTFStructName }}, len(processedElementsByName))
980+
981+
// To keep indices correct, processed entries were stored in a map, with element
982+
// index being part of the entryWithState structure. Now it has to be converted
983+
// into a list that can be set in the plan.
984+
// First, create a list with a length matching number of elements in the
985+
// stateElementsByName and fill it out with elements from processedElementsByName
986+
// map.
987+
unfiltered := make([]elementWithState, len(stateElementsByName))
981988
for _, elt := range processedElementsByName {
982-
objects[elt.StateIdx] = *elt.Element
989+
unfiltered[elt.StateIdx] = elt
990+
}
991+
992+
// If some elements were removed in the plan, unfiltered array is now going to have
993+
// empty spaces. We need to process it and remove them before we pass it back
994+
// to terraform.
995+
var objects []{{ $resourceTFStructName }}
996+
for _, elt := range unfiltered {
997+
if elt.Element != nil {
998+
objects = append(objects, *elt.Element)
999+
}
9831000
}
9841001
{{- end }}
9851002
@@ -1164,11 +1181,14 @@ for name, elt := range elements {
11641181
}
11651182
11661183
type entryState string
1167-
const entryUnknown entryState = "unknown"
1168-
const entryMissing entryState = "missing"
1169-
const entryOutdated entryState = "outdated"
1170-
const entryRenamed entryState = "renamed"
1171-
const entryOk entryState = "ok"
1184+
const (
1185+
entryUnknown entryState = "unknown"
1186+
entryMissing entryState = "missing"
1187+
entryOutdated entryState = "outdated"
1188+
entryRenamed entryState = "renamed"
1189+
entryDeleted entryState = "deleted"
1190+
entryOk entryState = "ok"
1191+
)
11721192
11731193
type entryWithState struct {
11741194
Entry *{{ $resourceSDKStructName }}

0 commit comments

Comments
 (0)