From 14cd7707090ec3f7dc8a447d10055eaf85f0575a 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 e257bdeded7253cf5de34f7b63a0fbdd4252716b Mon Sep 17 00:00:00 2001 From: akinross Date: Thu, 27 Nov 2025 13:12:08 +0100 Subject: [PATCH 2/2] [minor_change] Add support for copp interface access policy with resources aci_copp_interface_policy and aci_copp_interface_protocol_policy --- docs/data-sources/annotation.md | 4 +- docs/data-sources/copp_interface_policy.md | 74 + .../copp_interface_protocol_policy.md | 64 + docs/data-sources/tag.md | 4 +- docs/resources/annotation.md | 4 +- docs/resources/copp_interface_policy.md | 172 +++ .../copp_interface_protocol_policy.md | 132 ++ docs/resources/tag.md | 4 +- .../aci_copp_interface_policy/data-source.tf | 4 + .../aci_copp_interface_policy/provider.tf | 14 + .../data-source.tf | 5 + .../provider.tf | 14 + .../aci_copp_interface_policy/provider.tf | 14 + .../resource-all-attributes.tf | 46 + .../aci_copp_interface_policy/resource.tf | 4 + .../provider.tf | 14 + .../resource-all-attributes.tf | 25 + .../resource.tf | 5 + gen/definitions/classes.yaml | 17 + gen/definitions/properties.yaml | 20 + gen/meta/coppIfPol.json | 703 ++++++++++ gen/meta/coppProtoClassP.json | 852 +++++++++++ gen/testvars/coppIfPol.yaml | 97 ++ gen/testvars/coppProtoClassP.yaml | 58 + .../data_source_aci_copp_interface_policy.go | 239 ++++ ...a_source_aci_copp_interface_policy_test.go | 49 + ...urce_aci_copp_interface_protocol_policy.go | 179 +++ ...aci_copp_interface_protocol_policy_test.go | 56 + internal/provider/provider.go | 4 + .../resource_aci_copp_interface_policy.go | 1243 +++++++++++++++++ ...resource_aci_copp_interface_policy_test.go | 497 +++++++ ...urce_aci_copp_interface_protocol_policy.go | 788 +++++++++++ ...aci_copp_interface_protocol_policy_test.go | 349 +++++ 33 files changed, 5746 insertions(+), 8 deletions(-) create mode 100644 docs/data-sources/copp_interface_policy.md create mode 100644 docs/data-sources/copp_interface_protocol_policy.md create mode 100644 docs/resources/copp_interface_policy.md create mode 100644 docs/resources/copp_interface_protocol_policy.md create mode 100644 examples/data-sources/aci_copp_interface_policy/data-source.tf create mode 100644 examples/data-sources/aci_copp_interface_policy/provider.tf create mode 100644 examples/data-sources/aci_copp_interface_protocol_policy/data-source.tf create mode 100644 examples/data-sources/aci_copp_interface_protocol_policy/provider.tf create mode 100644 examples/resources/aci_copp_interface_policy/provider.tf create mode 100644 examples/resources/aci_copp_interface_policy/resource-all-attributes.tf create mode 100644 examples/resources/aci_copp_interface_policy/resource.tf create mode 100644 examples/resources/aci_copp_interface_protocol_policy/provider.tf create mode 100644 examples/resources/aci_copp_interface_protocol_policy/resource-all-attributes.tf create mode 100644 examples/resources/aci_copp_interface_protocol_policy/resource.tf create mode 100644 gen/meta/coppIfPol.json create mode 100644 gen/meta/coppProtoClassP.json create mode 100644 gen/testvars/coppIfPol.yaml create mode 100644 gen/testvars/coppProtoClassP.yaml create mode 100644 internal/provider/data_source_aci_copp_interface_policy.go create mode 100644 internal/provider/data_source_aci_copp_interface_policy_test.go create mode 100644 internal/provider/data_source_aci_copp_interface_protocol_policy.go create mode 100644 internal/provider/data_source_aci_copp_interface_protocol_policy_test.go create mode 100644 internal/provider/resource_aci_copp_interface_policy.go create mode 100644 internal/provider/resource_aci_copp_interface_policy_test.go create mode 100644 internal/provider/resource_aci_copp_interface_protocol_policy.go create mode 100644 internal/provider/resource_aci_copp_interface_protocol_policy_test.go diff --git a/docs/data-sources/annotation.md b/docs/data-sources/annotation.md index 137ce7cd0..129778e1e 100644 --- a/docs/data-sources/annotation.md +++ b/docs/data-sources/annotation.md @@ -60,6 +60,8 @@ data "aci_annotation" "example_application_epg" { - [aci_cloud_external_epg](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/cloud_external_epg) ([cloudExtEPg](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/cloudExtEPg/overview)) - [aci_cloud_service_epg](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/cloud_service_epg) ([cloudSvcEPg](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/cloudSvcEPg/overview)) - [aci_management_access_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/management_access_policy) ([commPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/commPol/overview)) + - [aci_copp_interface_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/copp_interface_policy) ([coppIfPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/coppIfPol/overview)) + - [aci_copp_interface_protocol_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/copp_interface_protocol_policy) ([coppProtoClassP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/coppProtoClassP/overview)) - [aci_dhcp_relay_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/dhcp_relay_policy) ([dhcpRelayP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/dhcpRelayP/overview)) - [aci_eigrp_address_family_context](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/eigrp_address_family_context) ([eigrpCtxAfPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/eigrpCtxAfPol/overview)) - [aci_first_hop_security_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/first_hop_security_policy) ([fhsBDPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fhsBDPol/overview)) @@ -72,8 +74,6 @@ data "aci_annotation" "example_application_epg" { - [aci_epg_useg_dns_attribute](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/epg_useg_dns_attribute) ([fvDnsAttr](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvDnsAttr/overview)) - [aci_endpoint_security_group](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/endpoint_security_group) ([fvESg](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvESg/overview)) - [aci_endpoint_tag_ip](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/endpoint_tag_ip) ([fvEpIpTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvEpIpTag/overview)) - - [aci_endpoint_tag_mac](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/endpoint_tag_mac) ([fvEpMacTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvEpMacTag/overview)) - - [aci_end_point_retention_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/end_point_retention_policy) ([fvEpRetPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvEpRetPol/overview)) * `key` (key) - (string) The key used to uniquely identify this configuration object. ### Read-Only ### diff --git a/docs/data-sources/copp_interface_policy.md b/docs/data-sources/copp_interface_policy.md new file mode 100644 index 000000000..8c6a8791f --- /dev/null +++ b/docs/data-sources/copp_interface_policy.md @@ -0,0 +1,74 @@ +--- +# 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_copp_interface_policy" +sidebar_current: "docs-aci-data-source-aci_copp_interface_policy" +description: |- + Data source for ACI CoPP Interface Policy +--- + +# aci_copp_interface_policy # + +Data source for ACI CoPP Interface Policy + +## API Information ## + +* Class: [coppIfPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/coppIfPol/overview) + +* Supported in ACI versions: 2.3(1e) and later. + +* Distinguished Name Format: `uni/infra/coppifpol-{name}` + +## GUI Information ## + +* Location: `Fabric -> Access Policies -> Policies -> Interface -> CoPP Interface` + +## Example Usage ## + +```hcl + +data "aci_copp_interface_policy" "example" { + name = "test_name" +} + +``` + +## Schema ## + +### Required ### + +* `name` (name) - (string) The name of the CoPP Interface Policy object. + +### Read-Only ### + +* `id` - (string) The distinguished name (DN) of the CoPP Interface Policy object. +* `annotation` (annotation) - (string) The annotation of the CoPP Interface Policy object. This attribute is supported in ACI versions: 3.2(1l) and later. +* `description` (descr) - (string) The description of the CoPP Interface Policy object. +* `name_alias` (nameAlias) - (string) The name alias of the CoPP Interface Policy object. +* `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. +* `protocol_policies` - (list) A list of CoPP Interface Protocol Policies (ACI object [coppProtoClassP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/coppProtoClassP/overview)). + * `annotation` (annotation) - (string) The annotation of the CoPP Interface Protocol Policy object. This attribute is supported in ACI versions: 3.2(1l) and later. + * `burst` (burst) - (string) The burst size of the CoPP Interface Protocol Policy object. + * `description` (descr) - (string) The description of the CoPP Interface Protocol Policy object. + * `match_protocols` (matchProto) - (list) The protocols to match in the CoPP Interface Protocol Policy object. + * `name` (name) - (string) The name of the CoPP Interface Protocol Policy object. + * `name_alias` (nameAlias) - (string) The name alias of the CoPP Interface Protocol Policy object. + * `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. + * `rate` (rate) - (string) The rate of the CoPP Interface Protocol Policy 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. +* `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/data-sources/copp_interface_protocol_policy.md b/docs/data-sources/copp_interface_protocol_policy.md new file mode 100644 index 000000000..2972cbe6a --- /dev/null +++ b/docs/data-sources/copp_interface_protocol_policy.md @@ -0,0 +1,64 @@ +--- +# 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_copp_interface_protocol_policy" +sidebar_current: "docs-aci-data-source-aci_copp_interface_protocol_policy" +description: |- + Data source for ACI CoPP Interface Protocol Policy +--- + +# aci_copp_interface_protocol_policy # + +Data source for ACI CoPP Interface Protocol Policy + +## API Information ## + +* Class: [coppProtoClassP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/coppProtoClassP/overview) + +* Supported in ACI versions: 2.3(1e) and later. + +* Distinguished Name Format: `uni/infra/coppifpol-{name}/protoclassp-{name}` + +## GUI Information ## + +* Location: `Fabric -> Access Policies -> Policies -> Interface -> CoPP Interface -> CoPP Policy Protocol` + +## Example Usage ## + +```hcl + +data "aci_copp_interface_protocol_policy" "example_copp_interface_policy" { + parent_dn = aci_copp_interface_policy.example.id + name = "test_name" +} + +``` + +## Schema ## + +### Required ### + +* `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources: + - [aci_copp_interface_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/copp_interface_policy) ([coppIfPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/coppIfPol/overview)) +* `name` (name) - (string) The name of the CoPP Interface Protocol Policy object. + +### Read-Only ### + +* `id` - (string) The distinguished name (DN) of the CoPP Interface Protocol Policy object. +* `annotation` (annotation) - (string) The annotation of the CoPP Interface Protocol Policy object. This attribute is supported in ACI versions: 3.2(1l) and later. +* `burst` (burst) - (string) The burst size of the CoPP Interface Protocol Policy object. +* `description` (descr) - (string) The description of the CoPP Interface Protocol Policy object. +* `match_protocols` (matchProto) - (list) The protocols to match in the CoPP Interface Protocol Policy object. +* `name_alias` (nameAlias) - (string) The name alias of the CoPP Interface Protocol Policy object. +* `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. +* `rate` (rate) - (string) The rate of the CoPP Interface Protocol Policy 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/data-sources/tag.md b/docs/data-sources/tag.md index 78884737a..172e1648b 100644 --- a/docs/data-sources/tag.md +++ b/docs/data-sources/tag.md @@ -60,6 +60,8 @@ data "aci_tag" "example_application_epg" { - [aci_cloud_external_epg](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/cloud_external_epg) ([cloudExtEPg](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/cloudExtEPg/overview)) - [aci_cloud_service_epg](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/cloud_service_epg) ([cloudSvcEPg](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/cloudSvcEPg/overview)) - [aci_management_access_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/management_access_policy) ([commPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/commPol/overview)) + - [aci_copp_interface_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/copp_interface_policy) ([coppIfPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/coppIfPol/overview)) + - [aci_copp_interface_protocol_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/copp_interface_protocol_policy) ([coppProtoClassP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/coppProtoClassP/overview)) - [aci_dhcp_relay_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/dhcp_relay_policy) ([dhcpRelayP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/dhcpRelayP/overview)) - [aci_eigrp_address_family_context](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/eigrp_address_family_context) ([eigrpCtxAfPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/eigrpCtxAfPol/overview)) - [aci_first_hop_security_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/first_hop_security_policy) ([fhsBDPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fhsBDPol/overview)) @@ -72,8 +74,6 @@ data "aci_tag" "example_application_epg" { - [aci_epg_useg_dns_attribute](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/epg_useg_dns_attribute) ([fvDnsAttr](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvDnsAttr/overview)) - [aci_endpoint_security_group](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/endpoint_security_group) ([fvESg](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvESg/overview)) - [aci_endpoint_tag_ip](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/endpoint_tag_ip) ([fvEpIpTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvEpIpTag/overview)) - - [aci_endpoint_tag_mac](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/endpoint_tag_mac) ([fvEpMacTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvEpMacTag/overview)) - - [aci_end_point_retention_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/end_point_retention_policy) ([fvEpRetPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvEpRetPol/overview)) * `key` (key) - (string) The key used to uniquely identify this configuration object. ### Read-Only ### diff --git a/docs/resources/annotation.md b/docs/resources/annotation.md index 7534e8860..deedd3b86 100644 --- a/docs/resources/annotation.md +++ b/docs/resources/annotation.md @@ -69,6 +69,8 @@ All examples for the Annotation resource can be found in the [examples](https:// - [aci_cloud_external_epg](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/cloud_external_epg) ([cloudExtEPg](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/cloudExtEPg/overview)) - [aci_cloud_service_epg](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/cloud_service_epg) ([cloudSvcEPg](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/cloudSvcEPg/overview)) - [aci_management_access_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/management_access_policy) ([commPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/commPol/overview)) + - [aci_copp_interface_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/copp_interface_policy) ([coppIfPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/coppIfPol/overview)) + - [aci_copp_interface_protocol_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/copp_interface_protocol_policy) ([coppProtoClassP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/coppProtoClassP/overview)) - [aci_dhcp_relay_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/dhcp_relay_policy) ([dhcpRelayP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/dhcpRelayP/overview)) - [aci_eigrp_address_family_context](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/eigrp_address_family_context) ([eigrpCtxAfPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/eigrpCtxAfPol/overview)) - [aci_first_hop_security_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/first_hop_security_policy) ([fhsBDPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fhsBDPol/overview)) @@ -81,8 +83,6 @@ All examples for the Annotation resource can be found in the [examples](https:// - [aci_epg_useg_dns_attribute](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/epg_useg_dns_attribute) ([fvDnsAttr](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvDnsAttr/overview)) - [aci_endpoint_security_group](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/endpoint_security_group) ([fvESg](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvESg/overview)) - [aci_endpoint_tag_ip](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/endpoint_tag_ip) ([fvEpIpTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvEpIpTag/overview)) - - [aci_endpoint_tag_mac](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/endpoint_tag_mac) ([fvEpMacTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvEpMacTag/overview)) - - [aci_end_point_retention_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/end_point_retention_policy) ([fvEpRetPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvEpRetPol/overview)) * `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/copp_interface_policy.md b/docs/resources/copp_interface_policy.md new file mode 100644 index 000000000..52eadad07 --- /dev/null +++ b/docs/resources/copp_interface_policy.md @@ -0,0 +1,172 @@ +--- +# 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_copp_interface_policy" +sidebar_current: "docs-aci-resource-aci_copp_interface_policy" +description: |- + Manages ACI CoPP Interface Policy +--- + +# aci_copp_interface_policy # + +Manages ACI CoPP Interface Policy + + + +## API Information ## + +* Class: [coppIfPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/coppIfPol/overview) + +* Supported in ACI versions: 2.3(1e) and later. + +* Distinguished Name Format: `uni/infra/coppifpol-{name}` + +## GUI Information ## + +* Location: `Fabric -> Access Policies -> Policies -> Interface -> CoPP Interface` + +## Example Usage ## + +The configuration snippet below creates a CoPP Interface Policy with only required attributes. + +```hcl + +resource "aci_copp_interface_policy" "example" { + name = "test_name" +} + +``` +The configuration snippet below shows all possible attributes of the CoPP Interface Policy. + +!> This example might not be valid configuration and is only used to show all possible attributes. + +```hcl + +resource "aci_copp_interface_policy" "full_example" { + annotation = "annotation" + description = "description_1" + name = "test_name" + name_alias = "name_alias_1" + owner_key = "owner_key_1" + owner_tag = "owner_tag_1" + protocol_policies = [ + { + annotation = "annotation_1" + burst = "15" + description = "description_1" + match_protocols = ["arp", "bfd"] + name = "name_0" + name_alias = "name_alias_1" + owner_key = "owner_key_1" + owner_tag = "owner_tag_1" + rate = "15" + annotations = [ + { + key = "key_0" + value = "value_1" + } + ] + tags = [ + { + key = "key_0" + value = "value_1" + } + ] + } + ] + annotations = [ + { + key = "key_0" + value = "value_1" + } + ] + tags = [ + { + key = "key_0" + value = "value_1" + } + ] +} + +``` + +All examples for the CoPP Interface Policy resource can be found in the [examples](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/examples/resources/aci_copp_interface_policy) folder. + +## Schema ## + +### Required ### + +* `name` (name) - (string) The name of the CoPP Interface Policy object. + +### Read-Only ### + +* `id` - (string) The distinguished name (DN) of the CoPP Interface Policy object. + +### Optional ### + +* `annotation` (annotation) - (string) The annotation of the CoPP Interface Policy object. This attribute is supported in ACI versions: 3.2(1l) and later. + - Default: `"orchestrator:terraform"` +* `description` (descr) - (string) The description of the CoPP Interface Policy object. +* `name_alias` (nameAlias) - (string) The name alias of the CoPP Interface Policy object. +* `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. +* `protocol_policies` - (list) A list of CoPP Interface Protocol Policies (ACI object [coppProtoClassP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/coppProtoClassP/overview)). CoPP Interface Protocol Policies can also be configured using a separate [aci_copp_interface_protocol_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/copp_interface_protocol_policy) resource. + #### Required #### + + * `name` (name) - (string) The name of the CoPP Interface Protocol Policy object. + #### Optional #### + + * `annotation` (annotation) - (string) The annotation of the CoPP Interface Protocol Policy object. This attribute is supported in ACI versions: 3.2(1l) and later. + - Default: `"orchestrator:terraform"` + * `burst` (burst) - (string) The burst size of the CoPP Interface Protocol Policy object. + - Default: `"10"` + * `description` (descr) - (string) The description of the CoPP Interface Protocol Policy object. + * `match_protocols` (matchProto) - (list) The protocols to match in the CoPP Interface Protocol Policy object. + - Default: `[]` + - Valid Values: `"arp"`, `"bfd"`, `"bgp"`, `"cdp"`, `"icmp"`, `"lacp"`, `"lldp"`, `"ospf"`, `"stp"`. + * `name_alias` (nameAlias) - (string) The name alias of the CoPP Interface Protocol Policy object. + * `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. + * `rate` (rate) - (string) The rate of the CoPP Interface Protocol Policy object. + - Default: `"10"` + * `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. +* `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 CoPP 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_copp_interface_policy.example uni/infra/coppifpol-{name} +``` + +Starting in Terraform version 1.5, an existing CoPP Interface Policy can be imported +using [import blocks](https://developer.hashicorp.com/terraform/language/import) via the following configuration: + +``` +import { + id = "uni/infra/coppifpol-{name}" + to = aci_copp_interface_policy.example +} +``` diff --git a/docs/resources/copp_interface_protocol_policy.md b/docs/resources/copp_interface_protocol_policy.md new file mode 100644 index 000000000..9fc857ad6 --- /dev/null +++ b/docs/resources/copp_interface_protocol_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_copp_interface_protocol_policy" +sidebar_current: "docs-aci-resource-aci_copp_interface_protocol_policy" +description: |- + Manages ACI CoPP Interface Protocol Policy +--- + +# aci_copp_interface_protocol_policy # + +Manages ACI CoPP Interface Protocol Policy + + + +## API Information ## + +* Class: [coppProtoClassP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/coppProtoClassP/overview) + +* Supported in ACI versions: 2.3(1e) and later. + +* Distinguished Name Format: `uni/infra/coppifpol-{name}/protoclassp-{name}` + +## GUI Information ## + +* Location: `Fabric -> Access Policies -> Policies -> Interface -> CoPP Interface -> CoPP Policy Protocol` + +## Example Usage ## + +The configuration snippet below creates a CoPP Interface Protocol Policy with only required attributes. + +```hcl + +resource "aci_copp_interface_protocol_policy" "example_copp_interface_policy" { + parent_dn = aci_copp_interface_policy.example.id + name = "test_name" +} + +``` +The configuration snippet below shows all possible attributes of the CoPP Interface Protocol Policy. + +!> This example might not be valid configuration and is only used to show all possible attributes. + +```hcl + +resource "aci_copp_interface_protocol_policy" "full_example_copp_interface_policy" { + parent_dn = aci_copp_interface_policy.example.id + annotation = "annotation" + burst = "15" + description = "description_1" + match_protocols = ["arp", "bfd"] + name = "test_name" + name_alias = "name_alias_1" + owner_key = "owner_key_1" + owner_tag = "owner_tag_1" + rate = "15" + annotations = [ + { + key = "key_0" + value = "value_1" + } + ] + tags = [ + { + key = "key_0" + value = "value_1" + } + ] +} + +``` + +All examples for the CoPP Interface Protocol Policy resource can be found in the [examples](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/examples/resources/aci_copp_interface_protocol_policy) folder. + +## Schema ## + +### Required ### + +* `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources: + - [aci_copp_interface_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/copp_interface_policy) ([coppIfPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/coppIfPol/overview)) +* `name` (name) - (string) The name of the CoPP Interface Protocol Policy object. + +### Read-Only ### + +* `id` - (string) The distinguished name (DN) of the CoPP Interface Protocol Policy object. + +### Optional ### + +* `annotation` (annotation) - (string) The annotation of the CoPP Interface Protocol Policy object. This attribute is supported in ACI versions: 3.2(1l) and later. + - Default: `"orchestrator:terraform"` +* `burst` (burst) - (string) The burst size of the CoPP Interface Protocol Policy object. + - Default: `"10"` +* `description` (descr) - (string) The description of the CoPP Interface Protocol Policy object. +* `match_protocols` (matchProto) - (list) The protocols to match in the CoPP Interface Protocol Policy object. + - Default: `[]` + - Valid Values: `"arp"`, `"bfd"`, `"bgp"`, `"cdp"`, `"icmp"`, `"lacp"`, `"lldp"`, `"ospf"`, `"stp"`. +* `name_alias` (nameAlias) - (string) The name alias of the CoPP Interface Protocol Policy object. +* `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. +* `rate` (rate) - (string) The rate of the CoPP Interface Protocol Policy object. + - Default: `"10"` +* `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 CoPP Interface Protocol 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_copp_interface_protocol_policy.example_copp_interface_policy uni/infra/coppifpol-{name}/protoclassp-{name} +``` + +Starting in Terraform version 1.5, an existing CoPP Interface Protocol Policy can be imported +using [import blocks](https://developer.hashicorp.com/terraform/language/import) via the following configuration: + +``` +import { + id = "uni/infra/coppifpol-{name}/protoclassp-{name}" + to = aci_copp_interface_protocol_policy.example_copp_interface_policy +} +``` diff --git a/docs/resources/tag.md b/docs/resources/tag.md index 76b465cc5..ec6f8ad74 100644 --- a/docs/resources/tag.md +++ b/docs/resources/tag.md @@ -69,6 +69,8 @@ All examples for the Tag resource can be found in the [examples](https://github. - [aci_cloud_external_epg](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/cloud_external_epg) ([cloudExtEPg](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/cloudExtEPg/overview)) - [aci_cloud_service_epg](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/cloud_service_epg) ([cloudSvcEPg](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/cloudSvcEPg/overview)) - [aci_management_access_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/management_access_policy) ([commPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/commPol/overview)) + - [aci_copp_interface_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/copp_interface_policy) ([coppIfPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/coppIfPol/overview)) + - [aci_copp_interface_protocol_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/copp_interface_protocol_policy) ([coppProtoClassP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/coppProtoClassP/overview)) - [aci_dhcp_relay_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/dhcp_relay_policy) ([dhcpRelayP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/dhcpRelayP/overview)) - [aci_eigrp_address_family_context](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/eigrp_address_family_context) ([eigrpCtxAfPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/eigrpCtxAfPol/overview)) - [aci_first_hop_security_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/first_hop_security_policy) ([fhsBDPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fhsBDPol/overview)) @@ -81,8 +83,6 @@ All examples for the Tag resource can be found in the [examples](https://github. - [aci_epg_useg_dns_attribute](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/epg_useg_dns_attribute) ([fvDnsAttr](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvDnsAttr/overview)) - [aci_endpoint_security_group](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/endpoint_security_group) ([fvESg](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvESg/overview)) - [aci_endpoint_tag_ip](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/endpoint_tag_ip) ([fvEpIpTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvEpIpTag/overview)) - - [aci_endpoint_tag_mac](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/endpoint_tag_mac) ([fvEpMacTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvEpMacTag/overview)) - - [aci_end_point_retention_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/end_point_retention_policy) ([fvEpRetPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvEpRetPol/overview)) * `key` (key) - (string) The key used to uniquely identify this configuration object. * `value` (value) - (string) The value of the property. diff --git a/examples/data-sources/aci_copp_interface_policy/data-source.tf b/examples/data-sources/aci_copp_interface_policy/data-source.tf new file mode 100644 index 000000000..f93fc3789 --- /dev/null +++ b/examples/data-sources/aci_copp_interface_policy/data-source.tf @@ -0,0 +1,4 @@ + +data "aci_copp_interface_policy" "example" { + name = "test_name" +} diff --git a/examples/data-sources/aci_copp_interface_policy/provider.tf b/examples/data-sources/aci_copp_interface_policy/provider.tf new file mode 100644 index 000000000..975fca093 --- /dev/null +++ b/examples/data-sources/aci_copp_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/data-sources/aci_copp_interface_protocol_policy/data-source.tf b/examples/data-sources/aci_copp_interface_protocol_policy/data-source.tf new file mode 100644 index 000000000..e64f32345 --- /dev/null +++ b/examples/data-sources/aci_copp_interface_protocol_policy/data-source.tf @@ -0,0 +1,5 @@ + +data "aci_copp_interface_protocol_policy" "example_copp_interface_policy" { + parent_dn = aci_copp_interface_policy.example.id + name = "test_name" +} diff --git a/examples/data-sources/aci_copp_interface_protocol_policy/provider.tf b/examples/data-sources/aci_copp_interface_protocol_policy/provider.tf new file mode 100644 index 000000000..975fca093 --- /dev/null +++ b/examples/data-sources/aci_copp_interface_protocol_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_copp_interface_policy/provider.tf b/examples/resources/aci_copp_interface_policy/provider.tf new file mode 100644 index 000000000..975fca093 --- /dev/null +++ b/examples/resources/aci_copp_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_copp_interface_policy/resource-all-attributes.tf b/examples/resources/aci_copp_interface_policy/resource-all-attributes.tf new file mode 100644 index 000000000..ab41671a0 --- /dev/null +++ b/examples/resources/aci_copp_interface_policy/resource-all-attributes.tf @@ -0,0 +1,46 @@ + +resource "aci_copp_interface_policy" "full_example" { + annotation = "annotation" + description = "description_1" + name = "test_name" + name_alias = "name_alias_1" + owner_key = "owner_key_1" + owner_tag = "owner_tag_1" + protocol_policies = [ + { + annotation = "annotation_1" + burst = "15" + description = "description_1" + match_protocols = ["arp", "bfd"] + name = "name_0" + name_alias = "name_alias_1" + owner_key = "owner_key_1" + owner_tag = "owner_tag_1" + rate = "15" + annotations = [ + { + key = "key_0" + value = "value_1" + } + ] + tags = [ + { + key = "key_0" + value = "value_1" + } + ] + } + ] + annotations = [ + { + key = "key_0" + value = "value_1" + } + ] + tags = [ + { + key = "key_0" + value = "value_1" + } + ] +} diff --git a/examples/resources/aci_copp_interface_policy/resource.tf b/examples/resources/aci_copp_interface_policy/resource.tf new file mode 100644 index 000000000..2911959e3 --- /dev/null +++ b/examples/resources/aci_copp_interface_policy/resource.tf @@ -0,0 +1,4 @@ + +resource "aci_copp_interface_policy" "example" { + name = "test_name" +} diff --git a/examples/resources/aci_copp_interface_protocol_policy/provider.tf b/examples/resources/aci_copp_interface_protocol_policy/provider.tf new file mode 100644 index 000000000..975fca093 --- /dev/null +++ b/examples/resources/aci_copp_interface_protocol_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_copp_interface_protocol_policy/resource-all-attributes.tf b/examples/resources/aci_copp_interface_protocol_policy/resource-all-attributes.tf new file mode 100644 index 000000000..28fbb7c2d --- /dev/null +++ b/examples/resources/aci_copp_interface_protocol_policy/resource-all-attributes.tf @@ -0,0 +1,25 @@ + +resource "aci_copp_interface_protocol_policy" "full_example_copp_interface_policy" { + parent_dn = aci_copp_interface_policy.example.id + annotation = "annotation" + burst = "15" + description = "description_1" + match_protocols = ["arp", "bfd"] + name = "test_name" + name_alias = "name_alias_1" + owner_key = "owner_key_1" + owner_tag = "owner_tag_1" + rate = "15" + annotations = [ + { + key = "key_0" + value = "value_1" + } + ] + tags = [ + { + key = "key_0" + value = "value_1" + } + ] +} diff --git a/examples/resources/aci_copp_interface_protocol_policy/resource.tf b/examples/resources/aci_copp_interface_protocol_policy/resource.tf new file mode 100644 index 000000000..3aecda970 --- /dev/null +++ b/examples/resources/aci_copp_interface_protocol_policy/resource.tf @@ -0,0 +1,5 @@ + +resource "aci_copp_interface_protocol_policy" "example_copp_interface_policy" { + parent_dn = aci_copp_interface_policy.example.id + name = "test_name" +} diff --git a/gen/definitions/classes.yaml b/gen/definitions/classes.yaml index 567a3256e..8f9edfc0e 100644 --- a/gen/definitions/classes.yaml +++ b/gen/definitions/classes.yaml @@ -1266,3 +1266,20 @@ infraRsAccBndlSubgrp: infraAccBndlSubgrp: resource_name: "leaf_access_bundle_policy_sub_group" + +coppIfPol: + resource_name: "copp_interface_policy" + sub_category: "Access Policies" + ui_locations: + - "Fabric -> Access Policies -> Policies -> Interface -> CoPP Interface" + contained_by: + - "polUni" + rn_prepend: "infra" + children: + - "coppProtoClassP" + +coppProtoClassP: + resource_name: "copp_interface_protocol_policy" + sub_category: "Access Policies" + ui_locations: + - "Fabric -> Access Policies -> Policies -> Interface -> CoPP Interface -> CoPP Policy Protocol" diff --git a/gen/definitions/properties.yaml b/gen/definitions/properties.yaml index 96af5d8a4..7919a031e 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" + Copp: "CoPP" ignores: - "userdom" @@ -2895,3 +2896,22 @@ 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: "" +coppProtoClassP: + overwrites: + match_proto: match_protocols + copp_interface_protocol_policys: protocol_policies + documentation: + rate: "The rate of the %s object." + burst: "The burst size of the %s object." + matchProto: "The protocols to match in the %s object." + default_values: + matchProto: "@aci_gen_default_value_overwrite_to_empty_list!" + test_values: + default: + match_protocols: [] + rate: "10" + burst: "10" + all: + match_protocols: ["arp", "bfd"] + rate: "15" + burst: "15" diff --git a/gen/meta/coppIfPol.json b/gen/meta/coppIfPol.json new file mode 100644 index 000000000..89106facc --- /dev/null +++ b/gen/meta/coppIfPol.json @@ -0,0 +1,703 @@ +{ + "copp:IfPol": { + "contains": { + "aaa:RbacAnnotation": "", + "copp:ProtoClassP": "", + "copp:RtCoppIfPol": "", + "copp:RtCoppIfPolCons": "", + "fault:Delegate": "", + "tag:Annotation": "", + "tag:Tag": "" + }, + "rnMap": { + "annotationKey-": "tag:Annotation", + "fd-": "fault:Delegate", + "protoclassp-": "copp:ProtoClassP", + "rbacDom-": "aaa:RbacAnnotation", + "rtinfraCoppIfPol-": "copp:RtCoppIfPol", + "rtl1CoppIfPolCons-": "copp:RtCoppIfPolCons", + "tagKey-": "tag:Tag" + }, + "identifiedBy": [ + "name" + ], + "rnFormat": "coppifpol-{name}", + "containedBy": { + "infra:Infra": "" + }, + "superClasses": [ + "fabric:L2IfPol", + "fabric:ProtoIfPol", + "fabric:ProtoPol", + "pol:Def", + "pol:Obj", + "naming:NamedObject" + ], + "subClasses": { + + }, + "relationFrom": { + "copp:RtCoppIfPol": "infra:AAccGrp", + "copp:RtCoppIfPolCons": "l1:EthIf" + }, + "relationTo": { + + }, + "dnFormats": [ + "uni/infra/coppifpol-{name}" + ], + "writeAccess": [ + "access-connectivity", + "admin", + "custom-port-privilege" + ], + "readAccess": [ + "access-connectivity", + "admin", + "custom-port-privilege" + ], + "faults": { + + }, + "events": { + "E4211291": "creation||copp:IfPol", + "E4211292": "modification||copp:IfPol", + "E4211293": "deletion||copp:IfPol" + }, + "stats": { + + }, + "versions": "2.3(1e)-", + "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": "Default", + "isCreatableDeletable": "always", + "platformFlavors": [ + "apic" + ], + "classId": "9907", + "className": "IfPol", + "classPkg": "copp", + "featureTag": "", + "moCategory": "Regular", + "label": "Per interface per protocol CoPP policy", + "comment": [ + "Per interface per protocol CoPP policy" + ], + "properties": { + "annotation": { + "versions": "3.2(1l)-", + "comment": [ + "User annotation. Suggested format orchestrator:value" + ], + "isConfigurable": true, + "propGlobalId": "38653", + "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 + }, + "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": "40792", + "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 + }, + "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.3(1e)-", + "comment": [ + "The name of the object." + ], + "isConfigurable": true, + "propGlobalId": "30155", + "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/meta/coppProtoClassP.json b/gen/meta/coppProtoClassP.json new file mode 100644 index 000000000..d5c02acae --- /dev/null +++ b/gen/meta/coppProtoClassP.json @@ -0,0 +1,852 @@ +{ + "copp:ProtoClassP": { + "contains": { + "aaa:RbacAnnotation": "", + "fault:Delegate": "", + "tag:Annotation": "", + "tag:Tag": "" + }, + "rnMap": { + "annotationKey-": "tag:Annotation", + "fd-": "fault:Delegate", + "rbacDom-": "aaa:RbacAnnotation", + "tagKey-": "tag:Tag" + }, + "identifiedBy": [ + "name" + ], + "rnFormat": "protoclassp-{name}", + "containedBy": { + "copp:IfPol": "" + }, + "superClasses": [ + "fabric:L2IfPol", + "fabric:ProtoIfPol", + "fabric:ProtoPol", + "pol:Def", + "pol:Obj", + "naming:NamedObject" + ], + "subClasses": { + + }, + "relationFrom": { + + }, + "relationTo": { + + }, + "dnFormats": [ + "uni/infra/coppifpol-{name}/protoclassp-{name}" + ], + "writeAccess": [ + "access-connectivity", + "admin", + "custom-port-privilege" + ], + "readAccess": [ + "access-connectivity", + "admin", + "custom-port-privilege" + ], + "faults": { + + }, + "events": { + "E4211300": "creation||copp:ProtoClassP", + "E4211301": "modification||copp:ProtoClassP", + "E4211302": "deletion||copp:ProtoClassP" + }, + "stats": { + + }, + "versions": "2.3(1e)-", + "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": "Default", + "isCreatableDeletable": "always", + "platformFlavors": [ + "apic" + ], + "classId": "9908", + "className": "ProtoClassP", + "classPkg": "copp", + "featureTag": "", + "moCategory": "Regular", + "label": "Per interface per protocol CoPP policy", + "properties": { + "annotation": { + "versions": "3.2(1l)-", + "comment": [ + "User annotation. Suggested format orchestrator:value" + ], + "isConfigurable": true, + "propGlobalId": "38654", + "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 + }, + "burst": { + "versions": "2.3(1e)-", + "comment": [ + "A committed burst size. This is the number of packets allowed at line rate during a burst." + ], + "isConfigurable": true, + "propGlobalId": "30154", + "propLocalId": "986", + "label": "Burst", + "baseType": "scalar:Uint64", + "modelType": "copp:Burst", + "needsPropDelimiters": false, + "uitype": "number", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validators": [ + {"min" : 10, "max": 549755813760 } + ], + "validValues": [ + { "value": "10", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "} + ], + "default": 10, + "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 + }, + "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": "40793", + "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 + }, + "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 + }, + "matchProto": { + "versions": "2.3(1e)-", + "isConfigurable": true, + "propGlobalId": "30152", + "propLocalId": "7465", + "label": "Match proto", + "baseType": "scalar:Bitmask64", + "modelType": "copp:Protocol", + "needsPropDelimiters": false, + "uitype": "bitmask", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "128", "localName": "arp", + "platformFlavors": [ + + ], + "label": "ARP "}, + { "value": "32768", "localName": "bfd", + "platformFlavors": [ + + ], + "label": "BFD "}, + { "value": "1", "localName": "bgp", + "platformFlavors": [ + + ], + "label": "BGP "}, + { "value": "4", "localName": "cdp", + "platformFlavors": [ + + ], + "label": "CDP "}, + { "value": "0", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "1024", "localName": "icmp", + "platformFlavors": [ + + ], + "label": "ICMP "}, + { "value": "32", "localName": "lacp", + "platformFlavors": [ + + ], + "label": "LACP "}, + { "value": "16", "localName": "lldp", + "platformFlavors": [ + + ], + "label": "LLDP "}, + { "value": "2", "localName": "ospf", + "platformFlavors": [ + + ], + "label": "OSPF "}, + { "value": "16384", "localName": "stp", + "platformFlavors": [ + + ], + "label": "STP "} + ], + "default": "0", + "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.3(1e)-", + "comment": [ + "The name of the object." + ], + "isConfigurable": true, + "propGlobalId": "30156", + "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 + }, + "rate": { + "versions": "2.3(1e)-", + "comment": [ + "An allowed rate. This is the committed rate at which the packets are allowed into the system (raw NTPD format)." + ], + "isConfigurable": true, + "propGlobalId": "30153", + "propLocalId": "985", + "label": "Rate", + "baseType": "scalar:Uint64", + "modelType": "copp:Rate", + "needsPropDelimiters": false, + "uitype": "number", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validators": [ + {"min" : 10, "max": 4398046510080 } + ], + "validValues": [ + { "value": "10", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "} + ], + "default": 10, + "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/coppIfPol.yaml b/gen/testvars/coppIfPol.yaml new file mode 100644 index 000000000..8af2368c6 --- /dev/null +++ b/gen/testvars/coppIfPol.yaml @@ -0,0 +1,97 @@ +# 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" + description: "" + 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" + description: "description_1" + name_alias: "name_alias_1" + owner_key: "owner_key_1" + owner_tag: "owner_tag_1" + +children: + protocol_policies: + - annotation: "annotation_1" + burst: "15" + description: "description_1" + match_protocols: ["arp","bfd"] + name: "name_0" + name_alias: "name_alias_1" + owner_key: "owner_key_1" + owner_tag: "owner_tag_1" + rate: "15" + + 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" + + - annotation: "annotation_2" + burst: "10" + description: "description_2" + match_protocols: [] + name: "name_1" + name_alias: "name_alias_2" + owner_key: "owner_key_2" + owner_tag: "owner_tag_2" + rate: "10" + + 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" + + 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.3(1e)- diff --git a/gen/testvars/coppProtoClassP.yaml b/gen/testvars/coppProtoClassP.yaml new file mode 100644 index 000000000..f1e688b9d --- /dev/null +++ b/gen/testvars/coppProtoClassP.yaml @@ -0,0 +1,58 @@ +# 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" + burst: "10" + description: "" + match_protocols: [] + name_alias: "" + owner_key: "" + owner_tag: "" + rate: "10" + +datasource_non_existing: + name: "non_existing_name" + +datasource_required: + name: "test_name" + +resource_required: + name: "test_name" + +all: + annotation: "annotation" + burst: "15" + description: "description_1" + match_protocols: + - "arp" + - "bfd" + name_alias: "name_alias_1" + owner_key: "owner_key_1" + owner_tag: "owner_tag_1" + rate: "15" + +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" + +parents: + - class_name: "coppIfPol" + parent_dependency: "" + parent_dn: "aci_copp_interface_policy.test.id" + class_in_parent: false + test_type: apic +class_version: 2.3(1e)- diff --git a/internal/provider/data_source_aci_copp_interface_policy.go b/internal/provider/data_source_aci_copp_interface_policy.go new file mode 100644 index 000000000..27e41211b --- /dev/null +++ b/internal/provider/data_source_aci_copp_interface_policy.go @@ -0,0 +1,239 @@ +// 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-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var _ datasource.DataSource = &CoppIfPolDataSource{} + +func NewCoppIfPolDataSource() datasource.DataSource { + return &CoppIfPolDataSource{} +} + +// CoppIfPolDataSource defines the data source implementation. +type CoppIfPolDataSource struct { + client *client.Client +} + +func (d *CoppIfPolDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + tflog.Debug(ctx, "Start metadata of datasource: aci_copp_interface_policy") + resp.TypeName = req.ProviderTypeName + "_copp_interface_policy" + tflog.Debug(ctx, "End metadata of datasource: aci_copp_interface_policy") +} + +func (d *CoppIfPolDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + tflog.Debug(ctx, "Start schema of datasource: aci_copp_interface_policy") + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: "The copp_interface_policy datasource for the 'coppIfPol' class", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + MarkdownDescription: "The distinguished name (DN) of the CoPP Interface Policy object.", + }, + "annotation": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The annotation of the CoPP Interface Policy object.`, + }, + "description": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The description of the CoPP Interface Policy object.`, + }, + "name": schema.StringAttribute{ + Required: true, + MarkdownDescription: `The name of the CoPP Interface Policy object.`, + }, + "name_alias": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The name alias of the CoPP 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.`, + }, + "protocol_policies": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "annotation": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The annotation of the CoPP Interface Protocol Policy object.`, + }, + "burst": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The burst size of the CoPP Interface Protocol Policy object.`, + }, + "description": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The description of the CoPP Interface Protocol Policy object.`, + }, + "match_protocols": schema.SetAttribute{ + Computed: true, + MarkdownDescription: `The protocols to match in the CoPP Interface Protocol Policy object.`, + ElementType: types.StringType, + }, + "name": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The name of the CoPP Interface Protocol Policy object.`, + }, + "name_alias": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The name alias of the CoPP Interface Protocol 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.`, + }, + "rate": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The rate of the CoPP Interface Protocol Policy 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.`, + }, + }, + }, + }, + }, + }, + }, + "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_copp_interface_policy") +} + +func (d *CoppIfPolDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + tflog.Debug(ctx, "Start configure of datasource: aci_copp_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_copp_interface_policy") +} + +func (d *CoppIfPolDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + tflog.Debug(ctx, "Start read of datasource: aci_copp_interface_policy") + var data *CoppIfPolResourceModel + + // Read Terraform configuration data into the model + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + setCoppIfPolId(ctx, data) + + // Create a copy of the Id for when not found during getAndSetCoppIfPolAttributes + cachedId := data.Id.ValueString() + + tflog.Debug(ctx, fmt.Sprintf("Read of datasource aci_copp_interface_policy with id '%s'", data.Id.ValueString())) + + getAndSetCoppIfPolAttributes(ctx, &resp.Diagnostics, d.client, data) + + if data.Id.IsNull() { + resp.Diagnostics.AddError( + "Failed to read aci_copp_interface_policy data source", + fmt.Sprintf("The aci_copp_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_copp_interface_policy with id '%s'", data.Id.ValueString())) +} diff --git a/internal/provider/data_source_aci_copp_interface_policy_test.go b/internal/provider/data_source_aci_copp_interface_policy_test.go new file mode 100644 index 000000000..4de461d31 --- /dev/null +++ b/internal/provider/data_source_aci_copp_interface_policy_test.go @@ -0,0 +1,49 @@ +// 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 TestAccDataSourceCoppIfPol(t *testing.T) { + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "apic", "2.3(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testConfigCoppIfPolDataSource, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.aci_copp_interface_policy.test", "annotation", "annotation"), + resource.TestCheckResourceAttr("data.aci_copp_interface_policy.test", "description", "description_1"), + resource.TestCheckResourceAttr("data.aci_copp_interface_policy.test", "name_alias", "name_alias_1"), + resource.TestCheckResourceAttr("data.aci_copp_interface_policy.test", "owner_key", "owner_key_1"), + resource.TestCheckResourceAttr("data.aci_copp_interface_policy.test", "owner_tag", "owner_tag_1"), + ), + }, + { + Config: testConfigCoppIfPolNotExisting, + ExpectError: regexp.MustCompile("Failed to read aci_copp_interface_policy data source"), + }, + }, + }) +} + +const testConfigCoppIfPolDataSource = testConfigCoppIfPolAll + ` +data "aci_copp_interface_policy" "test" { + name = "test_name" + depends_on = [aci_copp_interface_policy.test] +} +` + +const testConfigCoppIfPolNotExisting = testConfigCoppIfPolAll + ` +data "aci_copp_interface_policy" "test_non_existing" { + name = "non_existing_name" +} +` diff --git a/internal/provider/data_source_aci_copp_interface_protocol_policy.go b/internal/provider/data_source_aci_copp_interface_protocol_policy.go new file mode 100644 index 000000000..3f173dbf4 --- /dev/null +++ b/internal/provider/data_source_aci_copp_interface_protocol_policy.go @@ -0,0 +1,179 @@ +// 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-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var _ datasource.DataSource = &CoppProtoClassPDataSource{} + +func NewCoppProtoClassPDataSource() datasource.DataSource { + return &CoppProtoClassPDataSource{} +} + +// CoppProtoClassPDataSource defines the data source implementation. +type CoppProtoClassPDataSource struct { + client *client.Client +} + +func (d *CoppProtoClassPDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + tflog.Debug(ctx, "Start metadata of datasource: aci_copp_interface_protocol_policy") + resp.TypeName = req.ProviderTypeName + "_copp_interface_protocol_policy" + tflog.Debug(ctx, "End metadata of datasource: aci_copp_interface_protocol_policy") +} + +func (d *CoppProtoClassPDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + tflog.Debug(ctx, "Start schema of datasource: aci_copp_interface_protocol_policy") + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: "The copp_interface_protocol_policy datasource for the 'coppProtoClassP' class", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + MarkdownDescription: "The distinguished name (DN) of the CoPP Interface Protocol Policy object.", + }, + "parent_dn": schema.StringAttribute{ + Required: true, + MarkdownDescription: "The distinguished name (DN) of the parent object.", + }, + "annotation": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The annotation of the CoPP Interface Protocol Policy object.`, + }, + "burst": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The burst size of the CoPP Interface Protocol Policy object.`, + }, + "description": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The description of the CoPP Interface Protocol Policy object.`, + }, + "match_protocols": schema.SetAttribute{ + Computed: true, + MarkdownDescription: `The protocols to match in the CoPP Interface Protocol Policy object.`, + ElementType: types.StringType, + }, + "name": schema.StringAttribute{ + Required: true, + MarkdownDescription: `The name of the CoPP Interface Protocol Policy object.`, + }, + "name_alias": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The name alias of the CoPP Interface Protocol 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.`, + }, + "rate": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The rate of the CoPP Interface Protocol Policy 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_copp_interface_protocol_policy") +} + +func (d *CoppProtoClassPDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + tflog.Debug(ctx, "Start configure of datasource: aci_copp_interface_protocol_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_copp_interface_protocol_policy") +} + +func (d *CoppProtoClassPDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + tflog.Debug(ctx, "Start read of datasource: aci_copp_interface_protocol_policy") + var data *CoppProtoClassPResourceModel + + // Read Terraform configuration data into the model + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + setCoppProtoClassPId(ctx, data) + + // Create a copy of the Id for when not found during getAndSetCoppProtoClassPAttributes + cachedId := data.Id.ValueString() + + tflog.Debug(ctx, fmt.Sprintf("Read of datasource aci_copp_interface_protocol_policy with id '%s'", data.Id.ValueString())) + + getAndSetCoppProtoClassPAttributes(ctx, &resp.Diagnostics, d.client, data) + + if data.Id.IsNull() { + resp.Diagnostics.AddError( + "Failed to read aci_copp_interface_protocol_policy data source", + fmt.Sprintf("The aci_copp_interface_protocol_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_copp_interface_protocol_policy with id '%s'", data.Id.ValueString())) +} diff --git a/internal/provider/data_source_aci_copp_interface_protocol_policy_test.go b/internal/provider/data_source_aci_copp_interface_protocol_policy_test.go new file mode 100644 index 000000000..65740b028 --- /dev/null +++ b/internal/provider/data_source_aci_copp_interface_protocol_policy_test.go @@ -0,0 +1,56 @@ +// 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 TestAccDataSourceCoppProtoClassPWithCoppIfPol(t *testing.T) { + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "apic", "2.3(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testConfigCoppProtoClassPDataSourceDependencyWithCoppIfPol, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.aci_copp_interface_protocol_policy.test", "name", "test_name"), + resource.TestCheckResourceAttr("data.aci_copp_interface_protocol_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("data.aci_copp_interface_protocol_policy.test", "burst", "10"), + resource.TestCheckResourceAttr("data.aci_copp_interface_protocol_policy.test", "description", ""), + resource.TestCheckResourceAttr("data.aci_copp_interface_protocol_policy.test", "match_protocols.#", "0"), + resource.TestCheckResourceAttr("data.aci_copp_interface_protocol_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("data.aci_copp_interface_protocol_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("data.aci_copp_interface_protocol_policy.test", "owner_tag", ""), + resource.TestCheckResourceAttr("data.aci_copp_interface_protocol_policy.test", "rate", "10"), + ), + }, + { + Config: testConfigCoppProtoClassPNotExistingCoppIfPol, + ExpectError: regexp.MustCompile("Failed to read aci_copp_interface_protocol_policy data source"), + }, + }, + }) +} + +const testConfigCoppProtoClassPDataSourceDependencyWithCoppIfPol = testConfigCoppProtoClassPMinDependencyWithCoppIfPol + ` +data "aci_copp_interface_protocol_policy" "test" { + parent_dn = aci_copp_interface_policy.test.id + name = "test_name" + depends_on = [aci_copp_interface_protocol_policy.test] +} +` + +const testConfigCoppProtoClassPNotExistingCoppIfPol = testConfigCoppIfPolMin + ` +data "aci_copp_interface_protocol_policy" "test_non_existing" { + parent_dn = aci_copp_interface_policy.test.id + name = "non_existing_name" +} +` diff --git a/internal/provider/provider.go b/internal/provider/provider.go index d2b05da06..73c574604 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -207,6 +207,8 @@ func (p *AciProvider) Configure(ctx context.Context, req provider.ConfigureReque func (p *AciProvider) Resources(ctx context.Context) []func() resource.Resource { return []func() resource.Resource{ NewCommPolResource, + NewCoppIfPolResource, + NewCoppProtoClassPResource, NewEigrpCtxAfPolResource, NewFhsBDPolResource, NewFhsTrustCtrlPolResource, @@ -310,6 +312,8 @@ func (p *AciProvider) Resources(ctx context.Context) []func() resource.Resource func (p *AciProvider) DataSources(ctx context.Context) []func() datasource.DataSource { return []func() datasource.DataSource{ NewCommPolDataSource, + NewCoppIfPolDataSource, + NewCoppProtoClassPDataSource, NewEigrpCtxAfPolDataSource, NewFhsBDPolDataSource, NewFhsTrustCtrlPolDataSource, diff --git a/internal/provider/resource_aci_copp_interface_policy.go b/internal/provider/resource_aci_copp_interface_policy.go new file mode 100644 index 000000000..2be6a47c2 --- /dev/null +++ b/internal/provider/resource_aci_copp_interface_policy.go @@ -0,0 +1,1243 @@ +// 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/setvalidator" + "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 = &CoppIfPolResource{} +var _ resource.ResourceWithImportState = &CoppIfPolResource{} + +func NewCoppIfPolResource() resource.Resource { + return &CoppIfPolResource{} +} + +// CoppIfPolResource defines the resource implementation. +type CoppIfPolResource struct { + client *client.Client +} + +// CoppIfPolResourceModel describes the resource data model. +type CoppIfPolResourceModel struct { + Id types.String `tfsdk:"id"` + Annotation types.String `tfsdk:"annotation"` + Descr types.String `tfsdk:"description"` + Name types.String `tfsdk:"name"` + NameAlias types.String `tfsdk:"name_alias"` + OwnerKey types.String `tfsdk:"owner_key"` + OwnerTag types.String `tfsdk:"owner_tag"` + CoppProtoClassP types.Set `tfsdk:"protocol_policies"` + TagAnnotation types.Set `tfsdk:"annotations"` + TagTag types.Set `tfsdk:"tags"` +} + +func getEmptyCoppIfPolResourceModel() *CoppIfPolResourceModel { + return &CoppIfPolResourceModel{ + Id: basetypes.NewStringNull(), + Annotation: basetypes.NewStringNull(), + Descr: basetypes.NewStringNull(), + Name: basetypes.NewStringNull(), + NameAlias: basetypes.NewStringNull(), + OwnerKey: basetypes.NewStringNull(), + OwnerTag: basetypes.NewStringNull(), + CoppProtoClassP: types.SetNull(types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "annotation": types.StringType, + "burst": types.StringType, + "description": types.StringType, + "match_protocols": types.SetType{ElemType: types.StringType}, + "name": types.StringType, + "name_alias": types.StringType, + "owner_key": types.StringType, + "owner_tag": types.StringType, + "rate": types.StringType, + "annotations": types.SetType{ElemType: TagAnnotationCoppProtoClassPCoppIfPolType}, + "tags": types.SetType{ElemType: TagTagCoppProtoClassPCoppIfPolType}, + }, + }), + 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, + }, + }), + } +} + +// CoppProtoClassPCoppIfPolResourceModel describes the resource data model for the children without relation ships. +type CoppProtoClassPCoppIfPolResourceModel struct { + Annotation types.String `tfsdk:"annotation"` + Burst types.String `tfsdk:"burst"` + Descr types.String `tfsdk:"description"` + MatchProto types.Set `tfsdk:"match_protocols"` + Name types.String `tfsdk:"name"` + NameAlias types.String `tfsdk:"name_alias"` + OwnerKey types.String `tfsdk:"owner_key"` + OwnerTag types.String `tfsdk:"owner_tag"` + Rate types.String `tfsdk:"rate"` + TagAnnotation types.Set `tfsdk:"annotations"` + TagTag types.Set `tfsdk:"tags"` +} + +func getEmptyCoppProtoClassPCoppIfPolResourceModel() CoppProtoClassPCoppIfPolResourceModel { + return CoppProtoClassPCoppIfPolResourceModel{ + Annotation: basetypes.NewStringNull(), + Burst: basetypes.NewStringNull(), + Descr: basetypes.NewStringNull(), + MatchProto: types.SetNull(types.StringType), + Name: basetypes.NewStringNull(), + NameAlias: basetypes.NewStringNull(), + OwnerKey: basetypes.NewStringNull(), + OwnerTag: basetypes.NewStringNull(), + Rate: 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, + }, + }), + } +} + +var CoppProtoClassPCoppIfPolType = types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "annotation": types.StringType, + "burst": types.StringType, + "description": types.StringType, + "match_protocols": types.SetType{ElemType: types.StringType}, + "name": types.StringType, + "name_alias": types.StringType, + "owner_key": types.StringType, + "owner_tag": types.StringType, + "rate": types.StringType, + "annotations": types.SetType{ElemType: TagAnnotationCoppProtoClassPCoppIfPolType}, + "tags": types.SetType{ElemType: TagTagCoppProtoClassPCoppIfPolType}, + }, +} + +func CoppProtoClassPCoppIfPolSetToSetNullWhenStateIsNullPlanIsUnknownDuringUpdate(ctx context.Context, planValue, stateValue types.Set) basetypes.SetValue { + // Function is needed to handle the case that an attribute is not yet supported in a version and gets set to null during read + var planSetValues, stateSetValues []CoppProtoClassPCoppIfPolResourceModel + stateValue.ElementsAs(ctx, &stateSetValues, false) + planValue.ElementsAs(ctx, &planSetValues, false) + + // If the length of the state and plan values are different a change is already detected the loop can be skipped + if len(stateSetValues) == len(planSetValues) { + for index, stateValue := range stateSetValues { + nullInStateFound := false + if stateValue.Annotation.IsNull() { + nullInStateFound = true + planSetValues[index].Annotation = basetypes.NewStringNull() + } + if stateValue.Burst.IsNull() { + nullInStateFound = true + planSetValues[index].Burst = basetypes.NewStringNull() + } + if stateValue.Descr.IsNull() { + nullInStateFound = true + planSetValues[index].Descr = basetypes.NewStringNull() + } + if stateValue.MatchProto.IsNull() { + nullInStateFound = true + planSetValues[index].MatchProto = basetypes.NewSetNull(types.StringType) + } + if stateValue.Name.IsNull() { + nullInStateFound = true + planSetValues[index].Name = basetypes.NewStringNull() + } + if stateValue.NameAlias.IsNull() { + nullInStateFound = true + planSetValues[index].NameAlias = basetypes.NewStringNull() + } + if stateValue.OwnerKey.IsNull() { + nullInStateFound = true + planSetValues[index].OwnerKey = basetypes.NewStringNull() + } + if stateValue.OwnerTag.IsNull() { + nullInStateFound = true + planSetValues[index].OwnerTag = basetypes.NewStringNull() + } + if stateValue.Rate.IsNull() { + nullInStateFound = true + planSetValues[index].Rate = basetypes.NewStringNull() + } + if !nullInStateFound { + // when there are no null fields we can conclude the version supports all attributes in set + break + } + } + } + planSet, _ := types.SetValueFrom(ctx, CoppProtoClassPCoppIfPolType, planSetValues) + return planSet + +} + +// TagAnnotationCoppProtoClassPCoppIfPolResourceModel describes the resource data model for the children without relation ships. +type TagAnnotationCoppProtoClassPCoppIfPolResourceModel struct { + Key types.String `tfsdk:"key"` + Value types.String `tfsdk:"value"` +} + +func getEmptyTagAnnotationCoppProtoClassPCoppIfPolResourceModel() TagAnnotationCoppProtoClassPCoppIfPolResourceModel { + return TagAnnotationCoppProtoClassPCoppIfPolResourceModel{ + Key: basetypes.NewStringNull(), + Value: basetypes.NewStringNull(), + } +} + +var TagAnnotationCoppProtoClassPCoppIfPolType = types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "key": types.StringType, + "value": types.StringType, + }, +} + +// TagTagCoppProtoClassPCoppIfPolResourceModel describes the resource data model for the children without relation ships. +type TagTagCoppProtoClassPCoppIfPolResourceModel struct { + Key types.String `tfsdk:"key"` + Value types.String `tfsdk:"value"` +} + +func getEmptyTagTagCoppProtoClassPCoppIfPolResourceModel() TagTagCoppProtoClassPCoppIfPolResourceModel { + return TagTagCoppProtoClassPCoppIfPolResourceModel{ + Key: basetypes.NewStringNull(), + Value: basetypes.NewStringNull(), + } +} + +var TagTagCoppProtoClassPCoppIfPolType = types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "key": types.StringType, + "value": types.StringType, + }, +} + +// TagAnnotationCoppIfPolResourceModel describes the resource data model for the children without relation ships. +type TagAnnotationCoppIfPolResourceModel struct { + Key types.String `tfsdk:"key"` + Value types.String `tfsdk:"value"` +} + +func getEmptyTagAnnotationCoppIfPolResourceModel() TagAnnotationCoppIfPolResourceModel { + return TagAnnotationCoppIfPolResourceModel{ + Key: basetypes.NewStringNull(), + Value: basetypes.NewStringNull(), + } +} + +var TagAnnotationCoppIfPolType = types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "key": types.StringType, + "value": types.StringType, + }, +} + +// TagTagCoppIfPolResourceModel describes the resource data model for the children without relation ships. +type TagTagCoppIfPolResourceModel struct { + Key types.String `tfsdk:"key"` + Value types.String `tfsdk:"value"` +} + +func getEmptyTagTagCoppIfPolResourceModel() TagTagCoppIfPolResourceModel { + return TagTagCoppIfPolResourceModel{ + Key: basetypes.NewStringNull(), + Value: basetypes.NewStringNull(), + } +} + +var TagTagCoppIfPolType = types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "key": types.StringType, + "value": types.StringType, + }, +} + +type CoppIfPolIdentifier struct { + Name types.String +} + +func (r *CoppIfPolResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if !req.Plan.Raw.IsNull() { + var planData, stateData *CoppIfPolResourceModel + 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() { + setCoppIfPolId(ctx, planData) + } + + if stateData == nil && !globalAllowExistingOnCreate && !planData.Id.IsUnknown() && !planData.Id.IsNull() { + CheckDn(ctx, &resp.Diagnostics, r.client, "coppIfPol", planData.Id.ValueString()) + if resp.Diagnostics.HasError() { + return + } + } + + resp.Diagnostics.Append(resp.Plan.Set(ctx, &planData)...) + } +} + +func (r *CoppIfPolResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + tflog.Debug(ctx, "Start metadata of resource: aci_copp_interface_policy") + resp.TypeName = req.ProviderTypeName + "_copp_interface_policy" + tflog.Debug(ctx, "End metadata of resource: aci_copp_interface_policy") +} + +func (r *CoppIfPolResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + tflog.Debug(ctx, "Start schema of resource: aci_copp_interface_policy") + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: "The copp_interface_policy resource for the 'coppIfPol' class", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + MarkdownDescription: "The distinguished name (DN) of the CoPP 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 CoPP Interface Policy object.`, + }, + "description": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `The description of the CoPP Interface Policy object.`, + }, + "name": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + stringplanmodifier.RequiresReplace(), + }, + MarkdownDescription: `The name of the CoPP Interface Policy object.`, + }, + "name_alias": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `The name alias of the CoPP 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.`, + }, + "protocol_policies": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Set{ + setplanmodifier.UseStateForUnknown(), + SetToSetNullWhenStateIsNullPlanIsUnknownDuringUpdate(CoppProtoClassPCoppIfPolSetToSetNullWhenStateIsNullPlanIsUnknownDuringUpdate), + }, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "annotation": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The annotation of the CoPP Interface Protocol Policy object.`, + }, + "burst": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The burst size of the CoPP Interface Protocol Policy object.`, + }, + "description": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The description of the CoPP Interface Protocol Policy object.`, + }, + "match_protocols": schema.SetAttribute{ + MarkdownDescription: `The protocols to match in the CoPP Interface Protocol Policy object.`, + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Set{ + setplanmodifier.UseStateForUnknown(), + }, + Validators: []validator.Set{ + setvalidator.SizeAtMost(9), + setvalidator.ValueStringsAre( + stringvalidator.OneOf("arp", "bfd", "bgp", "cdp", "icmp", "lacp", "lldp", "ospf", "stp"), + ), + }, + ElementType: types.StringType, + }, + "name": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The name of the CoPP Interface Protocol Policy object.`, + }, + "name_alias": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The name alias of the CoPP Interface Protocol Policy object.`, + }, + "owner_key": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + 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(), + }, + MarkdownDescription: `A tag for enabling clients to add their own data. For example, to indicate who created this object.`, + }, + "rate": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The rate of the CoPP Interface Protocol Policy 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.`, + }, + }, + }, + }, + }, + }, + }, + "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_copp_interface_policy") +} + +func (r *CoppIfPolResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + tflog.Debug(ctx, "Start configure of resource: aci_copp_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_copp_interface_policy") +} + +func (r *CoppIfPolResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + tflog.Debug(ctx, "Start create of resource: aci_copp_interface_policy") + // On create retrieve information on current state prior to making any changes in order to determine child delete operations + var stateData *CoppIfPolResourceModel + resp.Diagnostics.Append(req.Plan.Get(ctx, &stateData)...) + if stateData.Id.IsUnknown() || stateData.Id.IsNull() { + setCoppIfPolId(ctx, stateData) + } + getAndSetCoppIfPolAttributes(ctx, &resp.Diagnostics, r.client, stateData) + if !globalAllowExistingOnCreate && !stateData.Id.IsNull() { + resp.Diagnostics.AddError( + "Object Already Exists", + fmt.Sprintf("The coppIfPol object with DN '%s' already exists.", stateData.Id.ValueString()), + ) + return + } + + var data *CoppIfPolResourceModel + + // 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() { + setCoppIfPolId(ctx, data) + } + + tflog.Debug(ctx, fmt.Sprintf("Create of resource aci_copp_interface_policy with id '%s'", data.Id.ValueString())) + + var coppProtoClassPPlan, coppProtoClassPState []CoppProtoClassPCoppIfPolResourceModel + data.CoppProtoClassP.ElementsAs(ctx, &coppProtoClassPPlan, false) + stateData.CoppProtoClassP.ElementsAs(ctx, &coppProtoClassPState, false) + var tagAnnotationPlan, tagAnnotationState []TagAnnotationCoppIfPolResourceModel + data.TagAnnotation.ElementsAs(ctx, &tagAnnotationPlan, false) + stateData.TagAnnotation.ElementsAs(ctx, &tagAnnotationState, false) + var tagTagPlan, tagTagState []TagTagCoppIfPolResourceModel + data.TagTag.ElementsAs(ctx, &tagTagPlan, false) + stateData.TagTag.ElementsAs(ctx, &tagTagState, false) + jsonPayload := getCoppIfPolCreateJsonPayload(ctx, &resp.Diagnostics, true, data, coppProtoClassPPlan, coppProtoClassPState, 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 + } + + getAndSetCoppIfPolAttributes(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_copp_interface_policy with id '%s'", data.Id.ValueString())) +} + +func (r *CoppIfPolResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + tflog.Debug(ctx, "Start read of resource: aci_copp_interface_policy") + var data *CoppIfPolResourceModel + + // 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_copp_interface_policy with id '%s'", data.Id.ValueString())) + + getAndSetCoppIfPolAttributes(ctx, &resp.Diagnostics, r.client, data) + + // Save updated data into Terraform state + if data.Id.IsNull() { + var emptyData *CoppIfPolResourceModel + 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_copp_interface_policy with id '%s'", data.Id.ValueString())) +} + +func (r *CoppIfPolResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + tflog.Debug(ctx, "Start update of resource: aci_copp_interface_policy") + var data *CoppIfPolResourceModel + var stateData *CoppIfPolResourceModel + + // 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_copp_interface_policy with id '%s'", data.Id.ValueString())) + + var coppProtoClassPPlan, coppProtoClassPState []CoppProtoClassPCoppIfPolResourceModel + data.CoppProtoClassP.ElementsAs(ctx, &coppProtoClassPPlan, false) + stateData.CoppProtoClassP.ElementsAs(ctx, &coppProtoClassPState, false) + var tagAnnotationPlan, tagAnnotationState []TagAnnotationCoppIfPolResourceModel + data.TagAnnotation.ElementsAs(ctx, &tagAnnotationPlan, false) + stateData.TagAnnotation.ElementsAs(ctx, &tagAnnotationState, false) + var tagTagPlan, tagTagState []TagTagCoppIfPolResourceModel + data.TagTag.ElementsAs(ctx, &tagTagPlan, false) + stateData.TagTag.ElementsAs(ctx, &tagTagState, false) + jsonPayload := getCoppIfPolCreateJsonPayload(ctx, &resp.Diagnostics, false, data, coppProtoClassPPlan, coppProtoClassPState, 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 + } + + getAndSetCoppIfPolAttributes(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_copp_interface_policy with id '%s'", data.Id.ValueString())) +} + +func (r *CoppIfPolResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + tflog.Debug(ctx, "Start delete of resource: aci_copp_interface_policy") + var data *CoppIfPolResourceModel + + // 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_copp_interface_policy with id '%s'", data.Id.ValueString())) + jsonPayload := GetDeleteJsonPayload(ctx, &resp.Diagnostics, "coppIfPol", 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_copp_interface_policy with id '%s'", data.Id.ValueString())) +} + +func (r *CoppIfPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + tflog.Debug(ctx, "Start import state of resource: aci_copp_interface_policy") + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + + var stateData *CoppIfPolResourceModel + resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_copp_interface_policy with id '%s'", stateData.Id.ValueString())) + + tflog.Debug(ctx, "End import of state resource: aci_copp_interface_policy") +} + +func getAndSetCoppIfPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *CoppIfPolResourceModel) { + requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "coppIfPol,coppProtoClassP,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) + + readData := getEmptyCoppIfPolResourceModel() + + if diags.HasError() { + return + } + if requestData.Search("imdata").Search("coppIfPol").Data() != nil { + classReadInfo := requestData.Search("imdata").Search("coppIfPol").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 == "descr" { + readData.Descr = 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)) + } + } + CoppProtoClassPCoppIfPolList := make([]CoppProtoClassPCoppIfPolResourceModel, 0) + TagAnnotationCoppIfPolList := make([]TagAnnotationCoppIfPolResourceModel, 0) + TagTagCoppIfPolList := make([]TagTagCoppIfPolResourceModel, 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 == "coppProtoClassP" { + CoppProtoClassPCoppIfPol := getEmptyCoppProtoClassPCoppIfPolResourceModel() + for childAttributeName, childAttributeValue := range childAttributes { + if childAttributeName == "annotation" { + CoppProtoClassPCoppIfPol.Annotation = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "burst" { + CoppProtoClassPCoppIfPol.Burst = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "descr" { + CoppProtoClassPCoppIfPol.Descr = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "matchProto" { + matchProtoList := make([]string, 0) + if childAttributeValue.(string) != "" { + matchProtoList = strings.Split(childAttributeValue.(string), ",") + } + matchProtoSet, _ := types.SetValueFrom(ctx, basetypes.StringType{}, matchProtoList) + CoppProtoClassPCoppIfPol.MatchProto = matchProtoSet + + } + if childAttributeName == "name" { + CoppProtoClassPCoppIfPol.Name = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "nameAlias" { + CoppProtoClassPCoppIfPol.NameAlias = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "ownerKey" { + CoppProtoClassPCoppIfPol.OwnerKey = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "ownerTag" { + CoppProtoClassPCoppIfPol.OwnerTag = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "rate" { + CoppProtoClassPCoppIfPol.Rate = basetypes.NewStringValue(childAttributeValue.(string)) + } + + } + TagAnnotationCoppProtoClassPCoppIfPolList := make([]TagAnnotationCoppProtoClassPCoppIfPolResourceModel, 0) + TagTagCoppProtoClassPCoppIfPolList := make([]TagTagCoppProtoClassPCoppIfPolResourceModel, 0) + childrenOfCoppProtoClassPCoppIfPol, childrenOfCoppProtoClassPCoppIfPolExist := childClassDetails.(map[string]interface{})["children"] + if childrenOfCoppProtoClassPCoppIfPolExist { + for _, childCoppProtoClassPCoppIfPol := range childrenOfCoppProtoClassPCoppIfPol.([]interface{}) { + for childClassNameCoppProtoClassPCoppIfPol, childClassDetailsCoppProtoClassPCoppIfPol := range childCoppProtoClassPCoppIfPol.(map[string]interface{}) { + if childClassNameCoppProtoClassPCoppIfPol == "tagAnnotation" { + TagAnnotationCoppProtoClassPCoppIfPol := getEmptyTagAnnotationCoppProtoClassPCoppIfPolResourceModel() + tagAnnotationchildAttributeValue := childClassDetailsCoppProtoClassPCoppIfPol.(map[string]interface{})["attributes"].(map[string]interface{}) + for childAttributeName, childAttributeValue := range tagAnnotationchildAttributeValue { + if childAttributeName == "key" { + TagAnnotationCoppProtoClassPCoppIfPol.Key = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "value" { + TagAnnotationCoppProtoClassPCoppIfPol.Value = basetypes.NewStringValue(childAttributeValue.(string)) + } + } + TagAnnotationCoppProtoClassPCoppIfPolList = append(TagAnnotationCoppProtoClassPCoppIfPolList, TagAnnotationCoppProtoClassPCoppIfPol) + } + if childClassNameCoppProtoClassPCoppIfPol == "tagTag" { + TagTagCoppProtoClassPCoppIfPol := getEmptyTagTagCoppProtoClassPCoppIfPolResourceModel() + tagTagchildAttributeValue := childClassDetailsCoppProtoClassPCoppIfPol.(map[string]interface{})["attributes"].(map[string]interface{}) + for childAttributeName, childAttributeValue := range tagTagchildAttributeValue { + if childAttributeName == "key" { + TagTagCoppProtoClassPCoppIfPol.Key = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "value" { + TagTagCoppProtoClassPCoppIfPol.Value = basetypes.NewStringValue(childAttributeValue.(string)) + } + } + TagTagCoppProtoClassPCoppIfPolList = append(TagTagCoppProtoClassPCoppIfPolList, TagTagCoppProtoClassPCoppIfPol) + } + } + } + } + TagAnnotationCoppProtoClassPCoppIfPolSet, _ := types.SetValueFrom(ctx, TagAnnotationCoppProtoClassPCoppIfPolType, TagAnnotationCoppProtoClassPCoppIfPolList) + CoppProtoClassPCoppIfPol.TagAnnotation = TagAnnotationCoppProtoClassPCoppIfPolSet + TagTagCoppProtoClassPCoppIfPolSet, _ := types.SetValueFrom(ctx, TagTagCoppProtoClassPCoppIfPolType, TagTagCoppProtoClassPCoppIfPolList) + CoppProtoClassPCoppIfPol.TagTag = TagTagCoppProtoClassPCoppIfPolSet + CoppProtoClassPCoppIfPolList = append(CoppProtoClassPCoppIfPolList, CoppProtoClassPCoppIfPol) + } + if childClassName == "tagAnnotation" { + TagAnnotationCoppIfPol := getEmptyTagAnnotationCoppIfPolResourceModel() + for childAttributeName, childAttributeValue := range childAttributes { + if childAttributeName == "key" { + TagAnnotationCoppIfPol.Key = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "value" { + TagAnnotationCoppIfPol.Value = basetypes.NewStringValue(childAttributeValue.(string)) + } + + } + TagAnnotationCoppIfPolList = append(TagAnnotationCoppIfPolList, TagAnnotationCoppIfPol) + } + if childClassName == "tagTag" { + TagTagCoppIfPol := getEmptyTagTagCoppIfPolResourceModel() + for childAttributeName, childAttributeValue := range childAttributes { + if childAttributeName == "key" { + TagTagCoppIfPol.Key = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "value" { + TagTagCoppIfPol.Value = basetypes.NewStringValue(childAttributeValue.(string)) + } + + } + TagTagCoppIfPolList = append(TagTagCoppIfPolList, TagTagCoppIfPol) + } + } + } + } + coppProtoClassPSet, _ := types.SetValueFrom(ctx, readData.CoppProtoClassP.ElementType(ctx), CoppProtoClassPCoppIfPolList) + readData.CoppProtoClassP = coppProtoClassPSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationCoppIfPolList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagCoppIfPolList) + readData.TagTag = tagTagSet + } else { + diags.AddError( + "too many results in response", + fmt.Sprintf("%v matches returned for class 'coppIfPol'. Please report this issue to the provider developers.", len(classReadInfo)), + ) + } + } else { + readData.Id = basetypes.NewStringNull() + } + *data = *readData +} + +func getCoppIfPolRn(ctx context.Context, data *CoppIfPolResourceModel) string { + return fmt.Sprintf("infra/coppifpol-%s", data.Name.ValueString()) +} + +func setCoppIfPolId(ctx context.Context, data *CoppIfPolResourceModel) { + rn := getCoppIfPolRn(ctx, data) + data.Id = types.StringValue(fmt.Sprintf("%s/%s", strings.Split([]string{"uni/infra/coppifpol-{name}"}[0], "/")[0], rn)) +} + +func getCoppIfPolCoppProtoClassPChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *CoppIfPolResourceModel, coppProtoClassPCoppIfPolPlan, coppProtoClassPCoppIfPolState []CoppProtoClassPCoppIfPolResourceModel) []map[string]interface{} { + childPayloads := []map[string]interface{}{} + if !data.CoppProtoClassP.IsNull() && !data.CoppProtoClassP.IsUnknown() { + coppProtoClassPIdentifiers := []CoppProtoClassPIdentifier{} + for _, coppProtoClassPCoppIfPol := range coppProtoClassPCoppIfPolPlan { + CoppProtoClassPCoppIfPolChildren := make([]map[string]interface{}, 0) + childMap := NewAciObject() + if !coppProtoClassPCoppIfPol.Annotation.IsNull() && !coppProtoClassPCoppIfPol.Annotation.IsUnknown() { + childMap.Attributes["annotation"] = coppProtoClassPCoppIfPol.Annotation.ValueString() + } else { + childMap.Attributes["annotation"] = globalAnnotation + } + if !coppProtoClassPCoppIfPol.Burst.IsNull() && !coppProtoClassPCoppIfPol.Burst.IsUnknown() { + childMap.Attributes["burst"] = coppProtoClassPCoppIfPol.Burst.ValueString() + } + if !coppProtoClassPCoppIfPol.Descr.IsNull() && !coppProtoClassPCoppIfPol.Descr.IsUnknown() { + childMap.Attributes["descr"] = coppProtoClassPCoppIfPol.Descr.ValueString() + } + if !coppProtoClassPCoppIfPol.MatchProto.IsNull() && !coppProtoClassPCoppIfPol.MatchProto.IsUnknown() { + var tmpMatchProto []string + coppProtoClassPCoppIfPol.MatchProto.ElementsAs(ctx, &tmpMatchProto, false) + childMap.Attributes["matchProto"] = strings.Join(tmpMatchProto, ",") + } + if !coppProtoClassPCoppIfPol.Name.IsNull() && !coppProtoClassPCoppIfPol.Name.IsUnknown() { + childMap.Attributes["name"] = coppProtoClassPCoppIfPol.Name.ValueString() + } + if !coppProtoClassPCoppIfPol.NameAlias.IsNull() && !coppProtoClassPCoppIfPol.NameAlias.IsUnknown() { + childMap.Attributes["nameAlias"] = coppProtoClassPCoppIfPol.NameAlias.ValueString() + } + if !coppProtoClassPCoppIfPol.OwnerKey.IsNull() && !coppProtoClassPCoppIfPol.OwnerKey.IsUnknown() { + childMap.Attributes["ownerKey"] = coppProtoClassPCoppIfPol.OwnerKey.ValueString() + } + if !coppProtoClassPCoppIfPol.OwnerTag.IsNull() && !coppProtoClassPCoppIfPol.OwnerTag.IsUnknown() { + childMap.Attributes["ownerTag"] = coppProtoClassPCoppIfPol.OwnerTag.ValueString() + } + if !coppProtoClassPCoppIfPol.Rate.IsNull() && !coppProtoClassPCoppIfPol.Rate.IsUnknown() { + childMap.Attributes["rate"] = coppProtoClassPCoppIfPol.Rate.ValueString() + } + + var tagAnnotationCoppProtoClassPCoppIfPolPlan, tagAnnotationCoppProtoClassPCoppIfPolState []TagAnnotationCoppProtoClassPCoppIfPolResourceModel + coppProtoClassPCoppIfPol.TagAnnotation.ElementsAs(ctx, &tagAnnotationCoppProtoClassPCoppIfPolPlan, false) + for _, tagAnnotationCoppProtoClassPCoppIfPolstate := range coppProtoClassPCoppIfPolState { + tagAnnotationCoppProtoClassPCoppIfPolstate.TagAnnotation.ElementsAs(ctx, &tagAnnotationCoppProtoClassPCoppIfPolState, false) + } + if !coppProtoClassPCoppIfPol.TagAnnotation.IsNull() && !coppProtoClassPCoppIfPol.TagAnnotation.IsUnknown() { + tagAnnotationIdentifiers := []TagAnnotationIdentifier{} + for _, tagAnnotationCoppProtoClassPCoppIfPol := range tagAnnotationCoppProtoClassPCoppIfPolPlan { + tagAnnotationCoppProtoClassPCoppIfPolChildMap := NewAciObject() + if !tagAnnotationCoppProtoClassPCoppIfPol.Key.IsNull() && !tagAnnotationCoppProtoClassPCoppIfPol.Key.IsUnknown() { + tagAnnotationCoppProtoClassPCoppIfPolChildMap.Attributes["key"] = tagAnnotationCoppProtoClassPCoppIfPol.Key.ValueString() + } + if !tagAnnotationCoppProtoClassPCoppIfPol.Value.IsNull() && !tagAnnotationCoppProtoClassPCoppIfPol.Value.IsUnknown() { + tagAnnotationCoppProtoClassPCoppIfPolChildMap.Attributes["value"] = tagAnnotationCoppProtoClassPCoppIfPol.Value.ValueString() + } + CoppProtoClassPCoppIfPolChildren = append(CoppProtoClassPCoppIfPolChildren, map[string]interface{}{"tagAnnotation": tagAnnotationCoppProtoClassPCoppIfPolChildMap}) + tagAnnotationIdentifier := TagAnnotationIdentifier{} + tagAnnotationIdentifier.Key = tagAnnotationCoppProtoClassPCoppIfPol.Key + tagAnnotationIdentifiers = append(tagAnnotationIdentifiers, tagAnnotationIdentifier) + } + for _, tagAnnotationCoppProtoClassPCoppIfPol := range tagAnnotationCoppProtoClassPCoppIfPolState { + delete := true + for _, tagAnnotationIdentifier := range tagAnnotationIdentifiers { + if tagAnnotationIdentifier.Key == tagAnnotationCoppProtoClassPCoppIfPol.Key { + delete = false + break + } + } + if delete { + tagAnnotationCoppProtoClassPCoppIfPolChildMapForDelete := NewAciObject() + tagAnnotationCoppProtoClassPCoppIfPolChildMapForDelete.Attributes["status"] = "deleted" + tagAnnotationCoppProtoClassPCoppIfPolChildMapForDelete.Attributes["key"] = tagAnnotationCoppProtoClassPCoppIfPol.Key.ValueString() + CoppProtoClassPCoppIfPolChildren = append(CoppProtoClassPCoppIfPolChildren, map[string]interface{}{"tagAnnotation": tagAnnotationCoppProtoClassPCoppIfPolChildMapForDelete}) + } + } + } + + var tagTagCoppProtoClassPCoppIfPolPlan, tagTagCoppProtoClassPCoppIfPolState []TagTagCoppProtoClassPCoppIfPolResourceModel + coppProtoClassPCoppIfPol.TagTag.ElementsAs(ctx, &tagTagCoppProtoClassPCoppIfPolPlan, false) + for _, tagTagCoppProtoClassPCoppIfPolstate := range coppProtoClassPCoppIfPolState { + tagTagCoppProtoClassPCoppIfPolstate.TagTag.ElementsAs(ctx, &tagTagCoppProtoClassPCoppIfPolState, false) + } + if !coppProtoClassPCoppIfPol.TagTag.IsNull() && !coppProtoClassPCoppIfPol.TagTag.IsUnknown() { + tagTagIdentifiers := []TagTagIdentifier{} + for _, tagTagCoppProtoClassPCoppIfPol := range tagTagCoppProtoClassPCoppIfPolPlan { + tagTagCoppProtoClassPCoppIfPolChildMap := NewAciObject() + if !tagTagCoppProtoClassPCoppIfPol.Key.IsNull() && !tagTagCoppProtoClassPCoppIfPol.Key.IsUnknown() { + tagTagCoppProtoClassPCoppIfPolChildMap.Attributes["key"] = tagTagCoppProtoClassPCoppIfPol.Key.ValueString() + } + if !tagTagCoppProtoClassPCoppIfPol.Value.IsNull() && !tagTagCoppProtoClassPCoppIfPol.Value.IsUnknown() { + tagTagCoppProtoClassPCoppIfPolChildMap.Attributes["value"] = tagTagCoppProtoClassPCoppIfPol.Value.ValueString() + } + CoppProtoClassPCoppIfPolChildren = append(CoppProtoClassPCoppIfPolChildren, map[string]interface{}{"tagTag": tagTagCoppProtoClassPCoppIfPolChildMap}) + tagTagIdentifier := TagTagIdentifier{} + tagTagIdentifier.Key = tagTagCoppProtoClassPCoppIfPol.Key + tagTagIdentifiers = append(tagTagIdentifiers, tagTagIdentifier) + } + for _, tagTagCoppProtoClassPCoppIfPol := range tagTagCoppProtoClassPCoppIfPolState { + delete := true + for _, tagTagIdentifier := range tagTagIdentifiers { + if tagTagIdentifier.Key == tagTagCoppProtoClassPCoppIfPol.Key { + delete = false + break + } + } + if delete { + tagTagCoppProtoClassPCoppIfPolChildMapForDelete := NewAciObject() + tagTagCoppProtoClassPCoppIfPolChildMapForDelete.Attributes["status"] = "deleted" + tagTagCoppProtoClassPCoppIfPolChildMapForDelete.Attributes["key"] = tagTagCoppProtoClassPCoppIfPol.Key.ValueString() + CoppProtoClassPCoppIfPolChildren = append(CoppProtoClassPCoppIfPolChildren, map[string]interface{}{"tagTag": tagTagCoppProtoClassPCoppIfPolChildMapForDelete}) + } + } + } + childMap.Children = CoppProtoClassPCoppIfPolChildren + childPayloads = append(childPayloads, map[string]interface{}{"coppProtoClassP": childMap}) + coppProtoClassPIdentifier := CoppProtoClassPIdentifier{} + coppProtoClassPIdentifier.Name = coppProtoClassPCoppIfPol.Name + coppProtoClassPIdentifiers = append(coppProtoClassPIdentifiers, coppProtoClassPIdentifier) + } + for _, coppProtoClassP := range coppProtoClassPCoppIfPolState { + delete := true + for _, coppProtoClassPIdentifier := range coppProtoClassPIdentifiers { + if coppProtoClassPIdentifier.Name == coppProtoClassP.Name { + delete = false + break + } + } + if delete { + coppProtoClassPChildMapForDelete := NewAciObject() + coppProtoClassPChildMapForDelete.Attributes["status"] = "deleted" + coppProtoClassPChildMapForDelete.Attributes["name"] = coppProtoClassP.Name.ValueString() + childPayloads = append(childPayloads, map[string]interface{}{"coppProtoClassP": coppProtoClassPChildMapForDelete}) + } + } + } else { + data.CoppProtoClassP = types.SetNull(data.CoppProtoClassP.ElementType(ctx)) + } + + return childPayloads +} + +func getCoppIfPolTagAnnotationChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *CoppIfPolResourceModel, tagAnnotationCoppIfPolPlan, tagAnnotationCoppIfPolState []TagAnnotationCoppIfPolResourceModel) []map[string]interface{} { + childPayloads := []map[string]interface{}{} + if !data.TagAnnotation.IsNull() && !data.TagAnnotation.IsUnknown() { + tagAnnotationIdentifiers := []TagAnnotationIdentifier{} + for _, tagAnnotationCoppIfPol := range tagAnnotationCoppIfPolPlan { + childMap := NewAciObject() + if !tagAnnotationCoppIfPol.Key.IsNull() && !tagAnnotationCoppIfPol.Key.IsUnknown() { + childMap.Attributes["key"] = tagAnnotationCoppIfPol.Key.ValueString() + } + if !tagAnnotationCoppIfPol.Value.IsNull() && !tagAnnotationCoppIfPol.Value.IsUnknown() { + childMap.Attributes["value"] = tagAnnotationCoppIfPol.Value.ValueString() + } + childPayloads = append(childPayloads, map[string]interface{}{"tagAnnotation": childMap}) + tagAnnotationIdentifier := TagAnnotationIdentifier{} + tagAnnotationIdentifier.Key = tagAnnotationCoppIfPol.Key + tagAnnotationIdentifiers = append(tagAnnotationIdentifiers, tagAnnotationIdentifier) + } + for _, tagAnnotation := range tagAnnotationCoppIfPolState { + 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 getCoppIfPolTagTagChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *CoppIfPolResourceModel, tagTagCoppIfPolPlan, tagTagCoppIfPolState []TagTagCoppIfPolResourceModel) []map[string]interface{} { + childPayloads := []map[string]interface{}{} + if !data.TagTag.IsNull() && !data.TagTag.IsUnknown() { + tagTagIdentifiers := []TagTagIdentifier{} + for _, tagTagCoppIfPol := range tagTagCoppIfPolPlan { + childMap := NewAciObject() + if !tagTagCoppIfPol.Key.IsNull() && !tagTagCoppIfPol.Key.IsUnknown() { + childMap.Attributes["key"] = tagTagCoppIfPol.Key.ValueString() + } + if !tagTagCoppIfPol.Value.IsNull() && !tagTagCoppIfPol.Value.IsUnknown() { + childMap.Attributes["value"] = tagTagCoppIfPol.Value.ValueString() + } + childPayloads = append(childPayloads, map[string]interface{}{"tagTag": childMap}) + tagTagIdentifier := TagTagIdentifier{} + tagTagIdentifier.Key = tagTagCoppIfPol.Key + tagTagIdentifiers = append(tagTagIdentifiers, tagTagIdentifier) + } + for _, tagTag := range tagTagCoppIfPolState { + 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 getCoppIfPolCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, createType bool, data *CoppIfPolResourceModel, coppProtoClassPPlan, coppProtoClassPState []CoppProtoClassPCoppIfPolResourceModel, tagAnnotationPlan, tagAnnotationState []TagAnnotationCoppIfPolResourceModel, tagTagPlan, tagTagState []TagTagCoppIfPolResourceModel) *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{}{} + + CoppProtoClassPchildPayloads := getCoppIfPolCoppProtoClassPChildPayloads(ctx, diags, data, coppProtoClassPPlan, coppProtoClassPState) + if CoppProtoClassPchildPayloads == nil { + return nil + } + childPayloads = append(childPayloads, CoppProtoClassPchildPayloads...) + + TagAnnotationchildPayloads := getCoppIfPolTagAnnotationChildPayloads(ctx, diags, data, tagAnnotationPlan, tagAnnotationState) + if TagAnnotationchildPayloads == nil { + return nil + } + childPayloads = append(childPayloads, TagAnnotationchildPayloads...) + + TagTagchildPayloads := getCoppIfPolTagTagChildPayloads(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.Descr.IsNull() && !data.Descr.IsUnknown() { + payloadMap["attributes"].(map[string]string)["descr"] = data.Descr.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{}{"coppIfPol": 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_copp_interface_policy_test.go b/internal/provider/resource_aci_copp_interface_policy_test.go new file mode 100644 index 000000000..8ce4dc090 --- /dev/null +++ b/internal/provider/resource_aci_copp_interface_policy_test.go @@ -0,0 +1,497 @@ +// 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 TestAccResourceCoppIfPol(t *testing.T) { + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "apic", "2.3(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigCoppIfPolMinAllowExisting, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test_2", "name", "test_name"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test_2", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test", "description", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test_2", "description", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test_2", "name_alias", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test_2", "owner_key", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_copp_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.3(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigCoppIfPolMinAllowExisting, + 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.3(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigCoppIfPolMinAllowExisting, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test_2", "name", "test_name"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test_2", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test", "description", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test_2", "description", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test_2", "name_alias", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test_2", "owner_key", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.allow_test_2", "owner_tag", ""), + ), + }, + }, + }) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "apic", "2.3(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigCoppIfPolMin, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "owner_tag", ""), + ), + }, + // Update with all config and verify default APIC values + { + Config: testConfigCoppIfPolAll, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotation", "annotation"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "description", "description_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "name_alias", "name_alias_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "owner_key", "owner_key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "owner_tag", "owner_tag_1"), + ), + }, + // Update with minimum config and verify config is unchanged + { + Config: testConfigCoppIfPolMin, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "description", "description_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "name_alias", "name_alias_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "owner_key", "owner_key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "owner_tag", "owner_tag_1"), + ), + }, + // Update with empty strings config or default value + { + Config: testConfigCoppIfPolReset, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "owner_tag", ""), + ), + }, + // Import testing + { + ResourceName: "aci_copp_interface_policy.test", + ImportState: true, + ImportStateVerify: true, + }, + // Update with children + { + Config: testConfigCoppIfPolChildren, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotations.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotations.#", "2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.annotation", "annotation_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.burst", "15"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.annotations.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.annotations.#", "2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.tags.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.tags.#", "2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.description", "description_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.match_protocols.#", "2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.match_protocols.0", "arp"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.match_protocols.1", "bfd"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.name", "name_0"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.name_alias", "name_alias_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.owner_key", "owner_key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.owner_tag", "owner_tag_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.rate", "15"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.annotation", "annotation_2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.burst", "10"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.annotations.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.annotations.#", "2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.tags.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.tags.#", "2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.description", "description_2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.match_protocols.#", "0"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.name", "name_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.name_alias", "name_alias_2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.owner_key", "owner_key_2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.owner_tag", "owner_tag_2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.rate", "10"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.#", "2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "tags.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "tags.#", "2"), + ), + }, + // Update with children removed from config + { + Config: testConfigCoppIfPolChildrenRemoveFromConfig, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotations.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotations.#", "2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.annotation", "annotation_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.burst", "15"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.annotations.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.annotations.#", "2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.tags.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.tags.#", "2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.description", "description_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.match_protocols.#", "2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.match_protocols.0", "arp"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.match_protocols.1", "bfd"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.name", "name_0"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.name_alias", "name_alias_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.owner_key", "owner_key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.owner_tag", "owner_tag_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.rate", "15"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.annotation", "annotation_2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.burst", "10"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.annotations.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.annotations.#", "2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.tags.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.tags.#", "2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.description", "description_2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.match_protocols.#", "0"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.name", "name_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.name_alias", "name_alias_2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.owner_key", "owner_key_2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.owner_tag", "owner_tag_2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.1.rate", "10"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.#", "2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "tags.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "tags.#", "2"), + ), + }, + // Update with children first child removed + { + Config: testConfigCoppIfPolChildrenRemoveOne, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotations.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotations.0.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotations.#", "1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.annotation", "annotation_2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.burst", "10"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.annotations.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.annotations.0.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.annotations.#", "1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.tags.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.tags.0.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.tags.#", "1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.description", "description_2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.match_protocols.#", "0"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.name", "name_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.name_alias", "name_alias_2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.owner_key", "owner_key_2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.owner_tag", "owner_tag_2"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.0.rate", "10"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.#", "1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "tags.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "tags.0.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "tags.#", "1"), + ), + }, + // Update with all children removed + { + Config: testConfigCoppIfPolChildrenRemoveAll, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "annotations.#", "0"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "protocol_policies.#", "0"), + resource.TestCheckResourceAttr("aci_copp_interface_policy.test", "tags.#", "0"), + ), + }, + }, + CheckDestroy: testCheckResourceDestroy, + }) +} + +const testConfigCoppIfPolMinAllowExisting = ` +resource "aci_copp_interface_policy" "allow_test" { + name = "test_name" +} +resource "aci_copp_interface_policy" "allow_test_2" { + name = "test_name" + depends_on = [aci_copp_interface_policy.allow_test] +} +` + +const testConfigCoppIfPolMin = ` +resource "aci_copp_interface_policy" "test" { + name = "test_name" +} +` + +const testConfigCoppIfPolAll = ` +resource "aci_copp_interface_policy" "test" { + name = "test_name" + annotation = "annotation" + description = "description_1" + name_alias = "name_alias_1" + owner_key = "owner_key_1" + owner_tag = "owner_tag_1" +} +` + +const testConfigCoppIfPolReset = ` +resource "aci_copp_interface_policy" "test" { + name = "test_name" + annotation = "orchestrator:terraform" + description = "" + name_alias = "" + owner_key = "" + owner_tag = "" +} +` +const testConfigCoppIfPolChildren = ` +resource "aci_copp_interface_policy" "test" { + name = "test_name" + annotations = [ + { + key = "key_0" + value = "value_1" + }, + { + key = "key_1" + value = "test_value" + }, + ] + protocol_policies = [ + { + annotation = "annotation_1" + burst = "15" + 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" + }, + ] + description = "description_1" + match_protocols = ["arp", "bfd"] + name = "name_0" + name_alias = "name_alias_1" + owner_key = "owner_key_1" + owner_tag = "owner_tag_1" + rate = "15" + }, + { + annotation = "annotation_2" + burst = "10" + 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" + }, + ] + description = "description_2" + match_protocols = [] + name = "name_1" + name_alias = "name_alias_2" + owner_key = "owner_key_2" + owner_tag = "owner_tag_2" + rate = "10" + }, + ] + tags = [ + { + key = "key_0" + value = "value_1" + }, + { + key = "key_1" + value = "test_value" + }, + ] +} +` + +const testConfigCoppIfPolChildrenRemoveFromConfig = ` +resource "aci_copp_interface_policy" "test" { + name = "test_name" +} +` + +const testConfigCoppIfPolChildrenRemoveOne = ` +resource "aci_copp_interface_policy" "test" { + name = "test_name" + annotations = [ + { + key = "key_1" + value = "test_value" + }, + ] + protocol_policies = [ + { + annotation = "annotation_2" + burst = "10" + annotations = [ + { + key = "key_1" + value = "test_value" + }, + ] + tags = [ + { + key = "key_1" + value = "test_value" + }, + ] + description = "description_2" + match_protocols = [] + name = "name_1" + name_alias = "name_alias_2" + owner_key = "owner_key_2" + owner_tag = "owner_tag_2" + rate = "10" + }, + ] + tags = [ + { + key = "key_1" + value = "test_value" + }, + ] +} +` + +const testConfigCoppIfPolChildrenRemoveAll = ` +resource "aci_copp_interface_policy" "test" { + name = "test_name" + annotations = [] + protocol_policies = [] + tags = [] +} +` diff --git a/internal/provider/resource_aci_copp_interface_protocol_policy.go b/internal/provider/resource_aci_copp_interface_protocol_policy.go new file mode 100644 index 000000000..d6d2257ee --- /dev/null +++ b/internal/provider/resource_aci_copp_interface_protocol_policy.go @@ -0,0 +1,788 @@ +// 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/setvalidator" + "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 = &CoppProtoClassPResource{} +var _ resource.ResourceWithImportState = &CoppProtoClassPResource{} + +func NewCoppProtoClassPResource() resource.Resource { + return &CoppProtoClassPResource{} +} + +// CoppProtoClassPResource defines the resource implementation. +type CoppProtoClassPResource struct { + client *client.Client +} + +// CoppProtoClassPResourceModel describes the resource data model. +type CoppProtoClassPResourceModel struct { + Id types.String `tfsdk:"id"` + ParentDn types.String `tfsdk:"parent_dn"` + Annotation types.String `tfsdk:"annotation"` + Burst types.String `tfsdk:"burst"` + Descr types.String `tfsdk:"description"` + MatchProto types.Set `tfsdk:"match_protocols"` + Name types.String `tfsdk:"name"` + NameAlias types.String `tfsdk:"name_alias"` + OwnerKey types.String `tfsdk:"owner_key"` + OwnerTag types.String `tfsdk:"owner_tag"` + Rate types.String `tfsdk:"rate"` + TagAnnotation types.Set `tfsdk:"annotations"` + TagTag types.Set `tfsdk:"tags"` +} + +func getEmptyCoppProtoClassPResourceModel() *CoppProtoClassPResourceModel { + return &CoppProtoClassPResourceModel{ + Id: basetypes.NewStringNull(), + ParentDn: basetypes.NewStringNull(), + Annotation: basetypes.NewStringNull(), + Burst: basetypes.NewStringNull(), + Descr: basetypes.NewStringNull(), + MatchProto: types.SetNull(types.StringType), + Name: basetypes.NewStringNull(), + NameAlias: basetypes.NewStringNull(), + OwnerKey: basetypes.NewStringNull(), + OwnerTag: basetypes.NewStringNull(), + Rate: 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, + }, + }), + } +} + +// TagAnnotationCoppProtoClassPResourceModel describes the resource data model for the children without relation ships. +type TagAnnotationCoppProtoClassPResourceModel struct { + Key types.String `tfsdk:"key"` + Value types.String `tfsdk:"value"` +} + +func getEmptyTagAnnotationCoppProtoClassPResourceModel() TagAnnotationCoppProtoClassPResourceModel { + return TagAnnotationCoppProtoClassPResourceModel{ + Key: basetypes.NewStringNull(), + Value: basetypes.NewStringNull(), + } +} + +var TagAnnotationCoppProtoClassPType = types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "key": types.StringType, + "value": types.StringType, + }, +} + +// TagTagCoppProtoClassPResourceModel describes the resource data model for the children without relation ships. +type TagTagCoppProtoClassPResourceModel struct { + Key types.String `tfsdk:"key"` + Value types.String `tfsdk:"value"` +} + +func getEmptyTagTagCoppProtoClassPResourceModel() TagTagCoppProtoClassPResourceModel { + return TagTagCoppProtoClassPResourceModel{ + Key: basetypes.NewStringNull(), + Value: basetypes.NewStringNull(), + } +} + +var TagTagCoppProtoClassPType = types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "key": types.StringType, + "value": types.StringType, + }, +} + +type CoppProtoClassPIdentifier struct { + Name types.String +} + +func (r *CoppProtoClassPResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if !req.Plan.Raw.IsNull() { + var planData, stateData *CoppProtoClassPResourceModel + 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.ParentDn.IsUnknown() && !planData.Name.IsUnknown() { + setCoppProtoClassPId(ctx, planData) + } + + if stateData == nil && !globalAllowExistingOnCreate && !planData.Id.IsUnknown() && !planData.Id.IsNull() { + CheckDn(ctx, &resp.Diagnostics, r.client, "coppProtoClassP", planData.Id.ValueString()) + if resp.Diagnostics.HasError() { + return + } + } + + resp.Diagnostics.Append(resp.Plan.Set(ctx, &planData)...) + } +} + +func (r *CoppProtoClassPResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + tflog.Debug(ctx, "Start metadata of resource: aci_copp_interface_protocol_policy") + resp.TypeName = req.ProviderTypeName + "_copp_interface_protocol_policy" + tflog.Debug(ctx, "End metadata of resource: aci_copp_interface_protocol_policy") +} + +func (r *CoppProtoClassPResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + tflog.Debug(ctx, "Start schema of resource: aci_copp_interface_protocol_policy") + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: "The copp_interface_protocol_policy resource for the 'coppProtoClassP' class", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + MarkdownDescription: "The distinguished name (DN) of the CoPP Interface Protocol Policy object.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "parent_dn": schema.StringAttribute{ + Required: true, + MarkdownDescription: "The distinguished name (DN) of the parent object.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + stringplanmodifier.RequiresReplace(), + }, + }, + "annotation": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + Default: stringdefault.StaticString(globalAnnotation), + MarkdownDescription: `The annotation of the CoPP Interface Protocol Policy object.`, + }, + "burst": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `The burst size of the CoPP Interface Protocol Policy object.`, + }, + "description": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `The description of the CoPP Interface Protocol Policy object.`, + }, + "match_protocols": schema.SetAttribute{ + MarkdownDescription: `The protocols to match in the CoPP Interface Protocol Policy object.`, + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Set{ + setplanmodifier.UseStateForUnknown(), + SetToSetNullWhenStateIsNullPlanIsUnknownDuringUpdate(nil), + }, + Validators: []validator.Set{ + setvalidator.SizeAtMost(9), + setvalidator.ValueStringsAre( + stringvalidator.OneOf("arp", "bfd", "bgp", "cdp", "icmp", "lacp", "lldp", "ospf", "stp"), + ), + }, + ElementType: types.StringType, + }, + "name": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + stringplanmodifier.RequiresReplace(), + }, + MarkdownDescription: `The name of the CoPP Interface Protocol Policy object.`, + }, + "name_alias": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `The name alias of the CoPP Interface Protocol 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.`, + }, + "rate": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `The rate of the CoPP Interface Protocol Policy 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_copp_interface_protocol_policy") +} + +func (r *CoppProtoClassPResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + tflog.Debug(ctx, "Start configure of resource: aci_copp_interface_protocol_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_copp_interface_protocol_policy") +} + +func (r *CoppProtoClassPResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + tflog.Debug(ctx, "Start create of resource: aci_copp_interface_protocol_policy") + // On create retrieve information on current state prior to making any changes in order to determine child delete operations + var stateData *CoppProtoClassPResourceModel + resp.Diagnostics.Append(req.Plan.Get(ctx, &stateData)...) + if stateData.Id.IsUnknown() || stateData.Id.IsNull() { + setCoppProtoClassPId(ctx, stateData) + } + getAndSetCoppProtoClassPAttributes(ctx, &resp.Diagnostics, r.client, stateData) + if !globalAllowExistingOnCreate && !stateData.Id.IsNull() { + resp.Diagnostics.AddError( + "Object Already Exists", + fmt.Sprintf("The coppProtoClassP object with DN '%s' already exists.", stateData.Id.ValueString()), + ) + return + } + + var data *CoppProtoClassPResourceModel + + // 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() { + setCoppProtoClassPId(ctx, data) + } + + tflog.Debug(ctx, fmt.Sprintf("Create of resource aci_copp_interface_protocol_policy with id '%s'", data.Id.ValueString())) + + var tagAnnotationPlan, tagAnnotationState []TagAnnotationCoppProtoClassPResourceModel + data.TagAnnotation.ElementsAs(ctx, &tagAnnotationPlan, false) + stateData.TagAnnotation.ElementsAs(ctx, &tagAnnotationState, false) + var tagTagPlan, tagTagState []TagTagCoppProtoClassPResourceModel + data.TagTag.ElementsAs(ctx, &tagTagPlan, false) + stateData.TagTag.ElementsAs(ctx, &tagTagState, false) + jsonPayload := getCoppProtoClassPCreateJsonPayload(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 + } + + getAndSetCoppProtoClassPAttributes(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_copp_interface_protocol_policy with id '%s'", data.Id.ValueString())) +} + +func (r *CoppProtoClassPResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + tflog.Debug(ctx, "Start read of resource: aci_copp_interface_protocol_policy") + var data *CoppProtoClassPResourceModel + + // 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_copp_interface_protocol_policy with id '%s'", data.Id.ValueString())) + + getAndSetCoppProtoClassPAttributes(ctx, &resp.Diagnostics, r.client, data) + + // Save updated data into Terraform state + if data.Id.IsNull() { + var emptyData *CoppProtoClassPResourceModel + 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_copp_interface_protocol_policy with id '%s'", data.Id.ValueString())) +} + +func (r *CoppProtoClassPResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + tflog.Debug(ctx, "Start update of resource: aci_copp_interface_protocol_policy") + var data *CoppProtoClassPResourceModel + var stateData *CoppProtoClassPResourceModel + + // 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_copp_interface_protocol_policy with id '%s'", data.Id.ValueString())) + + var tagAnnotationPlan, tagAnnotationState []TagAnnotationCoppProtoClassPResourceModel + data.TagAnnotation.ElementsAs(ctx, &tagAnnotationPlan, false) + stateData.TagAnnotation.ElementsAs(ctx, &tagAnnotationState, false) + var tagTagPlan, tagTagState []TagTagCoppProtoClassPResourceModel + data.TagTag.ElementsAs(ctx, &tagTagPlan, false) + stateData.TagTag.ElementsAs(ctx, &tagTagState, false) + jsonPayload := getCoppProtoClassPCreateJsonPayload(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 + } + + getAndSetCoppProtoClassPAttributes(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_copp_interface_protocol_policy with id '%s'", data.Id.ValueString())) +} + +func (r *CoppProtoClassPResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + tflog.Debug(ctx, "Start delete of resource: aci_copp_interface_protocol_policy") + var data *CoppProtoClassPResourceModel + + // 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_copp_interface_protocol_policy with id '%s'", data.Id.ValueString())) + jsonPayload := GetDeleteJsonPayload(ctx, &resp.Diagnostics, "coppProtoClassP", 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_copp_interface_protocol_policy with id '%s'", data.Id.ValueString())) +} + +func (r *CoppProtoClassPResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + tflog.Debug(ctx, "Start import state of resource: aci_copp_interface_protocol_policy") + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + + var stateData *CoppProtoClassPResourceModel + resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_copp_interface_protocol_policy with id '%s'", stateData.Id.ValueString())) + + tflog.Debug(ctx, "End import of state resource: aci_copp_interface_protocol_policy") +} + +func getAndSetCoppProtoClassPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *CoppProtoClassPResourceModel) { + requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "coppProtoClassP,tagAnnotation,tagTag"), "GET", nil) + + readData := getEmptyCoppProtoClassPResourceModel() + + if diags.HasError() { + return + } + if requestData.Search("imdata").Search("coppProtoClassP").Data() != nil { + classReadInfo := requestData.Search("imdata").Search("coppProtoClassP").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)) + setCoppProtoClassPParentDn(ctx, attributeValue.(string), readData) + } + if attributeName == "annotation" { + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "burst" { + readData.Burst = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "descr" { + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "matchProto" { + matchProtoList := make([]string, 0) + if attributeValue.(string) != "" { + matchProtoList = strings.Split(attributeValue.(string), ",") + } + matchProtoSet, _ := types.SetValueFrom(ctx, readData.MatchProto.ElementType(ctx), matchProtoList) + readData.MatchProto = matchProtoSet + } + 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)) + } + if attributeName == "rate" { + readData.Rate = basetypes.NewStringValue(attributeValue.(string)) + } + } + TagAnnotationCoppProtoClassPList := make([]TagAnnotationCoppProtoClassPResourceModel, 0) + TagTagCoppProtoClassPList := make([]TagTagCoppProtoClassPResourceModel, 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" { + TagAnnotationCoppProtoClassP := getEmptyTagAnnotationCoppProtoClassPResourceModel() + for childAttributeName, childAttributeValue := range childAttributes { + if childAttributeName == "key" { + TagAnnotationCoppProtoClassP.Key = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "value" { + TagAnnotationCoppProtoClassP.Value = basetypes.NewStringValue(childAttributeValue.(string)) + } + + } + TagAnnotationCoppProtoClassPList = append(TagAnnotationCoppProtoClassPList, TagAnnotationCoppProtoClassP) + } + if childClassName == "tagTag" { + TagTagCoppProtoClassP := getEmptyTagTagCoppProtoClassPResourceModel() + for childAttributeName, childAttributeValue := range childAttributes { + if childAttributeName == "key" { + TagTagCoppProtoClassP.Key = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "value" { + TagTagCoppProtoClassP.Value = basetypes.NewStringValue(childAttributeValue.(string)) + } + + } + TagTagCoppProtoClassPList = append(TagTagCoppProtoClassPList, TagTagCoppProtoClassP) + } + } + } + } + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationCoppProtoClassPList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagCoppProtoClassPList) + readData.TagTag = tagTagSet + } else { + diags.AddError( + "too many results in response", + fmt.Sprintf("%v matches returned for class 'coppProtoClassP'. Please report this issue to the provider developers.", len(classReadInfo)), + ) + } + } else { + readData.Id = basetypes.NewStringNull() + } + *data = *readData +} + +func getCoppProtoClassPRn(ctx context.Context, data *CoppProtoClassPResourceModel) string { + return fmt.Sprintf("protoclassp-%s", data.Name.ValueString()) +} + +func setCoppProtoClassPParentDn(ctx context.Context, dn string, data *CoppProtoClassPResourceModel) { + bracketIndex := 0 + rnIndex := 0 + for i := len(dn) - 1; i >= 0; i-- { + if string(dn[i]) == "]" { + bracketIndex = bracketIndex + 1 + } else if string(dn[i]) == "[" { + bracketIndex = bracketIndex - 1 + } else if string(dn[i]) == "/" && bracketIndex == 0 { + rnIndex = i + break + } + } + data.ParentDn = basetypes.NewStringValue(dn[:rnIndex]) +} + +func setCoppProtoClassPId(ctx context.Context, data *CoppProtoClassPResourceModel) { + rn := getCoppProtoClassPRn(ctx, data) + data.Id = types.StringValue(fmt.Sprintf("%s/%s", data.ParentDn.ValueString(), rn)) +} + +func getCoppProtoClassPTagAnnotationChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *CoppProtoClassPResourceModel, tagAnnotationCoppProtoClassPPlan, tagAnnotationCoppProtoClassPState []TagAnnotationCoppProtoClassPResourceModel) []map[string]interface{} { + childPayloads := []map[string]interface{}{} + if !data.TagAnnotation.IsNull() && !data.TagAnnotation.IsUnknown() { + tagAnnotationIdentifiers := []TagAnnotationIdentifier{} + for _, tagAnnotationCoppProtoClassP := range tagAnnotationCoppProtoClassPPlan { + childMap := NewAciObject() + if !tagAnnotationCoppProtoClassP.Key.IsNull() && !tagAnnotationCoppProtoClassP.Key.IsUnknown() { + childMap.Attributes["key"] = tagAnnotationCoppProtoClassP.Key.ValueString() + } + if !tagAnnotationCoppProtoClassP.Value.IsNull() && !tagAnnotationCoppProtoClassP.Value.IsUnknown() { + childMap.Attributes["value"] = tagAnnotationCoppProtoClassP.Value.ValueString() + } + childPayloads = append(childPayloads, map[string]interface{}{"tagAnnotation": childMap}) + tagAnnotationIdentifier := TagAnnotationIdentifier{} + tagAnnotationIdentifier.Key = tagAnnotationCoppProtoClassP.Key + tagAnnotationIdentifiers = append(tagAnnotationIdentifiers, tagAnnotationIdentifier) + } + for _, tagAnnotation := range tagAnnotationCoppProtoClassPState { + 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 getCoppProtoClassPTagTagChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *CoppProtoClassPResourceModel, tagTagCoppProtoClassPPlan, tagTagCoppProtoClassPState []TagTagCoppProtoClassPResourceModel) []map[string]interface{} { + childPayloads := []map[string]interface{}{} + if !data.TagTag.IsNull() && !data.TagTag.IsUnknown() { + tagTagIdentifiers := []TagTagIdentifier{} + for _, tagTagCoppProtoClassP := range tagTagCoppProtoClassPPlan { + childMap := NewAciObject() + if !tagTagCoppProtoClassP.Key.IsNull() && !tagTagCoppProtoClassP.Key.IsUnknown() { + childMap.Attributes["key"] = tagTagCoppProtoClassP.Key.ValueString() + } + if !tagTagCoppProtoClassP.Value.IsNull() && !tagTagCoppProtoClassP.Value.IsUnknown() { + childMap.Attributes["value"] = tagTagCoppProtoClassP.Value.ValueString() + } + childPayloads = append(childPayloads, map[string]interface{}{"tagTag": childMap}) + tagTagIdentifier := TagTagIdentifier{} + tagTagIdentifier.Key = tagTagCoppProtoClassP.Key + tagTagIdentifiers = append(tagTagIdentifiers, tagTagIdentifier) + } + for _, tagTag := range tagTagCoppProtoClassPState { + 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 getCoppProtoClassPCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, createType bool, data *CoppProtoClassPResourceModel, tagAnnotationPlan, tagAnnotationState []TagAnnotationCoppProtoClassPResourceModel, tagTagPlan, tagTagState []TagTagCoppProtoClassPResourceModel) *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 := getCoppProtoClassPTagAnnotationChildPayloads(ctx, diags, data, tagAnnotationPlan, tagAnnotationState) + if TagAnnotationchildPayloads == nil { + return nil + } + childPayloads = append(childPayloads, TagAnnotationchildPayloads...) + + TagTagchildPayloads := getCoppProtoClassPTagTagChildPayloads(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.Burst.IsNull() && !data.Burst.IsUnknown() { + payloadMap["attributes"].(map[string]string)["burst"] = data.Burst.ValueString() + } + if !data.Descr.IsNull() && !data.Descr.IsUnknown() { + payloadMap["attributes"].(map[string]string)["descr"] = data.Descr.ValueString() + } + if !data.MatchProto.IsNull() && !data.MatchProto.IsUnknown() { + var tmpMatchProto []string + data.MatchProto.ElementsAs(ctx, &tmpMatchProto, false) + payloadMap["attributes"].(map[string]string)["matchProto"] = strings.Join(tmpMatchProto, ",") + } + 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() + } + if !data.Rate.IsNull() && !data.Rate.IsUnknown() { + payloadMap["attributes"].(map[string]string)["rate"] = data.Rate.ValueString() + } + payload, err := json.Marshal(map[string]interface{}{"coppProtoClassP": 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_copp_interface_protocol_policy_test.go b/internal/provider/resource_aci_copp_interface_protocol_policy_test.go new file mode 100644 index 000000000..ef02c4673 --- /dev/null +++ b/internal/provider/resource_aci_copp_interface_protocol_policy_test.go @@ -0,0 +1,349 @@ +// 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 TestAccResourceCoppProtoClassPWithCoppIfPol(t *testing.T) { + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "apic", "2.3(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigCoppProtoClassPMinDependencyWithCoppIfPolAllowExisting, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test_2", "name", "test_name"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test_2", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test", "burst", "10"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test_2", "burst", "10"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test", "description", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test_2", "description", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test", "match_protocols.#", "0"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test_2", "match_protocols.#", "0"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test_2", "name_alias", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test_2", "owner_key", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test_2", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test", "rate", "10"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test_2", "rate", "10"), + ), + }, + }, + }) + + setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "apic", "2.3(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigCoppProtoClassPMinDependencyWithCoppIfPolAllowExisting, + 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.3(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigCoppProtoClassPMinDependencyWithCoppIfPolAllowExisting, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test_2", "name", "test_name"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test_2", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test", "burst", "10"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test_2", "burst", "10"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test", "description", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test_2", "description", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test", "match_protocols.#", "0"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test_2", "match_protocols.#", "0"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test_2", "name_alias", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test_2", "owner_key", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test_2", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test", "rate", "10"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.allow_test_2", "rate", "10"), + ), + }, + }, + }) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "apic", "2.3(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigCoppProtoClassPMinDependencyWithCoppIfPol, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "burst", "10"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "match_protocols.#", "0"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "rate", "10"), + ), + }, + // Update with all config and verify default APIC values + { + Config: testConfigCoppProtoClassPAllDependencyWithCoppIfPol, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "annotation", "annotation"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "burst", "15"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "description", "description_1"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "match_protocols.#", "2"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "match_protocols.0", "arp"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "match_protocols.1", "bfd"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "name_alias", "name_alias_1"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "owner_key", "owner_key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "owner_tag", "owner_tag_1"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "rate", "15"), + ), + }, + // Update with minimum config and verify config is unchanged + { + Config: testConfigCoppProtoClassPMinDependencyWithCoppIfPol, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "name", "test_name"), + ), + }, + // Update with empty strings config or default value + { + Config: testConfigCoppProtoClassPResetDependencyWithCoppIfPol, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "burst", "10"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "match_protocols.#", "0"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "rate", "10"), + ), + }, + // Import testing + { + ResourceName: "aci_copp_interface_protocol_policy.test", + ImportState: true, + ImportStateVerify: true, + }, + // Update with children + { + Config: testConfigCoppProtoClassPChildrenDependencyWithCoppIfPol, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "burst", "10"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "match_protocols.#", "0"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "rate", "10"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "annotations.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "tags.1.value", "test_value"), + ), + }, + // Refresh State before import testing to ensure that the state is up to date + { + RefreshState: true, + ExpectNonEmptyPlan: false, + }, + // Import testing with children + { + ResourceName: "aci_copp_interface_protocol_policy.test", + ImportState: true, + ImportStateVerify: true, + }, + // Update with children removed from config + { + Config: testConfigCoppProtoClassPChildrenRemoveFromConfigDependencyWithCoppIfPol, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "annotations.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "annotations.#", "2"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "tags.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "tags.#", "2"), + ), + }, + // Update with children first child removed + { + Config: testConfigCoppProtoClassPChildrenRemoveOneDependencyWithCoppIfPol, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "annotations.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "annotations.0.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "annotations.#", "1"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "tags.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "tags.0.value", "test_value"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "tags.#", "1"), + ), + }, + // Update with all children removed + { + Config: testConfigCoppProtoClassPChildrenRemoveAllDependencyWithCoppIfPol, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "annotations.#", "0"), + resource.TestCheckResourceAttr("aci_copp_interface_protocol_policy.test", "tags.#", "0"), + ), + }, + }, + CheckDestroy: testCheckResourceDestroy, + }) +} + +const testConfigCoppProtoClassPMinDependencyWithCoppIfPolAllowExisting = testConfigCoppIfPolMin + ` +resource "aci_copp_interface_protocol_policy" "allow_test" { + parent_dn = aci_copp_interface_policy.test.id + name = "test_name" +} +resource "aci_copp_interface_protocol_policy" "allow_test_2" { + parent_dn = aci_copp_interface_policy.test.id + name = "test_name" + depends_on = [aci_copp_interface_protocol_policy.allow_test] +} +` + +const testConfigCoppProtoClassPMinDependencyWithCoppIfPol = testConfigCoppIfPolMin + ` +resource "aci_copp_interface_protocol_policy" "test" { + parent_dn = aci_copp_interface_policy.test.id + name = "test_name" +} +` + +const testConfigCoppProtoClassPAllDependencyWithCoppIfPol = testConfigCoppIfPolMin + ` +resource "aci_copp_interface_protocol_policy" "test" { + parent_dn = aci_copp_interface_policy.test.id + name = "test_name" + annotation = "annotation" + burst = "15" + description = "description_1" + match_protocols = ["arp", "bfd"] + name_alias = "name_alias_1" + owner_key = "owner_key_1" + owner_tag = "owner_tag_1" + rate = "15" +} +` + +const testConfigCoppProtoClassPResetDependencyWithCoppIfPol = testConfigCoppIfPolMin + ` +resource "aci_copp_interface_protocol_policy" "test" { + parent_dn = aci_copp_interface_policy.test.id + name = "test_name" + annotation = "orchestrator:terraform" + burst = "10" + description = "" + match_protocols = [] + name_alias = "" + owner_key = "" + owner_tag = "" + rate = "10" +} +` +const testConfigCoppProtoClassPChildrenDependencyWithCoppIfPol = testConfigCoppIfPolMin + ` +resource "aci_copp_interface_protocol_policy" "test" { + parent_dn = aci_copp_interface_policy.test.id + 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 testConfigCoppProtoClassPChildrenRemoveFromConfigDependencyWithCoppIfPol = testConfigCoppIfPolMin + ` +resource "aci_copp_interface_protocol_policy" "test" { + parent_dn = aci_copp_interface_policy.test.id + name = "test_name" +} +` + +const testConfigCoppProtoClassPChildrenRemoveOneDependencyWithCoppIfPol = testConfigCoppIfPolMin + ` +resource "aci_copp_interface_protocol_policy" "test" { + parent_dn = aci_copp_interface_policy.test.id + name = "test_name" + annotations = [ + { + key = "key_1" + value = "test_value" + }, + ] + tags = [ + { + key = "key_1" + value = "test_value" + }, + ] +} +` + +const testConfigCoppProtoClassPChildrenRemoveAllDependencyWithCoppIfPol = testConfigCoppIfPolMin + ` +resource "aci_copp_interface_protocol_policy" "test" { + parent_dn = aci_copp_interface_policy.test.id + name = "test_name" + annotations = [] + tags = [] +} +`