Skip to content

Commit

Permalink
Bug fixes across terraform provider (#132)
Browse files Browse the repository at this point in the history
* Check if movement is required during Read()

* Fix DataSource Read() for Exhaustive

* Drop "UseStateForUnknown" UUID modifier

That doesn't work well with movements, should be investigated later post MVP.
  • Loading branch information
kklimonda-cl authored Aug 16, 2024
1 parent 4632f9b commit 8c4e3ce
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 84 deletions.
46 changes: 23 additions & 23 deletions pkg/translate/terraform_provider/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,29 +940,17 @@ func createSchemaAttributeForParameter(schemaTyp schemaType, packageName string,
computed = true
}

// TODO(kklimonda): This is pretty one-off implementation to
// support uuid-style resources, but could be expanded to be more
// generic if needed.
var modifiers *modifierCtx
if schemaTyp == schemaResource && computed && param.Default == "" {
modifiers = &modifierCtx{
SchemaType: fmt.Sprintf("planmodifier.%s", pascalCase(param.Type)),
Modifiers: []string{fmt.Sprintf("%splanmodifier.UseStateForUnknown()", param.Type)},
}
}

return attributeCtx{
Package: packageName,
Name: param.Name,
SchemaType: schemaType,
ElementType: elementType,
Description: param.Description,
Required: param.Required,
Optional: !param.Required,
Sensitive: param.Sensitive,
Default: defaultValue,
Computed: computed,
PlanModifiers: modifiers,
Package: packageName,
Name: param.Name,
SchemaType: schemaType,
ElementType: elementType,
Description: param.Description,
Required: param.Required,
Optional: !param.Required,
Sensitive: param.Sensitive,
Default: defaultValue,
Computed: computed,
}
}

Expand Down Expand Up @@ -2051,13 +2039,18 @@ func DataSourceReadFunction(resourceTyp properties.ResourceType, names *NameProv

var tmpl string
var listAttribute string
var exhaustive bool
switch resourceTyp {
case properties.ResourceEntry:
tmpl = resourceReadFunction
case properties.ResourceEntryPlural:
tmpl = resourceReadEntryListFunction
listAttribute = pascalCase(paramSpec.TerraformProviderConfig.PluralName)
case properties.ResourceUuid, properties.ResourceUuidPlural:
case properties.ResourceUuid:
exhaustive = true
tmpl = resourceReadManyFunction
listAttribute = pascalCase(paramSpec.TerraformProviderConfig.PluralName)
case properties.ResourceUuidPlural:
tmpl = resourceReadManyFunction
listAttribute = pascalCase(paramSpec.TerraformProviderConfig.PluralName)
}
Expand All @@ -2076,6 +2069,7 @@ func DataSourceReadFunction(resourceTyp properties.ResourceType, names *NameProv
"ResourceOrDS": "DataSource",
"ResourceIsMap": resourceIsMap,
"HasEncryptedResources": paramSpec.HasEncryptedResources(),
"Exhaustive": exhaustive,
"ListAttribute": listAttributeVariant,
"EntryOrConfig": paramSpec.EntryOrConfig(),
"HasEntryName": paramSpec.HasEntryName(),
Expand All @@ -2091,6 +2085,9 @@ func DataSourceReadFunction(resourceTyp properties.ResourceType, names *NameProv
"RenderLocationsPangoToState": func(source string, dest string) (string, error) {
return RenderLocationsPangoToState(names, paramSpec, source, dest)
},
"RenderCreateUpdateMovementRequired": func(state string, entries string) (string, error) {
return RendeCreateUpdateMovementRequired(state, entries)
},
"RenderLocationsStateToPango": func(source string, dest string) (string, error) {
return RenderLocationsStateToPango(names, paramSpec, source, dest)
},
Expand Down Expand Up @@ -2152,6 +2149,9 @@ func ResourceReadFunction(resourceTyp properties.ResourceType, names *NameProvid
"RenderLocationsPangoToState": func(source string, dest string) (string, error) {
return RenderLocationsPangoToState(names, paramSpec, source, dest)
},
"RenderCreateUpdateMovementRequired": func(state string, entries string) (string, error) {
return RendeCreateUpdateMovementRequired(state, entries)
},
"RenderLocationsStateToPango": func(source string, dest string) (string, error) {
return RenderLocationsStateToPango(names, paramSpec, source, dest)
},
Expand Down
Loading

0 comments on commit 8c4e3ce

Please sign in to comment.