-
Notifications
You must be signed in to change notification settings - Fork 107
Add logic for static custom type (DCNE-632) #1437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| // Code generated by "gen/generator.go"; DO NOT EDIT. | ||
|
||
| // In order to regenerate this file execute `go generate` from the repository root. | ||
| // More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md). | ||
|
|
||
| package customTypes | ||
|
|
||
| import ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,7 +57,7 @@ type {{.ResourceClassName}}ResourceModel struct { | |
| {{- else if eq .Name "Id"}} | ||
| {{.ResourceClassName}}{{ .Name }} types.String `tfsdk:"{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}"` | ||
| {{- else if .HasCustomType}} | ||
| {{ .Name }} customTypes.{{.ResourceClassName}}{{.Name}}StringValue `tfsdk:"{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}"` | ||
| {{ .Name }} customTypes.{{- if .StaticCustomType}}{{.StaticCustomType}}{{else}}{{.ResourceClassName}}{{.Name}}{{- end}}StringValue `tfsdk:"{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}"` | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing legacy attribute support and changes
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
| {{- else}} | ||
| {{ .Name }} types.String `tfsdk:"{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}"` | ||
| {{- end}} | ||
|
|
@@ -95,7 +95,7 @@ func getEmpty{{.ResourceClassName}}ResourceModel() *{{.ResourceClassName}}Resour | |
| {{- else if eq .Name "Id"}} | ||
| {{.ResourceClassName}}{{ .Name }}: basetypes.NewStringNull(), | ||
| {{- else if .HasCustomType}} | ||
| {{ .Name }}: customTypes.New{{.ResourceClassName}}{{.Name}}StringNull(), | ||
| {{ .Name }}: customTypes.New{{- if .StaticCustomType}}{{.StaticCustomType}}{{else}}{{.ResourceClassName}}{{.Name}}{{- end}}StringNull(), | ||
| {{- else}} | ||
| {{ .Name }}: basetypes.NewStringNull(), | ||
| {{- end}} | ||
|
|
@@ -299,7 +299,7 @@ func (r *{{.ResourceClassName}}Resource) UpgradeState(ctx context.Context) map[i | |
| {{- range .Properties}} | ||
| {{- if isLegacyAttribute .Name $.LegacyAttributes}} | ||
| {{- if .HasCustomType}} | ||
| {{ .Name }}: customTypes.{{.ResourceClassName}}{{.Name}}StringValue{ StringValue: priorStateData.{{ .Name }} }, | ||
| {{ .Name }}: customTypes.{{- if .StaticCustomType}}{{.StaticCustomType}}{{else}}{{.ResourceClassName}}{{.Name}}{{- end}}StringValue{ StringValue: priorStateData.{{ .Name }} }, | ||
| {{- else}} | ||
| {{ .Name }}: priorStateData.{{ .Name }}, | ||
| {{- end}} | ||
|
|
@@ -457,7 +457,7 @@ func (r *{{.ResourceClassName}}Resource) UpgradeState(ctx context.Context) map[i | |
| {{- if eq $AttributeName ""}} | ||
| {{ .Name }}: basetypes.NewStringNull(), | ||
| {{- else if .HasCustomType}} | ||
| {{ .Name }}: customTypes.{{.ResourceClassName}}{{.Name}}StringValue{StringValue: priorStateData{{.ResourceClassName}}.{{ $AttributeName }}}, | ||
| {{ .Name }}: customTypes.{{- if .StaticCustomType}}{{.StaticCustomType}}{{else}}{{.ResourceClassName}}{{.Name}}{{- end}}StringValue{StringValue: priorStateData{{.ResourceClassName}}.{{ $AttributeName }}}, | ||
| {{- else}} | ||
| {{ .Name }}: priorStateData{{.ResourceClassName}}.{{ $AttributeName }}, | ||
| {{- end}} | ||
|
|
@@ -516,7 +516,7 @@ func (r *{{.ResourceClassName}}Resource) UpgradeState(ctx context.Context) map[i | |
| {{- $AttributeName := getLegacyChildAttribute $PkgName $Overwrite . $.LegacyAttributes $.LegacyBlocks}} | ||
| {{- if eq $AttributeName ""}} | ||
| {{- if .HasCustomType}} | ||
| {{ .Name }}: customTypes.New{{.ResourceClassName}}{{.Name}}StringNull(), | ||
| {{ .Name }}: customTypes.New{{- if .StaticCustomType}}{{.StaticCustomType}}{{else}}{{.ResourceClassName}}{{.Name}}{{- end}}StringNull(), | ||
| {{- else}} | ||
| {{ .Name }}: basetypes.NewStringNull(), | ||
| {{- end}} | ||
|
|
@@ -1043,7 +1043,7 @@ func (r *{{.ResourceClassName}}Resource) ModifyPlan(ctx context.Context, req res | |
| {{ .ResourceClassName }}.{{ .Name }} = planData.Annotation | ||
| {{- else if ne .DefaultValue ""}} | ||
| {{- if .HasCustomType}} | ||
| {{ .ResourceClassName }}.{{ .Name }} = customTypes.New{{.ResourceClassName}}{{.Name}}StringUnknown() | ||
| {{ .ResourceClassName }}.{{ .Name }} = customTypes.New{{- if .StaticCustomType}}{{.StaticCustomType}}{{else}}{{.ResourceClassName}}{{.Name}}{{- end}}StringUnknown() | ||
| {{- else}} | ||
| {{ .ResourceClassName }}.{{ .Name }} = basetypes.NewStringUnknown() | ||
| {{- end}} | ||
|
|
@@ -1122,7 +1122,7 @@ func (r *{{.ResourceClassName}}Resource) ModifyPlan(ctx context.Context, req res | |
| {{ .Name }}: planData.{{ .Name }}, | ||
| {{- else if and (ne $AttributeName "") (not (isNewNamedClassAttribute $Overwrite)) }} | ||
| {{- if .HasCustomType}} | ||
| {{ .Name }}: customTypes.{{.ResourceClassName}}{{.Name}}StringValue{StringValue: attributeValue.{{ .Name }}}, | ||
| {{ .Name }}: customTypes.{{- if .StaticCustomType}}{{.StaticCustomType}}{{else}}{{.ResourceClassName}}{{.Name}}{{- end}}StringValue{StringValue: attributeValue.{{ .Name }}}, | ||
| {{- else}} | ||
| {{ .Name }}: attributeValue.{{ .Name }}, | ||
| {{- end}} | ||
|
|
@@ -1136,13 +1136,13 @@ func (r *{{.ResourceClassName}}Resource) ModifyPlan(ctx context.Context, req res | |
| {{- $AttributeName := getLegacyChildAttribute .PkgName $Overwrite . $.LegacyAttributes $.LegacyBlocks}} | ||
| if !attributeValue.{{ .Name }}.IsNull() { | ||
| {{- if .HasCustomType}} | ||
| {{ .ResourceClassName }}.{{ .Name }} = customTypes.{{.ResourceClassName}}{{.Name}}StringValue{StringValue: attributeValue.{{ .Name }}} | ||
| {{ .ResourceClassName }}.{{ .Name }} = customTypes.{{- if .StaticCustomType}}{{.StaticCustomType}}{{else}}{{.ResourceClassName}}{{.Name}}{{- end}}StringValue{StringValue: attributeValue.{{ .Name }}} | ||
| {{- else}} | ||
| {{ .ResourceClassName }}.{{ .Name }} = attributeValue.{{ .Name }} | ||
| {{- end}} | ||
| } else { | ||
| {{- if .HasCustomType}} | ||
| {{ .ResourceClassName }}.{{ .Name }} = customTypes.{{.ResourceClassName}}{{.Name}}StringValue{StringValue: basetypes.NewStringUnknown()} | ||
| {{ .ResourceClassName }}.{{ .Name }} = customTypes.{{- if .StaticCustomType}}{{.StaticCustomType}}{{else}}{{.ResourceClassName}}{{.Name}}{{- end}}StringValue{StringValue: basetypes.NewStringUnknown()} | ||
| {{- else}} | ||
| {{ .ResourceClassName }}.{{ .Name }} = basetypes.NewStringUnknown() | ||
| {{- end}} | ||
|
|
@@ -1602,7 +1602,7 @@ func (r *{{.ResourceClassName}}Resource) Schema(ctx context.Context, req resourc | |
| {{- else}} | ||
| "{{$OverwritePropertyName}}": schema.StringAttribute{ | ||
| {{- if .HasCustomType}} | ||
| CustomType: customTypes.{{.ResourceClassName}}{{.Name}}StringType{}, | ||
| CustomType: customTypes.{{- if .StaticCustomType}}{{.StaticCustomType}}{{else}}{{.ResourceClassName}}{{.Name}}{{- end}}StringType{}, | ||
| {{- end}} | ||
| {{- if or .IsNaming .IsRequired}} | ||
| {{- if ne $LegacyAttributeName ""}} | ||
|
|
@@ -1641,10 +1641,12 @@ func (r *{{.ResourceClassName}}Resource) Schema(ctx context.Context, req resourc | |
| {{- if eq .Name "Annotation"}} | ||
| Default: stringdefault.StaticString(globalAnnotation), | ||
| {{- end}} | ||
| {{- if .HasCustomType}} | ||
| {{- if and .HasCustomType (not .ValidateAsIPv4OrIPv6) }} | ||
| Validators: []validator.String{ | ||
| stringvalidator.Any( | ||
| {{- if .ValidValues}} | ||
| stringvalidator.OneOf({{- validatorStringCustomType .ValidValues .ValidValuesMap}}), | ||
| {{- end}} | ||
| validators.InBetweenFromString({{- index .Validators 0 "min"}}, {{- index .Validators 0 "max"}}), | ||
| ), | ||
| }, | ||
|
|
@@ -2091,7 +2093,7 @@ func getAndSet{{.ResourceClassName}}Attributes(ctx context.Context, diags *diag. | |
| {{- else}} | ||
| if attributeName == "{{.PropertyName}}" { | ||
| {{- if .HasCustomType}} | ||
| readData.{{.Name}} = customTypes.New{{.ResourceClassName}}{{.Name}}StringValue(attributeValue.(string)) | ||
| readData.{{.Name}} = customTypes.New{{- if .StaticCustomType}}{{.StaticCustomType}}{{else}}{{.ResourceClassName}}{{.Name}}{{- end}}StringValue(attributeValue.(string)) | ||
| {{- else}} | ||
| readData.{{- if eq .Name "Id"}}{{.ResourceClassName}}{{ .Name }}{{- else}}{{.Name}}{{- end}} = basetypes.NewStringValue(attributeValue.(string)) | ||
| {{- end}} | ||
|
|
@@ -2161,7 +2163,7 @@ func getAndSet{{.ResourceClassName}}Attributes(ctx context.Context, diags *diag. | |
| {{- else}} | ||
| if childAttributeName == "{{.PropertyName}}" { | ||
| {{- if .HasCustomType}} | ||
| {{.ResourceClassName}}{{$.ResourceClassName}}.{{.Name}} = customTypes.New{{.ResourceClassName}}{{.Name}}StringValue(childAttributeValue.(string)) | ||
| {{.ResourceClassName}}{{$.ResourceClassName}}.{{.Name}} = customTypes.New{{- if .StaticCustomType}}{{.StaticCustomType}}{{else}}{{.ResourceClassName}}{{.Name}}{{- end}}StringValue(childAttributeValue.(string)) | ||
| {{- else}} | ||
| {{.ResourceClassName}}{{$.ResourceClassName}}.{{- if eq .Name "Id"}}{{.ResourceClassName}}{{ .Name }}{{- else}}{{.Name}}{{- end}} = basetypes.NewStringValue(childAttributeValue.(string)) | ||
| {{- end}} | ||
|
|
@@ -2586,7 +2588,7 @@ type {{.ResourceClassName}}{{.ParentHierarchy}}ResourceModel struct { | |
| {{- else if eq .Name "Id"}} | ||
| {{.ResourceClassName}}{{ .Name }} types.String `tfsdk:"{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}"` | ||
| {{- else if .HasCustomType}} | ||
| {{ .Name }} customTypes.{{.ResourceClassName}}{{.Name}}StringValue `tfsdk:"{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}"` | ||
| {{ .Name }} customTypes.{{- if .StaticCustomType}}{{.StaticCustomType}}{{else}}{{.ResourceClassName}}{{.Name}}{{- end}}StringValue `tfsdk:"{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}"` | ||
| {{- else}} | ||
| {{ .Name }} types.String `tfsdk:"{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}"` | ||
| {{- end}} | ||
|
|
@@ -2608,7 +2610,7 @@ func getEmpty{{.ResourceClassName}}{{.ParentHierarchy}}ResourceModel() {{.Resour | |
| {{- else if eq .Name "Id"}} | ||
| {{.ResourceClassName}}{{ .Name }}: basetypes.NewStringNull(), | ||
| {{- else if .HasCustomType}} | ||
| {{ .Name }}: customTypes.New{{.ResourceClassName}}{{.Name}}StringNull(), | ||
| {{ .Name }}: customTypes.New{{- if .StaticCustomType}}{{.StaticCustomType}}{{else}}{{.ResourceClassName}}{{.Name}}{{- end}}StringNull(), | ||
| {{- else}} | ||
| {{ .Name }}: basetypes.NewStringNull(), | ||
| {{- end}} | ||
|
|
@@ -2717,7 +2719,7 @@ func {{.ResourceClassName}}{{.ParentHierarchy}}SetToSetNullWhenStateIsNullPlanIs | |
| {{- if eq .ValueType "bitmask"}} | ||
| planSetValues[index].{{ .Name }} = basetypes.NewSetNull(types.StringType) | ||
| {{- else if .HasCustomType}} | ||
| planSetValues[index].{{ .Name }} = customTypes.New{{.ResourceClassName}}{{.Name}}StringNull() | ||
| planSetValues[index].{{ .Name }} = customTypes.New{{- if .StaticCustomType}}{{.StaticCustomType}}{{else}}{{.ResourceClassName}}{{.Name}}{{- end}}StringNull() | ||
| {{- else}} | ||
| planSetValues[index].{{ .Name }} = basetypes.NewStringNull() | ||
| {{- end}} | ||
|
|
@@ -2864,7 +2866,7 @@ func {{.ResourceClassName}}{{.ParentHierarchy}}SetToSetNullWhenStateIsNullPlanIs | |
| {{- else}} | ||
| "{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}": schema.StringAttribute{ | ||
| {{- if .HasCustomType}} | ||
| CustomType: customTypes.{{.ResourceClassName}}{{.Name}}StringType{}, | ||
| CustomType: customTypes.{{- if .StaticCustomType}}{{.StaticCustomType}}{{else}}{{.ResourceClassName}}{{.Name}}{{- end}}StringType{}, | ||
| {{- end}} | ||
| {{- if and (or .IsNaming .IsRequired) (not $.TemplateProperties.HasReadOnlyProperties)}} | ||
| Required: true, | ||
|
|
@@ -2884,7 +2886,9 @@ func {{.ResourceClassName}}{{.ParentHierarchy}}SetToSetNullWhenStateIsNullPlanIs | |
| {{- if .HasCustomType}} | ||
| Validators: []validator.String{ | ||
| stringvalidator.Any( | ||
| stringvalidator.OneOf({{- validatorStringCustomType .ValidValues .ValidValuesMap}}), | ||
| {{- if .ValidValues}} | ||
| stringvalidator.OneOf({{- validatorStringCustomType .ValidValues .ValidValuesMap}}), | ||
| {{- end}} | ||
| validators.InBetweenFromString({{- index .Validators 0 "min"}}, {{- index .Validators 0 "max"}}), | ||
| ), | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you check for all other attributes in other resources where ipv6 types should be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!