Skip to content

Commit 41a943e

Browse files
committed
Add support for entry-style lists to Terraform CRUD functions
1 parent 556427f commit 41a943e

File tree

3 files changed

+369
-2
lines changed

3 files changed

+369
-2
lines changed

pkg/translate/terraform_provider/funcs.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,8 @@ func (o *{{ .StructName }}{{ .ObjectOrModel }}) getTypeFor(name string) attr.Typ
12791279
switch attr := attr.(type) {
12801280
case {{ .Package }}.ListNestedAttribute:
12811281
return attr.NestedObject.Type()
1282+
case {{ .Package }}.MapNestedAttribute:
1283+
return attr.NestedObject.Type()
12821284
default:
12831285
return attr.GetType()
12841286
}
@@ -1757,8 +1759,13 @@ func ResourceCreateFunction(resourceTyp properties.ResourceType, names *NameProv
17571759
LowerCamelCase: naming.CamelCase("", listAttribute, "", false),
17581760
}
17591761

1762+
var resourceIsMap bool
1763+
if resourceTyp == properties.ResourceEntryPlural {
1764+
resourceIsMap = true
1765+
}
17601766
data := map[string]interface{}{
17611767
"HasEncryptedResources": paramSpec.HasEncryptedResources(),
1768+
"ResourceIsMap": resourceIsMap,
17621769
"ListAttribute": listAttributeVariant,
17631770
"EntryOrConfig": paramSpec.EntryOrConfig(),
17641771
"HasEntryName": paramSpec.HasEntryName(),
@@ -1835,6 +1842,9 @@ func ResourceReadFunction(resourceTyp properties.ResourceType, names *NameProvid
18351842
switch resourceTyp {
18361843
case properties.ResourceEntry:
18371844
tmpl = resourceReadFunction
1845+
case properties.ResourceEntryPlural:
1846+
tmpl = resourceReadManyFunction
1847+
listAttribute = pascalCase(paramSpec.TerraformProviderConfig.PluralName)
18381848
case properties.ResourceUuid:
18391849
tmpl = resourceReadManyFunction
18401850
listAttribute = pascalCase(paramSpec.TerraformProviderConfig.PluralName)
@@ -1850,8 +1860,13 @@ func ResourceReadFunction(resourceTyp properties.ResourceType, names *NameProvid
18501860
LowerCamelCase: naming.CamelCase("", listAttribute, "", false),
18511861
}
18521862

1863+
var resourceIsMap bool
1864+
if resourceTyp == properties.ResourceEntryPlural {
1865+
resourceIsMap = true
1866+
}
18531867
data := map[string]interface{}{
18541868
"ResourceOrDS": "Resource",
1869+
"ResourceIsMap": resourceIsMap,
18551870
"HasEncryptedResources": paramSpec.HasEncryptedResources(),
18561871
"ListAttribute": listAttributeVariant,
18571872
"Exhaustive": exhaustive,
@@ -1887,6 +1902,9 @@ func ResourceUpdateFunction(resourceTyp properties.ResourceType, names *NameProv
18871902
switch resourceTyp {
18881903
case properties.ResourceEntry:
18891904
tmpl = resourceUpdateFunction
1905+
case properties.ResourceEntryPlural:
1906+
tmpl = resourceUpdateEntryListFunction
1907+
listAttribute = pascalCase(paramSpec.TerraformProviderConfig.PluralName)
18901908
case properties.ResourceUuid:
18911909
tmpl = resourceUpdateManyFunction
18921910
listAttribute = pascalCase(paramSpec.TerraformProviderConfig.PluralName)
@@ -1902,8 +1920,14 @@ func ResourceUpdateFunction(resourceTyp properties.ResourceType, names *NameProv
19021920
LowerCamelCase: naming.CamelCase("", listAttribute, "", false),
19031921
}
19041922

1923+
var resourceIsMap bool
1924+
if resourceTyp == properties.ResourceEntryPlural {
1925+
resourceIsMap = true
1926+
}
1927+
19051928
data := map[string]interface{}{
19061929
"HasEncryptedResources": paramSpec.HasEncryptedResources(),
1930+
"ResourceIsMap": resourceIsMap,
19071931
"ListAttribute": listAttributeVariant,
19081932
"Exhaustive": exhaustive,
19091933
"EntryOrConfig": paramSpec.EntryOrConfig(),

0 commit comments

Comments
 (0)