Skip to content

Commit

Permalink
[ignore] Add changes to custom type and remove reflect from rn constr…
Browse files Browse the repository at this point in the history
…uction function
  • Loading branch information
akinross authored and lhercot committed Nov 11, 2024
1 parent 079f3e4 commit 24898fb
Show file tree
Hide file tree
Showing 80 changed files with 166 additions and 515 deletions.
20 changes: 20 additions & 0 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ var templateFuncs = template.FuncMap{
"definedInList": DefinedInList,
"keyExists": KeyExists,
"isNewNamedClassAttributeMatch": IsNewNamedClassAttributeMatch,
"getRnFormat": GetRnFormat,
"identifierIsCustomType": IdentifierIsCustomType,
}

func ContainsRequired(properties map[string]Property) bool {
Expand Down Expand Up @@ -211,6 +213,24 @@ func GetPropertyNameForLegacyAttribute(name string, legacyAttributes map[string]
return ""
}

func GetRnFormat(rnformat string, identifiers []interface{}) string {
if len(identifiers) > 0 {
for _, identifier := range identifiers {
rnformat = strings.ReplaceAll(rnformat, fmt.Sprintf("{%s}", identifier), "%s")
}
}
return rnformat
}

func IdentifierIsCustomType(identifier string, properties map[string]Property) bool {
for propertyName, property := range properties {
if propertyName == identifier {
return property.HasCustomType
}
}
return false
}

func GetLegacyChildAttribute(className, overwriteProperty string, property Property, legacyAttributes map[string]LegacyAttribute, legacyBlocks []LegacyBlock) string {

for _, legacyBlock := range legacyBlocks {
Expand Down
4 changes: 4 additions & 0 deletions gen/templates/custom_type.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (v {{.ResourceClassName}}{{.Name}}StringValue) StringSemanticEquals(ctx con
return priorMappedValue.Equal(newMappedValue), diags
}

func (v {{.ResourceClassName}}{{.Name}}StringValue) NamedValueString() string {
return {{.ResourceClassName}}{{.Name}}ValueMap(basetypes.NewStringValue(v.ValueString())).ValueString()
}

func {{.ResourceClassName}}{{.Name}}ValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
{{- range $key, $value := .ValidValuesMap}}
Expand Down
3 changes: 3 additions & 0 deletions gen/templates/datasource.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ func (d *{{.ResourceClassName}}DataSource) Schema(ctx context.Context, req datas
{{- range .Properties}}
{{- if .IsNaming}}
"{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}": schema.StringAttribute{
{{- if .HasCustomType}}
CustomType: customTypes.{{.ResourceClassName}}{{.Name}}StringType{},
{{- end}}
Required: true,
MarkdownDescription: `{{.Comment}}`,
},{{else if eq .ValueType "bitmask"}}
Expand Down
20 changes: 9 additions & 11 deletions gen/templates/resource.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -1999,17 +1999,7 @@ func getAndSet{{.ResourceClassName}}Attributes(ctx context.Context, diags *diag.
}

func get{{.ResourceClassName}}Rn(ctx context.Context, data *{{.ResourceClassName}}ResourceModel) string {
{{- if .IdentifiedBy}}
rn := "{{.RnFormat}}"
for _, identifier := range []string{ {{- fromInterfacesToString .IdentifiedBy}} } {
fieldName := fmt.Sprintf("%s%s", strings.ToUpper(identifier[:1]), identifier[1:])
fieldValue := reflect.ValueOf(data).Elem().FieldByName(fieldName).Interface().(basetypes.StringValue).ValueString()
rn = strings.ReplaceAll(rn, fmt.Sprintf("{%s}", identifier), fieldValue)
}
return rn
{{- else}}
return "{{.RnFormat}}"
{{- end}}
return fmt.Sprintf("{{getRnFormat .RnFormat .IdentifiedBy}}", {{$i := 1}}{{$length := len .IdentifiedBy}}{{ range .IdentifiedBy}}data.{{capitalize .}}{{- if identifierIsCustomType . $.Properties}}.NamedValueString(){{else}}.ValueString(){{end}}{{ if ne $length $i}}{{$i = add $i 1}}, {{end}}{{- end}})
}

{{ if .HasParent}}
Expand Down Expand Up @@ -2138,7 +2128,11 @@ func get{{$.ResourceClassName}}{{ .ResourceClassName }}ChildPayloads(ctx context
{{ .PkgName }}Identifier := {{ .ResourceClassName }}Identifier{}
{{- range .Properties}}
{{- if .IsNaming}}
{{- if .HasCustomType}}
{{ .PkgName }}Identifier.{{.Name}} = basetypes.NewStringValue({{ .PkgName }}.{{- if eq .Name "Id"}}{{.ResourceClassName}}.ValueString(){{ .Name }}{{- else}}{{.Name}}.ValueString(){{- end}})
{{- else}}
{{ .PkgName }}Identifier.{{.Name}} = {{ .PkgName }}.{{- if eq .Name "Id"}}{{.ResourceClassName}}{{ .Name }}{{- else}}{{.Name}}{{- end}}
{{- end}}
{{- end}}
{{- end}}
{{ .PkgName }}Identifiers = append({{ .PkgName }}Identifiers, {{ .PkgName }}Identifier)
Expand All @@ -2151,7 +2145,11 @@ func get{{$.ResourceClassName}}{{ .ResourceClassName }}ChildPayloads(ctx context
if
{{- range .Properties}}
{{- if .IsNaming }}
{{- if .HasCustomType}}
{{ .PkgName }}Identifier.{{.Name}} == basetypes.NewStringValue({{ .PkgName }}.{{- if eq .Name "Id"}}{{.ResourceClassName}}.ValueString(){{ .Name }}{{- else}}{{.Name}}.ValueString(){{- end}}){{- if ne $length $i}} {{$i = add $i 1}} && {{- end}}
{{- else}}
{{ .PkgName }}Identifier.{{.Name}} == {{ .PkgName }}.{{- if eq .Name "Id"}}{{.ResourceClassName}}{{ .Name }}{{- else}}{{.Name}}{{- end}}{{- if ne $length $i}} {{$i = add $i 1}} && {{- end}}
{{- end}}
{{- end}}
{{- end}} {
delete = false
Expand Down
4 changes: 4 additions & 0 deletions internal/custom_types/fvAEPg_prio.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (v FvAEPgPrioStringValue) StringSemanticEquals(ctx context.Context, newValu
return priorMappedValue.Equal(newMappedValue), diags
}

func (v FvAEPgPrioStringValue) NamedValueString() string {
return FvAEPgPrioValueMap(basetypes.NewStringValue(v.ValueString())).ValueString()
}

func FvAEPgPrioValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
"0": "unspecified",
Expand Down
4 changes: 4 additions & 0 deletions internal/custom_types/fvRsConsIf_prio.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (v FvRsConsIfPrioStringValue) StringSemanticEquals(ctx context.Context, new
return priorMappedValue.Equal(newMappedValue), diags
}

func (v FvRsConsIfPrioStringValue) NamedValueString() string {
return FvRsConsIfPrioValueMap(basetypes.NewStringValue(v.ValueString())).ValueString()
}

func FvRsConsIfPrioValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
"0": "unspecified",
Expand Down
4 changes: 4 additions & 0 deletions internal/custom_types/fvRsCons_prio.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (v FvRsConsPrioStringValue) StringSemanticEquals(ctx context.Context, newVa
return priorMappedValue.Equal(newMappedValue), diags
}

func (v FvRsConsPrioStringValue) NamedValueString() string {
return FvRsConsPrioValueMap(basetypes.NewStringValue(v.ValueString())).ValueString()
}

func FvRsConsPrioValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
"0": "unspecified",
Expand Down
4 changes: 4 additions & 0 deletions internal/custom_types/fvRsProv_prio.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (v FvRsProvPrioStringValue) StringSemanticEquals(ctx context.Context, newVa
return priorMappedValue.Equal(newMappedValue), diags
}

func (v FvRsProvPrioStringValue) NamedValueString() string {
return FvRsProvPrioValueMap(basetypes.NewStringValue(v.ValueString())).ValueString()
}

func FvRsProvPrioValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
"0": "unspecified",
Expand Down
4 changes: 4 additions & 0 deletions internal/custom_types/mgmtInstP_prio.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (v MgmtInstPPrioStringValue) StringSemanticEquals(ctx context.Context, newV
return priorMappedValue.Equal(newMappedValue), diags
}

func (v MgmtInstPPrioStringValue) NamedValueString() string {
return MgmtInstPPrioValueMap(basetypes.NewStringValue(v.ValueString())).ValueString()
}

func MgmtInstPPrioValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
"0": "unspecified",
Expand Down
4 changes: 4 additions & 0 deletions internal/custom_types/mgmtRsOoBCons_prio.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (v MgmtRsOoBConsPrioStringValue) StringSemanticEquals(ctx context.Context,
return priorMappedValue.Equal(newMappedValue), diags
}

func (v MgmtRsOoBConsPrioStringValue) NamedValueString() string {
return MgmtRsOoBConsPrioValueMap(basetypes.NewStringValue(v.ValueString())).ValueString()
}

func MgmtRsOoBConsPrioValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
"0": "unspecified",
Expand Down
4 changes: 4 additions & 0 deletions internal/custom_types/netflowExporterPol_dscp.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (v NetflowExporterPolDscpStringValue) StringSemanticEquals(ctx context.Cont
return priorMappedValue.Equal(newMappedValue), diags
}

func (v NetflowExporterPolDscpStringValue) NamedValueString() string {
return NetflowExporterPolDscpValueMap(basetypes.NewStringValue(v.ValueString())).ValueString()
}

func NetflowExporterPolDscpValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
"0": "CS0",
Expand Down
4 changes: 4 additions & 0 deletions internal/custom_types/netflowExporterPol_dstPort.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (v NetflowExporterPolDstPortStringValue) StringSemanticEquals(ctx context.C
return priorMappedValue.Equal(newMappedValue), diags
}

func (v NetflowExporterPolDstPortStringValue) NamedValueString() string {
return NetflowExporterPolDstPortValueMap(basetypes.NewStringValue(v.ValueString())).ValueString()
}

func NetflowExporterPolDstPortValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
"0": "unspecified",
Expand Down
4 changes: 4 additions & 0 deletions internal/custom_types/qosDppPol_be.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (v QosDppPolBeStringValue) StringSemanticEquals(ctx context.Context, newVal
return priorMappedValue.Equal(newMappedValue), diags
}

func (v QosDppPolBeStringValue) NamedValueString() string {
return QosDppPolBeValueMap(basetypes.NewStringValue(v.ValueString())).ValueString()
}

func QosDppPolBeValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
"0xffffffffffffffff": "unspecified",
Expand Down
4 changes: 4 additions & 0 deletions internal/custom_types/qosDppPol_burst.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (v QosDppPolBurstStringValue) StringSemanticEquals(ctx context.Context, new
return priorMappedValue.Equal(newMappedValue), diags
}

func (v QosDppPolBurstStringValue) NamedValueString() string {
return QosDppPolBurstValueMap(basetypes.NewStringValue(v.ValueString())).ValueString()
}

func QosDppPolBurstValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
"0xffffffffffffffff": "unspecified",
Expand Down
4 changes: 4 additions & 0 deletions internal/custom_types/qosDppPol_conformMarkCos.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (v QosDppPolConformMarkCosStringValue) StringSemanticEquals(ctx context.Con
return priorMappedValue.Equal(newMappedValue), diags
}

func (v QosDppPolConformMarkCosStringValue) NamedValueString() string {
return QosDppPolConformMarkCosValueMap(basetypes.NewStringValue(v.ValueString())).ValueString()
}

func QosDppPolConformMarkCosValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
"0xffff": "unspecified",
Expand Down
4 changes: 4 additions & 0 deletions internal/custom_types/qosDppPol_conformMarkDscp.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (v QosDppPolConformMarkDscpStringValue) StringSemanticEquals(ctx context.Co
return priorMappedValue.Equal(newMappedValue), diags
}

func (v QosDppPolConformMarkDscpStringValue) NamedValueString() string {
return QosDppPolConformMarkDscpValueMap(basetypes.NewStringValue(v.ValueString())).ValueString()
}

func QosDppPolConformMarkDscpValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
"0xffff": "unspecified",
Expand Down
4 changes: 4 additions & 0 deletions internal/custom_types/qosDppPol_exceedMarkCos.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (v QosDppPolExceedMarkCosStringValue) StringSemanticEquals(ctx context.Cont
return priorMappedValue.Equal(newMappedValue), diags
}

func (v QosDppPolExceedMarkCosStringValue) NamedValueString() string {
return QosDppPolExceedMarkCosValueMap(basetypes.NewStringValue(v.ValueString())).ValueString()
}

func QosDppPolExceedMarkCosValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
"0xffff": "unspecified",
Expand Down
4 changes: 4 additions & 0 deletions internal/custom_types/qosDppPol_exceedMarkDscp.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (v QosDppPolExceedMarkDscpStringValue) StringSemanticEquals(ctx context.Con
return priorMappedValue.Equal(newMappedValue), diags
}

func (v QosDppPolExceedMarkDscpStringValue) NamedValueString() string {
return QosDppPolExceedMarkDscpValueMap(basetypes.NewStringValue(v.ValueString())).ValueString()
}

func QosDppPolExceedMarkDscpValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
"0xffff": "unspecified",
Expand Down
4 changes: 4 additions & 0 deletions internal/custom_types/qosDppPol_violateMarkCos.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (v QosDppPolViolateMarkCosStringValue) StringSemanticEquals(ctx context.Con
return priorMappedValue.Equal(newMappedValue), diags
}

func (v QosDppPolViolateMarkCosStringValue) NamedValueString() string {
return QosDppPolViolateMarkCosValueMap(basetypes.NewStringValue(v.ValueString())).ValueString()
}

func QosDppPolViolateMarkCosValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
"0xffff": "unspecified",
Expand Down
4 changes: 4 additions & 0 deletions internal/custom_types/qosDppPol_violateMarkDscp.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (v QosDppPolViolateMarkDscpStringValue) StringSemanticEquals(ctx context.Co
return priorMappedValue.Equal(newMappedValue), diags
}

func (v QosDppPolViolateMarkDscpStringValue) NamedValueString() string {
return QosDppPolViolateMarkDscpValueMap(basetypes.NewStringValue(v.ValueString())).ValueString()
}

func QosDppPolViolateMarkDscpValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
"0xffff": "unspecified",
Expand Down
4 changes: 4 additions & 0 deletions internal/custom_types/vzOOBBrCP_prio.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (v VzOOBBrCPPrioStringValue) StringSemanticEquals(ctx context.Context, newV
return priorMappedValue.Equal(newMappedValue), diags
}

func (v VzOOBBrCPPrioStringValue) NamedValueString() string {
return VzOOBBrCPPrioValueMap(basetypes.NewStringValue(v.ValueString())).ValueString()
}

func VzOOBBrCPPrioValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
"0": "unspecified",
Expand Down
4 changes: 4 additions & 0 deletions internal/custom_types/vzOOBBrCP_targetDscp.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (v VzOOBBrCPTargetDscpStringValue) StringSemanticEquals(ctx context.Context
return priorMappedValue.Equal(newMappedValue), diags
}

func (v VzOOBBrCPTargetDscpStringValue) NamedValueString() string {
return VzOOBBrCPTargetDscpValueMap(basetypes.NewStringValue(v.ValueString())).ValueString()
}

func VzOOBBrCPTargetDscpValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
"0": "CS0",
Expand Down
10 changes: 1 addition & 9 deletions internal/provider/resource_aci_access_interface_override.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions internal/provider/resource_aci_annotation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions internal/provider/resource_aci_application_epg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions internal/provider/resource_aci_bridge_domain.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 24898fb

Please sign in to comment.