From cb07ce9e7bedf3e55e7642ecde00d0f0fb7ac17d Mon Sep 17 00:00:00 2001 From: akinross Date: Thu, 27 Nov 2025 13:11:47 +0100 Subject: [PATCH 1/2] [ignore] template changes for lists --- gen/templates/resource.md.tmpl | 6 ++- gen/templates/resource_test.go.tmpl | 60 ++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/gen/templates/resource.md.tmpl b/gen/templates/resource.md.tmpl index d34c2b816..cbfca70f7 100644 --- a/gen/templates/resource.md.tmpl +++ b/gen/templates/resource.md.tmpl @@ -123,8 +123,8 @@ All examples for the {{.ResourceNameAsDescription}} resource can be found in the {{- if eq .ValueType "bitmask"}} * `{{- overwriteProperty .PkgName .SnakeCaseName $.Definitions}}` ({{- .PropertyName}}) - (list) {{.Comment}}{{if and (ne $.Versions .Versions) (ne .Versions "")}} This attribute is supported in ACI versions: {{ .Versions}}{{- end}} {{- if .DefaultValue }} - {{- if eq .DefaultValue "@aci_gen_default_value_overwrite_to_empty_string!"}} - - Default: `""` + {{- if eq .DefaultValue "@aci_gen_default_value_overwrite_to_empty_list!"}} + - Default: `[]` {{- else}} - Default: `"{{ .DefaultValue }}"` {{- end}} @@ -241,6 +241,8 @@ import { {{- if .DefaultValue }} {{- if eq .DefaultValue "@aci_gen_default_value_overwrite_to_empty_string!"}} {{ $indent }}- Default: `""` + {{- else if eq .DefaultValue "@aci_gen_default_value_overwrite_to_empty_list!"}} + {{ $indent }}- Default: `[]` {{- else}} {{ $indent }}- Default: `"{{ .DefaultValue }}"` {{- end}} diff --git a/gen/templates/resource_test.go.tmpl b/gen/templates/resource_test.go.tmpl index 940929783..ddc7fcc7b 100644 --- a/gen/templates/resource_test.go.tmpl +++ b/gen/templates/resource_test.go.tmpl @@ -1290,6 +1290,11 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- else }} {{- if eq $child_key "target_dn"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_index}}.{{$child_key}}", "{{getTestTargetDn $.child_targets $key $child_value false nil $child_index false}}"), + {{- else if (isInterfaceSlice $child_value)}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_index}}.{{$child_key}}.#", "{{len $child_value}}"), + {{- range $index, $subvalue := $child_value}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_index}}.{{$child_key}}.{{$index}}", "{{$subvalue}}"), + {{- end}} {{- else if and (ne $child_key "deletable_child") (ne $child_key "child_required")}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_index}}.{{$child_key}}", "{{$child_value}}"), {{- end}} @@ -1392,9 +1397,14 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- end }}), {{- end }} {{- else }} - {{- if eq $child_key "target_dn"}} + {{- if eq $child_key "target_dn"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_index}}.{{$child_key}}", "{{getTestTargetDn $.child_targets $key $child_value false nil $child_index false}}"), - {{- else if and (ne $child_key "deletable_child") (ne $child_key "child_required")}} + {{- else if (isInterfaceSlice $child_value)}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_index}}.{{$child_key}}.#", "{{len $child_value}}"), + {{- range $index, $subvalue := $child_value}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_index}}.{{$child_key}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else if and (ne $child_key "deletable_child") (ne $child_key "child_required")}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_index}}.{{$child_key}}", "{{$child_value}}"), {{- end}} {{- end}} @@ -1496,9 +1506,14 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- end }}), {{- end }} {{- else }} - {{- if eq $child_key "target_dn"}} + {{- if eq $child_key "target_dn"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.0.{{$child_key}}", "{{getTestTargetDn $.child_targets $key $child_value false nil 1 false}}"), - {{- else}} + {{- else if (isInterfaceSlice $child_value)}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.0.{{$child_key}}.#", "{{len $child_value}}"), + {{- range $index, $subvalue := $child_value}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.0.{{$child_key}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.0.{{$child_key}}", "{{$child_value}}"), {{- end}} {{- end}} @@ -2508,6 +2523,12 @@ resource "aci_{{$.resourceName}}" "test" { {{- else }} {{- if eq $child_key "target_dn"}}{{$attributeValue := getTestTargetDn $.child_targets $key $child_value true nil $index false}} {{$child_key}} = {{if isReference $attributeValue}}{{$attributeValue}}{{- else if isInterfaceSlice $attributeValue}}{{- if lt 0 (len $attributeValue)}}[{{fromInterfacesToString $attributeValue}}]{{else}}[]{{end}}{{else}}"{{$attributeValue}}"{{end}} + {{- else if (isInterfaceSlice $child_value)}} + {{- if lt 0 (len $child_value)}} + {{$child_key}} = [{{range $index, $subvalue := $child_value}}{{if lt $index (subtract (len $child_value) 1)}}"{{$subvalue}}", {{else}}"{{$subvalue}}"{{end}}{{end}}] + {{- else}} + {{$child_key}} = [] + {{- end}} {{- else if and (ne $child_key "deletable_child") (ne $child_key "child_required")}} {{$child_key}} = "{{$child_value}}" {{- end}} @@ -2537,7 +2558,7 @@ resource "aci_{{$.resourceName}}" "test" { {{- range $key, $value := $.resource_required}} {{- if eq $key "target_dn" }}{{$attributeValue := getTestTargetDn $.targets $.resourceName $value true nil 0 false}} {{$key}} = {{if isReference $attributeValue}}{{$attributeValue}}{{- else if isInterfaceSlice $attributeValue}}{{- if lt 0 (len $attributeValue)}}[{{fromInterfacesToString $attributeValue}}]{{else}}[]{{end}}{{else}}"{{$attributeValue}}"{{end}} - {{- else }} + {{- else }} {{$key}} = "{{$value}}" {{- end }} {{- end}} @@ -2610,7 +2631,13 @@ resource "aci_{{$.resourceName}}" "test" { {{- else }} {{- if eq $child_key "target_dn"}}{{$attributeValue := getTestTargetDn $.child_targets $key $child_value true nil 1 false}} {{$child_key}} = {{if isReference $attributeValue}}{{$attributeValue}}{{- else if isInterfaceSlice $attributeValue}}{{- if lt 0 (len $attributeValue)}}[{{fromInterfacesToString $attributeValue}}]{{else}}[]{{end}}{{else}}"{{$attributeValue}}"{{end}} - {{- else }} + {{- else if (isInterfaceSlice $child_value)}} + {{- if lt 0 (len $child_value)}} + {{$child_key}} = [{{range $index, $subvalue := $child_value}}{{if lt $index (subtract (len $child_value) 1)}}"{{$subvalue}}", {{else}}"{{$subvalue}}"{{end}}{{end}}] + {{- else}} + {{$child_key}} = [] + {{- end}} + {{- else }} {{$child_key}} = "{{$child_value}}" {{- end}} {{- end}} @@ -3170,16 +3197,16 @@ resource "aci_{{$.resourceName}}" "test" { {{- end }}{{- end }}), {{- end }} {{- else }} - {{- if eq $child_key "target_dn"}} + {{- if eq $child_key "target_dn"}} resource.TestCheckResourceAttr("{{$resourceName}}", "{{$inheritedKey}}.{{$key}}.{{$child_key}}", "{{getTestTargetDn $.child_targets $key $child_value false nil $child_index false}}"), - {{- else if (isInterfaceSlice $child_value)}} + {{- else if (isInterfaceSlice $child_value)}} resource.TestCheckResourceAttr("{{$resourceName}}", "{{$inheritedKey}}.{{$key}}.{{$child_key}}.#", "{{len $child_value}}"), - {{- range $index, $subvalue := $child_value}} + {{- range $index, $subvalue := $child_value}} resource.TestCheckResourceAttr("{{$resourceName}}", "{{$inheritedKey}}.{{$key}}.{{$child_key}}.{{$index}}", "{{$subvalue}}"), - {{- end}} - {{- else if and (ne $child_key "deletable_child") (ne $child_key "child_required")}} + {{- end}} + {{- else if and (ne $child_key "deletable_child") (ne $child_key "child_required")}} resource.TestCheckResourceAttr("{{$resourceName}}", "{{$inheritedKey}}.{{$key}}.{{$child_key}}", "{{$child_value}}"), - {{- end}} + {{- end}} {{- end}} {{- end}} {{- end }} @@ -3196,9 +3223,14 @@ resource "aci_{{$.resourceName}}" "test" { {{- end }}), {{- end }} {{- else }} - {{- if eq $child_key "target_dn"}} + {{- if eq $child_key "target_dn"}} resource.TestCheckResourceAttr("{{$resourceName}}", "{{$inheritedKey}}.{{$key}}.{{$child_index}}.{{$child_key}}", "{{getTestTargetDn $.child_targets $key $child_value false nil $child_index false}}"), - {{- else if and (ne $child_key "deletable_child") (ne $child_key "child_required")}} + {{- else if (isInterfaceSlice $child_value)}} + resource.TestCheckResourceAttr("{{$resourceName}}", "{{$inheritedKey}}.{{$key}}.{{$child_key}}.#", "{{len $child_value}}"), + {{- range $index, $subvalue := $child_value}} + resource.TestCheckResourceAttr("{{$resourceName}}", "{{$inheritedKey}}.{{$key}}.{{$child_key}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else if and (ne $child_key "deletable_child") (ne $child_key "child_required")}} resource.TestCheckResourceAttr("{{$resourceName}}", "{{$inheritedKey}}.{{$key}}.{{$child_index}}.{{$child_key}}", "{{$child_value}}"), {{- end}} {{- end}} From 921f245717cb9cc4b3a91cf8388397181836eb85 Mon Sep 17 00:00:00 2001 From: akinross Date: Sat, 29 Nov 2025 22:06:24 +0100 Subject: [PATCH 2/2] [minor_change] Add support for slow drain interface access policy with resource aci_slow_drain_interface_policy --- .../slow_drain_interface_policy.md | 62 ++ docs/resources/slow_drain_interface_policy.md | 132 +++ .../data-source.tf | 4 + .../provider.tf | 14 + .../provider.tf | 14 + .../resource-all-attributes.tf | 25 + .../resource.tf | 4 + gen/definitions/classes.yaml | 9 + gen/definitions/properties.yaml | 18 + gen/meta/qosSdIfPol.json | 871 ++++++++++++++++++ gen/testvars/qosSdIfPol.yaml | 54 ++ ..._source_aci_slow_drain_interface_policy.go | 177 ++++ ...ce_aci_slow_drain_interface_policy_test.go | 53 ++ internal/provider/provider.go | 2 + ...esource_aci_slow_drain_interface_policy.go | 769 ++++++++++++++++ ...ce_aci_slow_drain_interface_policy_test.go | 364 ++++++++ 16 files changed, 2572 insertions(+) create mode 100644 docs/data-sources/slow_drain_interface_policy.md create mode 100644 docs/resources/slow_drain_interface_policy.md create mode 100644 examples/data-sources/aci_slow_drain_interface_policy/data-source.tf create mode 100644 examples/data-sources/aci_slow_drain_interface_policy/provider.tf create mode 100644 examples/resources/aci_slow_drain_interface_policy/provider.tf create mode 100644 examples/resources/aci_slow_drain_interface_policy/resource-all-attributes.tf create mode 100644 examples/resources/aci_slow_drain_interface_policy/resource.tf create mode 100644 gen/meta/qosSdIfPol.json create mode 100644 gen/testvars/qosSdIfPol.yaml create mode 100644 internal/provider/data_source_aci_slow_drain_interface_policy.go create mode 100644 internal/provider/data_source_aci_slow_drain_interface_policy_test.go create mode 100644 internal/provider/resource_aci_slow_drain_interface_policy.go create mode 100644 internal/provider/resource_aci_slow_drain_interface_policy_test.go diff --git a/docs/data-sources/slow_drain_interface_policy.md b/docs/data-sources/slow_drain_interface_policy.md new file mode 100644 index 000000000..2d095054f --- /dev/null +++ b/docs/data-sources/slow_drain_interface_policy.md @@ -0,0 +1,62 @@ +--- +# Documentation 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). +subcategory: "Access Policies" +layout: "aci" +page_title: "ACI: aci_slow_drain_interface_policy" +sidebar_current: "docs-aci-data-source-aci_slow_drain_interface_policy" +description: |- + Data source for ACI Slow Drain Interface Policy +--- + +# aci_slow_drain_interface_policy # + +Data source for ACI Slow Drain Interface Policy + +## API Information ## + +* Class: [qosSdIfPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/qosSdIfPol/overview) + +* Supported in ACI versions: 2.0(1m) and later. + +* Distinguished Name Format: `uni/infra/qossdpol-{name}` + +## GUI Information ## + +* Location: `Fabric -> Access Policies -> Policies -> Interface -> Slow Drain` + +## Example Usage ## + +```hcl + +data "aci_slow_drain_interface_policy" "example" { + name = "test_name" +} + +``` + +## Schema ## + +### Required ### + +* `name` (name) - (string) The name of the Slow Drain Interface Policy object. + +### Read-Only ### + +* `id` - (string) The distinguished name (DN) of the Slow Drain Interface Policy object. +* `annotation` (annotation) - (string) The annotation of the Slow Drain Interface Policy object. This attribute is supported in ACI versions: 3.2(1l) and later. +* `congestion_clear_action` (congClearAction) - (string) The congestion clear action of the Slow Drain Interface Policy object. +* `congestion_detect_multiplier` (congDetectMult) - (string) The congestion detect multiplier of the Slow Drain Interface Policy object. The value must be in the range 1 - 10000. +* `description` (descr) - (string) The description of the Slow Drain Interface Policy object. +* `flush_admin_state` (flushAdminSt) - (string) The flush administrative state of the Slow Drain Interface Policy object. +* `flush_timeout` (flushIntvl) - (string) The flush timeout (milliseconds) of the Slow Drain Interface Policy object. The value must be in the range 100 - 1000. +* `name_alias` (nameAlias) - (string) The name alias of the Slow Drain Interface Policy object. This attribute is supported in ACI versions: 2.2(1k) and later. +* `owner_key` (ownerKey) - (string) The key for enabling clients to own their data for entity correlation. +* `owner_tag` (ownerTag) - (string) A tag for enabling clients to add their own data. For example, to indicate who created this object. +* `annotations` - (list) A list of Annotations (ACI object [tagAnnotation](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagAnnotation/overview)). This attribute is supported in ACI versions: 3.2(1l) and later. + * `key` (key) - (string) The key used to uniquely identify this configuration object. + * `value` (value) - (string) The value of the property. +* `tags` - (list) A list of Tags (ACI object [tagTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagTag/overview)). This attribute is supported in ACI versions: 3.2(1l) and later. + * `key` (key) - (string) The key used to uniquely identify this configuration object. + * `value` (value) - (string) The value of the property. diff --git a/docs/resources/slow_drain_interface_policy.md b/docs/resources/slow_drain_interface_policy.md new file mode 100644 index 000000000..95329f11b --- /dev/null +++ b/docs/resources/slow_drain_interface_policy.md @@ -0,0 +1,132 @@ +--- +# Documentation 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). +subcategory: "Access Policies" +layout: "aci" +page_title: "ACI: aci_slow_drain_interface_policy" +sidebar_current: "docs-aci-resource-aci_slow_drain_interface_policy" +description: |- + Manages ACI Slow Drain Interface Policy +--- + +# aci_slow_drain_interface_policy # + +Manages ACI Slow Drain Interface Policy + + + +## API Information ## + +* Class: [qosSdIfPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/qosSdIfPol/overview) + +* Supported in ACI versions: 2.0(1m) and later. + +* Distinguished Name Format: `uni/infra/qossdpol-{name}` + +## GUI Information ## + +* Location: `Fabric -> Access Policies -> Policies -> Interface -> Slow Drain` + +## Example Usage ## + +The configuration snippet below creates a Slow Drain Interface Policy with only required attributes. + +```hcl + +resource "aci_slow_drain_interface_policy" "example" { + name = "test_name" +} + +``` +The configuration snippet below shows all possible attributes of the Slow Drain Interface Policy. + +!> This example might not be valid configuration and is only used to show all possible attributes. + +```hcl + +resource "aci_slow_drain_interface_policy" "full_example" { + annotation = "annotation" + congestion_clear_action = "err-disable" + congestion_detect_multiplier = "15" + description = "description_1" + flush_admin_state = "disabled" + flush_timeout = "300" + name = "test_name" + name_alias = "name_alias_1" + owner_key = "owner_key_1" + owner_tag = "owner_tag_1" + annotations = [ + { + key = "key_0" + value = "value_1" + } + ] + tags = [ + { + key = "key_0" + value = "value_1" + } + ] +} + +``` + +All examples for the Slow Drain Interface Policy resource can be found in the [examples](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/examples/resources/aci_slow_drain_interface_policy) folder. + +## Schema ## + +### Required ### + +* `name` (name) - (string) The name of the Slow Drain Interface Policy object. + +### Read-Only ### + +* `id` - (string) The distinguished name (DN) of the Slow Drain Interface Policy object. + +### Optional ### + +* `annotation` (annotation) - (string) The annotation of the Slow Drain Interface Policy object. This attribute is supported in ACI versions: 3.2(1l) and later. + - Default: `"orchestrator:terraform"` +* `congestion_clear_action` (congClearAction) - (string) The congestion clear action of the Slow Drain Interface Policy object. + - Default: `"off"` + - Valid Values: `"err-disable"`, `"log"`, `"off"`. +* `congestion_detect_multiplier` (congDetectMult) - (string) The congestion detect multiplier of the Slow Drain Interface Policy object. The value must be in the range 1 - 10000. + - Default: `"10"` +* `description` (descr) - (string) The description of the Slow Drain Interface Policy object. +* `flush_admin_state` (flushAdminSt) - (string) The flush administrative state of the Slow Drain Interface Policy object. + - Default: `"disabled"` + - Valid Values: `"disabled"`, `"enabled"`. +* `flush_timeout` (flushIntvl) - (string) The flush timeout (milliseconds) of the Slow Drain Interface Policy object. The value must be in the range 100 - 1000. + - Default: `"500"` +* `name_alias` (nameAlias) - (string) The name alias of the Slow Drain Interface Policy object. This attribute is supported in ACI versions: 2.2(1k) and later. +* `owner_key` (ownerKey) - (string) The key for enabling clients to own their data for entity correlation. +* `owner_tag` (ownerTag) - (string) A tag for enabling clients to add their own data. For example, to indicate who created this object. +* `annotations` - (list) A list of Annotations (ACI object [tagAnnotation](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagAnnotation/overview)). Annotations can also be configured using a separate [aci_annotation](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/annotation) resource. This attribute is supported in ACI versions: 3.2(1l) and later. + #### Required #### + + * `key` (key) - (string) The key used to uniquely identify this configuration object. + * `value` (value) - (string) The value of the property. +* `tags` - (list) A list of Tags (ACI object [tagTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagTag/overview)). Tags can also be configured using a separate [aci_tag](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/tag) resource. This attribute is supported in ACI versions: 3.2(1l) and later. + #### Required #### + + * `key` (key) - (string) The key used to uniquely identify this configuration object. + * `value` (value) - (string) The value of the property. + +## Importing + +An existing Slow Drain Interface Policy can be [imported](https://www.terraform.io/docs/import/index.html) into this resource with its distinguished name (DN), via the following command: + +``` +terraform import aci_slow_drain_interface_policy.example uni/infra/qossdpol-{name} +``` + +Starting in Terraform version 1.5, an existing Slow Drain Interface Policy can be imported +using [import blocks](https://developer.hashicorp.com/terraform/language/import) via the following configuration: + +``` +import { + id = "uni/infra/qossdpol-{name}" + to = aci_slow_drain_interface_policy.example +} +``` diff --git a/examples/data-sources/aci_slow_drain_interface_policy/data-source.tf b/examples/data-sources/aci_slow_drain_interface_policy/data-source.tf new file mode 100644 index 000000000..d5abbf55c --- /dev/null +++ b/examples/data-sources/aci_slow_drain_interface_policy/data-source.tf @@ -0,0 +1,4 @@ + +data "aci_slow_drain_interface_policy" "example" { + name = "test_name" +} diff --git a/examples/data-sources/aci_slow_drain_interface_policy/provider.tf b/examples/data-sources/aci_slow_drain_interface_policy/provider.tf new file mode 100644 index 000000000..975fca093 --- /dev/null +++ b/examples/data-sources/aci_slow_drain_interface_policy/provider.tf @@ -0,0 +1,14 @@ +terraform { + required_providers { + aci = { + source = "ciscodevnet/aci" + } + } +} + +provider "aci" { + username = "" + password = "" + url = "" + insecure = true +} \ No newline at end of file diff --git a/examples/resources/aci_slow_drain_interface_policy/provider.tf b/examples/resources/aci_slow_drain_interface_policy/provider.tf new file mode 100644 index 000000000..975fca093 --- /dev/null +++ b/examples/resources/aci_slow_drain_interface_policy/provider.tf @@ -0,0 +1,14 @@ +terraform { + required_providers { + aci = { + source = "ciscodevnet/aci" + } + } +} + +provider "aci" { + username = "" + password = "" + url = "" + insecure = true +} \ No newline at end of file diff --git a/examples/resources/aci_slow_drain_interface_policy/resource-all-attributes.tf b/examples/resources/aci_slow_drain_interface_policy/resource-all-attributes.tf new file mode 100644 index 000000000..3bf8bada7 --- /dev/null +++ b/examples/resources/aci_slow_drain_interface_policy/resource-all-attributes.tf @@ -0,0 +1,25 @@ + +resource "aci_slow_drain_interface_policy" "full_example" { + annotation = "annotation" + congestion_clear_action = "err-disable" + congestion_detect_multiplier = "15" + description = "description_1" + flush_admin_state = "disabled" + flush_timeout = "300" + name = "test_name" + name_alias = "name_alias_1" + owner_key = "owner_key_1" + owner_tag = "owner_tag_1" + annotations = [ + { + key = "key_0" + value = "value_1" + } + ] + tags = [ + { + key = "key_0" + value = "value_1" + } + ] +} diff --git a/examples/resources/aci_slow_drain_interface_policy/resource.tf b/examples/resources/aci_slow_drain_interface_policy/resource.tf new file mode 100644 index 000000000..2af1d5e68 --- /dev/null +++ b/examples/resources/aci_slow_drain_interface_policy/resource.tf @@ -0,0 +1,4 @@ + +resource "aci_slow_drain_interface_policy" "example" { + name = "test_name" +} diff --git a/gen/definitions/classes.yaml b/gen/definitions/classes.yaml index 567a3256e..b08609b75 100644 --- a/gen/definitions/classes.yaml +++ b/gen/definitions/classes.yaml @@ -1266,3 +1266,12 @@ infraRsAccBndlSubgrp: infraAccBndlSubgrp: resource_name: "leaf_access_bundle_policy_sub_group" + +qosSdIfPol: + resource_name: "slow_drain_interface_policy" + sub_category: "Access Policies" + ui_locations: + - "Fabric -> Access Policies -> Policies -> Interface -> Slow Drain" + contained_by: + - "polUni" + rn_prepend: "infra" diff --git a/gen/definitions/properties.yaml b/gen/definitions/properties.yaml index 96af5d8a4..55257244c 100644 --- a/gen/definitions/properties.yaml +++ b/gen/definitions/properties.yaml @@ -90,6 +90,7 @@ global: Pc Vpc Override Policy: "PC VPC Override Policy" Fex: "FEX" From Attachable Access Entity Profile To Domains: "To Domains" + Dot1x: "802.1x" ignores: - "userdom" @@ -2895,3 +2896,20 @@ infraRsAccBndlSubgrp: # Response Status Code: 400, Error Code: 182, Error Message: Validation failed PortBlk has a reln to AccBndlSubgrp not contained by AccBndlGrp its parent is associated to. target_dn: "" +qosSdIfPol: + default_values: + flushAdminSt: "disabled" + overwrites: + cong_clear_action: congestion_clear_action + cong_detect_mult: congestion_detect_multiplier + flush_admin_st: flush_admin_state + flush_intvl: flush_timeout + documentation: + congClearAction: "The congestion clear action of the %s object." + congDetectMult: "The congestion detect multiplier of the %s object. The value must be in the range 1 - 10000." + flushAdminSt: "The flush administrative state of the %s object." + flushIntvl: "The flush timeout (milliseconds) of the %s object. The value must be in the range 100 - 1000." + test_values: + all: + flush_timeout: "300" + congestion_detect_multiplier: "15" diff --git a/gen/meta/qosSdIfPol.json b/gen/meta/qosSdIfPol.json new file mode 100644 index 000000000..feb95e0ff --- /dev/null +++ b/gen/meta/qosSdIfPol.json @@ -0,0 +1,871 @@ +{ + "qos:SdIfPol": { + "contains": { + "aaa:RbacAnnotation": "", + "fault:Delegate": "", + "qos:RtQosSdIfPol": "", + "qos:RtQosSdIfPolCons": "", + "tag:Annotation": "", + "tag:Tag": "" + }, + "rnMap": { + "annotationKey-": "tag:Annotation", + "fd-": "fault:Delegate", + "rbacDom-": "aaa:RbacAnnotation", + "rtinfraQosSdIfPol-": "qos:RtQosSdIfPol", + "rtl1QosSdIfPolCons-": "qos:RtQosSdIfPolCons", + "tagKey-": "tag:Tag" + }, + "identifiedBy": [ + "name" + ], + "rnFormat": "qossdpol-{name}", + "containedBy": { + "infra:Infra": "" + }, + "superClasses": [ + "pol:Def", + "pol:Obj", + "naming:NamedObject" + ], + "subClasses": { + + }, + "relationFrom": { + "qos:RtQosSdIfPol": "infra:AccGrp", + "qos:RtQosSdIfPolCons": "l1:EthIf" + }, + "relationTo": { + + }, + "dnFormats": [ + "uni/infra/qossdpol-{name}" + ], + "writeAccess": [ + "access-connectivity", + "access-qos", + "admin", + "custom-port-privilege" + ], + "readAccess": [ + "access-connectivity", + "access-qos", + "admin", + "custom-port-privilege" + ], + "faults": { + + }, + "events": { + "E4213106": "creation||qos:SdIfPol", + "E4213107": "modification||qos:SdIfPol", + "E4213108": "deletion||qos:SdIfPol" + }, + "stats": { + + }, + "versions": "2.0(1m)-", + "isAbstract": false, + "isConfigurable": true, + "isContextRoot": false, + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false, + "isEncrypted": false, + "isExportable": true, + "isPersistent": true, + "isSubjectToQuota": false, + "isObservable": false, + "hasStats": false, + "isStat": false, + "isFaultable": false, + "isDomainable": false, + "isHealthScorable": false, + "shouldCollectHealthStats": false, + "healthCollectionSource": "faults", + "hasEventRules": false, + "abstractionLayer": "logical", + "apicNxProcessing": false, + "monitoringPolicySource": "Parent", + "isCreatableDeletable": "always", + "platformFlavors": [ + "apic" + ], + "classId": "8797", + "className": "SdIfPol", + "classPkg": "qos", + "featureTag": "", + "moCategory": "Regular", + "label": "Slow Drain Policy", + "comment": [ + "Slow drain policy" + ], + "properties": { + "annotation": { + "versions": "3.2(1l)-", + "comment": [ + "User annotation. Suggested format orchestrator:value" + ], + "isConfigurable": true, + "propGlobalId": "38484", + "propLocalId": "8719", + "label": "Annotation", + "baseType": "string:Basic", + "modelType": "mo:Annotation", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validators": [ + {"min" : 0, "max": 128, + "regexs": [ + {"regex" : "^[a-zA-Z0-9_.:-]+$", "type": "include"} + ] + } + ], + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "childAction": { + "versions": "1.0(1e)-", + "comment": [ + "Delete or ignore. For internal use only." + ], + "isConfigurable": false, + "propGlobalId": "4", + "propLocalId": "5", + "label": "childAction", + "baseType": "scalar:Bitmask32", + "modelType": "mo:ModificationChildAction", + "needsPropDelimiters": false, + "uitype": "bitmask", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "16384", "localName": "deleteAll", + "platformFlavors": [ + + ], + "label": "Delete All "}, + { "value": "8192", "localName": "deleteNonPresent", + "platformFlavors": [ + + ], + "label": "Delete Non Present "}, + { "value": "4096", "localName": "ignore", + "platformFlavors": [ + + ], + "label": "Ignore "} + ], + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "congClearAction": { + "versions": "2.0(1m)-", + "isConfigurable": true, + "propGlobalId": "25464", + "propLocalId": "6076", + "label": "Congestion Clear Action", + "baseType": "scalar:Enum8", + "modelType": "l1:CongClearAction", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": true, + "likeProp": "l1:PrioFlowCtrlP:congClearAction", + "validValues": [ + { "value": "off", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "2", "localName": "err-disable", + "platformFlavors": [ + + ], + "label": "Err-disable "}, + { "value": "1", "localName": "log", + "platformFlavors": [ + + ], + "label": "Log "}, + { "value": "0", "localName": "off", + "platformFlavors": [ + + ], + "label": "Disabled "} + ], + "default": "off", + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "congDetectMult": { + "versions": "2.0(1m)-", + "isConfigurable": true, + "propGlobalId": "25463", + "propLocalId": "6075", + "label": "Congestion Detect Multiplier", + "baseType": "scalar:Uint16", + "modelType": "l1:CongDetectMult", + "needsPropDelimiters": false, + "uitype": "number", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": true, + "likeProp": "l1:PrioFlowCtrlP:congDetectMult", + "validators": [ + {"min" : 1, "max": 10000 } + ], + "validValues": [ + { "value": "10", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "} + ], + "default": 10, + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "descr": { + "versions": "1.0(1e)-", + "comment": [ + "Specifies a description of the policy definition." + ], + "isConfigurable": true, + "propGlobalId": "5579", + "propLocalId": "28", + "label": "Description", + "baseType": "string:Basic", + "modelType": "naming:Descr", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": true, + "likeProp": "naming:Described:descr", + "validators": [ + {"min" : 0, "max": 128, + "regexs": [ + {"regex" : "^[a-zA-Z0-9\\\\!#$%()*,-./:;@ _{|}~?&+]+$", "type": "include"} + ] + } + ], + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "dn": { + "versions": "1.0(1e)-", + "comment": [ + "A tag or metadata is a non-hierarchical keyword or term assigned to the fabric module." + ], + "isConfigurable": false, + "propGlobalId": "1", + "propLocalId": "2", + "label": "dn", + "baseType": "reference:BinRef", + "modelType": "reference:BinRef", + "needsPropDelimiters": true, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "extMngdBy": { + "versions": "3.2(1l)-", + "comment": [ + "Indicates which orchestrator is managing this MO" + ], + "isConfigurable": false, + "propGlobalId": "40623", + "propLocalId": "8023", + "label": "Managed By", + "baseType": "scalar:Bitmask32", + "modelType": "mo:ExtMngdByType", + "needsPropDelimiters": false, + "uitype": "bitmask", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "undefined", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "1", "localName": "msc", + "platformFlavors": [ + + ], + "label": "MSC "}, + { "value": "0", "localName": "undefined", + "platformFlavors": [ + + ], + "label": "Undefined "} + ], + "default": "undefined", + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "flushAdminSt": { + "versions": "2.0(1m)-", + "isConfigurable": true, + "propGlobalId": "25461", + "propLocalId": "6079", + "label": "Slowdrain flush mode admin state", + "baseType": "scalar:Enum8", + "modelType": "l1:PortFlushAdminSt", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": true, + "likeProp": "l1:PrioFlowCtrlP:flushAdminSt", + "validValues": [ + { "value": "false", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "0", "localName": "disabled", + "platformFlavors": [ + + ], + "label": "Disabled "}, + { "value": "1", "localName": "enabled", + "platformFlavors": [ + + ], + "label": "Enabled "} + ], + "default": "false", + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "flushIntvl": { + "versions": "2.0(1m)-", + "isConfigurable": true, + "propGlobalId": "25462", + "propLocalId": "6074", + "label": "Flush Timeout in milliseconds", + "baseType": "scalar:Uint16", + "modelType": "l1:PortFlushIntvl", + "needsPropDelimiters": false, + "uitype": "number", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": true, + "likeProp": "l1:PrioFlowCtrlP:flushIntvl", + "validators": [ + {"min" : 100, "max": 1000 } + ], + "validValues": [ + { "value": "500", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "} + ], + "default": 500, + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "lcOwn": { + "versions": "1.0(1e)-", + "comment": [ + "A value that indicates how this object was created. For internal use only." + ], + "isConfigurable": false, + "propGlobalId": "9", + "propLocalId": "9", + "label": "lcOwn", + "baseType": "scalar:Enum8", + "modelType": "mo:Owner", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "local", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "4", "localName": "implicit", + "platformFlavors": [ + + ], + "label": "Implicit "}, + { "value": "0", "localName": "local", + "platformFlavors": [ + + ], + "label": "Local "}, + { "value": "1", "localName": "policy", + "platformFlavors": [ + + ], + "label": "Policy "}, + { "value": "2", "localName": "replica", + "platformFlavors": [ + + ], + "label": "Replica "}, + { "value": "3", "localName": "resolveOnBehalf", + "platformFlavors": [ + + ], + "label": "Resolved On Behalf "} + ], + "default": "local", + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "modTs": { + "versions": "1.0(1e)-", + "comment": [ + "The time when this object was last modified." + ], + "isConfigurable": false, + "propGlobalId": "7", + "propLocalId": "7", + "label": "modTs", + "baseType": "scalar:Date", + "modelType": "mo:TStamp", + "needsPropDelimiters": false, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "never", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "0", "localName": "never", + "platformFlavors": [ + + ], + "label": "Never "} + ], + "default": "never", + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "name": { + "versions": "2.0(1m)-", + "comment": [ + "The name of the object." + ], + "isConfigurable": true, + "propGlobalId": "25567", + "propLocalId": "13", + "label": "Name", + "baseType": "string:Basic", + "modelType": "naming:Name", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": false, + "readOnly": false, + "isNaming": true, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": true, + "isLike": false, + "validators": [ + {"min" : 1, "max": 64, + "regexs": [ + {"regex" : "^[a-zA-Z0-9_.:-]+$", "type": "include"} + ] + } + ], + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "nameAlias": { + "versions": "2.2(1k)-", + "isConfigurable": true, + "propGlobalId": "28417", + "propLocalId": "6719", + "label": "Display Name", + "baseType": "string:Basic", + "modelType": "naming:NameAlias", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validators": [ + {"min" : 0, "max": 63, + "regexs": [ + {"regex" : "^[a-zA-Z0-9_.-]+$", "type": "include"} + ] + } + ], + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "ownerKey": { + "versions": "1.0(1e)-", + "comment": [ + "The key for enabling clients to own their data for entity correlation." + ], + "isConfigurable": true, + "propGlobalId": "15230", + "propLocalId": "4100", + "label": "ownerKey", + "baseType": "string:Basic", + "modelType": "naming:Descr", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validators": [ + {"min" : 0, "max": 128, + "regexs": [ + {"regex" : "^[a-zA-Z0-9\\\\!#$%()*,-./:;@ _{|}~?&+]+$", "type": "include"} + ] + } + ], + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "ownerTag": { + "versions": "1.0(1e)-", + "comment": [ + "A tag for enabling clients to add their own data. For example, to indicate who created this object." + ], + "isConfigurable": true, + "propGlobalId": "15231", + "propLocalId": "4101", + "label": "ownerTag", + "baseType": "string:Basic", + "modelType": "naming:Descr", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validators": [ + {"min" : 0, "max": 64, + "regexs": [ + {"regex" : "^[a-zA-Z0-9\\\\!#$%()*,-./:;@ _{|}~?&+]+$", "type": "include"} + ] + } + ], + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "rn": { + "versions": "1.0(1e)-", + "comment": [ + "Identifies an object from its siblings within the context of its parent object. The distinguished name contains a sequence of relative names." + ], + "isConfigurable": false, + "propGlobalId": "2", + "propLocalId": "3", + "label": "rn", + "baseType": "reference:BinRN", + "modelType": "reference:BinRN", + "needsPropDelimiters": true, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "status": { + "versions": "1.0(1e)-", + "comment": [ + "The upgrade status. This property is for internal use only." + ], + "isConfigurable": false, + "propGlobalId": "3", + "propLocalId": "4", + "label": "status", + "baseType": "scalar:Bitmask32", + "modelType": "mo:ModificationStatus", + "needsPropDelimiters": false, + "uitype": "bitmask", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "2", "localName": "created", + "platformFlavors": [ + + ], + "comment": [ + "In a setter method: specifies that an object should be created. An error is returned if the object already exists. \nIn the return value of a setter method: indicates that an object has been created. \n" + ], + "label": "Created "}, + { "value": "8", "localName": "deleted", + "platformFlavors": [ + + ], + "comment": [ + "In a setter method: specifies that an object should be deleted. \nIn the return value of a setter method: indicates that an object has been deleted.\n" + ], + "label": "Deleted "}, + { "value": "4", "localName": "modified", + "platformFlavors": [ + + ], + "comment": [ + "In a setter method: specifies that an object should be modified \nIn the return value of a setter method: indicates that an object has been modified.\n" + ], + "label": "Modified "} + ], + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "uid": { + "versions": "1.0(1e)-", + "comment": [ + "A unique identifier for this object." + ], + "isConfigurable": false, + "propGlobalId": "8", + "propLocalId": "8", + "label": "uid", + "baseType": "scalar:Uint16", + "modelType": "scalar:Uint16", + "needsPropDelimiters": false, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "userdom": { + "versions": "5.0(1k)-", + "isConfigurable": true, + "propGlobalId": "60657", + "propLocalId": "13244", + "label": "userdom", + "baseType": "string:Basic", + "modelType": "mo:UserDomType", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validators": [ + {"min" : 0, "max": 1024, + "regexs": [ + {"regex" : "^[a-zA-Z0-9_.:-]+$", "type": "include"} + ] + } + ], + "validValues": [ + { "value": "all", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "} + ], + "default": "all", + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + } + } + } +} diff --git a/gen/testvars/qosSdIfPol.yaml b/gen/testvars/qosSdIfPol.yaml new file mode 100644 index 000000000..d25318747 --- /dev/null +++ b/gen/testvars/qosSdIfPol.yaml @@ -0,0 +1,54 @@ +# 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). + + +default: + annotation: "orchestrator:terraform" + congestion_clear_action: "off" + congestion_detect_multiplier: "10" + description: "" + flush_admin_state: "disabled" + flush_timeout: "500" + name_alias: "" + owner_key: "" + owner_tag: "" + +datasource_non_existing: + name: "non_existing_name" + +datasource_required: + name: "test_name" + +resource_required: + name: "test_name" + +all: + annotation: "annotation" + congestion_clear_action: "err-disable" + congestion_detect_multiplier: "15" + description: "description_1" + flush_admin_state: "disabled" + flush_timeout: "300" + name_alias: "name_alias_1" + owner_key: "owner_key_1" + owner_tag: "owner_tag_1" + +children: + annotations: + - key: "key_0" + value: "value_1" + + - key: "key_1" + value: "test_value" + + tags: + - key: "key_0" + value: "value_1" + + - key: "key_1" + value: "test_value" + + +test_type: apic +class_version: 2.0(1m)- diff --git a/internal/provider/data_source_aci_slow_drain_interface_policy.go b/internal/provider/data_source_aci_slow_drain_interface_policy.go new file mode 100644 index 000000000..5193acc59 --- /dev/null +++ b/internal/provider/data_source_aci_slow_drain_interface_policy.go @@ -0,0 +1,177 @@ +// 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 provider + +import ( + "context" + "fmt" + + "github.com/ciscoecosystem/aci-go-client/v2/client" + + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var _ datasource.DataSource = &QosSdIfPolDataSource{} + +func NewQosSdIfPolDataSource() datasource.DataSource { + return &QosSdIfPolDataSource{} +} + +// QosSdIfPolDataSource defines the data source implementation. +type QosSdIfPolDataSource struct { + client *client.Client +} + +func (d *QosSdIfPolDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + tflog.Debug(ctx, "Start metadata of datasource: aci_slow_drain_interface_policy") + resp.TypeName = req.ProviderTypeName + "_slow_drain_interface_policy" + tflog.Debug(ctx, "End metadata of datasource: aci_slow_drain_interface_policy") +} + +func (d *QosSdIfPolDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + tflog.Debug(ctx, "Start schema of datasource: aci_slow_drain_interface_policy") + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: "The slow_drain_interface_policy datasource for the 'qosSdIfPol' class", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + MarkdownDescription: "The distinguished name (DN) of the Slow Drain Interface Policy object.", + }, + "annotation": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The annotation of the Slow Drain Interface Policy object.`, + }, + "congestion_clear_action": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The congestion clear action of the Slow Drain Interface Policy object.`, + }, + "congestion_detect_multiplier": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The congestion detect multiplier of the Slow Drain Interface Policy object. The value must be in the range 1 - 10000.`, + }, + "description": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The description of the Slow Drain Interface Policy object.`, + }, + "flush_admin_state": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The flush administrative state of the Slow Drain Interface Policy object.`, + }, + "flush_timeout": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The flush timeout (milliseconds) of the Slow Drain Interface Policy object. The value must be in the range 100 - 1000.`, + }, + "name": schema.StringAttribute{ + Required: true, + MarkdownDescription: `The name of the Slow Drain Interface Policy object.`, + }, + "name_alias": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The name alias of the Slow Drain Interface Policy object.`, + }, + "owner_key": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The key for enabling clients to own their data for entity correlation.`, + }, + "owner_tag": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `A tag for enabling clients to add their own data. For example, to indicate who created this object.`, + }, + "annotations": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "key": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The key used to uniquely identify this configuration object.`, + }, + "value": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The value of the property.`, + }, + }, + }, + }, + "tags": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "key": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The key used to uniquely identify this configuration object.`, + }, + "value": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The value of the property.`, + }, + }, + }, + }, + }, + } + tflog.Debug(ctx, "End schema of datasource: aci_slow_drain_interface_policy") +} + +func (d *QosSdIfPolDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + tflog.Debug(ctx, "Start configure of datasource: aci_slow_drain_interface_policy") + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + client, ok := req.ProviderData.(*client.Client) + + if !ok { + resp.Diagnostics.AddError( + "Unexpected Data Source Configure Type", + fmt.Sprintf("Expected *client.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + + return + } + + d.client = client + tflog.Debug(ctx, "End configure of datasource: aci_slow_drain_interface_policy") +} + +func (d *QosSdIfPolDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + tflog.Debug(ctx, "Start read of datasource: aci_slow_drain_interface_policy") + var data *QosSdIfPolResourceModel + + // Read Terraform configuration data into the model + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + setQosSdIfPolId(ctx, data) + + // Create a copy of the Id for when not found during getAndSetQosSdIfPolAttributes + cachedId := data.Id.ValueString() + + tflog.Debug(ctx, fmt.Sprintf("Read of datasource aci_slow_drain_interface_policy with id '%s'", data.Id.ValueString())) + + getAndSetQosSdIfPolAttributes(ctx, &resp.Diagnostics, d.client, data) + + if data.Id.IsNull() { + resp.Diagnostics.AddError( + "Failed to read aci_slow_drain_interface_policy data source", + fmt.Sprintf("The aci_slow_drain_interface_policy data source with id '%s' has not been found", cachedId), + ) + return + } + + // Save data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + tflog.Debug(ctx, fmt.Sprintf("End read of datasource aci_slow_drain_interface_policy with id '%s'", data.Id.ValueString())) +} diff --git a/internal/provider/data_source_aci_slow_drain_interface_policy_test.go b/internal/provider/data_source_aci_slow_drain_interface_policy_test.go new file mode 100644 index 000000000..6d6ddc4d8 --- /dev/null +++ b/internal/provider/data_source_aci_slow_drain_interface_policy_test.go @@ -0,0 +1,53 @@ +// 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 provider + +import ( + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccDataSourceQosSdIfPol(t *testing.T) { + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testConfigQosSdIfPolDataSource, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.aci_slow_drain_interface_policy.test", "annotation", "annotation"), + resource.TestCheckResourceAttr("data.aci_slow_drain_interface_policy.test", "congestion_clear_action", "err-disable"), + resource.TestCheckResourceAttr("data.aci_slow_drain_interface_policy.test", "congestion_detect_multiplier", "15"), + resource.TestCheckResourceAttr("data.aci_slow_drain_interface_policy.test", "description", "description_1"), + resource.TestCheckResourceAttr("data.aci_slow_drain_interface_policy.test", "flush_admin_state", "disabled"), + resource.TestCheckResourceAttr("data.aci_slow_drain_interface_policy.test", "flush_timeout", "300"), + resource.TestCheckResourceAttr("data.aci_slow_drain_interface_policy.test", "name_alias", "name_alias_1"), + resource.TestCheckResourceAttr("data.aci_slow_drain_interface_policy.test", "owner_key", "owner_key_1"), + resource.TestCheckResourceAttr("data.aci_slow_drain_interface_policy.test", "owner_tag", "owner_tag_1"), + ), + }, + { + Config: testConfigQosSdIfPolNotExisting, + ExpectError: regexp.MustCompile("Failed to read aci_slow_drain_interface_policy data source"), + }, + }, + }) +} + +const testConfigQosSdIfPolDataSource = testConfigQosSdIfPolAll + ` +data "aci_slow_drain_interface_policy" "test" { + name = "test_name" + depends_on = [aci_slow_drain_interface_policy.test] +} +` + +const testConfigQosSdIfPolNotExisting = testConfigQosSdIfPolAll + ` +data "aci_slow_drain_interface_policy" "test_non_existing" { + name = "non_existing_name" +} +` diff --git a/internal/provider/provider.go b/internal/provider/provider.go index d2b05da06..9373a84b4 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -288,6 +288,7 @@ func (p *AciProvider) Resources(ctx context.Context) []func() resource.Resource NewQosDot1PClassResource, NewQosDppPolResource, NewQosDscpClassResource, + NewQosSdIfPolResource, NewRtctrlProfileResource, NewTagAnnotationResource, NewTagTagResource, @@ -391,6 +392,7 @@ func (p *AciProvider) DataSources(ctx context.Context) []func() datasource.DataS NewQosDot1PClassDataSource, NewQosDppPolDataSource, NewQosDscpClassDataSource, + NewQosSdIfPolDataSource, NewRtctrlProfileDataSource, NewTagAnnotationDataSource, NewTagTagDataSource, diff --git a/internal/provider/resource_aci_slow_drain_interface_policy.go b/internal/provider/resource_aci_slow_drain_interface_policy.go new file mode 100644 index 000000000..798d80a2b --- /dev/null +++ b/internal/provider/resource_aci_slow_drain_interface_policy.go @@ -0,0 +1,769 @@ +// 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 provider + +import ( + "context" + "encoding/json" + "fmt" + "strings" + + "github.com/ciscoecosystem/aci-go-client/v2/client" + "github.com/ciscoecosystem/aci-go-client/v2/container" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var _ resource.Resource = &QosSdIfPolResource{} +var _ resource.ResourceWithImportState = &QosSdIfPolResource{} + +func NewQosSdIfPolResource() resource.Resource { + return &QosSdIfPolResource{} +} + +// QosSdIfPolResource defines the resource implementation. +type QosSdIfPolResource struct { + client *client.Client +} + +// QosSdIfPolResourceModel describes the resource data model. +type QosSdIfPolResourceModel struct { + Id types.String `tfsdk:"id"` + Annotation types.String `tfsdk:"annotation"` + CongClearAction types.String `tfsdk:"congestion_clear_action"` + CongDetectMult types.String `tfsdk:"congestion_detect_multiplier"` + Descr types.String `tfsdk:"description"` + FlushAdminSt types.String `tfsdk:"flush_admin_state"` + FlushIntvl types.String `tfsdk:"flush_timeout"` + Name types.String `tfsdk:"name"` + NameAlias types.String `tfsdk:"name_alias"` + OwnerKey types.String `tfsdk:"owner_key"` + OwnerTag types.String `tfsdk:"owner_tag"` + TagAnnotation types.Set `tfsdk:"annotations"` + TagTag types.Set `tfsdk:"tags"` +} + +func getEmptyQosSdIfPolResourceModel() *QosSdIfPolResourceModel { + return &QosSdIfPolResourceModel{ + Id: basetypes.NewStringNull(), + Annotation: basetypes.NewStringNull(), + CongClearAction: basetypes.NewStringNull(), + CongDetectMult: basetypes.NewStringNull(), + Descr: basetypes.NewStringNull(), + FlushAdminSt: basetypes.NewStringNull(), + FlushIntvl: basetypes.NewStringNull(), + Name: basetypes.NewStringNull(), + NameAlias: basetypes.NewStringNull(), + OwnerKey: basetypes.NewStringNull(), + OwnerTag: basetypes.NewStringNull(), + TagAnnotation: types.SetNull(types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "key": types.StringType, + "value": types.StringType, + }, + }), + TagTag: types.SetNull(types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "key": types.StringType, + "value": types.StringType, + }, + }), + } +} + +// TagAnnotationQosSdIfPolResourceModel describes the resource data model for the children without relation ships. +type TagAnnotationQosSdIfPolResourceModel struct { + Key types.String `tfsdk:"key"` + Value types.String `tfsdk:"value"` +} + +func getEmptyTagAnnotationQosSdIfPolResourceModel() TagAnnotationQosSdIfPolResourceModel { + return TagAnnotationQosSdIfPolResourceModel{ + Key: basetypes.NewStringNull(), + Value: basetypes.NewStringNull(), + } +} + +var TagAnnotationQosSdIfPolType = types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "key": types.StringType, + "value": types.StringType, + }, +} + +// TagTagQosSdIfPolResourceModel describes the resource data model for the children without relation ships. +type TagTagQosSdIfPolResourceModel struct { + Key types.String `tfsdk:"key"` + Value types.String `tfsdk:"value"` +} + +func getEmptyTagTagQosSdIfPolResourceModel() TagTagQosSdIfPolResourceModel { + return TagTagQosSdIfPolResourceModel{ + Key: basetypes.NewStringNull(), + Value: basetypes.NewStringNull(), + } +} + +var TagTagQosSdIfPolType = types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "key": types.StringType, + "value": types.StringType, + }, +} + +type QosSdIfPolIdentifier struct { + Name types.String +} + +func (r *QosSdIfPolResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if !req.Plan.Raw.IsNull() { + var planData, stateData *QosSdIfPolResourceModel + resp.Diagnostics.Append(req.Plan.Get(ctx, &planData)...) + resp.Diagnostics.Append(req.State.Get(ctx, &stateData)...) + + if resp.Diagnostics.HasError() { + return + } + + if (planData.Id.IsUnknown() || planData.Id.IsNull()) && !planData.Name.IsUnknown() { + setQosSdIfPolId(ctx, planData) + } + + if stateData == nil && !globalAllowExistingOnCreate && !planData.Id.IsUnknown() && !planData.Id.IsNull() { + CheckDn(ctx, &resp.Diagnostics, r.client, "qosSdIfPol", planData.Id.ValueString()) + if resp.Diagnostics.HasError() { + return + } + } + + resp.Diagnostics.Append(resp.Plan.Set(ctx, &planData)...) + } +} + +func (r *QosSdIfPolResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + tflog.Debug(ctx, "Start metadata of resource: aci_slow_drain_interface_policy") + resp.TypeName = req.ProviderTypeName + "_slow_drain_interface_policy" + tflog.Debug(ctx, "End metadata of resource: aci_slow_drain_interface_policy") +} + +func (r *QosSdIfPolResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + tflog.Debug(ctx, "Start schema of resource: aci_slow_drain_interface_policy") + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: "The slow_drain_interface_policy resource for the 'qosSdIfPol' class", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + MarkdownDescription: "The distinguished name (DN) of the Slow Drain Interface Policy object.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "annotation": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + Default: stringdefault.StaticString(globalAnnotation), + MarkdownDescription: `The annotation of the Slow Drain Interface Policy object.`, + }, + "congestion_clear_action": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + Validators: []validator.String{ + stringvalidator.OneOf("err-disable", "log", "off"), + }, + MarkdownDescription: `The congestion clear action of the Slow Drain Interface Policy object.`, + }, + "congestion_detect_multiplier": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `The congestion detect multiplier of the Slow Drain Interface Policy object. The value must be in the range 1 - 10000.`, + }, + "description": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `The description of the Slow Drain Interface Policy object.`, + }, + "flush_admin_state": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + Validators: []validator.String{ + stringvalidator.OneOf("disabled", "enabled"), + }, + MarkdownDescription: `The flush administrative state of the Slow Drain Interface Policy object.`, + }, + "flush_timeout": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `The flush timeout (milliseconds) of the Slow Drain Interface Policy object. The value must be in the range 100 - 1000.`, + }, + "name": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + stringplanmodifier.RequiresReplace(), + }, + MarkdownDescription: `The name of the Slow Drain Interface Policy object.`, + }, + "name_alias": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `The name alias of the Slow Drain Interface Policy object.`, + }, + "owner_key": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `The key for enabling clients to own their data for entity correlation.`, + }, + "owner_tag": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `A tag for enabling clients to add their own data. For example, to indicate who created this object.`, + }, + "annotations": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Set{ + setplanmodifier.UseStateForUnknown(), + }, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "key": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The key used to uniquely identify this configuration object.`, + }, + "value": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The value of the property.`, + }, + }, + }, + }, + "tags": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Set{ + setplanmodifier.UseStateForUnknown(), + }, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "key": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The key used to uniquely identify this configuration object.`, + }, + "value": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The value of the property.`, + }, + }, + }, + }, + }, + } + tflog.Debug(ctx, "End schema of resource: aci_slow_drain_interface_policy") +} + +func (r *QosSdIfPolResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + tflog.Debug(ctx, "Start configure of resource: aci_slow_drain_interface_policy") + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + client, ok := req.ProviderData.(*client.Client) + + if !ok { + resp.Diagnostics.AddError( + "Unexpected Resource Configure Type", + fmt.Sprintf("Expected *client.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + + return + } + + r.client = client + tflog.Debug(ctx, "End configure of resource: aci_slow_drain_interface_policy") +} + +func (r *QosSdIfPolResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + tflog.Debug(ctx, "Start create of resource: aci_slow_drain_interface_policy") + // On create retrieve information on current state prior to making any changes in order to determine child delete operations + var stateData *QosSdIfPolResourceModel + resp.Diagnostics.Append(req.Plan.Get(ctx, &stateData)...) + if stateData.Id.IsUnknown() || stateData.Id.IsNull() { + setQosSdIfPolId(ctx, stateData) + } + getAndSetQosSdIfPolAttributes(ctx, &resp.Diagnostics, r.client, stateData) + if !globalAllowExistingOnCreate && !stateData.Id.IsNull() { + resp.Diagnostics.AddError( + "Object Already Exists", + fmt.Sprintf("The qosSdIfPol object with DN '%s' already exists.", stateData.Id.ValueString()), + ) + return + } + + var data *QosSdIfPolResourceModel + + // Read Terraform plan data into the model + resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + if data.Id.IsUnknown() || data.Id.IsNull() { + setQosSdIfPolId(ctx, data) + } + + tflog.Debug(ctx, fmt.Sprintf("Create of resource aci_slow_drain_interface_policy with id '%s'", data.Id.ValueString())) + + var tagAnnotationPlan, tagAnnotationState []TagAnnotationQosSdIfPolResourceModel + data.TagAnnotation.ElementsAs(ctx, &tagAnnotationPlan, false) + stateData.TagAnnotation.ElementsAs(ctx, &tagAnnotationState, false) + var tagTagPlan, tagTagState []TagTagQosSdIfPolResourceModel + data.TagTag.ElementsAs(ctx, &tagTagPlan, false) + stateData.TagTag.ElementsAs(ctx, &tagTagState, false) + jsonPayload := getQosSdIfPolCreateJsonPayload(ctx, &resp.Diagnostics, true, data, tagAnnotationPlan, tagAnnotationState, tagTagPlan, tagTagState) + + if resp.Diagnostics.HasError() { + return + } + + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + + if resp.Diagnostics.HasError() { + return + } + + getAndSetQosSdIfPolAttributes(ctx, &resp.Diagnostics, r.client, data) + + // Save data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_slow_drain_interface_policy with id '%s'", data.Id.ValueString())) +} + +func (r *QosSdIfPolResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + tflog.Debug(ctx, "Start read of resource: aci_slow_drain_interface_policy") + var data *QosSdIfPolResourceModel + + // Read Terraform prior state data into the model + resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("Read of resource aci_slow_drain_interface_policy with id '%s'", data.Id.ValueString())) + + getAndSetQosSdIfPolAttributes(ctx, &resp.Diagnostics, r.client, data) + + // Save updated data into Terraform state + if data.Id.IsNull() { + var emptyData *QosSdIfPolResourceModel + resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) + } else { + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + } + + tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_slow_drain_interface_policy with id '%s'", data.Id.ValueString())) +} + +func (r *QosSdIfPolResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + tflog.Debug(ctx, "Start update of resource: aci_slow_drain_interface_policy") + var data *QosSdIfPolResourceModel + var stateData *QosSdIfPolResourceModel + + // Read Terraform plan data into the model + resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) + resp.Diagnostics.Append(req.State.Get(ctx, &stateData)...) + + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("Update of resource aci_slow_drain_interface_policy with id '%s'", data.Id.ValueString())) + + var tagAnnotationPlan, tagAnnotationState []TagAnnotationQosSdIfPolResourceModel + data.TagAnnotation.ElementsAs(ctx, &tagAnnotationPlan, false) + stateData.TagAnnotation.ElementsAs(ctx, &tagAnnotationState, false) + var tagTagPlan, tagTagState []TagTagQosSdIfPolResourceModel + data.TagTag.ElementsAs(ctx, &tagTagPlan, false) + stateData.TagTag.ElementsAs(ctx, &tagTagState, false) + jsonPayload := getQosSdIfPolCreateJsonPayload(ctx, &resp.Diagnostics, false, data, tagAnnotationPlan, tagAnnotationState, tagTagPlan, tagTagState) + + if resp.Diagnostics.HasError() { + return + } + + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + + if resp.Diagnostics.HasError() { + return + } + + getAndSetQosSdIfPolAttributes(ctx, &resp.Diagnostics, r.client, data) + + // Save updated data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_slow_drain_interface_policy with id '%s'", data.Id.ValueString())) +} + +func (r *QosSdIfPolResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + tflog.Debug(ctx, "Start delete of resource: aci_slow_drain_interface_policy") + var data *QosSdIfPolResourceModel + + // Read Terraform prior state data into the model + resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("Delete of resource aci_slow_drain_interface_policy with id '%s'", data.Id.ValueString())) + jsonPayload := GetDeleteJsonPayload(ctx, &resp.Diagnostics, "qosSdIfPol", data.Id.ValueString()) + if resp.Diagnostics.HasError() { + return + } + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { + return + } + tflog.Debug(ctx, fmt.Sprintf("End delete of resource aci_slow_drain_interface_policy with id '%s'", data.Id.ValueString())) +} + +func (r *QosSdIfPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + tflog.Debug(ctx, "Start import state of resource: aci_slow_drain_interface_policy") + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + + var stateData *QosSdIfPolResourceModel + resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_slow_drain_interface_policy with id '%s'", stateData.Id.ValueString())) + + tflog.Debug(ctx, "End import of state resource: aci_slow_drain_interface_policy") +} + +func getAndSetQosSdIfPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *QosSdIfPolResourceModel) { + requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "qosSdIfPol,tagAnnotation,tagTag"), "GET", nil) + + readData := getEmptyQosSdIfPolResourceModel() + + if diags.HasError() { + return + } + if requestData.Search("imdata").Search("qosSdIfPol").Data() != nil { + classReadInfo := requestData.Search("imdata").Search("qosSdIfPol").Data().([]interface{}) + if len(classReadInfo) == 1 { + attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) + for attributeName, attributeValue := range attributes { + if attributeName == "dn" { + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "annotation" { + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "congClearAction" { + readData.CongClearAction = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "congDetectMult" { + readData.CongDetectMult = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "descr" { + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "flushAdminSt" { + readData.FlushAdminSt = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "flushIntvl" { + readData.FlushIntvl = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "name" { + readData.Name = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "nameAlias" { + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "ownerKey" { + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "ownerTag" { + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + } + } + TagAnnotationQosSdIfPolList := make([]TagAnnotationQosSdIfPolResourceModel, 0) + TagTagQosSdIfPolList := make([]TagTagQosSdIfPolResourceModel, 0) + _, ok := classReadInfo[0].(map[string]interface{})["children"] + if ok { + children := classReadInfo[0].(map[string]interface{})["children"].([]interface{}) + for _, child := range children { + for childClassName, childClassDetails := range child.(map[string]interface{}) { + childAttributes := childClassDetails.(map[string]interface{})["attributes"].(map[string]interface{}) + if childClassName == "tagAnnotation" { + TagAnnotationQosSdIfPol := getEmptyTagAnnotationQosSdIfPolResourceModel() + for childAttributeName, childAttributeValue := range childAttributes { + if childAttributeName == "key" { + TagAnnotationQosSdIfPol.Key = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "value" { + TagAnnotationQosSdIfPol.Value = basetypes.NewStringValue(childAttributeValue.(string)) + } + + } + TagAnnotationQosSdIfPolList = append(TagAnnotationQosSdIfPolList, TagAnnotationQosSdIfPol) + } + if childClassName == "tagTag" { + TagTagQosSdIfPol := getEmptyTagTagQosSdIfPolResourceModel() + for childAttributeName, childAttributeValue := range childAttributes { + if childAttributeName == "key" { + TagTagQosSdIfPol.Key = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "value" { + TagTagQosSdIfPol.Value = basetypes.NewStringValue(childAttributeValue.(string)) + } + + } + TagTagQosSdIfPolList = append(TagTagQosSdIfPolList, TagTagQosSdIfPol) + } + } + } + } + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationQosSdIfPolList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagQosSdIfPolList) + readData.TagTag = tagTagSet + } else { + diags.AddError( + "too many results in response", + fmt.Sprintf("%v matches returned for class 'qosSdIfPol'. Please report this issue to the provider developers.", len(classReadInfo)), + ) + } + } else { + readData.Id = basetypes.NewStringNull() + } + *data = *readData +} + +func getQosSdIfPolRn(ctx context.Context, data *QosSdIfPolResourceModel) string { + return fmt.Sprintf("infra/qossdpol-%s", data.Name.ValueString()) +} + +func setQosSdIfPolId(ctx context.Context, data *QosSdIfPolResourceModel) { + rn := getQosSdIfPolRn(ctx, data) + data.Id = types.StringValue(fmt.Sprintf("%s/%s", strings.Split([]string{"uni/infra/qossdpol-{name}"}[0], "/")[0], rn)) +} + +func getQosSdIfPolTagAnnotationChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *QosSdIfPolResourceModel, tagAnnotationQosSdIfPolPlan, tagAnnotationQosSdIfPolState []TagAnnotationQosSdIfPolResourceModel) []map[string]interface{} { + childPayloads := []map[string]interface{}{} + if !data.TagAnnotation.IsNull() && !data.TagAnnotation.IsUnknown() { + tagAnnotationIdentifiers := []TagAnnotationIdentifier{} + for _, tagAnnotationQosSdIfPol := range tagAnnotationQosSdIfPolPlan { + childMap := NewAciObject() + if !tagAnnotationQosSdIfPol.Key.IsNull() && !tagAnnotationQosSdIfPol.Key.IsUnknown() { + childMap.Attributes["key"] = tagAnnotationQosSdIfPol.Key.ValueString() + } + if !tagAnnotationQosSdIfPol.Value.IsNull() && !tagAnnotationQosSdIfPol.Value.IsUnknown() { + childMap.Attributes["value"] = tagAnnotationQosSdIfPol.Value.ValueString() + } + childPayloads = append(childPayloads, map[string]interface{}{"tagAnnotation": childMap}) + tagAnnotationIdentifier := TagAnnotationIdentifier{} + tagAnnotationIdentifier.Key = tagAnnotationQosSdIfPol.Key + tagAnnotationIdentifiers = append(tagAnnotationIdentifiers, tagAnnotationIdentifier) + } + for _, tagAnnotation := range tagAnnotationQosSdIfPolState { + delete := true + for _, tagAnnotationIdentifier := range tagAnnotationIdentifiers { + if tagAnnotationIdentifier.Key == tagAnnotation.Key { + delete = false + break + } + } + if delete { + tagAnnotationChildMapForDelete := NewAciObject() + tagAnnotationChildMapForDelete.Attributes["status"] = "deleted" + tagAnnotationChildMapForDelete.Attributes["key"] = tagAnnotation.Key.ValueString() + childPayloads = append(childPayloads, map[string]interface{}{"tagAnnotation": tagAnnotationChildMapForDelete}) + } + } + } else { + data.TagAnnotation = types.SetNull(data.TagAnnotation.ElementType(ctx)) + } + + return childPayloads +} + +func getQosSdIfPolTagTagChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *QosSdIfPolResourceModel, tagTagQosSdIfPolPlan, tagTagQosSdIfPolState []TagTagQosSdIfPolResourceModel) []map[string]interface{} { + childPayloads := []map[string]interface{}{} + if !data.TagTag.IsNull() && !data.TagTag.IsUnknown() { + tagTagIdentifiers := []TagTagIdentifier{} + for _, tagTagQosSdIfPol := range tagTagQosSdIfPolPlan { + childMap := NewAciObject() + if !tagTagQosSdIfPol.Key.IsNull() && !tagTagQosSdIfPol.Key.IsUnknown() { + childMap.Attributes["key"] = tagTagQosSdIfPol.Key.ValueString() + } + if !tagTagQosSdIfPol.Value.IsNull() && !tagTagQosSdIfPol.Value.IsUnknown() { + childMap.Attributes["value"] = tagTagQosSdIfPol.Value.ValueString() + } + childPayloads = append(childPayloads, map[string]interface{}{"tagTag": childMap}) + tagTagIdentifier := TagTagIdentifier{} + tagTagIdentifier.Key = tagTagQosSdIfPol.Key + tagTagIdentifiers = append(tagTagIdentifiers, tagTagIdentifier) + } + for _, tagTag := range tagTagQosSdIfPolState { + delete := true + for _, tagTagIdentifier := range tagTagIdentifiers { + if tagTagIdentifier.Key == tagTag.Key { + delete = false + break + } + } + if delete { + tagTagChildMapForDelete := NewAciObject() + tagTagChildMapForDelete.Attributes["status"] = "deleted" + tagTagChildMapForDelete.Attributes["key"] = tagTag.Key.ValueString() + childPayloads = append(childPayloads, map[string]interface{}{"tagTag": tagTagChildMapForDelete}) + } + } + } else { + data.TagTag = types.SetNull(data.TagTag.ElementType(ctx)) + } + + return childPayloads +} + +func getQosSdIfPolCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, createType bool, data *QosSdIfPolResourceModel, tagAnnotationPlan, tagAnnotationState []TagAnnotationQosSdIfPolResourceModel, tagTagPlan, tagTagState []TagTagQosSdIfPolResourceModel) *container.Container { + payloadMap := map[string]interface{}{} + payloadMap["attributes"] = map[string]string{} + + if createType && !globalAllowExistingOnCreate { + payloadMap["attributes"].(map[string]string)["status"] = "created" + } + childPayloads := []map[string]interface{}{} + + TagAnnotationchildPayloads := getQosSdIfPolTagAnnotationChildPayloads(ctx, diags, data, tagAnnotationPlan, tagAnnotationState) + if TagAnnotationchildPayloads == nil { + return nil + } + childPayloads = append(childPayloads, TagAnnotationchildPayloads...) + + TagTagchildPayloads := getQosSdIfPolTagTagChildPayloads(ctx, diags, data, tagTagPlan, tagTagState) + if TagTagchildPayloads == nil { + return nil + } + childPayloads = append(childPayloads, TagTagchildPayloads...) + + payloadMap["children"] = childPayloads + if !data.Annotation.IsNull() && !data.Annotation.IsUnknown() { + payloadMap["attributes"].(map[string]string)["annotation"] = data.Annotation.ValueString() + } + if !data.CongClearAction.IsNull() && !data.CongClearAction.IsUnknown() { + payloadMap["attributes"].(map[string]string)["congClearAction"] = data.CongClearAction.ValueString() + } + if !data.CongDetectMult.IsNull() && !data.CongDetectMult.IsUnknown() { + payloadMap["attributes"].(map[string]string)["congDetectMult"] = data.CongDetectMult.ValueString() + } + if !data.Descr.IsNull() && !data.Descr.IsUnknown() { + payloadMap["attributes"].(map[string]string)["descr"] = data.Descr.ValueString() + } + if !data.FlushAdminSt.IsNull() && !data.FlushAdminSt.IsUnknown() { + payloadMap["attributes"].(map[string]string)["flushAdminSt"] = data.FlushAdminSt.ValueString() + } + if !data.FlushIntvl.IsNull() && !data.FlushIntvl.IsUnknown() { + payloadMap["attributes"].(map[string]string)["flushIntvl"] = data.FlushIntvl.ValueString() + } + if !data.Name.IsNull() && !data.Name.IsUnknown() { + payloadMap["attributes"].(map[string]string)["name"] = data.Name.ValueString() + } + if !data.NameAlias.IsNull() && !data.NameAlias.IsUnknown() { + payloadMap["attributes"].(map[string]string)["nameAlias"] = data.NameAlias.ValueString() + } + if !data.OwnerKey.IsNull() && !data.OwnerKey.IsUnknown() { + payloadMap["attributes"].(map[string]string)["ownerKey"] = data.OwnerKey.ValueString() + } + if !data.OwnerTag.IsNull() && !data.OwnerTag.IsUnknown() { + payloadMap["attributes"].(map[string]string)["ownerTag"] = data.OwnerTag.ValueString() + } + payload, err := json.Marshal(map[string]interface{}{"qosSdIfPol": payloadMap}) + if err != nil { + diags.AddError( + "Marshalling of json payload failed", + fmt.Sprintf("Err: %s. Please report this issue to the provider developers.", err), + ) + return nil + } + + jsonPayload, err := container.ParseJSON(payload) + + if err != nil { + diags.AddError( + "Construction of json payload failed", + fmt.Sprintf("Err: %s. Please report this issue to the provider developers.", err), + ) + return nil + } + return jsonPayload +} diff --git a/internal/provider/resource_aci_slow_drain_interface_policy_test.go b/internal/provider/resource_aci_slow_drain_interface_policy_test.go new file mode 100644 index 000000000..13a1bd3e0 --- /dev/null +++ b/internal/provider/resource_aci_slow_drain_interface_policy_test.go @@ -0,0 +1,364 @@ +// 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 provider + +import ( + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccResourceQosSdIfPol(t *testing.T) { + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigQosSdIfPolMinAllowExisting, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "name", "test_name"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "congestion_clear_action", "off"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "congestion_clear_action", "off"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "congestion_detect_multiplier", "10"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "congestion_detect_multiplier", "10"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "description", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "description", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "flush_admin_state", "disabled"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "flush_admin_state", "disabled"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "flush_timeout", "500"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "flush_timeout", "500"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "name_alias", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "owner_key", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "owner_tag", ""), + ), + }, + }, + }) + + setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigQosSdIfPolMinAllowExisting, + ExpectError: regexp.MustCompile("Object Already Exists"), + }, + }, + }) + + setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigQosSdIfPolMinAllowExisting, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "name", "test_name"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "congestion_clear_action", "off"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "congestion_clear_action", "off"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "congestion_detect_multiplier", "10"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "congestion_detect_multiplier", "10"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "description", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "description", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "flush_admin_state", "disabled"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "flush_admin_state", "disabled"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "flush_timeout", "500"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "flush_timeout", "500"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "name_alias", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "owner_key", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.allow_test_2", "owner_tag", ""), + ), + }, + }, + }) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigQosSdIfPolMin, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "congestion_clear_action", "off"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "congestion_detect_multiplier", "10"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "flush_admin_state", "disabled"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "flush_timeout", "500"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "owner_tag", ""), + ), + }, + // Update with all config and verify default APIC values + { + Config: testConfigQosSdIfPolAll, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotation", "annotation"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "congestion_clear_action", "err-disable"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "congestion_detect_multiplier", "15"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "description", "description_1"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "flush_admin_state", "disabled"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "flush_timeout", "300"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "name_alias", "name_alias_1"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "owner_key", "owner_key_1"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "owner_tag", "owner_tag_1"), + ), + }, + // Update with minimum config and verify config is unchanged + { + Config: testConfigQosSdIfPolMin, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "congestion_clear_action", "err-disable"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "congestion_detect_multiplier", "15"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "description", "description_1"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "flush_admin_state", "disabled"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "flush_timeout", "300"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "name_alias", "name_alias_1"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "owner_key", "owner_key_1"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "owner_tag", "owner_tag_1"), + ), + }, + // Update with empty strings config or default value + { + Config: testConfigQosSdIfPolReset, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "congestion_clear_action", "off"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "congestion_detect_multiplier", "10"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "flush_admin_state", "disabled"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "flush_timeout", "500"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "owner_tag", ""), + ), + }, + // Import testing + { + ResourceName: "aci_slow_drain_interface_policy.test", + ImportState: true, + ImportStateVerify: true, + }, + // Update with children + { + Config: testConfigQosSdIfPolChildren, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "congestion_clear_action", "off"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "congestion_detect_multiplier", "10"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "flush_admin_state", "disabled"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "flush_timeout", "500"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotations.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotations.#", "2"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "tags.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "tags.#", "2"), + ), + }, + // Update with children removed from config + { + Config: testConfigQosSdIfPolChildrenRemoveFromConfig, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "congestion_clear_action", "off"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "congestion_detect_multiplier", "10"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "flush_admin_state", "disabled"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "flush_timeout", "500"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotations.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotations.#", "2"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "tags.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "tags.#", "2"), + ), + }, + // Update with children first child removed + { + Config: testConfigQosSdIfPolChildrenRemoveOne, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "congestion_clear_action", "off"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "congestion_detect_multiplier", "10"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "flush_admin_state", "disabled"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "flush_timeout", "500"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotations.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotations.0.value", "test_value"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotations.#", "1"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "tags.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "tags.0.value", "test_value"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "tags.#", "1"), + ), + }, + // Update with all children removed + { + Config: testConfigQosSdIfPolChildrenRemoveAll, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "congestion_clear_action", "off"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "congestion_detect_multiplier", "10"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "flush_admin_state", "disabled"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "flush_timeout", "500"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "annotations.#", "0"), + resource.TestCheckResourceAttr("aci_slow_drain_interface_policy.test", "tags.#", "0"), + ), + }, + }, + CheckDestroy: testCheckResourceDestroy, + }) +} + +const testConfigQosSdIfPolMinAllowExisting = ` +resource "aci_slow_drain_interface_policy" "allow_test" { + name = "test_name" +} +resource "aci_slow_drain_interface_policy" "allow_test_2" { + name = "test_name" + depends_on = [aci_slow_drain_interface_policy.allow_test] +} +` + +const testConfigQosSdIfPolMin = ` +resource "aci_slow_drain_interface_policy" "test" { + name = "test_name" +} +` + +const testConfigQosSdIfPolAll = ` +resource "aci_slow_drain_interface_policy" "test" { + name = "test_name" + annotation = "annotation" + congestion_clear_action = "err-disable" + congestion_detect_multiplier = "15" + description = "description_1" + flush_admin_state = "disabled" + flush_timeout = "300" + name_alias = "name_alias_1" + owner_key = "owner_key_1" + owner_tag = "owner_tag_1" +} +` + +const testConfigQosSdIfPolReset = ` +resource "aci_slow_drain_interface_policy" "test" { + name = "test_name" + annotation = "orchestrator:terraform" + congestion_clear_action = "off" + congestion_detect_multiplier = "10" + description = "" + flush_admin_state = "disabled" + flush_timeout = "500" + name_alias = "" + owner_key = "" + owner_tag = "" +} +` +const testConfigQosSdIfPolChildren = ` +resource "aci_slow_drain_interface_policy" "test" { + name = "test_name" + annotations = [ + { + key = "key_0" + value = "value_1" + }, + { + key = "key_1" + value = "test_value" + }, + ] + tags = [ + { + key = "key_0" + value = "value_1" + }, + { + key = "key_1" + value = "test_value" + }, + ] +} +` + +const testConfigQosSdIfPolChildrenRemoveFromConfig = ` +resource "aci_slow_drain_interface_policy" "test" { + name = "test_name" +} +` + +const testConfigQosSdIfPolChildrenRemoveOne = ` +resource "aci_slow_drain_interface_policy" "test" { + name = "test_name" + annotations = [ + { + key = "key_1" + value = "test_value" + }, + ] + tags = [ + { + key = "key_1" + value = "test_value" + }, + ] +} +` + +const testConfigQosSdIfPolChildrenRemoveAll = ` +resource "aci_slow_drain_interface_policy" "test" { + name = "test_name" + annotations = [] + tags = [] +} +`