Skip to content

Commit

Permalink
Add config.Resource.RemoveSingletonListConversion to be able to remove
Browse files Browse the repository at this point in the history
already configured singleton list conversions.

- The main use case is to prevent singleton list conversions for
  configuration arguments with single nested blocks.

Signed-off-by: Alper Rifat Ulucinar <[email protected]>
  • Loading branch information
ulucinar committed May 29, 2024
1 parent a444cc1 commit fc6948e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/config/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,28 @@ func (r *Resource) AddSingletonListConversion(tfPath, crdPath string) {
r.listConversionPaths[tfPath] = crdPath
}

// RemoveSingletonListConversion removes the singleton list conversion path
// for the specified Terraform configuration path. The specified fieldpath
// expression must be a Terraform field path with or without the wildcard
// segments. Returns true if the path has already been registered for
// singleton list conversion.
func (r *Resource) RemoveSingletonListConversion(tfPath string) bool {
nPath := strings.ReplaceAll(tfPath, "[*]", "")
nPath = strings.ReplaceAll(nPath, "[0]", "")
for p := range r.listConversionPaths {
n := strings.ReplaceAll(p, "[*]", "")
n = strings.ReplaceAll(n, "[0]", "")
if n == nPath {
delete(r.listConversionPaths, p)
if r.SchemaElementOptions[n] != nil {
r.SchemaElementOptions[n].EmbeddedObject = false
}
return true
}
}
return false
}

// SetEmbeddedObject sets the EmbeddedObject for the specified key.
// The key is a Terraform field path without the wildcard segments.
func (m SchemaElementOptions) SetEmbeddedObject(el string) {
Expand Down

0 comments on commit fc6948e

Please sign in to comment.