Skip to content

Commit

Permalink
Mark some parameters as computed in terraform provider via spec
Browse files Browse the repository at this point in the history
  • Loading branch information
kklimonda-cl committed Aug 8, 2024
1 parent e3f2124 commit cc8f2a0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
31 changes: 18 additions & 13 deletions pkg/properties/normalized.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,20 @@ type ConstValue struct {
}

type SpecParam struct {
Name *NameVariant
Description string `json:"description" yaml:"description"`
Type string `json:"type" yaml:"type"`
Default string `json:"default" yaml:"default"`
Required bool `json:"required" yaml:"required"`
Sensitive bool `json:"sensitive" yaml:"sensitive"`
Length *SpecParamLength `json:"length" yaml:"length,omitempty"`
Count *SpecParamCount `json:"count" yaml:"count,omitempty"`
Hashing *SpecParamHashing `json:"hashing" yaml:"hashing,omitempty"`
Items *SpecParamItems `json:"items" yaml:"items,omitempty"`
Regex string `json:"regex" yaml:"regex,omitempty"`
Profiles []*SpecParamProfile `json:"profiles" yaml:"profiles"`
Spec *Spec `json:"spec" yaml:"spec"`
Name *NameVariant
Description string `json:"description" yaml:"description"`
TerraformProviderConfig *SpecParamTerraformProviderConfig `json:"terraform_provider_config" yaml:"terraform_provider_config"`
Type string `json:"type" yaml:"type"`
Default string `json:"default" yaml:"default"`
Required bool `json:"required" yaml:"required"`
Sensitive bool `json:"sensitive" yaml:"sensitive"`
Length *SpecParamLength `json:"length" yaml:"length,omitempty"`
Count *SpecParamCount `json:"count" yaml:"count,omitempty"`
Hashing *SpecParamHashing `json:"hashing" yaml:"hashing,omitempty"`
Items *SpecParamItems `json:"items" yaml:"items,omitempty"`
Regex string `json:"regex" yaml:"regex,omitempty"`
Profiles []*SpecParamProfile `json:"profiles" yaml:"profiles"`
Spec *Spec `json:"spec" yaml:"spec"`
}

type SpecParamLength struct {
Expand All @@ -139,6 +140,10 @@ type SpecParamHashing struct {
Type string `json:"type" yaml:"type"`
}

type SpecParamTerraformProviderConfig struct {
Computed bool `json:"computed" yaml:"computed"`
}

type SpecParamItems struct {
Type string `json:"type" yaml:"type"`
Length *SpecParamItemsLength `json:"length" yaml:"length"`
Expand Down
24 changes: 22 additions & 2 deletions pkg/translate/terraform_provider/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,11 +776,22 @@ func createSchemaSpecForParameter(typ schemaType, structPrefix string, packageNa
LowerCamelCase: naming.CamelCase("", "name", "", false),
}

var computed, optional bool
if param.TerraformProviderConfig != nil {
computed = param.TerraformProviderConfig.Computed
optional = !computed
} else if param.Default != "" {
computed = true
optional = true
}

attributes = append(attributes, attributeCtx{
Package: packageName,
Name: name,
SchemaType: "StringAttribute",
Required: true,
Computed: computed,
Optional: optional,
})
}

Expand Down Expand Up @@ -859,17 +870,26 @@ func createSchemaAttributeForParameter(typ schemaType, packageName string, param
}
}

var optional, computed bool
if param.TerraformProviderConfig != nil {
computed = param.TerraformProviderConfig.Computed
optional = !computed
} else if param.Default != "" {
optional = true
computed = true
}

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

Expand Down

0 comments on commit cc8f2a0

Please sign in to comment.