Skip to content

Commit 33df5c1

Browse files
committed
[ignore] Added IPv6 Address static custom type support to the generated resources
1 parent e508b9c commit 33df5c1

File tree

72 files changed

+439
-395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+439
-395
lines changed

gen/definitions/properties/fvBD.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,9 @@ test_values:
8181
link_local_ipv6_address: fe80::1
8282
unicast_routing: "yes"
8383
virtual_mac_address: 00:22:BD:F8:19:FB
84+
custom_type:
85+
link_local_ipv6_address: fe80::0002
8486
type_overwrites:
8587
epMoveDetectMode: string
88+
static_custom_type:
89+
llAddr: ipv6_address

gen/definitions/properties/fvEpIpTag.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ test_values:
1313
ip: 10.0.0.1
1414
resource_required:
1515
ip: 10.0.0.2
16+
custom_type:
17+
ip: fe80::0001
18+
static_custom_type:
19+
ip: ipv6_address

gen/definitions/properties/fvFBRMember.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ test_values:
1818
test_values_for_parent:
1919
- fallback_member: 2.2.2.2
2020
- fallback_member: 2.2.2.3
21+
custom_type:
22+
fallback_member: fe80::0001
23+
static_custom_type:
24+
rnhAddr: ipv6_address

gen/definitions/properties/mplsNodeSidP.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ test_values:
2323
segment_id: "1"
2424
resource_required:
2525
segment_id: "1"
26+
custom_type:
27+
loopback_address: fe80::0002
28+
static_custom_type:
29+
loopbackAddr: ipv6_address

gen/definitions/properties/netflowExporterPol.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,9 @@ test_values:
4444
destination_port: https
4545
name: netfow_exporter
4646
source_ip_address: 1.1.1.1/10
47+
custom_type:
48+
source_ip_address: 2001:db8::1/116
49+
destination_ip_address: 2001:db8::2
50+
static_custom_type:
51+
srcAddr: ipv6_address
52+
dstAddr: ipv6_address

gen/definitions/properties/pimRouteMapEntry.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,11 @@ test_values:
2424
source_ip: 0.0.0.0
2525
resource_required:
2626
order: "1"
27+
custom_type:
28+
group_ip: ff0e::0101/128
29+
rendezvous_point_ip: 2001:0db8:ffff::1/128
30+
source_ip: 2001:0db8:100::10/128
31+
static_custom_type:
32+
grp: ipv6_address
33+
rp: ipv6_address
34+
src: ipv6_address

gen/generator.go

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,7 @@ func main() {
13501350
renderTemplate("custom_type.go.tmpl", fmt.Sprintf("%s_%s.go", model.PkgName, propertyName), "./internal/custom_types", property)
13511351
}
13521352
}
1353+
13531354
renderTemplate("resource.go.tmpl", fmt.Sprintf("resource_%s_%s.go", providerName, model.ResourceName), providerPath, model)
13541355
renderTemplate("datasource.go.tmpl", fmt.Sprintf("data_source_%s_%s.go", providerName, model.ResourceName), providerPath, model)
13551356

@@ -1514,14 +1515,16 @@ type LegacyBlock struct {
15141515
}
15151516

15161517
type LegacyAttribute struct {
1517-
Name string
1518-
AttributeName string
1519-
ValueType []string
1520-
ReplacedBy ReplacementAttribute
1521-
Optional bool
1522-
Computed bool
1523-
Required bool
1524-
NeedsCustomType bool
1518+
Name string
1519+
AttributeName string
1520+
ValueType []string
1521+
ReplacedBy ReplacementAttribute
1522+
Optional bool
1523+
Computed bool
1524+
Required bool
1525+
NeedsCustomType bool
1526+
StaticCustomType string
1527+
ValidateAsIPv4OrIPv6 bool
15251528
}
15261529

