Skip to content

Commit 2781a2c

Browse files
committed
fix(): expand ignore changes path for converted singleton lists
Signed-off-by: Lubomir Kaplan <castor@castor.sk>
1 parent c6d5213 commit 2781a2c

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

pkg/controller/external_tfpluginsdk.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func (c *TerraformPluginSDKConnector) Connect(ctx context.Context, mg xpresource
323323
}, nil
324324
}
325325

326-
func filterInitExclusiveDiffs(tr resource.Terraformed, instanceDiff *tf.InstanceDiff) error { //nolint:gocyclo
326+
func filterInitExclusiveDiffs(config *config.Resource, tr resource.Terraformed, instanceDiff *tf.InstanceDiff) error { //nolint:gocyclo
327327
if instanceDiff == nil || instanceDiff.Empty() {
328328
return nil
329329
}
@@ -338,6 +338,25 @@ func filterInitExclusiveDiffs(tr resource.Terraformed, instanceDiff *tf.Instance
338338
}
339339

340340
initProviderExclusiveParamKeys := getTerraformIgnoreChanges(paramsForProvider, paramsInitProvider)
341+
342+
/* process singleton list expansions */
343+
initProviderExclusiveParamKeysConverted := []string{}
344+
for _, key := range initProviderExclusiveParamKeys {
345+
matched := false
346+
for _, p := range config.TFListConversionPaths() {
347+
matchPrefix := fmt.Sprintf("%s.", p)
348+
if strings.HasPrefix(key, matchPrefix) {
349+
initProviderExclusiveParamKeysConverted = append(initProviderExclusiveParamKeysConverted, strings.Replace(key, matchPrefix, fmt.Sprintf("%s0.", matchPrefix), 1))
350+
matched = true
351+
continue
352+
}
353+
}
354+
if !matched {
355+
initProviderExclusiveParamKeysConverted = append(initProviderExclusiveParamKeysConverted, key)
356+
}
357+
}
358+
initProviderExclusiveParamKeys = initProviderExclusiveParamKeysConverted
359+
341360
for _, keyToIgnore := range initProviderExclusiveParamKeys {
342361
for attributeKey := range instanceDiff.Attributes {
343362
keyToIgnoreAsPrefix := fmt.Sprintf("%s.", keyToIgnore)
@@ -451,7 +470,7 @@ func (n *terraformPluginSDKExternal) getResourceDataDiff(tr resource.Terraformed
451470
}
452471

453472
if resourceExists {
454-
if err := filterInitExclusiveDiffs(tr, instanceDiff); err != nil {
473+
if err := filterInitExclusiveDiffs(n.config, tr, instanceDiff); err != nil {
455474
return nil, errors.Wrap(err, "failed to filter the diffs exclusive to spec.initProvider in the terraform.InstanceDiff")
456475
}
457476
}

0 commit comments

Comments
 (0)