Skip to content

Commit

Permalink
Add support for entry-style lists to Terraform CRUD functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kklimonda-cl committed Aug 9, 2024
1 parent 65d898b commit cde8f01
Show file tree
Hide file tree
Showing 4 changed files with 398 additions and 15 deletions.
25 changes: 25 additions & 0 deletions pkg/translate/terraform_provider/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,8 @@ func (o *{{ .StructName }}{{ .ObjectOrModel }}) getTypeFor(name string) attr.Typ
switch attr := attr.(type) {
case {{ .Package }}.ListNestedAttribute:
return attr.NestedObject.Type()
case {{ .Package }}.MapNestedAttribute:
return attr.NestedObject.Type()
default:
return attr.GetType()
}
Expand Down Expand Up @@ -1761,6 +1763,7 @@ func ResourceCreateFunction(resourceTyp properties.ResourceType, names *NameProv
var exhaustive bool
switch resourceTyp {

Check failure on line 1764 in pkg/translate/terraform_provider/funcs.go

View workflow job for this annotation

GitHub Actions / lint

missing cases in switch of type properties.ResourceType: properties.ResourceEntryPlural (exhaustive)
case properties.ResourceEntry:
exhaustive = true
tmpl = resourceCreateFunction
case properties.ResourceUuid:
exhaustive = true
Expand All @@ -1778,9 +1781,14 @@ func ResourceCreateFunction(resourceTyp properties.ResourceType, names *NameProv
LowerCamelCase: naming.CamelCase("", listAttribute, "", false),
}

var resourceIsMap bool
if resourceTyp == properties.ResourceEntryPlural {
resourceIsMap = true
}
data := map[string]interface{}{
"HasEncryptedResources": paramSpec.HasEncryptedResources(),
"Exhaustive": exhaustive,
"ResourceIsMap": resourceIsMap,
"ListAttribute": listAttributeVariant,
"EntryOrConfig": paramSpec.EntryOrConfig(),
"HasEntryName": paramSpec.HasEntryName(),
Expand Down Expand Up @@ -1857,6 +1865,9 @@ func ResourceReadFunction(resourceTyp properties.ResourceType, names *NameProvid
switch resourceTyp {
case properties.ResourceEntry:
tmpl = resourceReadFunction
case properties.ResourceEntryPlural:
tmpl = resourceReadManyFunction
listAttribute = pascalCase(paramSpec.TerraformProviderConfig.PluralName)
case properties.ResourceUuid:
tmpl = resourceReadManyFunction
listAttribute = pascalCase(paramSpec.TerraformProviderConfig.PluralName)
Expand All @@ -1872,8 +1883,13 @@ func ResourceReadFunction(resourceTyp properties.ResourceType, names *NameProvid
LowerCamelCase: naming.CamelCase("", listAttribute, "", false),
}

var resourceIsMap bool
if resourceTyp == properties.ResourceEntryPlural {
resourceIsMap = true
}
data := map[string]interface{}{
"ResourceOrDS": "Resource",
"ResourceIsMap": resourceIsMap,
"HasEncryptedResources": paramSpec.HasEncryptedResources(),
"ListAttribute": listAttributeVariant,
"Exhaustive": exhaustive,
Expand Down Expand Up @@ -1910,6 +1926,9 @@ func ResourceUpdateFunction(resourceTyp properties.ResourceType, names *NameProv
switch resourceTyp {
case properties.ResourceEntry:
tmpl = resourceUpdateFunction
case properties.ResourceEntryPlural:
tmpl = resourceUpdateEntryListFunction
listAttribute = pascalCase(paramSpec.TerraformProviderConfig.PluralName)
case properties.ResourceUuid:
tmpl = resourceUpdateManyFunction
listAttribute = pascalCase(paramSpec.TerraformProviderConfig.PluralName)
Expand All @@ -1925,8 +1944,14 @@ func ResourceUpdateFunction(resourceTyp properties.ResourceType, names *NameProv
LowerCamelCase: naming.CamelCase("", listAttribute, "", false),
}

var resourceIsMap bool
if resourceTyp == properties.ResourceEntryPlural {
resourceIsMap = true
}

data := map[string]interface{}{
"HasEncryptedResources": paramSpec.HasEncryptedResources(),
"ResourceIsMap": resourceIsMap,
"ListAttribute": listAttributeVariant,
"Exhaustive": exhaustive,
"EntryOrConfig": paramSpec.EntryOrConfig(),
Expand Down
Loading

0 comments on commit cde8f01

Please sign in to comment.