15271530
type ReplacementAttribute struct {
@@ -2452,7 +2455,6 @@ func (m *Model) SetLegacyAttributes(definitions Definitions) {
24522455
legacyResource := definitions.Migration["provider_schemas"].(map[string]interface{})["registry.terraform.io/ciscodevnet/aci"].(map[string]interface{})["resource_schemas"].(map[string]interface{})[resourceName]
24532456

24542457
if legacyResource != nil {
2455-
24562458
attributeNames := []string{}
24572459
for _, property := range m.Properties {
24582460
attributeNames = append(attributeNames, property.SnakeCaseName)
@@ -2569,23 +2571,32 @@ func (m *Model) GetLegacyAttribute(attributeName, className string, attributeVal
25692571
}
25702572
}
25712573

2572-
needsCustomType := false
2574+
// needsCustomType := false
2575+
var validateAsIPv4OrIPv6, needsCustomType bool
2576+
var staticCustomType string
25732577
for _, property := range m.Properties {
2574-
if propertyName == property.Name && len(property.ValidValuesMap) > 0 && len(property.Validators) > 0 {
2575-
needsCustomType = true
2576-
break
2578+
if propertyName == property.Name {
2579+
if property.StaticCustomType != "" {
2580+
staticCustomType = property.StaticCustomType
2581+
validateAsIPv4OrIPv6 = property.ValidateAsIPv4OrIPv6
2582+
}
2583+
if len(property.ValidValuesMap) > 0 && len(property.Validators) > 0 {
2584+
needsCustomType = true
2585+
break
2586+
}
25772587
}
2578-
25792588
}
25802589

25812590
legacyAttribute := LegacyAttribute{
2582-
Name: propertyName,
2583-
AttributeName: attributeName,
2584-
ValueType: valueType,
2585-
Optional: optional,
2586-
Computed: computed,
2587-
Required: required,
2588-
NeedsCustomType: needsCustomType,
2591+
Name: propertyName,
2592+
AttributeName: attributeName,
2593+
ValueType: valueType,
2594+
Optional: optional,
2595+
Computed: computed,
2596+
Required: required,
2597+
NeedsCustomType: needsCustomType,
2598+
StaticCustomType: staticCustomType,
2599+
ValidateAsIPv4OrIPv6: validateAsIPv4OrIPv6,
25892600
}
25902601

25912602
if replacedBy != nil {

gen/templates/custom_type.go.tmpl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// Code generated by "gen/generator.go"; DO NOT EDIT.
2-
// In order to regenerate this file execute `go generate` from the repository root.
3-
// More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md).
4-
51
package customTypes
62

73
import (

gen/templates/datasource.go.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ func (d *{{.ResourceClassName}}DataSource) Schema(ctx context.Context, req datas
5555
{{- if ne .ReplacedBy.AttributeName "" }}{{$ReplacedAttribute := overwriteProperty .ReplacedBy.ClassName (getConflictingAttributeName .ReplacedBy.AttributeName) $.Definitions}}
5656
{{- if eq (getMigrationType .ValueType) "String"}}
5757
"{{.AttributeName}}": schema.StringAttribute{
58+
{{- if ne .StaticCustomType "" }}
59+
CustomType: customTypes.{{- if .StaticCustomType}}{{.StaticCustomType}}{{else}}{{.ResourceClassName}}{{.Name}}{{- end}}StringType{},
60+
{{- end}}
5861
Computed: true,
5962
DeprecationMessage: "Attribute '{{.AttributeName}}' is deprecated, please refer to '{{$ReplacedAttribute}}' instead. The attribute will be removed in the next major version of the provider.",
6063
},

gen/templates/resource.go.tmpl

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ type {{.ResourceClassName}}ResourceModel struct {
7272
{{- if .LegacyAttributes}}
7373
{{- range .LegacyAttributes}}
7474
{{- if ne .ReplacedBy.AttributeName "" }}
75-
Deprecated{{ .Name }} types.{{getMigrationType .ValueType}} `tfsdk:"{{.AttributeName}}"`
75+
Deprecated{{ .Name }} {{ if .StaticCustomType}} customTypes.{{.StaticCustomType}}StringValue{{else}}types.{{getMigrationType .ValueType}}{{ end}} `tfsdk:"{{.AttributeName}}"`
7676
{{- else if containsString .Name .AttributeName}}
77-
{{ .Name }} types.{{getMigrationType .ValueType}} `tfsdk:"{{.AttributeName}}"`
77+
{{ .Name }} {{ if .StaticCustomType}} customTypes.{{.StaticCustomType}}StringValue{{else}}types.{{getMigrationType .ValueType}}{{ end}} `tfsdk:"{{.AttributeName}}"`
7878
{{- end }}
7979
{{- end }}
8080
{{- range .LegacyBlocks}}
@@ -143,13 +143,13 @@ func getEmpty{{.ResourceClassName}}ResourceModel() *{{.ResourceClassName}}Resour
143143
{{- range .LegacyAttributes}}
144144
{{- if ne .ReplacedBy.AttributeName "" }}
145145
{{- if eq (getMigrationType .ValueType) "String"}}
146-
Deprecated{{ .Name }}: types.{{getMigrationType .ValueType}}{},
146+
Deprecated{{ .Name }}: {{ if .StaticCustomType}} customTypes.{{.StaticCustomType}}StringValue{{else}}types.{{getMigrationType .ValueType}}{{ end}}{},
147147
{{- else if eq (getMigrationType .ValueType) "Set"}}
148148
Deprecated{{ .Name }}: types.SetNull(types.StringType),
149149
{{- end }}
150150
{{- else if containsString .Name .AttributeName}}
151151
{{- if eq (getMigrationType .ValueType) "String"}}
152-
{{ .Name }}: types.{{getMigrationType .ValueType}}{},
152+
{{ .Name }}: {{ if .StaticCustomType}} customTypes.{{.StaticCustomType}}StringValue{{else}}types.{{getMigrationType .ValueType}}{{ end}}{},
153153
{{- else if eq (getMigrationType .ValueType) "Set"}}
154154
{{ .Name }}: types.SetNull(types.StringType),
155155
{{- end }}
@@ -191,7 +191,7 @@ var deprecated{{ capitalize .ClassName }}Type = types.ObjectType{
191191

192192
type {{.ResourceClassName}}ResourceModelV{{.LegacySchemaVersion}} struct {
193193
{{- range .LegacyAttributes}}
194-
{{ .Name }} types.{{getMigrationType .ValueType}} `tfsdk:"{{.AttributeName}}"`
194+
{{ .Name }} {{ if .StaticCustomType}} customTypes.{{.StaticCustomType}}StringValue{{else}}types.{{getMigrationType .ValueType}}{{ end}} `tfsdk:"{{.AttributeName}}"`
195195
{{- end }}
196196
{{- range .LegacyBlocks}}
197197
{{ capitalize .ClassName }} types.Set `tfsdk:"{{.Name}}"`
@@ -201,7 +201,7 @@ type {{.ResourceClassName}}ResourceModelV{{.LegacySchemaVersion}} struct {
201201
{{ range .LegacyBlocks}}
202202
type {{ capitalize .ClassName }}{{$.ResourceClassName}}ResourceModelV{{$.LegacySchemaVersion}} struct {
203203
{{- range .Attributes}}
204-
{{ .Name }} types.{{getMigrationType .ValueType}} `tfsdk:"{{.AttributeName}}"`
204+
{{ .Name }} {{ if .StaticCustomType}} customTypes.{{.StaticCustomType}}StringValue{{else}}types.{{getMigrationType .ValueType}}{{ end}} `tfsdk:"{{.AttributeName}}"`
205205
{{- end}}
206206
}
207207

@@ -299,7 +299,7 @@ func (r *{{.ResourceClassName}}Resource) UpgradeState(ctx context.Context) map[i
299299
{{- range .Properties}}
300300
{{- if isLegacyAttribute .Name $.LegacyAttributes}}
301301
{{- if .HasCustomType}}
302-
{{ .Name }}: customTypes.{{- if .StaticCustomType}}{{.StaticCustomType}}{{else}}{{.ResourceClassName}}{{.Name}}{{- end}}StringValue{ StringValue: priorStateData.{{ .Name }} },
302+
{{ .Name }}: customTypes.{{- if .StaticCustomType}}{{.StaticCustomType}}StringValue{ StringValue: basetypes.NewStringValue(priorStateData.{{ .Name }}.NamedValueString()){{else}}{{.ResourceClassName}}{{.Name}}StringValue{ StringValue: priorStateData.{{ .Name }}{{- end}} },
303303
{{- else}}
304304
{{ .Name }}: priorStateData.{{ .Name }},
305305
{{- end}}
@@ -664,13 +664,13 @@ func set{{ .ResourceClassName }}LegacyAttributes(ctx context.Context, diags *dia
664664
{{- if and (isNewAttributeStringType .ReplacedBy.AttributeName) (ne .Name "ParentDn")}}
665665
{{- if legacyAttributeContainsNoneValue . $.Properties}}
666666
if attributeName == "{{decapitalize .Name}}" && attributeValue.(string) == "" {
667-
data.Deprecated{{.Name}} = basetypes.NewStringValue("none")
667+
data.Deprecated{{.Name}} = {{- if .StaticCustomType}}customTypes.New{{.StaticCustomType}}StringValue("none"){{ else }}basetypes.NewStringValue("none"){{- end }}
668668
} else if attributeName == "{{decapitalize .Name}}" {
669-
data.Deprecated{{.Name}} = basetypes.NewStringValue(attributeValue.(string))
669+
data.Deprecated{{.Name}} = {{- if .StaticCustomType}}customTypes.New{{.StaticCustomType}}StringValue(attributeValue.(string)){{ else }}basetypes.NewStringValue(attributeValue.(string)){{- end }}
670670
}
671671
{{- else}}
672672
if attributeName == "{{decapitalize .Name}}" {
673-
data.Deprecated{{.Name}} = basetypes.NewStringValue(attributeValue.(string))
673+
data.Deprecated{{.Name}} = {{- if .StaticCustomType}}customTypes.New{{.StaticCustomType}}StringValue(attributeValue.(string)){{ else }}basetypes.NewStringValue(attributeValue.(string)){{- end }}
674674
}
675675
{{- end}}
676676
{{- end }}{{- end }}
@@ -1246,7 +1246,7 @@ func avoid{{.ResourceClassName}}PlanChangeForKnownAfterApplyOnly(ctx context.Con
12461246
{{- if and (ne .ReplacedBy.AttributeName "") (not (isSensitiveAttribute .AttributeName $.Properties)) }}
12471247
{{- if eq (getMigrationType .ValueType) "String"}}
12481248
if configData.Deprecated{{.Name}}.IsNull() {
1249-
planData.Deprecated{{.Name}} = basetypes.NewStringUnknown()
1249+
planData.Deprecated{{.Name}} = {{- if .StaticCustomType}}customTypes.New{{.StaticCustomType}}StringUnknown(){{else}}basetypes.NewStringUnknown(){{- end}}
12501250
}
12511251
{{- else if eq (getMigrationType .ValueType) "Set"}}
12521252
if configData.Deprecated{{.Name}}.IsNull() {
@@ -1457,6 +1457,9 @@ func (r *{{.ResourceClassName}}Resource) Schema(ctx context.Context, req resourc
14571457
{{- if ne .ReplacedBy.AttributeName "" }}{{$ReplacedAttribute := overwriteProperty .ReplacedBy.ClassName (getConflictingAttributeName .ReplacedBy.AttributeName) $.Definitions}}
14581458
{{- if eq (getMigrationType .ValueType) "String"}}
14591459
"{{.AttributeName}}": schema.StringAttribute{
1460+
{{- if ne .StaticCustomType "" }}
1461+
CustomType: customTypes.{{- if .StaticCustomType}}{{.StaticCustomType}}{{else}}{{.ResourceClassName}}{{.Name}}{{- end}}StringType{},
1462+
{{- end}}
14601463
Optional: true,
14611464
Computed: true,
14621465
{{- if isSensitiveAttribute .AttributeName $.Properties }}
@@ -2883,7 +2886,7 @@ func {{.ResourceClassName}}{{.ParentHierarchy}}SetToSetNullWhenStateIsNullPlanIs
28832886
stringplanmodifier.UseNonNullStateForUnknown(),
28842887
},
28852888
{{- end}}
2886-
{{- if .HasCustomType}}
2889+
{{- if and .HasCustomType (not .ValidateAsIPv4OrIPv6) }}
28872890
Validators: []validator.String{
28882891
stringvalidator.Any(
28892892
{{- if .ValidValues}}

0 commit comments

Comments
 (0)