Skip to content

Commit 562aba7

Browse files
committed
Mark some parameters as computed in terraform provider via spec
1 parent 0860984 commit 562aba7

File tree

3 files changed

+52
-21
lines changed

3 files changed

+52
-21
lines changed

pkg/properties/normalized.go

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

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

124125
type SpecParamLength struct {
@@ -135,6 +136,10 @@ type SpecParamHashing struct {
135136
Type string `json:"type" yaml:"type"`
136137
}
137138

139+
type SpecParamTerraformProviderConfig struct {
140+
Computed bool `json:"computed" yaml:"computed"`
141+
}
142+
138143
type SpecParamItems struct {
139144
Type string `json:"type" yaml:"type"`
140145
Length *SpecParamItemsLength `json:"length" yaml:"length"`

pkg/translate/terraform_provider/funcs.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,11 +789,17 @@ func createSchemaSpecForParameter(typ schemaType, structPrefix string, packageNa
789789
LowerCamelCase: naming.CamelCase("", "name", "", false),
790790
}
791791

792+
var computed bool
793+
if param.TerraformProviderConfig != nil {
794+
computed = param.TerraformProviderConfig.Computed
795+
}
796+
792797
attributes = append(attributes, attributeCtx{
793798
Package: packageName,
794799
Name: name,
795800
SchemaType: "StringAttribute",
796801
Required: true,
802+
Computed: computed,
797803
})
798804
}
799805

@@ -872,17 +878,26 @@ func createSchemaAttributeForParameter(typ schemaType, packageName string, param
872878
}
873879
}
874880

881+
var optional, computed bool
882+
if param.TerraformProviderConfig != nil {
883+
computed = param.TerraformProviderConfig.Computed
884+
optional = !computed
885+
} else if param.Default != "" {
886+
optional = true
887+
computed = true
888+
}
889+
875890
return attributeCtx{
876891
Package: packageName,
877892
Name: param.Name,
878893
SchemaType: schemaType,
879894
ElementType: elementType,
880895
Description: param.Description,
881896
Required: param.Required,
882-
Optional: !param.Required,
897+
Optional: optional,
883898
Sensitive: param.Sensitive,
884899
Default: defaultValue,
885-
Computed: param.Default != "",
900+
Computed: computed,
886901
}
887902
}
888903

specs/network/interface/ethernet.yaml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,26 @@ spec:
178178
- xpath: ["advertise"]
179179
spec:
180180
params:
181+
enable:
182+
type: bool
183+
profiles:
184+
- xpath: ["enable"]
181185
valid-lifetime:
186+
type: string
182187
profiles:
183188
- xpath: ["valid-lifetime"]
184-
spec:
185-
one_of:
186-
value:
187-
type: int64
188-
enum:
189-
type: string
189+
preferred-lifetime:
190+
type: string
191+
profiles:
192+
- xpath: ["preferred-lifetime"]
193+
onlink-flag:
194+
type: bool
195+
profiles:
196+
- xpath: ["onlink-flag"]
197+
auto-config-flag:
198+
type: bool
199+
profiles:
200+
- xpath: ["auto-config-flag"]
190201
anycast:
191202
type: bool
192203
profiles:

0 commit comments

Comments
 (0)