Skip to content

Commit cc8f2a0

Browse files
committed
Mark some parameters as computed in terraform provider via spec
1 parent e3f2124 commit cc8f2a0

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

pkg/properties/normalized.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,20 @@ type ConstValue struct {
110110
}
111111

112112
type SpecParam struct {
113-
Name *NameVariant
114-
Description string `json:"description" yaml:"description"`
115-
Type string `json:"type" yaml:"type"`
116-
Default string `json:"default" yaml:"default"`
117-
Required bool `json:"required" yaml:"required"`
118-
Sensitive bool `json:"sensitive" yaml:"sensitive"`
119-
Length *SpecParamLength `json:"length" yaml:"length,omitempty"`
120-
Count *SpecParamCount `json:"count" yaml:"count,omitempty"`
121-
Hashing *SpecParamHashing `json:"hashing" yaml:"hashing,omitempty"`
122-
Items *SpecParamItems `json:"items" yaml:"items,omitempty"`
123-
Regex string `json:"regex" yaml:"regex,omitempty"`
124-
Profiles []*SpecParamProfile `json:"profiles" yaml:"profiles"`
125-
Spec *Spec `json:"spec" yaml:"spec"`
113+
Name *NameVariant
114+
Description string `json:"description" yaml:"description"`
115+
TerraformProviderConfig *SpecParamTerraformProviderConfig `json:"terraform_provider_config" yaml:"terraform_provider_config"`
116+
Type string `json:"type" yaml:"type"`
117+
Default string `json:"default" yaml:"default"`
118+
Required bool `json:"required" yaml:"required"`
119+
Sensitive bool `json:"sensitive" yaml:"sensitive"`
120+
Length *SpecParamLength `json:"length" yaml:"length,omitempty"`
121+
Count *SpecParamCount `json:"count" yaml:"count,omitempty"`
122+
Hashing *SpecParamHashing `json:"hashing" yaml:"hashing,omitempty"`
123+
Items *SpecParamItems `json:"items" yaml:"items,omitempty"`
124+
Regex string `json:"regex" yaml:"regex,omitempty"`
125+
Profiles []*SpecParamProfile `json:"profiles" yaml:"profiles"`
126+
Spec *Spec `json:"spec" yaml:"spec"`
126127
}
127128

128129
type SpecParamLength struct {
@@ -139,6 +140,10 @@ type SpecParamHashing struct {
139140
Type string `json:"type" yaml:"type"`
140141
}
141142

143+
type SpecParamTerraformProviderConfig struct {
144+
Computed bool `json:"computed" yaml:"computed"`
145+
}
146+
142147
type SpecParamItems struct {
143148
Type string `json:"type" yaml:"type"`
144149
Length *SpecParamItemsLength `json:"length" yaml:"length"`

pkg/translate/terraform_provider/funcs.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,11 +776,22 @@ func createSchemaSpecForParameter(typ schemaType, structPrefix string, packageNa
776776
LowerCamelCase: naming.CamelCase("", "name", "", false),
777777
}
778778

779+
var computed, optional bool
780+
if param.TerraformProviderConfig != nil {
781+
computed = param.TerraformProviderConfig.Computed
782+
optional = !computed
783+
} else if param.Default != "" {
784+
computed = true
785+
optional = true
786+
}
787+
779788
attributes = append(attributes, attributeCtx{
780789
Package: packageName,
781790
Name: name,
782791
SchemaType: "StringAttribute",
783792
Required: true,
793+
Computed: computed,
794+
Optional: optional,
784795
})
785796
}
786797

@@ -859,17 +870,26 @@ func createSchemaAttributeForParameter(typ schemaType, packageName string, param
859870
}
860871
}
861872

873+
var optional, computed bool
874+
if param.TerraformProviderConfig != nil {
875+
computed = param.TerraformProviderConfig.Computed
876+
optional = !computed
877+
} else if param.Default != "" {
878+
optional = true
879+
computed = true
880+
}
881+
862882
return attributeCtx{
863883
Package: packageName,
864884
Name: param.Name,
865885
SchemaType: schemaType,
866886
ElementType: elementType,
867887
Description: param.Description,
868888
Required: param.Required,
869-
Optional: !param.Required,
889+
Optional: optional,
870890
Sensitive: param.Sensitive,
871891
Default: defaultValue,
872-
Computed: param.Default != "",
892+
Computed: computed,
873893
}
874894
}
875895

0 commit comments

Comments
 (0)