Skip to content

Commit cde8f01

Browse files
committed
Add support for entry-style lists to Terraform CRUD functions
1 parent 65d898b commit cde8f01

File tree

4 files changed

+398
-15
lines changed

4 files changed

+398
-15
lines changed

pkg/translate/terraform_provider/funcs.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,8 @@ func (o *{{ .StructName }}{{ .ObjectOrModel }}) getTypeFor(name string) attr.Typ
12941294
switch attr := attr.(type) {
12951295
case {{ .Package }}.ListNestedAttribute:
12961296
return attr.NestedObject.Type()
1297+
case {{ .Package }}.MapNestedAttribute:
1298+
return attr.NestedObject.Type()
12971299
default:
12981300
return attr.GetType()
12991301
}
@@ -1761,6 +1763,7 @@ func ResourceCreateFunction(resourceTyp properties.ResourceType, names *NameProv
17611763
var exhaustive bool
17621764
switch resourceTyp {
17631765
case properties.ResourceEntry:
1766+
exhaustive = true
17641767
tmpl = resourceCreateFunction
17651768
case properties.ResourceUuid:
17661769
exhaustive = true
@@ -1778,9 +1781,14 @@ func ResourceCreateFunction(resourceTyp properties.ResourceType, names *NameProv
17781781
LowerCamelCase: naming.CamelCase("", listAttribute, "", false),
17791782
}
17801783

1784+
var resourceIsMap bool
1785+
if resourceTyp == properties.ResourceEntryPlural {
1786+
resourceIsMap = true
1787+
}
17811788
data := map[string]interface{}{
17821789
"HasEncryptedResources": paramSpec.HasEncryptedResources(),
17831790
"Exhaustive": exhaustive,
1791+
"ResourceIsMap": resourceIsMap,
17841792
"ListAttribute": listAttributeVariant,
17851793
"EntryOrConfig": paramSpec.EntryOrConfig(),
17861794
"HasEntryName": paramSpec.HasEntryName(),
@@ -1857,6 +1865,9 @@ func ResourceReadFunction(resourceTyp properties.ResourceType, names *NameProvid
18571865
switch resourceTyp {
18581866
case properties.ResourceEntry:
18591867
tmpl = resourceReadFunction
1868+
case properties.ResourceEntryPlural:
1869+
tmpl = resourceReadManyFunction
1870+
listAttribute = pascalCase(paramSpec.TerraformProviderConfig.PluralName)
18601871
case properties.ResourceUuid:
18611872
tmpl = resourceReadManyFunction
18621873
listAttribute = pascalCase(paramSpec.TerraformProviderConfig.PluralName)
@@ -1872,8 +1883,13 @@ func ResourceReadFunction(resourceTyp properties.ResourceType, names *NameProvid
18721883
LowerCamelCase: naming.CamelCase("", listAttribute, "", false),
18731884
}
18741885

1886+
var resourceIsMap bool
1887+
if resourceTyp == properties.ResourceEntryPlural {
1888+
resourceIsMap = true
1889+
}
18751890
data := map[string]interface{}{
18761891
"ResourceOrDS": "Resource",
1892+
"ResourceIsMap": resourceIsMap,
18771893
"HasEncryptedResources": paramSpec.HasEncryptedResources(),
18781894
"ListAttribute": listAttributeVariant,
18791895
"Exhaustive": exhaustive,
@@ -1910,6 +1926,9 @@ func ResourceUpdateFunction(resourceTyp properties.ResourceType, names *NameProv
19101926
switch resourceTyp {
19111927
case properties.ResourceEntry:
19121928
tmpl = resourceUpdateFunction
1929+
case properties.ResourceEntryPlural:
1930+
tmpl = resourceUpdateEntryListFunction
1931+
listAttribute = pascalCase(paramSpec.TerraformProviderConfig.PluralName)
19131932
case properties.ResourceUuid:
19141933
tmpl = resourceUpdateManyFunction
19151934
listAttribute = pascalCase(paramSpec.TerraformProviderConfig.PluralName)
@@ -1925,8 +1944,14 @@ func ResourceUpdateFunction(resourceTyp properties.ResourceType, names *NameProv
19251944
LowerCamelCase: naming.CamelCase("", listAttribute, "", false),
19261945
}
19271946

1947+
var resourceIsMap bool
1948+
if resourceTyp == properties.ResourceEntryPlural {
1949+
resourceIsMap = true
1950+
}
1951+
19281952
data := map[string]interface{}{
19291953
"HasEncryptedResources": paramSpec.HasEncryptedResources(),
1954+
"ResourceIsMap": resourceIsMap,
19301955
"ListAttribute": listAttributeVariant,
19311956
"Exhaustive": exhaustive,
19321957
"EntryOrConfig": paramSpec.EntryOrConfig(),

0 commit comments

Comments
 (0)