Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/resources/vmm_domain.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ resource "aci_vmm_domain" "full_example" {
parent_dn = "uni/vmmp-VMware"
access_mode = "read-only"
annotation = "annotation"
arp_learning = ""
arp_learning = "disabled"
ave_time_out = "30"
configure_infra_port_groups = "no"
endpoint_data_path_verification = "epDpVerify"
Expand Down Expand Up @@ -222,7 +222,8 @@ All examples for the VMM Domain resource can be found in the [examples](https://
- Default: `"orchestrator:terraform"`
* `arp_learning` (arpLearning) - (string) Enable ARP learning for the the VMM Domain object, this attribute is only applicable for Application Virtual Switch (AVS). This attribute is supported in ACI versions: 3.1(1i) and later.
- Default: `"disabled"`
- Valid Values: `""`, `"disabled"`, `"enabled"`.
- Valid Values:
* `"disabled"`, `"enabled"`.
* `ave_time_out` (aveTimeOut) - (string) The timeout in seconds that the Cisco ACI Virtual Edge (AVE), the virtual switch for ACI, can remain in a non-working state before vCenter takes action. This attribute is supported in ACI versions: 3.2(10e) to 3.2(10g), 3.2(3n) and later.
- Default: `"30"`
* `configure_infra_port_groups` (configInfraPg) - (string) Configure port groups for the virtual APIC. This attribute is supported in ACI versions: 4.0(1h) and later.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resource "aci_vmm_domain" "full_example" {
parent_dn = "uni/vmmp-VMware"
access_mode = "read-only"
annotation = "annotation"
arp_learning = ""
arp_learning = "disabled"
ave_time_out = "30"
configure_infra_port_groups = "no"
endpoint_data_path_verification = "epDpVerify"
Expand Down
4 changes: 4 additions & 0 deletions gen/definitions/classes/vmmDomP.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ static_parent: true
sub_category: Virtual Networking
ui_locations:
- Virtual Networking -> Provider -> Domain
# ignoring due to bug in ACI where the imported value does not match state
# there is custom type logic in place to handle this aci exception
# the bug (CSCws11715) raised will not be fixed because it could break other functionality
ignore_import_state_verify_in_test: true
16 changes: 11 additions & 5 deletions gen/definitions/properties/vmmDomP.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
add_valid_values:
arpLearning:
- ""
parentDn:
- uni/vmmp-VMware
- uni/vmmp-Microsoft
Expand All @@ -11,7 +9,7 @@ add_valid_values:
- uni/vmmp-Redhat
- uni/vmmp-Nutanix
default_values:
arpLearning: ""
arpLearning: "disabled"
configInfraPg: "no"
enableAVE: "no"
enableTag: "no"
Expand Down Expand Up @@ -52,7 +50,7 @@ overwrites:
pref_encap_mode: default_encapsulation_mode
test_values:
all:
arp_learning: ""
arp_learning: "disabled"
custom_switch_name: ""
delimiter: '@'
multicast_address: 224.0.1.0
Expand All @@ -61,8 +59,10 @@ test_values:
parent_dn: uni/vmmp-VMware
datasource_required:
parent_dn: uni/vmmp-VMware
ignore_in_datasource:
- arp_learning
default:
arp_learning: ""
arp_learning: "disabled"
custom_switch_name: ""
delimiter: ""
multicast_address: 0.0.0.0
Expand All @@ -74,8 +74,14 @@ test_values:
multicast_address: 0.0.0.0
parent_dn: uni/vmmp-VMware
switch_type: default
arp_learning: "disabled"
custom_type:
arp_learning: "disabled"
resource_required:
parent_dn: uni/vmmp-VMware
arp_learning: "disabled"
type_overwrites:
arpLearning: string
ctrlKnob: string
static_custom_type:
arpLearning: vmm_arp_learning
42 changes: 40 additions & 2 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ const providerName = "aci"
const pubhupDevnetBaseUrl = "https://pubhub.devnetcloud.com/media/model-doc-latest/docs"

var staticCustomTypeMap = map[string]string{
"ip_address": "IPAddress",
"ip_address": "IPAddress",
"vmm_arp_learning": "VMMArpLearning",
}

// Function map used during template rendering in order to call functions from the template
Expand Down Expand Up @@ -1139,6 +1140,9 @@ func getTestVars(model Model) (map[string]interface{}, error) {
// Adds the resource name and resource class name to the testVars map to be used in test template rendering
testVarsMap["resourceName"] = model.ResourceName
testVarsMap["resourceClassName"] = model.ResourceClassName
testVarsMap["importStateVerify"] = model.IgnoreStateVerify
testVarsMap["ignoreDataSourceAttributes"] = model.IgnoreDataSourceAttributes
testVarsMap["ignoreResourceAttributes"] = model.IgnoreResourceAttributes
return testVarsMap, nil
}

Expand Down Expand Up @@ -1263,7 +1267,7 @@ func cleanDirectories() {
cleanDirectory(resourcesDocsPath, []string{})
cleanDirectory(datasourcesDocsPath, []string{"system.md"})
cleanDirectory(testVarsPath, []string{})
cleanDirectory("./internal/custom_types", []string{"ipAddress.go"})
cleanDirectory("./internal/custom_types", []string{"ipAddress.go", "arpLearning.go"})

// The *ExamplesPath directories are removed and recreated to ensure all previously rendered files are removed
// The provider example file is not removed because it contains static provider configuration
Expand Down Expand Up @@ -1584,6 +1588,9 @@ type Model struct {
RequiredAsChild bool
ContainsDefaultParentDn bool
DataSourceHasNoNameIdentifier bool
IgnoreStateVerify bool
IgnoreDataSourceAttributes []interface{}
IgnoreResourceAttributes []interface{}
}

type TypeChange struct {
Expand Down Expand Up @@ -1715,6 +1722,8 @@ func (m *Model) setClassModel(metaPath string, isChildIteration bool, definition
m.SetTestApplicableFromVersion(classDetails)
m.SetRequiredAsChild(m.PkgName, definitions)
m.SetDataSourceHasNoNameIdentifier()
m.SetIgnoreStateVerification()
m.SetIgnoreTestAttributes()
}

/*
Expand Down Expand Up @@ -2641,6 +2650,35 @@ func (m *Model) SetDataSourceHasNoNameIdentifier() {
}
}

func (m *Model) SetIgnoreStateVerification() {
// This function is an exception override function when custom types are required to handle state deviation
// This was introduced to mitigate CSCws11715 where the default value of disabled is transformed into an empty string
if classDetails, ok := m.Definitions.Classes[m.PkgName]; ok {
for key, value := range classDetails.(map[string]interface{}) {
if key == "ignore_import_state_verify_in_test" {
m.IgnoreStateVerify = value.(bool)
}
}
}
}

func (m *Model) SetIgnoreTestAttributes() {
if classDetails, ok := m.Definitions.Properties[m.PkgName]; ok {
for key, value := range classDetails.(map[string]interface{}) {
if key == "test_values" {
for test_type, test_type_values := range value.(map[interface{}]interface{}) {
if test_type.(string) == "ignore_in_datasource" {
m.IgnoreDataSourceAttributes = test_type_values.([]interface{})
}
if test_type.(string) == "ignore_in_resource" {
m.IgnoreResourceAttributes = test_type_values.([]interface{})
}
}
}
}
}
}

func (m *Model) GetLegacyAttribute(attributeName, className string, attributeValue interface{}, definitions Definitions) (LegacyAttribute, string) {
optional := false
if attributeValue.(map[string]interface{})["optional"] != nil {
Expand Down
4 changes: 2 additions & 2 deletions gen/templates/datasource_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ func TestAccDataSource{{.resourceClassName}}(t *testing.T) {
Config: testConfig{{.resourceClassName}}DataSource{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}},
Check: resource.ComposeAggregateTestCheckFunc(
{{- range $key, $value := .min}}
{{- if not (definedInList $.exclude_attributes $key) }}
resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"),
{{- end}}
{{- end}}
{{- range $key, $value := .all}}
{{- if eq $key "version_mismatch" }}
{{- range $version, $attributes := $value }}
Expand All @@ -118,7 +116,9 @@ func TestAccDataSource{{.resourceClassName}}(t *testing.T) {
resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test", "{{$key}}.{{$index}}", "{{$subvalue}}"),
{{- end}}
{{- else}}
{{- if not (definedInList $.ignoreDataSourceAttributes $key) }}
resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"),
{{- end}}
{{- end}}
{{- end}}
{{- end}}
Expand Down
6 changes: 5 additions & 1 deletion gen/templates/resource.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,9 @@ func (r *{{.ResourceClassName}}Resource) Schema(ctx context.Context, req resourc
{{- if .ValidValues}}
stringvalidator.OneOf({{- validatorStringCustomType .ValidValues .ValidValuesMap}}),
{{- end}}
validators.InBetweenFromString({{- index .Validators 0 "min"}}, {{- index .Validators 0 "max"}}),
{{- if ne 0 (len .Validators)}}
validators.InBetweenFromString({{- index .Validators 0 "min"}}, {{- index .Validators 0 "max"}}),
{{- end}}
),
},
{{- else if or .ValidValues (ne $LegacyAttributeName "")}}
Expand Down Expand Up @@ -2933,7 +2935,9 @@ func {{.ResourceClassName}}{{.ParentHierarchy}}SetToSetNullWhenStateIsNullPlanIs
{{- if .ValidValues}}
stringvalidator.OneOf({{- validatorStringCustomType .ValidValues .ValidValuesMap}}),
{{- end}}
{{- if ne 0 (len .Validators)}}
validators.InBetweenFromString({{- index .Validators 0 "min"}}, {{- index .Validators 0 "max"}}),
{{- end}}
),
},
{{- else if or .ValidValues $.TemplateProperties.HasReadOnlyProperties}}
Expand Down
2 changes: 2 additions & 0 deletions gen/templates/resource.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ All examples for the {{.ResourceNameAsDescription}} resource can be found in the
{{- if .ValidValues}}
*{{ range .ValidValues}} `"{{ . }}"`{{ if ne $length $i}}{{$i = add $i 1}}, {{- else}}.{{- end}}{{- end}}
{{- end}}
{{- if ne 0 (len .Validators)}}
* {{if .ValidValues}}Or a{{else}}A{{end}} value in the range of `{{ printf "%.0f" (index .Validators 0 "min") }}` to `{{ printf "%.0f" (index .Validators 0 "max") }}`.
{{- end}}
{{- else if .ValidValues }}{{$i := 1}}{{$length := len .ValidValues}}
- Valid Values:{{ range .ValidValues}} `"{{ . }}"`{{ if ne $length $i}}{{$i = add $i 1}}, {{- else}}.{{- end}}{{- end}}
{{- end}}
Expand Down
21 changes: 19 additions & 2 deletions gen/templates/resource_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,11 @@ PreCheck: func() { testAccPreCheck(t, "{{.test_type}}", "{{$.class_version}}") }
{
ResourceName: "aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}",
ImportState: true,
ImportStateVerify: true,
{{- if $.importStateVerify }}
// skipping ImportStateVerify due to overwrite in class definition file
{{- else}}
ImportStateVerify: true,
{{- end}}
{{- if $.exclude_attributes }}
ImportStateVerifyIgnore: []string{
{{- range $.exclude_attributes }}"{{.}}",{{- end}}
Expand Down Expand Up @@ -494,7 +498,11 @@ PreCheck: func() { testAccPreCheck(t, "{{.test_type}}", "{{$.class_version}}") }
{
ResourceName: "aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}",
ImportState: true,
{{- if $.importStateVerify }}
// skipping ImportStateVerify due to overwrite in class definition file
{{- else}}
ImportStateVerify: true,
{{- end}}
{{- if $.exclude_attributes }}
ImportStateVerifyIgnore: []string{
{{- range $.exclude_attributes }}"{{.}}",{{- end}}
Expand Down Expand Up @@ -1212,7 +1220,11 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) {
{
ResourceName: "aci_{{$.resourceName}}.test",
ImportState: true,
ImportStateVerify: true,
{{- if $.importStateVerify }}
// skipping ImportStateVerify due to overwrite in class definition file
{{- else}}
ImportStateVerify: true,
{{- end}}
},
{{- if $.children}}
// Update with children
Expand Down Expand Up @@ -2783,6 +2795,11 @@ resource "aci_{{$.resourceName}}" "test" {
{{if $.custom_type}}
const testConfig{{.resourceClassName}}CustomType = `
resource "aci_{{$.resourceName}}" "test" {
{{- range $key, $value := $.resource_required}}
{{- if eq $key "parent_dn"}}
{{$key}} = "{{$value}}"
{{- end}}
{{- end}}
{{- range $key, $value := $.custom_type}}
{{$key}} = "{{$value}}"
{{- end}}
Expand Down
9 changes: 7 additions & 2 deletions gen/testvars/vmmDomP.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ignore_in_legacy:
default:
access_mode: "read-write"
annotation: "orchestrator:terraform"
arp_learning: ""
arp_learning: "disabled"
ave_time_out: "30"
endpoint_data_path_verification: "epDpVerify"
delimiter: ""
Expand Down Expand Up @@ -80,12 +80,17 @@ datasource_required:

resource_required:
parent_dn: "uni/vmmp-VMware"
arp_learning: "disabled"
name: "test_name"

custom_type:
arp_learning: "disabled"
name: "test_name"

all:
access_mode: "read-only"
annotation: "annotation"
arp_learning: ""
arp_learning: "disabled"
ave_time_out: "30"
endpoint_data_path_verification: "epDpVerify"
delimiter: "@"
Expand Down
Loading
Loading