Skip to content

Commit

Permalink
[ignore] Rebase and incorporate custom types to changes made to resou…
Browse files Browse the repository at this point in the history
…rce.go template.
  • Loading branch information
gmicol committed Aug 9, 2024
1 parent ff91c82 commit 916650e
Show file tree
Hide file tree
Showing 53 changed files with 2,186 additions and 674 deletions.
4 changes: 2 additions & 2 deletions docs/data-sources/netflow_exporter_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ layout: "aci"
page_title: "ACI: aci_netflow_exporter_policy"
sidebar_current: "docs-aci-data-source-aci_netflow_exporter_policy"
description: |-
Data source for Netflow Exporter Policy
Data source for ACI Netflow Exporter Policy
---

# aci_netflow_exporter_policy #

Data source for Netflow Exporter Policy
Data source for ACI Netflow Exporter Policy

## API Information ##

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/epg_useg_dns_attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ resource "aci_epg_useg_dns_attribute" "full_example_epg_useg_block_statement" {
parent_dn = aci_epg_useg_block_statement.example.id
annotation = "annotation"
description = "description_1"
filter = "filter_1"
filter = "test_filter"
name = "dns_attribute"
name_alias = "name_alias_1"
owner_key = "owner_key_1"
Expand Down
8 changes: 4 additions & 4 deletions docs/resources/netflow_exporter_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ The configuration snippet below shows all possible attributes of the Netflow Exp
resource "aci_netflow_exporter_policy" "full_example_tenant" {
parent_dn = aci_tenant.example.id
annotation = "annotation"
description = "description"
description = "description_1"
dscp = "AF11"
destination_address = "2.2.2.1"
destination_port = "https"
name = "netfow_exporter"
name_alias = "name_alias"
owner_key = "owner_key"
owner_tag = "owner_tag"
name_alias = "name_alias_1"
owner_key = "owner_key_1"
owner_tag = "owner_tag_1"
source_ip_type = "custom-src-ip"
source_address = "1.1.1.1/10"
version = "v9"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resource "aci_epg_useg_dns_attribute" "full_example_epg_useg_block_statement" {
parent_dn = aci_epg_useg_block_statement.example.id
annotation = "annotation"
description = "description_1"
filter = "filter_1"
filter = "test_filter"
name = "dns_attribute"
name_alias = "name_alias_1"
owner_key = "owner_key_1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
resource "aci_netflow_exporter_policy" "full_example_tenant" {
parent_dn = aci_tenant.example.id
annotation = "annotation"
description = "description"
description = "description_1"
dscp = "AF11"
destination_address = "2.2.2.1"
destination_port = "https"
name = "netfow_exporter"
name_alias = "name_alias"
owner_key = "owner_key"
owner_tag = "owner_tag"
name_alias = "name_alias_1"
owner_key = "owner_key_1"
owner_tag = "owner_tag_1"
source_ip_type = "custom-src-ip"
source_address = "1.1.1.1/10"
version = "v9"
Expand Down
37 changes: 24 additions & 13 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,13 +893,14 @@ type LegacyBlock struct {
}

type LegacyAttribute struct {
Name string
AttributeName string
ValueType []string
ReplacedBy ReplacementAttribute
Optional bool
Computed bool
Required bool
Name string
AttributeName string
ValueType []string
ReplacedBy ReplacementAttribute
Optional bool
Computed bool
Required bool
NeedCustomType bool
}

type ReplacementAttribute struct {
Expand Down Expand Up @@ -1624,13 +1625,23 @@ func (m *Model) GetLegacyAttribute(attributeName, className string, attributeVal
}
}

needCustomType := false
for _, property := range m.Properties {
if propertyName == property.Name && len(property.ValidValuesMap) > 0 && len(property.Validators) > 0 {
needCustomType = true
break
}

}

legacyAttribute := LegacyAttribute{
Name: propertyName,
AttributeName: attributeName,
ValueType: valueType,
Optional: optional,
Computed: computed,
Required: required,
Name: propertyName,
AttributeName: attributeName,
ValueType: valueType,
Optional: optional,
Computed: computed,
Required: required,
NeedCustomType: needCustomType,
}

if replacedBy != nil {
Expand Down
64 changes: 32 additions & 32 deletions gen/templates/custom_type.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (
"github.com/hashicorp/terraform-plugin-go/tftypes"
)

// {{.ResourceClassName}}{{.PropertyName}} custom string type.
// {{.ResourceClassName}}{{.Name}} custom string type.

var _ basetypes.StringTypable = {{.ResourceClassName}}{{.PropertyName}}StringType{}
var _ basetypes.StringTypable = {{.ResourceClassName}}{{.Name}}StringType{}

type {{.ResourceClassName}}{{.PropertyName}}StringType struct {
type {{.ResourceClassName}}{{.Name}}StringType struct {
basetypes.StringType
}

func (t {{.ResourceClassName}}{{.PropertyName}}StringType) Equal(o attr.Type) bool {
other, ok := o.({{.ResourceClassName}}{{.PropertyName}}StringType)
func (t {{.ResourceClassName}}{{.Name}}StringType) Equal(o attr.Type) bool {
other, ok := o.({{.ResourceClassName}}{{.Name}}StringType)

if !ok {
return false
Expand All @@ -28,19 +28,19 @@ func (t {{.ResourceClassName}}{{.PropertyName}}StringType) Equal(o attr.Type) bo
return t.StringType.Equal(other.StringType)
}

func (t {{.ResourceClassName}}{{.PropertyName}}StringType) String() string {
return "{{.ResourceClassName}}{{.PropertyName}}StringType"
func (t {{.ResourceClassName}}{{.Name}}StringType) String() string {
return "{{.ResourceClassName}}{{.Name}}StringType"
}

func (t {{.ResourceClassName}}{{.PropertyName}}StringType) ValueFromString(ctx context.Context, in basetypes.StringValue) (basetypes.StringValuable, diag.Diagnostics) {
value := {{.ResourceClassName}}{{.PropertyName}}StringValue{
func (t {{.ResourceClassName}}{{.Name}}StringType) ValueFromString(ctx context.Context, in basetypes.StringValue) (basetypes.StringValuable, diag.Diagnostics) {
value := {{.ResourceClassName}}{{.Name}}StringValue{
StringValue: in,
}

return value, nil
}

func (t {{.ResourceClassName}}{{.PropertyName}}StringType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) {
func (t {{.ResourceClassName}}{{.Name}}StringType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) {
attrValue, err := t.StringType.ValueFromTerraform(ctx, in)

if err != nil {
Expand All @@ -62,20 +62,20 @@ func (t {{.ResourceClassName}}{{.PropertyName}}StringType) ValueFromTerraform(ct
return stringValuable, nil
}

func (t {{.ResourceClassName}}{{.PropertyName}}StringType) ValueType(ctx context.Context) attr.Value {
return {{.ResourceClassName}}{{.PropertyName}}StringValue{}
func (t {{.ResourceClassName}}{{.Name}}StringType) ValueType(ctx context.Context) attr.Value {
return {{.ResourceClassName}}{{.Name}}StringValue{}
}

// {{.ResourceClassName}}{{.PropertyName}} custom string value.
// {{.ResourceClassName}}{{.Name}} custom string value.

var _ basetypes.StringValuableWithSemanticEquals = {{.ResourceClassName}}{{.PropertyName}}StringValue{}
var _ basetypes.StringValuableWithSemanticEquals = {{.ResourceClassName}}{{.Name}}StringValue{}

type {{.ResourceClassName}}{{.PropertyName}}StringValue struct {
type {{.ResourceClassName}}{{.Name}}StringValue struct {
basetypes.StringValue
}

func (v {{.ResourceClassName}}{{.PropertyName}}StringValue) Equal(o attr.Value) bool {
other, ok := o.({{.ResourceClassName}}{{.PropertyName}}StringValue)
func (v {{.ResourceClassName}}{{.Name}}StringValue) Equal(o attr.Value) bool {
other, ok := o.({{.ResourceClassName}}{{.Name}}StringValue)

if !ok {
return false
Expand All @@ -84,14 +84,14 @@ func (v {{.ResourceClassName}}{{.PropertyName}}StringValue) Equal(o attr.Value)
return v.StringValue.Equal(other.StringValue)
}

func (v {{.ResourceClassName}}{{.PropertyName}}StringValue) Type(ctx context.Context) attr.Type {
return {{.ResourceClassName}}{{.PropertyName}}StringType{}
func (v {{.ResourceClassName}}{{.Name}}StringValue) Type(ctx context.Context) attr.Type {
return {{.ResourceClassName}}{{.Name}}StringType{}
}

func (v {{.ResourceClassName}}{{.PropertyName}}StringValue) StringSemanticEquals(ctx context.Context, newValuable basetypes.StringValuable) (bool, diag.Diagnostics) {
func (v {{.ResourceClassName}}{{.Name}}StringValue) StringSemanticEquals(ctx context.Context, newValuable basetypes.StringValuable) (bool, diag.Diagnostics) {
var diags diag.Diagnostics

newValue, ok := newValuable.({{.ResourceClassName}}{{.PropertyName}}StringValue)
newValue, ok := newValuable.({{.ResourceClassName}}{{.Name}}StringValue)

if !ok {
diags.AddError(
Expand All @@ -105,14 +105,14 @@ func (v {{.ResourceClassName}}{{.PropertyName}}StringValue) StringSemanticEquals
return false, diags
}

priorMappedValue := {{.ResourceClassName}}{{.PropertyName}}ValueMap(v.StringValue)
priorMappedValue := {{.ResourceClassName}}{{.Name}}ValueMap(v.StringValue)

newMappedValue := {{.ResourceClassName}}{{.PropertyName}}ValueMap(newValue.StringValue)
newMappedValue := {{.ResourceClassName}}{{.Name}}ValueMap(newValue.StringValue)

return priorMappedValue.Equal(newMappedValue), diags
}

func {{.ResourceClassName}}{{.PropertyName}}ValueMap(value basetypes.StringValue) basetypes.StringValue {
func {{.ResourceClassName}}{{.Name}}ValueMap(value basetypes.StringValue) basetypes.StringValue {
matchMap := map[string]string{
{{- range $key, $value := .ValidValuesMap}}
"{{$key}}": "{{$value}}",
Expand All @@ -126,26 +126,26 @@ func {{.ResourceClassName}}{{.PropertyName}}ValueMap(value basetypes.StringValue
return value
}

func New{{.ResourceClassName}}{{.PropertyName}}StringNull() {{.ResourceClassName}}{{.PropertyName}}StringValue {
return {{.ResourceClassName}}{{.PropertyName}}StringValue{
func New{{.ResourceClassName}}{{.Name}}StringNull() {{.ResourceClassName}}{{.Name}}StringValue {
return {{.ResourceClassName}}{{.Name}}StringValue{
StringValue: basetypes.NewStringNull(),
}
}

func New{{.ResourceClassName}}{{.PropertyName}}StringUnknown() {{.ResourceClassName}}{{.PropertyName}}StringValue {
return {{.ResourceClassName}}{{.PropertyName}}StringValue{
func New{{.ResourceClassName}}{{.Name}}StringUnknown() {{.ResourceClassName}}{{.Name}}StringValue {
return {{.ResourceClassName}}{{.Name}}StringValue{
StringValue: basetypes.NewStringUnknown(),
}
}

func New{{.ResourceClassName}}{{.PropertyName}}StringValue(value string) {{.ResourceClassName}}{{.PropertyName}}StringValue {
return {{.ResourceClassName}}{{.PropertyName}}StringValue{
func New{{.ResourceClassName}}{{.Name}}StringValue(value string) {{.ResourceClassName}}{{.Name}}StringValue {
return {{.ResourceClassName}}{{.Name}}StringValue{
StringValue: basetypes.NewStringValue(value),
}
}

func New{{.ResourceClassName}}{{.PropertyName}}StringPointerValue(value *string) {{.ResourceClassName}}{{.PropertyName}}StringValue {
return {{.ResourceClassName}}{{.PropertyName}}StringValue{
func New{{.ResourceClassName}}{{.Name}}StringPointerValue(value *string) {{.ResourceClassName}}{{.Name}}StringValue {
return {{.ResourceClassName}}{{.Name}}StringValue{
StringValue: basetypes.NewStringPointerValue(value),
}
}
4 changes: 2 additions & 2 deletions gen/templates/datasource.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (d *{{.ResourceClassName}}DataSource) Schema(ctx context.Context, req datas
},{{else}}
"{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}": schema.StringAttribute{
{{- if and (lt 0 (len .ValidValuesMap)) (lt 0 (len .Validators))}}
CustomType: customTypes.{{.ResourceClassName}}{{.PropertyName}}StringType{},
CustomType: customTypes.{{.ResourceClassName}}{{.Name}}StringType{},
{{- end}}
Computed: true,
MarkdownDescription: `{{.Comment}}`,
Expand All @@ -128,7 +128,7 @@ func (d *{{.ResourceClassName}}DataSource) Schema(ctx context.Context, req datas
},{{else}}
"{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}": schema.StringAttribute{
{{- if and (lt 0 (len .ValidValuesMap)) (lt 0 (len .Validators))}}
CustomType: customTypes.{{.ResourceClassName}}{{.PropertyName}}StringType{},
CustomType: customTypes.{{.ResourceClassName}}{{.Name}}StringType{},
{{- end}}
Computed: true,
MarkdownDescription: `{{.Comment}}`,
Expand Down
Loading

0 comments on commit 916650e

Please sign in to comment.