From cdbb174ce58589174e583d02ffa8584626012ce3 Mon Sep 17 00:00:00 2001 From: Shreyas Date: Tue, 23 Jan 2024 09:24:29 -0500 Subject: [PATCH] [minor_change] Addition of new generated resource and data source for pkiTP --- .github/workflows/checks.yml | 2 +- docs/data-sources/application_epg.md | 1 - docs/data-sources/certificate_authority.md | 77 + docs/data-sources/key_ring.md | 84 ++ docs/data-sources/relation_to_domain.md | 1 - docs/resources/application_epg.md | 4 - docs/resources/certificate_authority.md | 223 +++ docs/resources/key_ring.md | 255 ++++ docs/resources/relation_to_domain.md | 4 - .../aci_certificate_authority/data-source.tf | 10 + .../aci_certificate_authority/provider.tf | 14 + .../data-sources/aci_key_ring/data-source.tf | 10 + .../data-sources/aci_key_ring/provider.tf | 14 + .../resource-all-attributes.tf | 1 - .../aci_certificate_authority/provider.tf | 14 + .../resource-all-attributes.tf | 76 + .../aci_certificate_authority/resource.tf | 42 + examples/resources/aci_key_ring/provider.tf | 14 + .../aci_key_ring/resource-all-attributes.tf | 124 ++ examples/resources/aci_key_ring/resource.tf | 10 + .../resource-all-attributes.tf | 1 - gen/definitions/classes.yaml | 23 + gen/definitions/properties.yaml | 53 + gen/generator.go | 555 +++++-- gen/meta/cloudCertStore.json | 615 ++++++++ gen/meta/pkiEp.json | 743 ++++++++++ gen/meta/pkiKeyRing.json | 1283 +++++++++++++++++ gen/meta/pkiTP.json | 911 ++++++++++++ gen/templates/datasource.md.tmpl | 10 +- gen/templates/datasource_example.tf.tmpl | 39 +- gen/templates/datasource_test.go.tmpl | 64 +- gen/templates/provider.go.tmpl | 8 + gen/templates/resource.go.tmpl | 211 ++- gen/templates/resource_example.tf.tmpl | 39 +- .../resource_example_all_attributes.tf.tmpl | 50 +- gen/templates/resource_test.go.tmpl | 852 +++++++++-- gen/templates/testvars.yaml.tmpl | 241 +++- gen/testvars/fhsTrustCtrlPol.yaml | 3 + gen/testvars/fvAEPg.yaml | 47 +- gen/testvars/fvCrtrn.yaml | 17 +- gen/testvars/fvDnsAttr.yaml | 3 + gen/testvars/fvESg.yaml | 13 +- gen/testvars/fvEpIpTag.yaml | 3 + gen/testvars/fvEpMacTag.yaml | 3 + gen/testvars/fvFBRGroup.yaml | 3 + gen/testvars/fvFBRMember.yaml | 3 + gen/testvars/fvFBRoute.yaml | 3 + gen/testvars/fvIdGroupAttr.yaml | 3 + gen/testvars/fvIpAttr.yaml | 3 + gen/testvars/fvMacAttr.yaml | 3 + gen/testvars/fvRsCons.yaml | 4 + gen/testvars/fvRsConsIf.yaml | 4 + gen/testvars/fvRsDomAtt.yaml | 29 +- gen/testvars/fvRsFcPathAtt.yaml | 3 + gen/testvars/fvRsIntraEpg.yaml | 4 + gen/testvars/fvRsNodeAtt.yaml | 3 + gen/testvars/fvRsPathAtt.yaml | 3 + gen/testvars/fvRsProtBy.yaml | 3 + gen/testvars/fvRsProv.yaml | 4 + gen/testvars/fvRsSecInherited.yaml | 4 + gen/testvars/fvSCrtrn.yaml | 4 + gen/testvars/fvVmAttr.yaml | 4 + gen/testvars/infraHPathS.yaml | 3 + gen/testvars/l3extConsLbl.yaml | 3 + gen/testvars/l3extProvLbl.yaml | 3 + gen/testvars/l3extRsLblToInstP.yaml | 3 + gen/testvars/l3extRsLblToProfile.yaml | 3 + gen/testvars/l3extRsOutToFBRGroup.yaml | 3 + gen/testvars/l3extRsRedistributePol.yaml | 3 + gen/testvars/mgmtInstP.yaml | 3 + gen/testvars/mgmtRsOoBCons.yaml | 3 + gen/testvars/mgmtSubnet.yaml | 3 + gen/testvars/mplsNodeSidP.yaml | 3 + gen/testvars/netflowExporterPol.yaml | 3 + gen/testvars/netflowMonitorPol.yaml | 3 + gen/testvars/netflowRecordPol.yaml | 3 + gen/testvars/netflowRsMonitorToExporter.yaml | 3 + gen/testvars/pimRouteMapEntry.yaml | 3 + gen/testvars/pimRouteMapPol.yaml | 3 + gen/testvars/pkiKeyRing.yaml | 95 ++ gen/testvars/pkiTP.yaml | 60 + gen/testvars/qosCustomPol.yaml | 3 + gen/testvars/qosDppPol.yaml | 3 + gen/testvars/rtctrlProfile.yaml | 14 +- gen/testvars/tagAnnotation.yaml | 4 + gen/testvars/tagTag.yaml | 4 + gen/testvars/vzOOBBrCP.yaml | 13 +- go.mod | 2 +- ...urce_aci_access_interface_override_test.go | 2 +- .../data_source_aci_annotation_test.go | 4 +- .../data_source_aci_application_epg.go | 4 - .../data_source_aci_application_epg_test.go | 11 +- .../data_source_aci_certificate_authority.go | 174 +++ ...a_source_aci_certificate_authority_test.go | 92 ++ .../data_source_aci_custom_qos_policy_test.go | 2 +- ...rce_aci_data_plane_policing_policy_test.go | 2 +- ...source_aci_endpoint_security_group_test.go | 9 +- .../data_source_aci_endpoint_tag_ip_test.go | 2 +- .../data_source_aci_endpoint_tag_mac_test.go | 2 +- ...ce_aci_epg_useg_ad_group_attribute_test.go | 2 +- ...ource_aci_epg_useg_block_statement_test.go | 11 +- ..._source_aci_epg_useg_dns_attribute_test.go | 2 +- ...a_source_aci_epg_useg_ip_attribute_test.go | 2 +- ..._source_aci_epg_useg_mac_attribute_test.go | 2 +- ...e_aci_epg_useg_sub_block_statement_test.go | 4 +- ...a_source_aci_epg_useg_vm_attribute_test.go | 4 +- ...anagement_network_instance_profile_test.go | 2 +- ...external_management_network_subnet_test.go | 2 +- internal/provider/data_source_aci_key_ring.go | 202 +++ .../provider/data_source_aci_key_ring_test.go | 106 ++ ...ta_source_aci_l3out_consumer_label_test.go | 2 +- ..._source_aci_l3out_node_sid_profile_test.go | 2 +- ...ta_source_aci_l3out_provider_label_test.go | 2 +- ...urce_aci_l3out_redistribute_policy_test.go | 2 +- ...source_aci_netflow_exporter_policy_test.go | 2 +- ..._source_aci_netflow_monitor_policy_test.go | 2 +- ...a_source_aci_netflow_record_policy_test.go | 2 +- ...ta_source_aci_out_of_band_contract_test.go | 9 +- ...ata_source_aci_pim_route_map_entry_test.go | 2 +- ...ta_source_aci_pim_route_map_policy_test.go | 2 +- ...out_consumer_label_to_external_epg_test.go | 2 +- ...mer_label_to_route_control_profile_test.go | 2 +- ..._aci_relation_to_consumed_contract_test.go | 4 +- ...n_to_consumed_out_of_band_contract_test.go | 2 +- ...ce_aci_relation_to_contract_master_test.go | 4 +- .../data_source_aci_relation_to_domain.go | 4 - ...data_source_aci_relation_to_domain_test.go | 17 +- ...aci_relation_to_fibre_channel_path_test.go | 2 +- ..._aci_relation_to_imported_contract_test.go | 4 +- ...aci_relation_to_intra_epg_contract_test.go | 4 +- ...e_aci_relation_to_netflow_exporter_test.go | 2 +- ..._aci_relation_to_provided_contract_test.go | 4 +- ...source_aci_relation_to_static_leaf_test.go | 2 +- ...source_aci_relation_to_static_path_test.go | 2 +- ...rce_aci_relation_to_taboo_contract_test.go | 2 +- ...lation_to_vrf_fallback_route_group_test.go | 2 +- .../data_source_aci_rest_managed_test.go | 2 +- ...a_source_aci_route_control_profile_test.go | 18 +- .../provider/data_source_aci_system_test.go | 2 +- internal/provider/data_source_aci_tag_test.go | 4 +- ...ta_source_aci_trust_control_policy_test.go | 2 +- ...ci_vrf_fallback_route_group_member_test.go | 2 +- ...ource_aci_vrf_fallback_route_group_test.go | 2 +- ...data_source_aci_vrf_fallback_route_test.go | 2 +- .../provider/function_compare_versions.go | 204 +++ .../function_compare_versions_test.go | 71 + internal/provider/provider.go | 12 + internal/provider/provider_test.go | 158 +- .../resource_aci_access_interface_override.go | 39 +- ...urce_aci_access_interface_override_test.go | 9 +- internal/provider/resource_aci_annotation.go | 15 +- .../provider/resource_aci_annotation_test.go | 18 +- .../provider/resource_aci_application_epg.go | 140 +- .../resource_aci_application_epg_test.go | 175 +-- .../resource_aci_certificate_authority.go | 793 ++++++++++ ...resource_aci_certificate_authority_test.go | 648 +++++++++ .../resource_aci_custom_qos_policy.go | 31 +- .../resource_aci_custom_qos_policy_test.go | 9 +- ...resource_aci_data_plane_policing_policy.go | 73 +- ...rce_aci_data_plane_policing_policy_test.go | 9 +- .../resource_aci_endpoint_security_group.go | 65 +- ...source_aci_endpoint_security_group_test.go | 57 +- .../provider/resource_aci_endpoint_tag_ip.go | 31 +- .../resource_aci_endpoint_tag_ip_test.go | 9 +- .../provider/resource_aci_endpoint_tag_mac.go | 31 +- .../resource_aci_endpoint_tag_mac_test.go | 9 +- ...esource_aci_epg_useg_ad_group_attribute.go | 33 +- ...ce_aci_epg_useg_ad_group_attribute_test.go | 9 +- .../resource_aci_epg_useg_block_statement.go | 37 +- ...ource_aci_epg_useg_block_statement_test.go | 84 +- .../resource_aci_epg_useg_dns_attribute.go | 33 +- ...esource_aci_epg_useg_dns_attribute_test.go | 9 +- .../resource_aci_epg_useg_ip_attribute.go | 35 +- ...resource_aci_epg_useg_ip_attribute_test.go | 9 +- .../resource_aci_epg_useg_mac_attribute.go | 33 +- ...esource_aci_epg_useg_mac_attribute_test.go | 9 +- ...source_aci_epg_useg_sub_block_statement.go | 33 +- ...e_aci_epg_useg_sub_block_statement_test.go | 18 +- .../resource_aci_epg_useg_vm_attribute.go | 41 +- ...resource_aci_epg_useg_vm_attribute_test.go | 18 +- ...nal_management_network_instance_profile.go | 31 +- ...anagement_network_instance_profile_test.go | 9 +- ..._aci_external_management_network_subnet.go | 29 +- ...external_management_network_subnet_test.go | 9 +- internal/provider/resource_aci_key_ring.go | 933 ++++++++++++ .../provider/resource_aci_key_ring_test.go | 779 ++++++++++ .../resource_aci_l3out_consumer_label.go | 43 +- .../resource_aci_l3out_consumer_label_test.go | 9 +- .../resource_aci_l3out_node_sid_profile.go | 31 +- ...esource_aci_l3out_node_sid_profile_test.go | 9 +- .../resource_aci_l3out_provider_label.go | 33 +- .../resource_aci_l3out_provider_label_test.go | 9 +- .../resource_aci_l3out_redistribute_policy.go | 25 +- ...urce_aci_l3out_redistribute_policy_test.go | 9 +- .../resource_aci_netflow_exporter_policy.go | 51 +- ...source_aci_netflow_exporter_policy_test.go | 9 +- .../resource_aci_netflow_monitor_policy.go | 39 +- ...esource_aci_netflow_monitor_policy_test.go | 9 +- .../resource_aci_netflow_record_policy.go | 41 +- ...resource_aci_netflow_record_policy_test.go | 9 +- .../resource_aci_out_of_band_contract.go | 37 +- .../resource_aci_out_of_band_contract_test.go | 67 +- .../resource_aci_pim_route_map_entry.go | 37 +- .../resource_aci_pim_route_map_entry_test.go | 9 +- .../resource_aci_pim_route_map_policy.go | 31 +- .../resource_aci_pim_route_map_policy_test.go | 9 +- ...om_l3out_consumer_label_to_external_epg.go | 23 +- ...out_consumer_label_to_external_epg_test.go | 9 +- ...consumer_label_to_route_control_profile.go | 25 +- ...mer_label_to_route_control_profile_test.go | 9 +- ...ource_aci_relation_to_consumed_contract.go | 25 +- ..._aci_relation_to_consumed_contract_test.go | 18 +- ...lation_to_consumed_out_of_band_contract.go | 25 +- ...n_to_consumed_out_of_band_contract_test.go | 9 +- ...esource_aci_relation_to_contract_master.go | 23 +- ...ce_aci_relation_to_contract_master_test.go | 18 +- .../resource_aci_relation_to_domain.go | 93 +- .../resource_aci_relation_to_domain_test.go | 133 +- ...urce_aci_relation_to_fibre_channel_path.go | 29 +- ...aci_relation_to_fibre_channel_path_test.go | 9 +- ...ource_aci_relation_to_imported_contract.go | 25 +- ..._aci_relation_to_imported_contract_test.go | 18 +- ...urce_aci_relation_to_intra_epg_contract.go | 23 +- ...aci_relation_to_intra_epg_contract_test.go | 18 +- ...source_aci_relation_to_netflow_exporter.go | 23 +- ...e_aci_relation_to_netflow_exporter_test.go | 9 +- ...ource_aci_relation_to_provided_contract.go | 27 +- ..._aci_relation_to_provided_contract_test.go | 18 +- .../resource_aci_relation_to_static_leaf.go | 31 +- ...source_aci_relation_to_static_leaf_test.go | 9 +- .../resource_aci_relation_to_static_path.go | 33 +- ...source_aci_relation_to_static_path_test.go | 9 +- ...resource_aci_relation_to_taboo_contract.go | 23 +- ...rce_aci_relation_to_taboo_contract_test.go | 9 +- ...ci_relation_to_vrf_fallback_route_group.go | 23 +- ...lation_to_vrf_fallback_route_group_test.go | 9 +- .../resource_aci_rest_managed_test.go | 36 +- .../resource_aci_route_control_profile.go | 35 +- ...resource_aci_route_control_profile_test.go | 114 +- internal/provider/resource_aci_tag.go | 15 +- internal/provider/resource_aci_tag_test.go | 18 +- .../resource_aci_trust_control_policy.go | 43 +- .../resource_aci_trust_control_policy_test.go | 9 +- .../resource_aci_vrf_fallback_route.go | 29 +- .../resource_aci_vrf_fallback_route_group.go | 35 +- ...rce_aci_vrf_fallback_route_group_member.go | 29 +- ...ci_vrf_fallback_route_group_member_test.go | 9 +- ...ource_aci_vrf_fallback_route_group_test.go | 9 +- .../resource_aci_vrf_fallback_route_test.go | 9 +- internal/provider/test_constants.go | 53 +- 250 files changed, 12561 insertions(+), 1816 deletions(-) create mode 100644 docs/data-sources/certificate_authority.md create mode 100644 docs/data-sources/key_ring.md create mode 100644 docs/resources/certificate_authority.md create mode 100644 docs/resources/key_ring.md create mode 100644 examples/data-sources/aci_certificate_authority/data-source.tf create mode 100644 examples/data-sources/aci_certificate_authority/provider.tf create mode 100644 examples/data-sources/aci_key_ring/data-source.tf create mode 100644 examples/data-sources/aci_key_ring/provider.tf create mode 100644 examples/resources/aci_certificate_authority/provider.tf create mode 100644 examples/resources/aci_certificate_authority/resource-all-attributes.tf create mode 100644 examples/resources/aci_certificate_authority/resource.tf create mode 100644 examples/resources/aci_key_ring/provider.tf create mode 100644 examples/resources/aci_key_ring/resource-all-attributes.tf create mode 100644 examples/resources/aci_key_ring/resource.tf create mode 100644 gen/meta/cloudCertStore.json create mode 100644 gen/meta/pkiEp.json create mode 100644 gen/meta/pkiKeyRing.json create mode 100644 gen/meta/pkiTP.json create mode 100644 gen/testvars/pkiKeyRing.yaml create mode 100644 gen/testvars/pkiTP.yaml create mode 100644 internal/provider/data_source_aci_certificate_authority.go create mode 100644 internal/provider/data_source_aci_certificate_authority_test.go create mode 100644 internal/provider/data_source_aci_key_ring.go create mode 100644 internal/provider/data_source_aci_key_ring_test.go create mode 100644 internal/provider/function_compare_versions.go create mode 100644 internal/provider/function_compare_versions_test.go create mode 100644 internal/provider/resource_aci_certificate_authority.go create mode 100644 internal/provider/resource_aci_certificate_authority_test.go create mode 100644 internal/provider/resource_aci_key_ring.go create mode 100644 internal/provider/resource_aci_key_ring_test.go diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 41ee00a91..d398150d6 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -90,7 +90,7 @@ jobs: go-version-file: 'go.mod' - uses: hashicorp/setup-terraform@v3 with: - terraform_version: '1.7.*' + terraform_version: '1.9.*' terraform_wrapper: false - name: Terraform Acceptance Test (APIC ${{ matrix.apic_host.name }}) run: go test github.com/CiscoDevNet/terraform-provider-aci/v2/internal/provider -v -race -timeout 300m -coverprofile=coverage.out -covermode=atomic diff --git a/docs/data-sources/application_epg.md b/docs/data-sources/application_epg.md index f058b8ec9..d5a60f09e 100644 --- a/docs/data-sources/application_epg.md +++ b/docs/data-sources/application_epg.md @@ -127,7 +127,6 @@ data "aci_application_epg" "example_application_profile" { * `switching_mode` (switchingMode) - (string) The switching mode of the Relation To Domain object. * `target_dn` (tDn) - (string) The distinguished name of the target Domain object. * `untagged` (untagged) - (string) The untagged status of the Relation To Domain object. - * `vnet_only` (vnetOnly) - (string) The VNET only status of the Relation To Domain object. * `relation_to_data_plane_policing_policy` - (map) A map of Relation To Data Plane Policing Policy (ACI object [fvRsDppPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvRsDppPol/overview)) pointing to Data Plane Policing Policy (ACI Object [qosDppPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/qosDppPol/overview)). This attribute is supported in ACI versions: 3.0(1k) and later. * `annotation` (annotation) - (string) The annotation of the Relation To Data Plane Policing Policy object. diff --git a/docs/data-sources/certificate_authority.md b/docs/data-sources/certificate_authority.md new file mode 100644 index 000000000..d9ed7d901 --- /dev/null +++ b/docs/data-sources/certificate_authority.md @@ -0,0 +1,77 @@ +--- +# 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: "AAA" +layout: "aci" +page_title: "ACI: aci_certificate_authority" +sidebar_current: "docs-aci-data-source-aci_certificate_authority" +description: |- + Data source for ACI Certificate Authority +--- + +# aci_certificate_authority # + +Data source for ACI Certificate Authority + +## API Information ## + +* Class: [pkiTP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/pkiTP/overview) + +* Supported in ACI versions: 1.0(1e) and later. + +* Distinguished Name Formats: + - `uni/tn-{name}/certstore/tp-{name}` + - `uni/userext/pkiext/tp-{name}` + +## GUI Information ## + +* Locations: + - `Admin -> AAA -> Security -> Certificate Authorities` + - `Cloud Network Controller -> Administrative -> Security -> Certificate Authorities` + +## Example Usage ## + +```hcl + +data "aci_certificate_authority" "example" { + name = "test_name" +} + +// This example is only applicable to Cisco Cloud Network Controller +data "aci_certificate_authority" "example_tenant" { + parent_dn = aci_tenant.example.id + name = "test_name" +} + +``` + +## Schema ## + +### Required ### + +* `name` (name) - (string) The name of the Certificate Authority object. + +### Optional ### + +* `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources: + - [aci_tenant](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/fvTenant) ([fvTenant](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvTenant/overview)) + - Default: `uni/userext/pkiext` + +### Read-Only ### + +* `id` - (string) The distinguished name (DN) of the Certificate Authority object. +* `annotation` (annotation) - (string) The annotation of the Certificate Authority object. +* `certificate_chain` (certChain) - (string) The PEM-encoded chain of trust from the trustpoint to a trusted root authority. +* `description` (descr) - (string) The description of the Certificate Authority object. +* `name_alias` (nameAlias) - (string) The name alias of the Certificate Authority 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. + +* `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/key_ring.md b/docs/data-sources/key_ring.md new file mode 100644 index 000000000..d08d85844 --- /dev/null +++ b/docs/data-sources/key_ring.md @@ -0,0 +1,84 @@ +--- +# 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: "AAA" +layout: "aci" +page_title: "ACI: aci_key_ring" +sidebar_current: "docs-aci-data-source-aci_key_ring" +description: |- + Data source for ACI Key Ring +--- + +# aci_key_ring # + +Data source for ACI Key Ring + +## API Information ## + +* Class: [pkiKeyRing](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/pkiKeyRing/overview) + +* Supported in ACI versions: 1.0(1e) and later. + +* Distinguished Name Formats: + - `uni/tn-{name}/certstore/keyring-{name}` + - `uni/userext/pkiext/keyring-{name}` + +## GUI Information ## + +* Locations: + - `Admin -> AAA -> Security -> Key Rings` + - `Cloud Network Controller -> Administrative -> Security -> Key Rings` + +## Example Usage ## + +```hcl + +data "aci_key_ring" "example" { + name = "test_name" +} + +// This example is only applicable to Cisco Cloud Network Controller +data "aci_key_ring" "example_tenant" { + parent_dn = aci_tenant.example.id + name = "test_name" +} + +``` + +## Schema ## + +### Required ### + +* `name` (name) - (string) The name of the Key Ring object. + +### Optional ### + +* `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources: + - [aci_tenant](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/fvTenant) ([fvTenant](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvTenant/overview)) + - Default: `uni/userext/pkiext` + +### Read-Only ### + +* `id` - (string) The distinguished name (DN) of the Key Ring object. +* `admin_state` (adminState) - (string) The current administrative state of the certificate request process. +* `annotation` (annotation) - (string) The annotation of the Key Ring object. +* `certificate` (cert) - (string) A certificate contains a device's public key along with signed information verifying the identity of the device. +* `description` (descr) - (string) The description of the Key Ring object. +* `elliptic_curve` (eccCurve) - (string) The elliptic curve used by the provided key. +* `key` (key) - (string) The private key of the certificate. This sensitive value is excluded from the resource's lifecycle configuration and is not tracked by Terraform. +* `key_type` (keyType) - (string) The type used by the provided key. +* `modulus` (modulus) - (string) The length of the encryption keys. A longer key length increases the difficulty of breaking the key. +* `name_alias` (nameAlias) - (string) The name alias of the Key Ring 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. +* `regenerate` (regen) - (string) Forces regeneration of the keypair. Each PKI device holds a pair of asymmetric Rivest-Shamir-Adleman (RSA) or Elliptic Curve Cryptography (ECC) encryption keys, one kept private and one made public, stored in an internal key ring. +* `certificate_authority` (tp) - (string) The certificate of the Certificate Authority (CA) that issued the certificate provided in the 'certificate' attribute. The CA can be a root CA, an intermediate CA, or a trust anchor in a chain of trust leading to a root CA. + +* `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/relation_to_domain.md b/docs/data-sources/relation_to_domain.md index 1b481932b..0a27de9a0 100644 --- a/docs/data-sources/relation_to_domain.md +++ b/docs/data-sources/relation_to_domain.md @@ -72,7 +72,6 @@ data "aci_relation_to_domain" "example_application_epg" { * `secondary_encapsulation_inner` (secondaryEncapInner) - (string) The secondary inner encapsulation of the Relation To Domain object. This is used for the portgroup at the VMWare Distributed Virtual Switch (DVS). This VLAN is internal to the DVS and is used for communication between the other VMs and the AVE VM at a host. Traffic is not forwarded to the fabric over the VLAN. Only applicable for Cisco ACI Virtual Edge (AVE) domains. * `switching_mode` (switchingMode) - (string) The switching mode of the Relation To Domain object. * `untagged` (untagged) - (string) The untagged status of the Relation To Domain object. -* `vnet_only` (vnetOnly) - (string) The VNET only status of the Relation To Domain 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. diff --git a/docs/resources/application_epg.md b/docs/resources/application_epg.md index 73c074192..e3885cf62 100644 --- a/docs/resources/application_epg.md +++ b/docs/resources/application_epg.md @@ -126,7 +126,6 @@ resource "aci_application_epg" "full_example_application_profile" { switching_mode = "AVE" target_dn = "uni/vmmp-VMware/dom-domain_1" untagged = "no" - vnet_only = "no" } ] relation_to_data_plane_policing_policy = { @@ -398,9 +397,6 @@ All examples for the Application EPG resource can be found in the [examples](htt * `untagged` (untagged) - (string) The untagged status of the Relation To Domain object. - Default: `no` - Valid Values: `no`, `yes`. - * `vnet_only` (vnetOnly) - (string) The VNET only status of the Relation To Domain object. - - Default: `no` - - Valid Values: `no`, `yes`. * `relation_to_data_plane_policing_policy` - (map) A map of Relation To Data Plane Policing Policy (ACI object [fvRsDppPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvRsDppPol/overview)) pointing to Data Plane Policing Policy (ACI Object [qosDppPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/qosDppPol/overview)) which can be configured using the [aci_data_plane_policing_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/data_plane_policing_policy) resource. This attribute is supported in ACI versions: 3.0(1k) and later. diff --git a/docs/resources/certificate_authority.md b/docs/resources/certificate_authority.md new file mode 100644 index 000000000..bcf2c27e8 --- /dev/null +++ b/docs/resources/certificate_authority.md @@ -0,0 +1,223 @@ +--- +# 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: "AAA" +layout: "aci" +page_title: "ACI: aci_certificate_authority" +sidebar_current: "docs-aci-resource-aci_certificate_authority" +description: |- + Manages ACI Certificate Authority +--- + +# aci_certificate_authority # + +Manages ACI Certificate Authority + + + +## API Information ## + +* Class: [pkiTP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/pkiTP/overview) + +* Supported in ACI versions: 1.0(1e) and later. + +* Distinguished Name Formats: + - `uni/tn-{name}/certstore/tp-{name}` + - `uni/userext/pkiext/tp-{name}` + +## GUI Information ## + +* Locations: + - `Admin -> AAA -> Security -> Certificate Authorities` + - `Cloud Network Controller -> Administrative -> Security -> Certificate Authorities` + +## Example Usage ## + +The configuration snippet below creates a Certificate Authority with only required attributes. + +```hcl + +resource "aci_certificate_authority" "example" { + certificate_chain = < This example might not be valid configuration and is only used to show all possible attributes. + +```hcl + +resource "aci_certificate_authority" "full_example" { + annotation = "annotation" + certificate_chain = < AAA -> Security -> Key Rings` + - `Cloud Network Controller -> Administrative -> Security -> Key Rings` + +## Example Usage ## + +The configuration snippet below creates a Key Ring with only required attributes. + +```hcl + +resource "aci_key_ring" "example" { + name = "test_name" +} + +// This example is only applicable to Cisco Cloud Network Controller +resource "aci_key_ring" "example_tenant" { + parent_dn = aci_tenant.example.id + name = "test_name" +} + +``` +The configuration snippet below shows all possible attributes of the Key Ring. + +!> This example might not be valid configuration and is only used to show all possible attributes. + +```hcl + +resource "aci_key_ring" "full_example" { + admin_state = "completed" + annotation = "annotation" + certificate = < AAA -> Security -> Certificate Authorities" + - "Cloud Network Controller -> Administrative -> Security -> Certificate Authorities" + multi_parents: + - rn_prepend: "certstore" + contained_by: "fvTenant" + wrapper_class: "cloudCertStore" + test_type: "cloud" + +pkiKeyRing: + sub_category: "AAA" + ui_locations: + - "Admin -> AAA -> Security -> Key Rings" + - "Cloud Network Controller -> Administrative -> Security -> Key Rings" + multi_parents: + - rn_prepend: "certstore" + contained_by: "fvTenant" + wrapper_class: "cloudCertStore" + test_type: "cloud" diff --git a/gen/definitions/properties.yaml b/gen/definitions/properties.yaml index 0722fde84..daba992e6 100644 --- a/gen/definitions/properties.yaml +++ b/gen/definitions/properties.yaml @@ -181,6 +181,21 @@ tagAnnotation: default: value: "test_value" +pkiTP: + default_values: + parent_dn: "uni/userext/pkiext" + overwrites: + cert_chain: "certificate_chain" + resource_required: + - "certChain" + test_values: + resource_required: + certificate_chain: -----BEGIN CERTIFICATE-----\\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\\n-----END CERTIFICATE----- + default: + certificate_chain: -----BEGIN CERTIFICATE-----\\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\\n-----END CERTIFICATE----- + all: + certificate_chain: -----BEGIN CERTIFICATE-----\\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\\n-----END CERTIFICATE----- + tagTag: documentation: key: "The key used to uniquely identify this configuration object." @@ -784,6 +799,7 @@ fvRsDomAtt: ipamEnabled: "no" ignores: - "apiMode" + - "vnetOnly" ignore_properties_in_test: "ipamDhcpOverride": "10.0.0.2" "ipamEnabled": "yes" @@ -1235,3 +1251,40 @@ topSystem: unicastXrEpLearnDisable: "Indicates whether the learning of unicast endpoints for external routing is disabled." version: "The version for this system." virtualMode: "The virtual mode of this system." + +pkiKeyRing: + default_values: + parent_dn: "uni/userext/pkiext" + regen : "no" + overwrites: + cert: "certificate" + regen: "regenerate" + ecc_curve: "elliptic_curve" + tp: "certificate_authority" + documentation: + key: "The private key of the certificate. This sensitive value is excluded from the resource's lifecycle configuration and is not tracked by Terraform." + eccCurve: "The elliptic curve used by the provided key." + keyType: "The type used by the provided key." + cert: "A certificate contains a device's public key along with signed information verifying the identity of the device." + tp: "The certificate of the Certificate Authority (CA) that issued the certificate provided in the 'certificate' attribute. The CA can be a root CA, an intermediate CA, or a trust anchor in a chain of trust leading to a root CA." + parents: + - target_classes: + - "pkiTp" + targets: + - class_name: "pkiTP" + properties: + name: "test_name" + certificate_chain: -----BEGIN CERTIFICATE-----\\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\\n-----END CERTIFICATE----- + test_values: + test_values: + default: + regenerate : "no" + elliptic_curve: "none" + key_type: "RSA" + all: + regenerate : "no" + elliptic_curve: "none" + key_type: "RSA" + certificate: -----BEGIN CERTIFICATE-----\\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\\n-----END CERTIFICATE----- + key: -----BEGIN PRIVATE KEY-----\\nMIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKIRv+2sbbewm0mj\\nD+6/tpoUymzYIdFsN+gu02teIr/lZi8ipEB514pyhoaerstzboPteWvniLuwq4KQ\\nVTEHgoln7J8EaHCnECViGA61pVx8RkJ99cmCkepspROw3I96zBcm58oXs6+Q/BnD\\n/OWET5sBvR9oTv9GNRVJ1rvSMAEJAgMBAAECgYByu3QO0qF9h7X3JEu0Ld4cKBnB\\ngiQ2uJC/et7KxIJ/LOvw9GopBthyt27KwG1ntBkJpkTuAaQHkyNns7vLkNB0S0IR\\n+owVFEcKYq9VCHTaiQU8TDp24gN+yPTrpRuH8YhDVq5SfVdVuTMgHVQdj4ya4VlF\\nGj+a7+ipxtGiLsVGrQJBAM7p0Fm0xmzi+tBOASUAcVrPLcteFIaTBFwfq16dm/ON\\n00Khla8Et5kMBttTbqbukl8mxFjBEEBlhQqb6EdQQ0sCQQDIhHx1a9diG7y/4DQA\\n4KvR3FCYwP8PBORlSamegzCo+P1OzxiEo0amX7yQMA5UyiP/kUsZrme2JBZgna8S\\np4R7AkEAr7rMhSOPUnMD6V4WgsJ5g1Jp5kqkzBaYoVUUSms5RASz4+cwJVCwTX91\\nY1jcpVIBZmaaY3a0wrx13ajEAa0dOQJBAIpjnb4wqpsEh7VpmJqOdSdGxb1XXfFQ\\nsA0T1OQYqQnFppWwqrxIL+d9pZdiA1ITnNqyvUFBNETqDSOrUHwwb2cCQGArE+vu\\nffPUWQ0j+fiK+covFG8NL7H+26NSGB5+Xsn9uwOGLj7K/YT6CbBtr9hJiuWjM1Al\\n0V4ltlTuu2mTMaw=\\n-----END PRIVATE KEY----- + certificate_authority: "test_name" diff --git a/gen/generator.go b/gen/generator.go index de07f8ed0..e28b8ad6d 100644 --- a/gen/generator.go +++ b/gen/generator.go @@ -55,6 +55,7 @@ import ( "golang.org/x/text/language" "gopkg.in/yaml.v2" + providerFunctions "github.com/CiscoDevNet/terraform-provider-aci/v2/internal/provider" "github.com/hashicorp/hcl/v2/hclwrite" ) @@ -128,6 +129,10 @@ var templateFuncs = template.FuncMap{ "containsSingleNestedChildren": ContainsSingleNestedChildren, "isResourceClass": IsResourceClass, "getOldType": GetOldType, + "contains": strings.Contains, + "hasKey": HasKey, + "definedInList": DefinedInList, + "keyExists": KeyExists, } func ContainsRequired(properties map[string]Property) bool { @@ -262,6 +267,8 @@ var targetRelationalPropertyClasses = map[string]string{} var alwaysIncludeChildren = []string{"tag:Annotation", "tag:Tag"} var excludeChildResourceNamesFromDocs = []string{"", "annotation", "tag"} var classesWithoutResource = []string{"fabricPathEp"} +var resourceIdentifier []interface{} +var alwaysMultiLineTypes = []string{"pkiCert", "pkiPrivateKey"} func IsResourceClass(className string) bool { return !slices.Contains(classesWithoutResource, className) @@ -279,7 +286,20 @@ func GetDevnetDocForClass(className string) string { return fmt.Sprintf("[%s](%s/app/index.html#/objects/%s/overview)", className, pubhupDevnetBaseUrl, className) } +func HasKey(dict map[interface{}]interface{}, key string) bool { + _, ok := dict[key] + return ok +} + +func KeyExists(m map[string][]string, key string) bool { + _, exists := m[key] + return exists +} + func Capitalize(s string) string { + if s == "" { + return "" + } return fmt.Sprintf("%s%s", strings.ToUpper(s[:1]), s[1:]) } @@ -287,6 +307,21 @@ func Decapitalize(s string) string { return fmt.Sprintf("%s%s", strings.ToLower(s[:1]), s[1:]) } +func DefinedInList(list interface{}, item string) bool { + listStr, ok := list.([]interface{}) + if !ok { + return false + } + + for _, v := range listStr { + if v == item { + return true + } + } + + return false +} + func ContainsString(s, sub string) bool { return strings.Contains(s, sub) } @@ -321,6 +356,43 @@ func ListToString(stringList []string) string { return strings.Join(stringList, ",") } +func isMultiLine(propertyName, classPkgName string, definitions Definitions, modelProperties map[string]Property) bool { + for _, property := range modelProperties { + if propertyName == property.SnakeCaseName && slices.Contains(alwaysMultiLineTypes, property.ModelType) { + return true + } + } + precedenceList := []string{classPkgName, "global"} + for _, precedence := range precedenceList { + if classDetails, ok := definitions.Properties[precedence]; ok { + for key, value := range classDetails.(map[interface{}]interface{}) { + if key.(string) == "multi_line" { + for _, v := range value.([]interface{}) { + if v.(string) == propertyName { + return true + } + } + } + } + } + } + return false +} + +func processMultiLine(multiLineValue string) string { + cert := strings.ReplaceAll(multiLineValue, "\\n", "\n") + return fmt.Sprintf( + `< 0 { + childResource := childResources[0].(map[interface{}]interface{}) + + if val, ok := childResource[propertyName]; ok { + return val.(string) + } + + if versionMismatch, ok := childResource["version_mismatch"].(map[interface{}]interface{}); ok { + for _, versionVars := range versionMismatch { + if versionVarsMap, ok := versionVars.(map[interface{}]interface{}); ok { + if val, ok := versionVarsMap[propertyName]; ok { + return val.(string) + } + } + } + } } } else { return fmt.Sprintf("%s_%d", propertyName, testValueIndex) @@ -491,10 +608,13 @@ func getClassModels(definitions Definitions) map[string]Model { pkgNames = append(pkgNames, strings.TrimSuffix(file.Name(), path.Ext(file.Name()))) } for _, pkgName := range pkgNames { - classModel := Model{PkgName: pkgName} classModel.setClassModel(metaPath, false, definitions, []string{}, pkgNames) classModels[pkgName] = classModel + + rnName := make(map[string]string) + rnName[pkgName] = classModel.RnFormat + resourceIdentifier = append(resourceIdentifier, rnName) } return classModels } @@ -619,7 +739,7 @@ func migrateLegacyDocumentation() { // Container function to clean all directories properly func cleanDirectories() { cleanDirectory(docsPath, []string{"resources", "data-sources"}) - cleanDirectory(providerPath, []string{"provider_test.go", "utils.go", "test_constants.go", "resource_aci_rest_managed.go", "resource_aci_rest_managed_test.go", "data_source_aci_rest_managed.go", "data_source_aci_rest_managed_test.go", "annotation_unsupported.go", "data_source_aci_system.go", "data_source_aci_system_test.go"}) + cleanDirectory(providerPath, []string{"provider_test.go", "utils.go", "test_constants.go", "resource_aci_rest_managed.go", "resource_aci_rest_managed_test.go", "data_source_aci_rest_managed.go", "data_source_aci_rest_managed_test.go", "annotation_unsupported.go", "data_source_aci_system.go", "data_source_aci_system_test.go", "function_compare_versions.go", "function_compare_versions_test.go"}) cleanDirectory(resourcesDocsPath, []string{}) cleanDirectory(datasourcesDocsPath, []string{"system.md"}) cleanDirectory(testVarsPath, []string{}) @@ -747,17 +867,16 @@ func main() { } for _, model := range classModels { - if len(model.IdentifiedBy) == 0 && !model.Include { + if (len(model.IdentifiedBy) == 0 && !model.Include) || model.Exclude { classesWithoutResource = append(classesWithoutResource, model.PkgName) } } for _, model := range classModels { - // Only render resources and datasources when the class has a unique identifier or is marked as include in the classes definitions YAML file // And if the class has a unique identifier, only render when the class is also not a Rs object and is not set to max one class allowed // TODO might need to modify this last condition in the future - if (len(model.IdentifiedBy) > 0 && !(strings.HasPrefix(model.RnFormat, "rs") && model.MaxOneClassAllowed)) || model.Include { + if (len(model.IdentifiedBy) > 0 && !(strings.HasPrefix(model.RnFormat, "rs") && model.MaxOneClassAllowed) && !model.Exclude) || model.Include { // All classmodels have been read, thus now the model, child and relational resources names can be set // When done before additional files would need to be opened and read which would slow down the generation process @@ -779,10 +898,19 @@ func main() { for _, relationshipClass := range childModel.RelationshipClasses { childModel.RelationshipResourceNames = append(childModel.RelationshipResourceNames, GetResourceName(relationshipClass, definitions)) } + + if len(childModel.VersionMismatched) > 0 { + updateVersionMismatchedWithChildren(&model, childModel.VersionMismatched) + } + childMap[childName] = childModel } model.Children = childMap + if model.VersionMismatched != nil { + sortVersionMismatched(model.VersionMismatched) + } + // Set the documentation specific information for the resource // This is done to ensure references can be made to parent/child resources and output amounts can be restricted setDocumentationData(&model, definitions) @@ -823,10 +951,8 @@ func main() { renderTemplate("datasource.md.tmpl", fmt.Sprintf("%s.md", model.ResourceName), datasourcesDocsPath, model) renderTemplate("resource_test.go.tmpl", fmt.Sprintf("resource_%s_%s_test.go", providerName, model.ResourceName), providerPath, model) renderTemplate("datasource_test.go.tmpl", fmt.Sprintf("data_source_%s_%s_test.go", providerName, model.ResourceName), providerPath, model) - } } - } // A Model that represents the provider @@ -847,57 +973,61 @@ type Metadata struct { // A Model represents a ACI class // All information is retrieved directly or deduced from the metadata type Model struct { - PkgName string - Label string - Name string - RnFormat string - RnPrepend string - Comment string - ResourceClassName string - ResourceName string - ResourceNameDocReference string - ChildResourceName string - ExampleDataSource string - ExampleResource string - ExampleResourceFull string - SubCategory string - RelationshipClasses []string - MultiRelationshipClass bool - RelationshipResourceNames []string - Versions string - ChildClasses []string - ContainedBy []string - Contains []string - DocumentationDnFormats []string - DocumentationParentDns []string - DocumentationExamples []string - TestDependencies []TestDependency - ChildTestDependencies []TestDependency - DocumentationChildren []string - ResourceNotes []string - ResourceWarnings []string - DatasourceNotes []string - DatasourceWarnings []string - Parents []string - UiLocations []string - IdentifiedBy []interface{} - MaxOneClassAllowed bool - DnFormats []interface{} - Properties map[string]Property - NamedProperties map[string]Property - RequiredPropertiesNames []string - LegacyAttributes map[string]LegacyAttribute - LegacyBlocks []LegacyBlock - LegacySchemaVersion int - LegacyChildren []string - MigrationClassTypes map[string]string - Children map[string]Model - Configuration map[string]interface{} - TestVars map[string]interface{} - Definitions Definitions - ResourceNameAsDescription string - TypeChanges map[int][]TypeChange - SchemaVersion int + PkgName string + Label string + Name string + RnFormat string + RnPrepend string + Comment string + ResourceClassName string + ResourceName string + ResourceNameDocReference string + ChildResourceName string + ExampleDataSource string + ExampleResource string + ExampleResourceFull string + SubCategory string + RelationshipClasses []string + MultiRelationshipClass bool + RelationshipResourceNames []string + Versions string + ChildClasses []string + ContainedBy []string + Contains []string + DocumentationDnFormats []string + DocumentationParentDns []string + DocumentationExamples []string + TestDependencies []TestDependency + ChildTestDependencies []TestDependency + DocumentationChildren []string + ResourceNotes []string + ResourceWarnings []string + DatasourceNotes []string + DatasourceWarnings []string + Parents []string + UiLocations []string + IdentifiedBy []interface{} + MaxOneClassAllowed bool + DnFormats []interface{} + Properties map[string]Property + NamedProperties map[string]Property + RequiredPropertiesNames []string + LegacyAttributes map[string]LegacyAttribute + LegacyBlocks []LegacyBlock + LegacySchemaVersion int + LegacyChildren []string + MigrationClassTypes map[string]string + Children map[string]Model + Configuration map[string]interface{} + TestVars map[string]interface{} + Definitions Definitions + ResourceNameAsDescription string + TypeChanges map[int][]TypeChange + SchemaVersion int + TestType string + MultiParentFormats map[string]MultiParentFormat + MultiParentFormatsTestTypes map[string]string + ClassVersion string // Below booleans are used during template rendering to determine correct rendering the go code AllowDelete bool AllowChildDelete bool @@ -915,6 +1045,8 @@ type Model struct { Include bool HasReadOnlyProperties bool HasCustomTypeProperties bool + Exclude bool + VersionMismatched map[string][]string } type TypeChange struct { @@ -975,6 +1107,8 @@ type Property struct { NamedPropertyClass string IgnoreInTestExampleValue string ValidValuesMap map[string]string + RawVersion string + ModelType string ValidValues []string IdentifiedBy []interface{} Validators []interface{} @@ -1017,9 +1151,11 @@ func (m *Model) setClassModel(metaPath string, child bool, definitions Definitio m.SetClassName(classDetails) m.SetRelationshipClasses(definitions) m.SetClassRnFormat(classDetails) + m.SetClassRnFormatList(classDetails) m.SetClassDnFormats(classDetails) m.SetClassIdentifiers(classDetails) m.SetClassInclude() + m.SetClassExclude() m.SetClassAllowDelete(classDetails) m.SetClassContainedByAndParent(classDetails, parents) m.SetClassContains(classDetails) @@ -1029,6 +1165,8 @@ func (m *Model) setClassModel(metaPath string, child bool, definitions Definitio m.SetClassChildren(classDetails, pkgNames) m.SetResourceNotesAndWarnigns(m.PkgName, definitions) m.SetResourceNameAsDescription(m.PkgName, definitions) + m.SetTestType(classDetails, definitions) + m.SetTestApplicableFromVersion(classDetails) } /* @@ -1324,6 +1462,34 @@ func (m *Model) SetResourceNameAsDescription(classPkgName string, definitions De m.ResourceNameAsDescription = GetResourceNameAsDescription(GetResourceName(classPkgName, definitions), definitions) } +func (m *Model) SetTestType(classDetails interface{}, definitions Definitions) { + m.TestType = GetOverwriteTestType(m.PkgName, definitions) + if m.TestType == "" { + if platformFlavors, ok := classDetails.(map[string]interface{})["platformFlavors"].([]interface{}); ok { + for _, value := range platformFlavors { + if value.(string) == "capic" { + m.TestType = "cloud" + } else if value.(string) == "apic" { + m.TestType = "apic" + } + } + if m.TestType == "" { + m.TestType = "both" + } + } + } +} + +func (m *Model) SetClassExclude() { + if classDetails, ok := m.Definitions.Classes[m.PkgName]; ok { + for key, value := range classDetails.(map[interface{}]interface{}) { + if key.(string) == "exclude" { + m.Exclude = value.(bool) + } + } + } +} + // Determine if a class is allowed to be deleted as defined in the classes.yaml file // Flag created to ensure classes that only classes allowed to be deleted are deleted func AllowClassDelete(classPkgName string, definitions Definitions) bool { @@ -1386,6 +1552,15 @@ func (m *Model) SetClassVersions(classDetails interface{}) { } } +func (m *Model) SetTestApplicableFromVersion(classDetails interface{}) { + versions, ok := classDetails.(map[string]interface{})["versions"] + if ok { + m.ClassVersion = versions.(string) + } else { + m.ClassVersion = "unknown" + } +} + func formatVersion(versions string) string { if versions[len(versions)-1:] == "-" { versions = fmt.Sprintf("%s and later.", versions[:len(versions)-1]) @@ -1540,6 +1715,23 @@ func (m *Model) SetClassProperties(classDetails interface{}) { m.HasNamedProperties = true } + /* The piece of code below modifies the documentation by adding the version of APIC in which the attributes were introduced. */ + // if propertyValue.(map[string]interface{})["versions"] != nil { + // property.Versions = formatVersion(propertyValue.(map[string]interface{})["versions"].(string)) + // } + + if propertyValue.(map[string]interface{})["versions"] != nil { + property.RawVersion = strings.TrimSuffix(propertyValue.(map[string]interface{})["versions"].(string), "-") + } + + if !property.IgnoreInTest { + updateVersionMismatched(m, m.Versions, property.RawVersion, property.PropertyName) + } + + if propertyValue.(map[string]interface{})["modelType"] != nil { + property.ModelType = strings.Replace(propertyValue.(map[string]interface{})["modelType"].(string), ":", "", -1) + } + properties[propertyName] = property } @@ -1553,6 +1745,67 @@ func (m *Model) SetClassProperties(classDetails interface{}) { } } +func ignoreTestProperty(propertyName, classPkgName string, definitions Definitions) (bool, string) { + + precedenceList := []string{classPkgName, "global"} + for _, precedence := range precedenceList { + if classDetails, ok := definitions.Properties[precedence]; ok { + for key, value := range classDetails.(map[interface{}]interface{}) { + if key.(string) == "ignore_properties_in_test" { + for k, v := range value.(map[interface{}]interface{}) { + if k.(string) == propertyName { + return true, v.(string) + } + } + } + } + } + } + return false, "" +} + +func updateVersionMismatched(model *Model, classVersion, propertyVersion, propertyName string) { + classVersionResult := providerFunctions.ParseVersion(classVersion) + propertyVersionResult := providerFunctions.ParseVersion(propertyVersion) + + if model.VersionMismatched == nil { + model.VersionMismatched = make(map[string][]string) + } + + if propertyVersionResult.Error == "unknown" { + model.VersionMismatched["unknown"] = append(model.VersionMismatched["unknown"], propertyName) + } else if providerFunctions.IsVersionGreater(*propertyVersionResult.Version, *classVersionResult.Version) && !providerFunctions.IsVersionLesser(*propertyVersionResult.Version, *providerFunctions.ParseVersion("4.0(0a)").Version) { + model.VersionMismatched[propertyVersion] = append(model.VersionMismatched[propertyVersion], propertyName) + } +} + +func updateVersionMismatchedWithChildren(model *Model, childVersionMap map[string][]string) { + + if model.VersionMismatched == nil { + model.VersionMismatched = make(map[string][]string) + } + + for childVersion, properties := range childVersionMap { + childVersionResult := providerFunctions.ParseVersion(childVersion) + if childVersionResult.Error == "unknown" { + for _, property := range properties { + model.VersionMismatched["unknown"] = append(model.VersionMismatched["unknown"], property) + } + } else { + for _, property := range properties { + model.VersionMismatched[childVersion] = append(model.VersionMismatched[childVersion], property) + } + } + } +} + +func sortVersionMismatched(versionMismatched map[string][]string) { + for version, properties := range versionMismatched { + sort.Strings(properties) + versionMismatched[version] = properties + } +} + func (m *Model) SetMigrationClassTypes(definitions Definitions) { migrationClassTypes := map[string]string{} @@ -1823,25 +2076,6 @@ func ignoreProperty(propertyName, classPkgName string, definitions Definitions) return false } -func ignoreTestProperty(propertyName, classPkgName string, definitions Definitions) (bool, string) { - - precedenceList := []string{classPkgName, "global"} - for _, precedence := range precedenceList { - if classDetails, ok := definitions.Properties[precedence]; ok { - for key, value := range classDetails.(map[interface{}]interface{}) { - if key.(string) == "ignore_properties_in_test" { - for k, v := range value.(map[interface{}]interface{}) { - if k.(string) == propertyName { - return true, v.(string) - } - } - } - } - } - } - return false, "" -} - func readOnlyProperties(classPkgName string, definitions Definitions) []string { readOnlyProperties := []string{} if classDetails, ok := definitions.Properties[classPkgName]; ok { @@ -1991,6 +2225,120 @@ func (m *Model) GetOverwriteRnFormat(rnFormat string) { } } +func GetOverwriteTestType(classPkgName string, definitions Definitions) string { + if v, ok := definitions.Classes[classPkgName]; ok { + for key, value := range v.(map[interface{}]interface{}) { + if key.(string) == "test_type" { + return value.(string) + } + } + } + return "" +} + +type MultiParentFormat struct { + RnPrepend string + WrapperClass string + TestType string + ContainedBy string + RnFormat string +} + +func GetMultiParentFormats(classPkgName string, definitions Definitions) map[string]MultiParentFormat { + multiParentFormats := make(map[string]MultiParentFormat) + if v, ok := definitions.Classes[classPkgName]; ok { + classMap, ok := v.(map[interface{}]interface{}) + if !ok { + return multiParentFormats + } + multiParentsValue, ok := classMap["multi_parents"] + if !ok { + return multiParentFormats + } + multiParentsSlice, ok := multiParentsValue.([]interface{}) + if !ok { + return multiParentFormats + } + for _, entry := range multiParentsSlice { + entryMap, ok := entry.(map[interface{}]interface{}) + if !ok { + continue + } + var multiParentEntry MultiParentFormat + for key, value := range entryMap { + switch key { + case "rn_prepend": + multiParentEntry.RnPrepend, ok = value.(string) + case "contained_by": + multiParentEntry.ContainedBy, ok = value.(string) + case "test_type": + multiParentEntry.TestType, ok = value.(string) + case "wrapper_class": + multiParentEntry.WrapperClass, ok = value.(string) + } + if !ok { + break + } + } + if ok { + identifier := GetOverwriteResourceIdentifier(multiParentEntry.ContainedBy, definitions) + pattern := regexp.MustCompile(`^(.*?)-[\[{]`) + if identifier == "" { + for _, item := range resourceIdentifier { + if rnMap, ok := item.(map[string]string); ok { + if value, found := rnMap[multiParentEntry.ContainedBy]; found { + matches := pattern.FindStringSubmatch(value) + if len(matches) > 1 { + identifier = matches[1] + "-" + } else { + identifier = "" + } + break + } + } + } + } + multiParentFormats[identifier] = MultiParentFormat{ + ContainedBy: multiParentEntry.ContainedBy, + RnPrepend: multiParentEntry.RnPrepend, + WrapperClass: multiParentEntry.WrapperClass, + TestType: multiParentEntry.TestType, + } + } + } + } + defaultParentEntry := GetDefaultValues(classPkgName, "parent_dn", definitions) + if defaultParentEntry != "" { + defaultMultiParentFormat := MultiParentFormat{ + ContainedBy: "", + RnPrepend: defaultParentEntry, + } + multiParentFormats["default"] = defaultMultiParentFormat + } + return multiParentFormats +} + +func GetOverwriteResourceIdentifier(classPkgName string, definitions Definitions) string { + if v, ok := definitions.Classes[classPkgName]; ok { + for key, value := range v.(map[interface{}]interface{}) { + if key.(string) == "resource_identifier" { + return value.(string) + } + } + } + return "" +} + +func (m *Model) SetClassRnFormatList(classDetails interface{}) { + rnFormat := classDetails.(map[string]interface{})["rnFormat"].(string) + getMultiParentFormats := GetMultiParentFormats(m.PkgName, m.Definitions) + for key, format := range getMultiParentFormats { + format.RnFormat = rnFormat + getMultiParentFormats[key] = format + } + m.MultiParentFormats = getMultiParentFormats +} + // Determine if possible dn formats in terraform documentation should be overwritten by dn formats from the classes.yaml file func GetOverwriteDnFormats(dnFormats []interface{}, classPkgName string, definitions Definitions) []interface{} { if v, ok := definitions.Classes[classPkgName]; ok { @@ -2291,6 +2639,15 @@ func isMigrationResource(classPkgName string, definitions Definitions) (bool, bo return version, changes } +func resourcesExcluded(excludeResources []interface{}, containedClassName string) bool { + for _, item := range excludeResources { + if s, ok := item.(string); ok && s == containedClassName { + return true + } + } + return false +} + // Set variables that are used during the rendering of the example and documentation templates func setDocumentationData(m *Model, definitions Definitions) { UiLocations := []string{} @@ -2337,11 +2694,13 @@ func setDocumentationData(m *Model, definitions Definitions) { } else { for _, resourceDetails := range resourcesFound { m.DocumentationParentDns = append(m.DocumentationParentDns, fmt.Sprintf("[%s_%s](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/%s) (%s)", providerName, resourceDetails[0], resourceDetails[0], GetDevnetDocForClass(resourceDetails[1]))) + } } if len(resourcesNotFound) != 0 && len(resourcesFound) < docsParentDnAmount { if len(resourcesNotFound) > docsParentDnAmount-len(resourcesFound) { + // TODO catch default classes and add to documentation resourcesNotFound = resourcesNotFound[0:(docsParentDnAmount - len(resourcesFound))] m.DocumentationParentDns = append(m.DocumentationParentDns, fmt.Sprintf("Too many classes to display, see model documentation for all possible classes of %s.", GetDevnetDocForClass(m.PkgName))) } else { @@ -2353,6 +2712,16 @@ func setDocumentationData(m *Model, definitions Definitions) { } } + getMultiParentFormats := GetMultiParentFormats(m.PkgName, definitions) + if len(getMultiParentFormats) > 0 { + m.DocumentationParentDns = nil + for _, format := range getMultiParentFormats { + if format.ContainedBy != "" { + m.DocumentationParentDns = append(m.DocumentationParentDns, fmt.Sprintf("[%s_%s](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/%s) (%s)", providerName, GetResourceName(format.ContainedBy, definitions), format.ContainedBy, GetDevnetDocForClass(format.ContainedBy))) + } + } + } + // TODO add overwrite to provide which documentation examples to be included docsExampleAmount := m.Configuration["docs_examples_amount"].(int) if len(m.ContainedBy) > docsExampleAmount { diff --git a/gen/meta/cloudCertStore.json b/gen/meta/cloudCertStore.json new file mode 100644 index 000000000..cdfe751a0 --- /dev/null +++ b/gen/meta/cloudCertStore.json @@ -0,0 +1,615 @@ +{ + "cloud:CertStore": { + "contains": { + "aaa:RbacAnnotation": "", + "fault:Counts": "", + "health:Inst": "", + "pki:KeyRing": "", + "pki:TP": "", + "tag:Annotation": "", + "tag:Tag": "" + }, + "rnMap": { + "annotationKey-": "tag:Annotation", + "fltCnts": "fault:Counts", + "health": "health:Inst", + "keyring-": "pki:KeyRing", + "rbacDom-": "aaa:RbacAnnotation", + "tagKey-": "tag:Tag", + "tp-": "pki:TP" + }, + "identifiedBy": [ + + ], + "rnFormat": "certstore", + "containedBy": { + "fv:Tenant": "" + }, + "superClasses": [ + "cloud:ACertStore", + "naming:NamedObject" + ], + "subClasses": { + + }, + "relationFrom": { + + }, + "relationTo": { + + }, + "dnFormats": [ + "uni/tn-{name}/certstore" + ], + "writeAccess": [ + "admin", + "nw-svc-policy" + ], + "readAccess": [ + "aaa", + "admin", + "nw-svc-policy" + ], + "faults": { + + }, + "events": { + "E4216577": "creation||cloud:CertStore", + "E4216578": "modification||cloud:CertStore", + "E4216579": "deletion||cloud:CertStore" + }, + "stats": { + + }, + "versions": "4.1(1i)-", + "isAbstract": false, + "isConfigurable": true, + "isContextRoot": false, + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false, + "isEncrypted": false, + "isExportable": true, + "isPersistent": true, + "isSubjectToQuota": false, + "isObservable": true, + "hasStats": false, + "isStat": false, + "isFaultable": false, + "isDomainable": false, + "isHealthScorable": true, + "shouldCollectHealthStats": false, + "healthCollectionSource": "faults", + "hasEventRules": false, + "abstractionLayer": "logical", + "apicNxProcessing": false, + "monitoringPolicySource": "Parent", + "isCreatableDeletable": "always", + "platformFlavors": [ + "capic" + ], + "classId": "15191", + "className": "CertStore", + "classPkg": "cloud", + "featureTag": "", + "moCategory": "Regular", + "label": "Certificate Store", + "properties": { + "annotation": { + "versions": "4.1(1i)-", + "comment": [ + "User annotation. Suggested format orchestrator:value" + ], + "isConfigurable": true, + "propGlobalId": "51999", + "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 + }, + "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": "4.1(1i)-", + "comment": [ + "Indicates which orchestrator is managing this MO" + ], + "isConfigurable": false, + "propGlobalId": "52000", + "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 + }, + "monPolDn": { + "versions": "4.1(1i)-", + "comment": [ + "The monitoring policy attached to this observable object." + ], + "isConfigurable": false, + "propGlobalId": "52687", + "propLocalId": "228", + "label": "Monitoring Policy", + "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 + }, + "name": { + "versions": "1.0(1e)-", + "comment": [ + "The name of the object." + ], + "isConfigurable": true, + "propGlobalId": "5577", + "propLocalId": "13", + "label": "Name", + "baseType": "string:Basic", + "modelType": "naming:Name", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": true, + "likeProp": "naming:Named:name", + "validators": [ + {"min" : 0, "max": 16, + "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 + }, + "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/pkiEp.json b/gen/meta/pkiEp.json new file mode 100644 index 000000000..731bb065d --- /dev/null +++ b/gen/meta/pkiEp.json @@ -0,0 +1,743 @@ +{ + "pki:Ep": { + "contains": { + "aaa:RbacAnnotation": "", + "fault:Counts": "", + "fault:Delegate": "", + "health:Inst": "", + "pki:CsyncPolicy": "", + "pki:CsyncSharedKey": "", + "pki:DebugPluginChallenge": "", + "pki:KeyRing": "", + "pki:RtResPkiEp": "", + "pki:SiteJwtPubKey": "", + "pki:TP": "", + "pki:TbkKey": "", + "pki:WebTokenData": "", + "tag:Annotation": "", + "tag:Tag": "" + }, + "rnMap": { + "annotationKey-": "tag:Annotation", + "csyncpolicy": "pki:CsyncPolicy", + "csyncsharedkey": "pki:CsyncSharedKey", + "dbgplgch": "pki:DebugPluginChallenge", + "fd-": "fault:Delegate", + "fltCnts": "fault:Counts", + "health": "health:Inst", + "keyring-": "pki:KeyRing", + "rbacDom-": "aaa:RbacAnnotation", + "rtfabricResPkiEp-": "pki:RtResPkiEp", + "sitejwtpubkey-": "pki:SiteJwtPubKey", + "tagKey-": "tag:Tag", + "tbkey-": "pki:TbkKey", + "tp-": "pki:TP", + "webtokendata": "pki:WebTokenData" + }, + "identifiedBy": [ + + ], + "rnFormat": "pkiext", + "containedBy": { + "aaa:UserEp": "" + }, + "superClasses": [ + "pki:Definition", + "pol:Def", + "pol:Obj", + "naming:NamedObject" + ], + "subClasses": { + + }, + "relationFrom": { + "pki:RtResPkiEp": "fabric:SecRelnHolder" + }, + "relationTo": { + + }, + "dnFormats": [ + "uni/userext/pkiext" + ], + "writeAccess": [ + "aaa", + "admin" + ], + "readAccess": [ + "aaa", + "admin" + ], + "faults": { + + }, + "events": { + "E4212884": "creation||pki:Ep", + "E4212885": "modification||pki:Ep", + "E4212886": "deletion||pki:Ep" + }, + "stats": { + + }, + "versions": "1.0(1e)-", + "isAbstract": false, + "isConfigurable": true, + "isContextRoot": false, + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false, + "isEncrypted": false, + "isExportable": true, + "isPersistent": true, + "isSubjectToQuota": false, + "isObservable": true, + "hasStats": false, + "isStat": false, + "isFaultable": false, + "isDomainable": false, + "isHealthScorable": true, + "shouldCollectHealthStats": false, + "healthCollectionSource": "faults", + "hasEventRules": false, + "abstractionLayer": "ambiguous", + "apicNxProcessing": false, + "monitoringPolicySource": "Parent", + "isCreatableDeletable": "never", + "platformFlavors": [ + + ], + "classId": "1478", + "className": "Ep", + "classPkg": "pki", + "featureTag": "", + "moCategory": "Regular", + "label": "Public Key Management", + "comment": [ + "The PKI configuration, which includes key rings and certificate authority (CA) credentials. Components of the PKI are used to establish secure communications between two devices." + ], + "properties": { + "annotation": { + "versions": "3.2(1l)-", + "comment": [ + "User annotation. Suggested format orchestrator:value" + ], + "isConfigurable": true, + "propGlobalId": "37505", + "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": "39644", + "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 + }, + "monPolDn": { + "versions": "3.1(1i)-", + "comment": [ + "The monitoring policy attached to this observable object." + ], + "isConfigurable": false, + "propGlobalId": "14133", + "propLocalId": "228", + "label": "Monitoring Policy", + "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 + }, + "name": { + "versions": "1.0(1e)-", + "comment": [ + "" + ], + "isConfigurable": true, + "propGlobalId": "1221", + "propLocalId": "13", + "label": "Name", + "baseType": "string:Basic", + "modelType": "naming:Name", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": true, + "readWrite": false, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": true, + "isLike": false, + "validators": [ + {"min" : 0, "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/pkiKeyRing.json b/gen/meta/pkiKeyRing.json new file mode 100644 index 000000000..e8be1d324 --- /dev/null +++ b/gen/meta/pkiKeyRing.json @@ -0,0 +1,1283 @@ +{ + "pki:KeyRing": { + "contains": { + "aaa:RbacAnnotation": "", + "fault:Counts": "", + "fault:Delegate": "", + "fault:Inst": "", + "health:Inst": "", + "pki:CertReq": "", + "pki:RtKeyRing": "", + "pki:RtKeyringRef": "", + "pki:RtListenerToCert": "", + "pki:RtSvrKeyRing": "", + "tag:Annotation": "", + "tag:Tag": "" + }, + "rnMap": { + "annotationKey-": "tag:Annotation", + "certreq": "pki:CertReq", + "fault-": "fault:Inst", + "fd-": "fault:Delegate", + "fltCnts": "fault:Counts", + "health": "health:Inst", + "rbacDom-": "aaa:RbacAnnotation", + "rtaaaKeyringRef-": "pki:RtKeyringRef", + "rtadepgSvrKeyRing-": "pki:RtSvrKeyRing", + "rtcloudListenerToCert-": "pki:RtListenerToCert", + "rtcommKeyRing-": "pki:RtKeyRing", + "tagKey-": "tag:Tag" + }, + "identifiedBy": [ + "name" + ], + "rnFormat": "keyring-{name}", + "containedBy": { + "cloud:CertStore": "", + "pki:Ep": "" + }, + "superClasses": [ + "pki:Item", + "pki:Definition", + "pol:Def", + "pol:Obj", + "naming:NamedObject" + ], + "subClasses": { + + }, + "relationFrom": { + "pki:RtKeyRing": "comm:Https", + "pki:RtKeyringRef": "aaa:KeyringRelnHolder", + "pki:RtListenerToCert": "cloud:Listener", + "pki:RtSvrKeyRing": "adepg:ASvr" + }, + "relationTo": { + + }, + "dnFormats": [ + "uni/tn-{name}/certstore/keyring-{name}", + "uni/userext/pkiext/keyring-{name}" + ], + "writeAccess": [ + "aaa", + "admin" + ], + "readAccess": [ + "aaa", + "admin", + "nw-svc-policy" + ], + "faults": { + "F4502": "fltPkiKeyRingCustomKeyRingExpired", + "F4501": "fltPkiKeyRingCustomKeyRingExpiring", + "F4510": "fltPkiKeyRingKeyRingInsecure" + }, + "events": { + "E4204952": "creation|createKeyRing|pki:KeyRing", + "E4204957": "deletion|deleteKeyRing|pki:KeyRing", + "E4204968": "modification|modKeyRing|pki:KeyRing", + "E4212893": "creation||pki:KeyRing", + "E4212894": "modification||pki:KeyRing", + "E4212895": "deletion||pki:KeyRing" + }, + "stats": { + + }, + "versions": "1.0(1e)-", + "isAbstract": false, + "isConfigurable": true, + "isContextRoot": false, + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false, + "isEncrypted": true, + "isExportable": true, + "isPersistent": true, + "isSubjectToQuota": false, + "isObservable": true, + "hasStats": false, + "isStat": false, + "isFaultable": true, + "isDomainable": false, + "isHealthScorable": true, + "shouldCollectHealthStats": false, + "healthCollectionSource": "faults", + "hasEventRules": false, + "abstractionLayer": "ambiguous", + "apicNxProcessing": false, + "monitoringPolicySource": "Parent", + "isCreatableDeletable": "always", + "platformFlavors": [ + + ], + "classId": "1482", + "className": "KeyRing", + "classPkg": "pki", + "featureTag": "", + "moCategory": "Regular", + "label": "Key Ring", + "comment": [ + "A keyring to create and hold an SSL certificate. The SSL certificate contains the public RSA key and signed identity information of a PKI device. The PKI device holds a pair of RSA encryption keys, one kept private and one made public, stored in an internal key ring. The keyring certificate merges into the PKI device keyring to create a trusted relationship." + ], + "properties": { + "adminState": { + "versions": "1.0(1e)-", + "comment": [ + "The current administrative state of the certificate request process." + ], + "isConfigurable": true, + "propGlobalId": "1199", + "propLocalId": "91", + "label": "adminState", + "baseType": "scalar:Enum8", + "modelType": "pki:KeyringState", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "5", "localName": "completed", + "platformFlavors": [ + + ], + "label": "Completed "}, + { "value": "2", "localName": "created", + "platformFlavors": [ + + ], + "label": "Created "}, + { "value": "started", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "3", "localName": "reqCreated", + "platformFlavors": [ + + ], + "label": "Request Created "}, + { "value": "1", "localName": "started", + "platformFlavors": [ + + ], + "label": "Started "}, + { "value": "4", "localName": "tpSet", + "platformFlavors": [ + + ], + "label": "Trust Provider Set "} + ], + "default": "started", + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "annotation": { + "versions": "3.2(1l)-", + "comment": [ + "User annotation. Suggested format orchestrator:value" + ], + "isConfigurable": true, + "propGlobalId": "37508", + "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 + }, + "cert": { + "versions": "1.0(1e)-", + "comment": [ + "A certificate is a file containing a device's public key along with signed information verifying the identity of the device." + ], + "isConfigurable": true, + "propGlobalId": "1203", + "propLocalId": "631", + "label": "Certificate", + "baseType": "string:CharBuffer", + "modelType": "pki:Cert", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "certValidUntil": { + "versions": "1.0(1e)-", + "comment": [ + "" + ], + "isConfigurable": false, + "propGlobalId": "1204", + "propLocalId": "632", + "label": "Certificate Validity", + "baseType": "string:CharBuffer", + "modelType": "pki:CertValidity", + "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 + }, + "certificateDecodeInformation": { + "versions": "1.0(1e)-", + "comment": [ + "" + ], + "isConfigurable": false, + "propGlobalId": "1205", + "propLocalId": "633", + "label": "Certificate Decode Information", + "baseType": "string:CharBuffer", + "modelType": "pki:Cert", + "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 + }, + "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 + }, + "creator": { + "versions": "6.0(2h)-", + "isConfigurable": false, + "propGlobalId": "68676", + "propLocalId": "14578", + "label": "MO creator origin", + "baseType": "scalar:Enum8", + "modelType": "fabric:CreatorType", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "1", "localName": "SYSTEM", + "platformFlavors": [ + + ], + "label": "system maintained "}, + { "value": "0", "localName": "USER", + "platformFlavors": [ + + ], + "label": "created by the user "}, + { "value": "USER", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "} + ], + "default": "USER", + "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 + }, + "eccCurve": { + "versions": "6.0(2h)-", + "isConfigurable": true, + "propGlobalId": "68747", + "propLocalId": "14922", + "label": "ECC Curve", + "baseType": "scalar:Enum16", + "modelType": "pki:EccCurve", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "0", "localName": "none", + "platformFlavors": [ + + ], + "label": "None "}, + { "value": "1", "localName": "prime256v1", + "platformFlavors": [ + + ], + "label": "P-256 "}, + { "value": "2", "localName": "secp384r1", + "platformFlavors": [ + + ], + "label": "P-384 "}, + { "value": "3", "localName": "secp521r1", + "platformFlavors": [ + + ], + "label": "P-521 "} + ], + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "expState": { + "versions": "3.1(1i)-", + "isConfigurable": false, + "propGlobalId": "35519", + "propLocalId": "8280", + "label": "expState", + "baseType": "scalar:Enum8", + "modelType": "pki:ExpStatus", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "1", "localName": "active", + "platformFlavors": [ + + ], + "label": "Active "}, + { "value": "active", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "3", "localName": "expired", + "platformFlavors": [ + + ], + "label": "Expired "}, + { "value": "2", "localName": "expiring", + "platformFlavors": [ + + ], + "label": "Expiring "} + ], + "default": "active", + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "extMngdBy": { + "versions": "3.2(1l)-", + "comment": [ + "Indicates which orchestrator is managing this MO" + ], + "isConfigurable": false, + "propGlobalId": "39647", + "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 + }, + "key": { + "versions": "1.0(1e)-", + "comment": [ + "The private key of the certificate." + ], + "isConfigurable": true, + "propGlobalId": "1201", + "propLocalId": "542", + "label": "key", + "baseType": "string:Password", + "modelType": "pki:PrivateKey", + "needsPropDelimiters": false, + "uitype": "password", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": true, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validators": [ + {"min" : 0, "max": 4096 } + ], + "validValues": [ + { "value": "", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "} + ], + "default": "", + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "keyType": { + "versions": "6.0(2h)-", + "isConfigurable": true, + "propGlobalId": "68746", + "propLocalId": "7905", + "label": "Key Type", + "baseType": "scalar:Enum8", + "modelType": "pki:KeyType", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "1", "localName": "ECC", + "platformFlavors": [ + + ], + "label": "ECC "}, + { "value": "0", "localName": "RSA", + "platformFlavors": [ + + ], + "label": "RSA "}, + { "value": "RSA", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "2", "localName": "indeterminate", + "platformFlavors": [ + + ], + "label": "indeterminate "} + ], + "default": "RSA", + "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 + }, + "modulus": { + "versions": "1.0(1e)-", + "comment": [ + "The length of the encryption keys. A longer key length increases the difficulty of breaking the key." + ], + "isConfigurable": true, + "propGlobalId": "1202", + "propLocalId": "630", + "label": "Modulus", + "baseType": "scalar:Enum16", + "modelType": "pki:Modulus", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "mod2048", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "1024", "localName": "mod1024", + "platformFlavors": [ + + ], + "label": "MOD 1024 "}, + { "value": "1536", "localName": "mod1536", + "platformFlavors": [ + + ], + "label": "MOD 1536 "}, + { "value": "2048", "localName": "mod2048", + "platformFlavors": [ + + ], + "label": "MOD 2048 "}, + { "value": "3072", "localName": "mod3072", + "platformFlavors": [ + + ], + "label": "MOD 2048 "}, + { "value": "4096", "localName": "mod4096", + "platformFlavors": [ + + ], + "label": "MOD 4096 "}, + { "value": "512", "localName": "mod512", + "platformFlavors": [ + + ], + "label": "MOD 512 "}, + { "value": "0", "localName": "none", + "platformFlavors": [ + + ], + "label": "none "} + ], + "default": "mod2048", + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "monPolDn": { + "versions": "3.1(1i)-", + "comment": [ + "The monitoring policy attached to this observable object." + ], + "isConfigurable": false, + "propGlobalId": "14135", + "propLocalId": "228", + "label": "Monitoring Policy", + "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 + }, + "name": { + "versions": "1.0(1e)-", + "comment": [ + "The name of the key ring." + ], + "isConfigurable": true, + "propGlobalId": "7017", + "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 + }, + "regen": { + "versions": "1.0(1e)-", + "comment": [ + "Forces regeneration of the keypair. Each PKI device holds a pair of asymmetric Rivest-Shamir-Adleman (RSA) or Elliptic Curve Cryptography (ECC) encryption keys, one kept private and one made public, stored in an internal key ring." + ], + "isConfigurable": true, + "propGlobalId": "1200", + "propLocalId": "629", + "label": "Regenerate", + "baseType": "scalar:Bool", + "modelType": "scalar:Bool", + "needsPropDelimiters": false, + "uitype": "boolean", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "false", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "false", "localName": "no", + "platformFlavors": [ + + ], + "label": "No "}, + { "value": "true", "localName": "yes", + "platformFlavors": [ + + ], + "label": "Yes "} + ], + "default": "false", + "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 + }, + "tp": { + "versions": "1.0(1e)-", + "comment": [ + "A third-party certificate from a trusted source, or trusted point, that affirms the identity of your device. The third-party certificate is signed by the issuing certificate authority (CA or trustpoint), which can be a root CA, an intermediate CA, or a trust anchor that is part of a trust chain that leads to a root CA." + ], + "isConfigurable": true, + "propGlobalId": "1206", + "propLocalId": "634", + "label": "Certificate Authority", + "baseType": "string:Basic", + "modelType": "naming:LongName", + "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 + }, + "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/pkiTP.json b/gen/meta/pkiTP.json new file mode 100644 index 000000000..ec7a4a055 --- /dev/null +++ b/gen/meta/pkiTP.json @@ -0,0 +1,911 @@ +{ + "pki:TP": { + "contains": { + "aaa:RbacAnnotation": "", + "fault:Counts": "", + "fault:Delegate": "", + "fault:Inst": "", + "health:Inst": "", + "pki:RtClientCertCA": "", + "pki:RtSvrCertChain": "", + "tag:Annotation": "", + "tag:Tag": "" + }, + "rnMap": { + "annotationKey-": "tag:Annotation", + "fault-": "fault:Inst", + "fd-": "fault:Delegate", + "fltCnts": "fault:Counts", + "health": "health:Inst", + "rbacDom-": "aaa:RbacAnnotation", + "rtadepgSvrCertChain-": "pki:RtSvrCertChain", + "rtcommClientCertCA-": "pki:RtClientCertCA", + "tagKey-": "tag:Tag" + }, + "identifiedBy": [ + "name" + ], + "rnFormat": "tp-{name}", + "containedBy": { + "cloud:CertStore": "", + "pki:Ep": "" + }, + "superClasses": [ + "pki:Item", + "pki:Definition", + "pol:Def", + "pol:Obj", + "naming:NamedObject" + ], + "subClasses": { + + }, + "relationFrom": { + "pki:RtClientCertCA": "comm:Https", + "pki:RtSvrCertChain": "adepg:ASvr" + }, + "relationTo": { + + }, + "dnFormats": [ + "uni/tn-{name}/certstore/tp-{name}", + "uni/userext/pkiext/tp-{name}" + ], + "writeAccess": [ + "aaa", + "admin" + ], + "readAccess": [ + "aaa", + "admin" + ], + "faults": { + "F4503": "fltPkiTPTPExpired" + }, + "events": { + "E4204971": "creation||pki:TP", + "E4204972": "deletion||pki:TP", + "E4204973": "modification||pki:TP", + "E4212896": "creation||pki:TP", + "E4212897": "modification||pki:TP", + "E4212898": "deletion||pki:TP" + }, + "stats": { + + }, + "versions": "1.0(1e)-", + "isAbstract": false, + "isConfigurable": true, + "isContextRoot": false, + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false, + "isEncrypted": false, + "isExportable": true, + "isPersistent": true, + "isSubjectToQuota": false, + "isObservable": true, + "hasStats": false, + "isStat": false, + "isFaultable": true, + "isDomainable": false, + "isHealthScorable": true, + "shouldCollectHealthStats": false, + "healthCollectionSource": "faults", + "hasEventRules": false, + "abstractionLayer": "ambiguous", + "apicNxProcessing": false, + "monitoringPolicySource": "Parent", + "isCreatableDeletable": "always", + "platformFlavors": [ + + ], + "classId": "1483", + "className": "TP", + "classPkg": "pki", + "featureTag": "", + "moCategory": "Regular", + "label": "Certificate Authority", + "comment": [ + "A trustpoint (certificate authority/CA), which issues and validates (signs) digital certificates. When participating in secure communications using the public key infrastructure (PKI), a participant can verify the identity of the other party through the CA that signed the other party's public key." + ], + "properties": { + "annotation": { + "versions": "3.2(1l)-", + "comment": [ + "User annotation. Suggested format orchestrator:value" + ], + "isConfigurable": true, + "propGlobalId": "37509", + "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 + }, + "certChain": { + "versions": "1.0(1e)-", + "comment": [ + "The PEM-encoded chain of trust from the trustpoint to a trusted root authority." + ], + "isConfigurable": true, + "propGlobalId": "1207", + "propLocalId": "635", + "label": "Certificate Chain", + "baseType": "string:CharBuffer", + "modelType": "pki:Cert", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "certValidUntil": { + "versions": "3.1(1i)-", + "comment": [ + "The certificate expiration date of the certificate posted by the user in the cert field." + ], + "isConfigurable": false, + "propGlobalId": "35520", + "propLocalId": "632", + "label": "Certificate Validity", + "baseType": "string:CharBuffer", + "modelType": "pki:CertValidity", + "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 + }, + "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 + }, + "expState": { + "versions": "3.1(1i)-", + "isConfigurable": false, + "propGlobalId": "35521", + "propLocalId": "8280", + "label": "expState", + "baseType": "scalar:Enum8", + "modelType": "pki:ExpStatus", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "1", "localName": "active", + "platformFlavors": [ + + ], + "label": "Active "}, + { "value": "active", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "3", "localName": "expired", + "platformFlavors": [ + + ], + "label": "Expired "}, + { "value": "2", "localName": "expiring", + "platformFlavors": [ + + ], + "label": "Expiring "} + ], + "default": "active", + "platformFlavors": [ + + ], + "isNxosConverged": false, + "isDeprecated": false, + "isHidden": false + }, + "extMngdBy": { + "versions": "3.2(1l)-", + "comment": [ + "Indicates which orchestrator is managing this MO" + ], + "isConfigurable": false, + "propGlobalId": "39648", + "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 + }, + "fp": { + "versions": "1.0(1e)-", + "comment": [ + "This property is managed internally and should not be modified by the user." + ], + "isConfigurable": false, + "propGlobalId": "1208", + "propLocalId": "636", + "label": "fp", + "baseType": "string:CharBuffer", + "modelType": "pki:FP", + "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 + }, + "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 + }, + "monPolDn": { + "versions": "3.1(1i)-", + "comment": [ + "The monitoring policy attached to this observable object." + ], + "isConfigurable": false, + "propGlobalId": "26561", + "propLocalId": "228", + "label": "Monitoring Policy", + "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 + }, + "name": { + "versions": "1.0(1e)-", + "comment": [ + "The name of the certificate authority (CA or trustpoint)." + ], + "isConfigurable": true, + "propGlobalId": "7018", + "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 + }, + "numCerts": { + "versions": "1.0(1e)-", + "comment": [ + "The number of certificates found in the certificate chain." + ], + "isConfigurable": false, + "propGlobalId": "1209", + "propLocalId": "637", + "label": "numCerts", + "baseType": "scalar:Uint32", + "modelType": "scalar:Uint32", + "needsPropDelimiters": false, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "0", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "} + ], + "default": "0", + "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/templates/datasource.md.tmpl b/gen/templates/datasource.md.tmpl index 592152454..ee01e5ef4 100644 --- a/gen/templates/datasource.md.tmpl +++ b/gen/templates/datasource.md.tmpl @@ -64,18 +64,16 @@ Data source for ACI {{.ResourceNameAsDescription}} {{- end}} {{- end}} -{{- if and .HasParent (getDefaultValues .PkgName "parent_dn" $.Definitions)}} +{{- if and .HasParent (getDefaultValues .PkgName "parent_dn" $.Definitions) }} ### Optional ### * `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources: - {{- range .DocumentationParentDns}} + {{- range .DocumentationParentDns }} - {{ . }} - {{- end}} - {{- if getDefaultValues .PkgName "parent_dn" $.Definitions}} + {{- end }} - Default: `{{ getDefaultValues .PkgName "parent_dn" $.Definitions}}` - {{- end}} -{{- end}} +{{- end }} ### Read-Only ### diff --git a/gen/templates/datasource_example.tf.tmpl b/gen/templates/datasource_example.tf.tmpl index 16e323564..36d43c4f3 100644 --- a/gen/templates/datasource_example.tf.tmpl +++ b/gen/templates/datasource_example.tf.tmpl @@ -1,4 +1,9 @@ +{{- if not .MultiParentFormats }} {{- if .DocumentationExamples}}{{$parentIndex := 0}}{{- range $key := .DocumentationExamples}} +{{- $testType := $.TestType }} +{{- if eq $testType "cloud"}} +// This example is only applicable to Cisco Cloud Network Controller +{{- end}} data "aci_{{$.ResourceName}}" "example_{{getResourceName $key $.Definitions}}" { {{- if $.HasParent}} parent_dn = {{createParentDnValue $key "example" $.Definitions}} @@ -13,16 +18,44 @@ data "aci_{{$.ResourceName}}" "example_{{getResourceName $key $.Definitions}}" { {{- end}} {{- end}} {{- else}} - {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions}}"{{- end}}{{- end}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions $.Properties}}{{- end}}{{- end}} {{- end}} } {{ end}} {{- else}} +{{- $testType := $.TestType }} +{{- if eq $testType "cloud"}} +// This example is only applicable to Cisco Cloud Network Controller +{{- end}} data "aci_{{$.ResourceName}}" "example" { {{- range $.Properties}}{{- if .IsNaming}}{{- if ne .NamedPropertyClass ""}} {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = aci_{{getResourceName .NamedPropertyClass $.Definitions}}.example.name {{- else}} - {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions}}"{{- end}}{{- end}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions $.Properties}}{{- end}}{{- end}} {{- end}} } -{{ end}} \ No newline at end of file +{{ end}} +{{- else}} +{{- $topContext := . }} +{{- range $formatKey, $formatValue := $topContext.MultiParentFormats }} +{{- $testType := $formatValue.TestType }} +{{- if eq $testType "cloud"}} +// This example is only applicable to Cisco Cloud Network Controller +{{- end}} +data "aci_{{ $topContext.ResourceName }}" {{- if ne $formatValue.ContainedBy ""}}"example_{{ getResourceName $formatValue.ContainedBy $topContext.Definitions }}"{{- else}}"example"{{- end }} { +{{- if ne $formatValue.ContainedBy ""}} + parent_dn = {{createParentDnValue $formatValue.ContainedBy "example" $topContext.Definitions}} + {{- end }} + {{- range $topContext.Properties }} + {{- if .IsNaming }} + {{- if ne .NamedPropertyClass "" }} + {{ overwriteProperty .PkgName .SnakeCaseName $topContext.Definitions }} = aci_{{getResourceName .NamedPropertyClass $.Definitions}}.example.name + {{- else }} + {{ overwriteProperty .PkgName .SnakeCaseName $topContext.Definitions }} = {{ lookupTestValue .PkgName .SnakeCaseName $topContext.TestVars $topContext.Definitions $topContext.Properties}} + {{- end }} + {{- end }} + {{- end }} +} +{{- println }} +{{- end -}} +{{- end}} \ No newline at end of file diff --git a/gen/templates/datasource_test.go.tmpl b/gen/templates/datasource_test.go.tmpl index 3daec51a0..8ad774bd8 100644 --- a/gen/templates/datasource_test.go.tmpl +++ b/gen/templates/datasource_test.go.tmpl @@ -14,24 +14,43 @@ import ( {{- if .parents}} {{- range .parents}}{{$target_classes := .target_classes}} {{- $parentClassName := capitalize .class_name }} -func TestAccDataSource{{$.resourceClassName}}With{{capitalize .class_name}} (t *testing.T) { +func TestAccDataSource{{$.resourceClassName}}{{if .class_name}}With{{capitalize .class_name}}{{end}} (t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "{{.test_type}}", "{{$.class_version}}") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testConfig{{$.resourceClassName}}DataSourceDependencyWith{{capitalize .class_name}} , + Config: testConfig{{$.resourceClassName}}DataSource{{if .class_name}}DependencyWith{{capitalize .class_name}}{{end}}{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, ExpectNonEmptyPlan: {{.class_in_parent}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := $.datasource_required}} {{- if eq $key "target_dn" }} resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{getTestTargetDn $.targets $.resourceName $value false $target_classes 0 false}}"), {{- else }} + {{- if not (definedInList $.exclude_attributes $key) }} resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), {{- end }} {{- end}} + {{- end}} {{- range $key, $value := $.default}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t, "{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + {{- if not (definedInList $.exclude_attributes $attributeName) }} + {{- if (isInterfaceSlice $attributeValue)}} + resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}.#", "{{len $attributeValue}}"), + {{- range $index, $subvalue := $attributeValue}} + resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else}} + resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}} + {{- end}} + {{- end}}), + {{- end}} + {{- else}} + {{- if not (definedInList $.exclude_attributes $key) }} {{- if (isInterfaceSlice $value)}} resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.#", "{{len $value}}"), {{- range $index, $subvalue := $value}} @@ -40,6 +59,8 @@ func TestAccDataSource{{$.resourceClassName}}With{{capitalize .class_name}} (t * {{- else}} resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), {{- end}} + {{- end}} + {{- end}} {{- end}} {{- range $index, $key := $.read_only}} resource.TestCheckResourceAttrSet("data.aci_{{$.resourceName}}.test", "{{$key}}"), @@ -47,7 +68,7 @@ func TestAccDataSource{{$.resourceClassName}}With{{capitalize .class_name}} (t * ), }, { - Config: testConfig{{$.resourceClassName}}NotExisting{{capitalize .class_name}}, + Config: testConfig{{$.resourceClassName}}NotExisting{{if .class_name}}{{capitalize .class_name}}{{end}}{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, ExpectError: regexp.MustCompile("Failed to read aci_{{$.resourceName}} data source"), }, }, @@ -58,16 +79,35 @@ func TestAccDataSource{{$.resourceClassName}}With{{capitalize .class_name}} (t * func TestAccDataSource{{.resourceClassName}}(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "{{.test_type}}", "{{.class_version}}") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testConfig{{.resourceClassName}}DataSource, + Config: testConfig{{.resourceClassName}}DataSource{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := .min}} + {{- if not (definedInList $.exclude_attributes $key) }} resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"), {{- end}} + {{- end}} {{- range $key, $value := .all}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t, "{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + {{- if not (definedInList $.exclude_attributes $attributeName) }} + {{- if (isInterfaceSlice $attributeValue)}} + resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test", "{{$attributeName}}.#", "{{len $attributeValue}}"), + {{- range $index, $subvalue := $attributeValue}} + resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else}} + resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}} + {{- end}} + {{- end }}), + {{- end }} + {{- else }} + {{- if not (definedInList $.exclude_attributes $key) }} {{- if (isInterfaceSlice $value)}} resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test", "{{$key}}.#", "{{len $value}}"), {{- range $index, $subvalue := $value}} @@ -77,10 +117,12 @@ func TestAccDataSource{{.resourceClassName}}(t *testing.T) { resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"), {{- end}} {{- end}} + {{- end}} + {{- end}} ), }, { - Config: testConfig{{.resourceClassName}}NotExisting, + Config: testConfig{{.resourceClassName}}NotExisting{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, ExpectError: regexp.MustCompile("Failed to read aci_{{$.resourceName}} data source"), }, }, @@ -91,9 +133,11 @@ func TestAccDataSource{{.resourceClassName}}(t *testing.T) { {{- if .parents}} {{- range .parents}}{{$target_classes := .target_classes}} {{- $parentClassName := capitalize .class_name }} -const testConfig{{$.resourceClassName}}DataSourceDependencyWith{{capitalize .class_name}} = testConfig{{$.resourceClassName}}MinDependencyWith{{capitalize .class_name}} + ` +const testConfig{{$.resourceClassName}}DataSource{{if .class_name}}DependencyWith{{capitalize .class_name}}{{end}} = testConfig{{$.resourceClassName}}Min{{if .class_name}}DependencyWith{{capitalize .class_name}}{{end}} + ` data "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}" { + {{- if ne .parent_dn ""}} parent_dn = {{.parent_dn}} + {{- end}} {{- range $key, $value := $.datasource_required}} {{- if eq $key "target_dn" }}{{$attributeValue := getTestTargetDn $.targets $.resourceName $value true $target_classes 0 false}} {{$key}} = {{if containsString $attributeValue "."}}{{$attributeValue}}{{else}}"{{$attributeValue}}"{{end}} @@ -105,9 +149,11 @@ data "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClassNam } ` -const testConfig{{$.resourceClassName}}NotExisting{{capitalize .class_name}} = testConfig{{capitalize .class_name}}Min{{- if ne .parent_dependency ""}}DependencyWith{{capitalize .parent_dependency}}{{if and (ne .parent_dependency_name nil) (ne .parent_dependency_name "")}}{{capitalize .parent_dependency_name }}{{- end }}{{- end}} + ` +const testConfig{{$.resourceClassName}}NotExisting{{if .class_name}}{{capitalize .class_name}}{{end}} = testConfig{{if .class_name}}{{capitalize .class_name}}{{else}}{{$.resourceClassName}}{{end}}Min{{- if ne .parent_dependency ""}}DependencyWith{{capitalize .parent_dependency}}{{if and (ne .parent_dependency_name nil) (ne .parent_dependency_name "")}}{{capitalize .parent_dependency_name }}{{- end }}{{- end}} + ` data "aci_{{$.resourceName}}" "test_non_existing" { + {{- if ne .parent_dn ""}} parent_dn = {{.parent_dn}} + {{- end}} {{- range $key, $value := $.datasource_non_existing}} {{- if and (eq $key "target_dn") (not (hasPrefix $value "topology/")) }} {{$key}} = "{{getTestTargetDn $.targets $.resourceName $value false $target_classes 0 false}}_not_existing" diff --git a/gen/templates/provider.go.tmpl b/gen/templates/provider.go.tmpl index dcd61f26a..b612c0371 100644 --- a/gen/templates/provider.go.tmpl +++ b/gen/templates/provider.go.tmpl @@ -24,6 +24,7 @@ import ( // "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-framework/function" ) var globalAnnotation string @@ -31,6 +32,7 @@ var globalAllowExistingOnCreate bool // Ensure AciProvider satisfies various provider interfaces. var _ provider.Provider = &AciProvider{} +var _ provider.ProviderWithFunctions = &AciProvider{} // AciProvider defines the provider implementation. type AciProvider struct { @@ -346,3 +348,9 @@ func stringToInt(resp *provider.ConfigureResponse, attributeName, stringValue st } return intValue } + +func (p *AciProvider) Functions(ctx context.Context) []func() function.Function { + return []func() function.Function{ + NewCompareVersionsFunction, + } +} diff --git a/gen/templates/resource.go.tmpl b/gen/templates/resource.go.tmpl index 778444608..6cc0a25ad 100644 --- a/gen/templates/resource.go.tmpl +++ b/gen/templates/resource.go.tmpl @@ -83,7 +83,7 @@ type {{.ResourceClassName}}ResourceModel struct { func getEmpty{{.ResourceClassName}}ResourceModel() *{{.ResourceClassName}}ResourceModel { return &{{.ResourceClassName}}ResourceModel{ Id: basetypes.NewStringNull(), - {{- if .HasParent}} + {{- if .HasParent }} ParentDn: basetypes.NewStringNull(), {{- end}} {{- range .Properties}} @@ -1208,10 +1208,16 @@ func (r *{{.ResourceClassName}}Resource) Schema(ctx context.Context, req resourc {{- if not .ReadOnly }} Optional: true, {{- end }} + {{- if ne .ValueType "password"}} Computed: true, + {{- else}} + Sensitive: true, + {{- end}} {{- if not .ReadOnly }} PlanModifiers: []planmodifier.Set{ setplanmodifier.UseStateForUnknown(), + SetToSetNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, {{- end}} {{- if .ValidValues}} @@ -1242,7 +1248,11 @@ func (r *{{.ResourceClassName}}Resource) Schema(ctx context.Context, req resourc {{- if not .ReadOnly }} Optional: true, {{- end }} + {{- if ne .ValueType "password"}} Computed: true, + {{- else}} + Sensitive: true, + {{- end}} {{- end}} {{- if not .ReadOnly }} PlanModifiers: []planmodifier.String{ @@ -1359,7 +1369,11 @@ func (r *{{.ResourceClassName}}Resource) Schema(ctx context.Context, req resourc {{- if not .ReadOnly }} Optional: true, {{- end }} + {{- if ne .ValueType "password"}} Computed: true, + {{- else}} + Sensitive: true, + {{- end}} {{- if not .ReadOnly }} PlanModifiers: []planmodifier.Set{ setplanmodifier.UseStateForUnknown(), @@ -1384,7 +1398,11 @@ func (r *{{.ResourceClassName}}Resource) Schema(ctx context.Context, req resourc Required: true, {{- else }} Optional: true, + {{- if ne .ValueType "password"}} Computed: true, + {{- else}} + Sensitive: true, + {{- end}} {{- end}} {{- if not .ReadOnly }} PlanModifiers: []planmodifier.String{ @@ -1497,9 +1515,9 @@ func (r *{{.ResourceClassName}}Resource) Configure(ctx context.Context, req reso func (r *{{.ResourceClassName}}Resource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { tflog.Debug(ctx, "Start create of resource: aci_{{.ResourceName}}") - {{- if .HasChild}} + {{- if .HasChild }} // On create retrieve information on current state prior to making any changes in order to determine child delete operations - var stateData *{{.ResourceClassName}}ResourceModel + var stateData *{{ .ResourceClassName }}ResourceModel resp.Diagnostics.Append(req.Plan.Get(ctx, &stateData)...) if stateData.Id.IsUnknown() || stateData.Id.IsNull() { set{{.ResourceClassName}}Id(ctx, stateData) @@ -1514,7 +1532,7 @@ func (r *{{.ResourceClassName}}Resource) Create(ctx context.Context, req resourc } {{- end}} - var data *{{.ResourceClassName}}ResourceModel + var data *{{ .ResourceClassName }}ResourceModel // Read Terraform plan data into the model resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -1529,6 +1547,7 @@ func (r *{{.ResourceClassName}}Resource) Create(ctx context.Context, req resourc tflog.Debug(ctx, fmt.Sprintf("Create of resource aci_{{.ResourceName}} with id '%s'", data.Id.ValueString())) + {{ if not .MultiParentFormats }} {{ if .HasChild}} {{- range .Children}} {{- if or (not .IdentifiedBy) .MaxOneClassAllowed}} @@ -1551,10 +1570,38 @@ func (r *{{.ResourceClassName}}Resource) Create(ctx context.Context, req resourc } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + {{- else }} + {{- if .HasChild }} + {{- range .Children }} + var {{ .PkgName }}Plan, {{ .PkgName }}State []{{ .ResourceClassName }}{{ $.ResourceClassName }}ResourceModel + data.{{ .ResourceClassName }}.ElementsAs(ctx, &{{ .PkgName }}Plan, false) + stateData.{{ .ResourceClassName }}.ElementsAs(ctx, &{{ .PkgName }}State, false) + {{- end }} + jsonPayload := get{{ .ResourceClassName }}CreateJsonPayload(ctx, &resp.Diagnostics, true, data{{- range .Children }}, {{ .PkgName }}Plan, {{ .PkgName }}State{{- end }}) + {{- else }} + jsonPayload := get{{ .ResourceClassName }}CreateJsonPayload(ctx, &resp.Diagnostics, true, data) + {{- end }} + if resp.Diagnostics.HasError() { return } - + + wrapperClassMap := map[string]string{ {{- range $key, $value := .MultiParentFormats }} "{{ $value.RnPrepend }}": "{{ $value.WrapperClass }}", {{- end }} } + for rnPrepend, wrapperClass := range wrapperClassMap { + if strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass != "" { + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s%s.json", strings.Split(data.Id.ValueString(), rnPrepend)[0], rnPrepend), "POST", jsonPayload) + break + } else if strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass == "" { + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + break + } + } + {{- end }} + + if resp.Diagnostics.HasError() { + return + } + getAndSet{{.ResourceClassName}}Attributes(ctx, &resp.Diagnostics, r.client, data) // Save data into Terraform state @@ -1591,9 +1638,9 @@ func (r *{{.ResourceClassName}}Resource) Read(ctx context.Context, req resource. func (r *{{.ResourceClassName}}Resource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { tflog.Debug(ctx, "Start update of resource: aci_{{.ResourceName}}") var data *{{.ResourceClassName}}ResourceModel - {{- if .HasChild}} - var stateData *{{.ResourceClassName}}ResourceModel - {{- end}} + {{- if .HasChild }} + var stateData *{{ .ResourceClassName }}ResourceModel + {{- end }} // Read Terraform plan data into the model resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -1612,12 +1659,13 @@ func (r *{{.ResourceClassName}}Resource) Update(ctx context.Context, req resourc {{- end}} {{- end}} - if resp.Diagnostics.HasError() { - return - } +if resp.Diagnostics.HasError() { + return +} - tflog.Debug(ctx, fmt.Sprintf("Update of resource aci_{{.ResourceName}} with id '%s'", data.Id.ValueString())) - +tflog.Debug(ctx, fmt.Sprintf("Update of resource aci_{{ .ResourceName }} with id '%s'", data.Id.ValueString())) + +{{ if not .MultiParentFormats }} {{ if .HasChild}} {{- range .Children}} {{- if or (not .IdentifiedBy) .MaxOneClassAllowed}} @@ -1640,7 +1688,38 @@ func (r *{{.ResourceClassName}}Resource) Update(ctx context.Context, req resourc } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) - +{{- else }} + {{- if .HasChild }} + {{- range .Children }} + var {{ .PkgName }}Plan, {{ .PkgName }}State []{{ .ResourceClassName }}{{ $.ResourceClassName }}ResourceModel + data.{{ .ResourceClassName }}.ElementsAs(ctx, &{{ .PkgName }}Plan, false) + stateData.{{ .ResourceClassName }}.ElementsAs(ctx, &{{ .PkgName }}State, false) + {{- end }} + jsonPayload := get{{ .ResourceClassName }}CreateJsonPayload(ctx, &resp.Diagnostics, false, data{{- range .Children }}, {{ .PkgName }}Plan, {{ .PkgName }}State{{- end }}) + {{- else }} + jsonPayload := get{{ .ResourceClassName }}CreateJsonPayload(ctx, &resp.Diagnostics, false, data) + {{- end }} + + if resp.Diagnostics.HasError() { + return + } + + wrapperClassMap := map[string]string{ + {{- range $key, $value := .MultiParentFormats }} + "{{ $value.RnPrepend }}": "{{ $value.WrapperClass }}", + {{- end }} + } + for rnPrepend, wrapperClass := range wrapperClassMap { + if strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass != "" { + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s%s.json", strings.Split(data.Id.ValueString(), rnPrepend)[0], rnPrepend), "POST", jsonPayload) + break + } else if strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass == "" { + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + break + } + } +{{- end }} + if resp.Diagnostics.HasError() { return } @@ -1707,7 +1786,7 @@ func getAndSet{{.ResourceClassName}}Attributes(ctx context.Context, diags *diag. requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "GET", nil) {{- end}} - *data = *getEmpty{{.ResourceClassName}}ResourceModel() + readData := getEmpty{{.ResourceClassName}}ResourceModel() if diags.HasError() { return @@ -1718,9 +1797,9 @@ func getAndSet{{.ResourceClassName}}Attributes(ctx context.Context, diags *diag. attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) {{- if .HasParent}} - set{{.ResourceClassName}}ParentDn(ctx, attributeValue.(string), data) + set{{.ResourceClassName}}ParentDn(ctx, attributeValue.(string), readData) {{- end}} } {{- range .Properties}} @@ -1730,29 +1809,32 @@ func getAndSet{{.ResourceClassName}}Attributes(ctx context.Context, diags *diag. if attributeValue.(string) != "" { {{.PropertyName}}List = strings.Split(attributeValue.(string), ",") } - {{.PropertyName}}Set, _ := types.SetValueFrom(ctx, data.{{.Name}}.ElementType(ctx), {{.PropertyName}}List) - data.{{.Name}} = {{.PropertyName}}Set + {{.PropertyName}}Set, _ := types.SetValueFrom(ctx, readData.{{.Name}}.ElementType(ctx), {{.PropertyName}}List) + readData.{{.Name}} = {{.PropertyName}}Set } + {{- else if eq .ValueType "password"}} + // Sensitive attributes are not returned by the APIC, so they are explicitly set to their current state values. + readData.{{.Name}} = data.{{.Name}} {{- else}} {{- if containsNoneAttributeValue .ValidValues}} if attributeName == "{{.PropertyName}}" && attributeValue.(string) == "" { - data.{{.Name}} = basetypes.NewStringValue("none") + readData.{{.Name}} = basetypes.NewStringValue("none") } else if attributeName == "{{.PropertyName}}" { - data.{{.Name}} = basetypes.NewStringValue(attributeValue.(string)) + readData.{{.Name}} = basetypes.NewStringValue(attributeValue.(string)) } {{- else}} if attributeName == "{{.PropertyName}}" { {{- if .HasCustomType}} - data.{{.Name}} = customTypes.New{{.ResourceClassName}}{{.Name}}StringValue(attributeValue.(string)) + readData.{{.Name}} = customTypes.New{{.ResourceClassName}}{{.Name}}StringValue(attributeValue.(string)) {{- else}} - data.{{- if eq .Name "Id"}}{{.ResourceClassName}}{{ .Name }}{{- else}}{{.Name}}{{- end}} = basetypes.NewStringValue(attributeValue.(string)) + readData.{{- if eq .Name "Id"}}{{.ResourceClassName}}{{ .Name }}{{- else}}{{.Name}}{{- end}} = basetypes.NewStringValue(attributeValue.(string)) {{- end}} } {{- end}} {{- end}} {{- end}} } - + {{- if .HasChild}} {{- range .Children}} {{ .ResourceClassName }}{{$.ResourceClassName}}List := make([]{{.ResourceClassName}}{{$.ResourceClassName}}ResourceModel, 0) @@ -1814,19 +1896,19 @@ func getAndSet{{.ResourceClassName}}Attributes(ctx context.Context, diags *diag. {{- if or (not .IdentifiedBy) .MaxOneClassAllowed}} if len({{.ResourceClassName}}{{$.ResourceClassName}}List) == 1 { {{ .PkgName }}Object, _ := types.ObjectValueFrom(ctx, {{ .ResourceClassName }}{{$.ResourceClassName}}Type, {{ .ResourceClassName }}{{$.ResourceClassName}}List[0]) - data.{{ .ResourceClassName }} = {{ .PkgName }}Object + readData.{{ .ResourceClassName }} = {{ .PkgName }}Object } else { {{ .PkgName }}Object, _ := types.ObjectValueFrom(ctx, {{ .ResourceClassName }}{{$.ResourceClassName}}Type, getEmpty{{ .ResourceClassName }}{{$.ResourceClassName}}ResourceModel()) - data.{{ .ResourceClassName }} = {{ .PkgName }}Object + readData.{{ .ResourceClassName }} = {{ .PkgName }}Object } {{- else}} - {{ .PkgName }}Set, _ := types.SetValueFrom(ctx, data.{{ .ResourceClassName }}.ElementType(ctx), {{ .ResourceClassName }}{{$.ResourceClassName}}List) - data.{{ .ResourceClassName }} = {{ .PkgName }}Set + {{ .PkgName }}Set, _ := types.SetValueFrom(ctx, readData.{{ .ResourceClassName }}.ElementType(ctx), {{ .ResourceClassName }}{{$.ResourceClassName}}List) + readData.{{ .ResourceClassName }} = {{ .PkgName }}Set {{- end}} {{- end}} {{- end}} {{- if .LegacyAttributes}} - set{{ .ResourceClassName }}LegacyAttributes(ctx, diags, data, classReadInfo) + set{{ .ResourceClassName }}LegacyAttributes(ctx, diags, readData, classReadInfo) {{- end}} } else { diags.AddError( @@ -1835,8 +1917,9 @@ func getAndSet{{.ResourceClassName}}Attributes(ctx context.Context, diags *diag. ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func get{{.ResourceClassName}}Rn(ctx context.Context, data *{{.ResourceClassName}}ResourceModel) string { @@ -1867,7 +1950,23 @@ func set{{.ResourceClassName}}ParentDn(ctx context.Context, dn string, data *{{. break } } - {{- if eq .RnPrepend ""}} + {{- if .MultiParentFormats }} + parentDn := dn[:rnIndex] + rnMap := map[string]string{ + {{- range $key, $value := .MultiParentFormats }} + {{- if ne $key "default" }} + "{{ $key }}": "{{ $value.RnPrepend }}", + {{- end }} + {{- end }} + } + for parentIdentifier, rnPrepend := range rnMap { + if strings.Contains(parentDn, parentIdentifier) { + parentDn = parentDn[:strings.Index(parentDn, fmt.Sprintf("/%s", rnPrepend))] + break + } + } + data.ParentDn = basetypes.NewStringValue(parentDn) + {{- else if eq .RnPrepend ""}} data.ParentDn = basetypes.NewStringValue(dn[:rnIndex]) {{- else}} parentDn := dn[:rnIndex] @@ -1879,10 +1978,29 @@ func set{{.ResourceClassName}}ParentDn(ctx context.Context, dn string, data *{{. func set{{.ResourceClassName}}Id(ctx context.Context, data *{{.ResourceClassName}}ResourceModel) { rn := get{{.ResourceClassName}}Rn(ctx, data) - {{- if .HasParent}} + {{- if .MultiParentFormats }} + parentDn := data.ParentDn.ValueString() + rnMap := map[string]string{ + {{- range $key, $value := .MultiParentFormats }} + {{- if ne $key "default" }} + "{{ $key }}": "{{ $value.RnPrepend }}", + {{- end }} + {{- end }} + } + id := fmt.Sprintf("%s/%s", parentDn, rn) + for parentIdentifier, rnPrepend := range rnMap { + if strings.Contains(parentDn, parentIdentifier) { + id = fmt.Sprintf("%s/%s/%s", parentDn, rnPrepend, rn) + break + } + } + data.Id = types.StringValue(id) + {{- else }} + {{- if .HasParent}} data.Id = types.StringValue(fmt.Sprintf("%s/%s", data.ParentDn.ValueString(), rn)) - {{- else}} + {{- else}} data.Id = types.StringValue(fmt.Sprintf("%s/%s", strings.Split([]string{ {{- fromInterfacesToString .DnFormats}} }[0], "/")[0], rn)) + {{- end}} {{- end}} } @@ -2047,8 +2165,33 @@ func get{{.ResourceClassName}}CreateJsonPayload(ctx context.Context, diags *diag } {{- end}} {{- end}}{{- end}} - + {{- if .MultiParentFormats }} + wrapperClassMap := map[string]string{ + {{- range $key, $value := .MultiParentFormats }} + "{{ $value.RnPrepend }}": "{{ $value.WrapperClass }}", + {{- end }} + } + + var payload []byte + var err error + for rnPrepend, wrapperClass := range wrapperClassMap { + if strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass != "" && createType { + wrapperPayloadMap := map[string]interface{}{ + wrapperClass: map[string]interface{}{ + "attributes": map[string]interface{}{}, + "children": []interface{}{map[string]interface{}{"{{ .PkgName }}": payloadMap}}, + }, + } + payload, err = json.Marshal(wrapperPayloadMap) + break + } else if (strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass == "") || !createType { + payload, err = json.Marshal(map[string]interface{}{"{{ .PkgName }}": payloadMap}) + break + } + } + {{- else }} payload, err := json.Marshal(map[string]interface{}{"{{.PkgName}}": payloadMap}) + {{- end}} if err != nil { diags.AddError( "Marshalling of json payload failed", diff --git a/gen/templates/resource_example.tf.tmpl b/gen/templates/resource_example.tf.tmpl index 5d28a8350..fea9a75fc 100644 --- a/gen/templates/resource_example.tf.tmpl +++ b/gen/templates/resource_example.tf.tmpl @@ -1,4 +1,9 @@ +{{- if not .MultiParentFormats }} {{- if .DocumentationExamples}}{{$parentIndex := 0}}{{- range $key := .DocumentationExamples}} +{{- $testType := $.TestType }} +{{- if eq $testType "cloud"}} +// This example is only applicable to Cisco Cloud Network Controller +{{- end}} resource "aci_{{$.ResourceName}}" "example_{{getResourceName $key $.Definitions}}" { {{- if $.HasParent}} parent_dn = {{createParentDnValue $key "example" $.Definitions}} @@ -13,16 +18,44 @@ resource "aci_{{$.ResourceName}}" "example_{{getResourceName $key $.Definitions} {{- end}} {{- end}} {{- else}} - {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions}}"{{- end}}{{- end}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions $.Properties}}{{- end}}{{- end}} {{- end}} } {{ end}} {{- else}} +{{- $testType := $.TestType }} +{{- if eq $testType "cloud"}} +// This example is only applicable to Cisco Cloud Network Controller +{{- end}} resource "aci_{{$.ResourceName}}" "example" { {{- range $.Properties}}{{- if .IsRequired}}{{- if ne .NamedPropertyClass ""}} {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = aci_{{getResourceName .NamedPropertyClass $.Definitions}}.example.name {{- else}} - {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions}}"{{- end}}{{- end}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions $.Properties}}{{- end}}{{- end}} {{- end}} } -{{ end}} \ No newline at end of file +{{ end}} +{{- else }} +{{- $topContext := . }} +{{- range $formatKey, $formatValue := $topContext.MultiParentFormats }} +{{- $testType := $formatValue.TestType }} +{{- if eq $testType "cloud"}} +// This example is only applicable to Cisco Cloud Network Controller +{{- end}} +resource "aci_{{$topContext.ResourceName}}" {{- if ne $formatValue.ContainedBy ""}} "example_{{ getResourceName $formatValue.ContainedBy $topContext.Definitions }}" {{- else}} "example" {{- end }} { +{{- if ne $formatValue.ContainedBy ""}} + parent_dn = {{ createParentDnValue $formatValue.ContainedBy "example" $topContext.Definitions }} +{{- end }} +{{- range $topContext.Properties }} +{{- if .IsRequired }} +{{- if ne .NamedPropertyClass ""}} + {{ overwriteProperty .PkgName .SnakeCaseName $.Definitions }} = aci_{{ getResourceName .NamedPropertyClass $.Definitions }}.example.name +{{- else }} + {{ overwriteProperty .PkgName .SnakeCaseName $.Definitions }} = {{ lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions $topContext.Properties}} +{{- end }} +{{- end }} +{{- end }} +} +{{- println }} +{{- end }} +{{- end}} \ No newline at end of file diff --git a/gen/templates/resource_example_all_attributes.tf.tmpl b/gen/templates/resource_example_all_attributes.tf.tmpl index f7b497740..9535bd7d9 100644 --- a/gen/templates/resource_example_all_attributes.tf.tmpl +++ b/gen/templates/resource_example_all_attributes.tf.tmpl @@ -1,4 +1,9 @@ +{{- if not .MultiParentFormats }} {{- if .DocumentationExamples}}{{$parentIndex := 0}}{{- range $key := .DocumentationExamples}} +{{- $testType := $.TestType }} +{{- if eq $testType "cloud"}} +// This example is only applicable to Cisco Cloud Network Controller +{{- end}} resource "aci_{{$.ResourceName}}" "full_example_{{getResourceName $key $.Definitions}}" { {{- if $.HasParent}} parent_dn = {{createParentDnValue $key "example" $.Definitions}} @@ -14,10 +19,10 @@ resource "aci_{{$.ResourceName}}" "full_example_{{getResourceName $key $.Definit {{- end}} {{- else if .IgnoreInTest}} {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{.IgnoreInTestExampleValue}}" - {{- else if eq .ValueType "bitmask"}}{{ $bitmaskTestValue := lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions}} + {{- else if eq .ValueType "bitmask"}}{{ $bitmaskTestValue := lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions $.Properties}} {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = [{{range $index, $value := $bitmaskTestValue}}{{if lt $index (subtract (len $bitmaskTestValue) 1)}}"{{$value}}",{{else}}"{{$value}}"{{end}}{{end}}] {{- else}} - {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions}}" + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions $.Properties}} {{- end}}{{- end}}{{- end}} {{- range $key, $value := $.Children}}{{$ChildResourceName := overwriteProperty .PkgName .ResourceName $.Definitions}} {{- if or (not .IdentifiedBy) .MaxOneClassAllowed}} @@ -54,15 +59,19 @@ resource "aci_{{$.ResourceName}}" "full_example_{{getResourceName $key $.Definit } {{ end}} {{- else}} +{{- $testType := $.TestType }} +{{- if eq $testType "cloud"}} +// This example is only applicable to Cisco Cloud Network Controller +{{- end}} resource "aci_{{$.ResourceName}}" "full_example" { {{- range $.Properties}}{{- if not .ReadOnly }}{{- if ne .NamedPropertyClass ""}} {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = aci_{{getResourceName .NamedPropertyClass $.Definitions}}.example.name {{- else if eq .SnakeCaseName "t_dn" }} - {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions | replace ".test_0.id" ".example.id"}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions $.Properties | replace ".test_0.id" ".example.id"}} {{- else if .IgnoreInTest}} {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{.IgnoreInTestExampleValue}}" {{- else}} - {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions}}" + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions $.Properties}} {{- end}}{{- end}}{{- end}} {{- range $key, $value := $.Children}}{{$ChildResourceName := overwriteProperty .PkgName .ResourceName $.Definitions}} {{- if or (not .IdentifiedBy) .MaxOneClassAllowed}} @@ -91,4 +100,35 @@ resource "aci_{{$.ResourceName}}" "full_example" { {{- end}} {{- end}} } -{{ end}} \ No newline at end of file +{{ end}} +{{- else -}} +{{- $topContext := . }} +{{- range $formatKey, $formatValue := $topContext.MultiParentFormats }} +{{- $testType := $formatValue.TestType }} +{{- if eq $testType "cloud"}} +// This example is only applicable to Cisco Cloud Network Controller +{{- end}} +resource "aci_{{$topContext.ResourceName}}" {{- if ne $formatValue.ContainedBy ""}}"full_example_{{ getResourceName $formatValue.ContainedBy $topContext.Definitions }}"{{- else}}"full_example"{{- end }} { + {{- if ne $formatValue.ContainedBy ""}} + parent_dn = {{createParentDnValue $formatValue.ContainedBy "example" $topContext.Definitions}} + {{- end }} + {{- range $topContext.Properties }} + {{- if ne .NamedPropertyClass ""}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = aci_{{getResourceName .NamedPropertyClass $.Definitions}}.example.name + {{- else}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions $.Properties}} + {{- end }} + {{- end }} + {{- range $key, $value := $.Children}}{{$ChildResourceName := .ResourceName}} + {{$ChildResourceName}} = [ + { {{- range .Properties}}{{- if ne .NamedPropertyClass ""}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = aci_{{getResourceName .NamedPropertyClass $.Definitions}}.example.name + {{- else}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{lookupChildTestValue .PkgName $ChildResourceName .SnakeCaseName $.TestVars 0 $.Definitions}}"{{- end}}{{ end}} + } + ] + {{- end}} +} +{{- println }} +{{- end -}} +{{- end}} \ No newline at end of file diff --git a/gen/templates/resource_test.go.tmpl b/gen/templates/resource_test.go.tmpl index 9ecdb17ea..a47215289 100644 --- a/gen/templates/resource_test.go.tmpl +++ b/gen/templates/resource_test.go.tmpl @@ -22,15 +22,15 @@ import ( {{- if .parents}} {{- range .parents}}{{$target_classes := .target_classes}} {{- $parentClassName := capitalize .class_name }} -func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *testing.T) { +func TestAccResource{{$.resourceClassName}}{{if .class_name}}With{{capitalize .class_name}}{{end}}(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, +PreCheck: func() { testAccPreCheck(t, "{{.test_type}}", "{{$.class_version}}") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfig{{$.resourceClassName}}MinDependencyWith{{capitalize .class_name}}AllowExisting, + Config: testConfig{{$.resourceClassName}}Min{{if .class_name}}DependencyWith{{capitalize .class_name}}{{end}}AllowExisting{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, ExpectNonEmptyPlan: {{.class_in_parent}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := $.resource_required}}{{$contains := definedInMap $key $.default}} @@ -39,23 +39,47 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test", "{{$key}}", "{{getTestTargetDn $.targets $.resourceName $value false $target_classes 0 false}}"), resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test_2", "{{$key}}", "{{getTestTargetDn $.targets $.resourceName $value false $target_classes 0 false}}"), {{- else }} + {{- if not (definedInList $.exclude_attributes $key) }} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test", "{{$key}}", "{{$value}}"), resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test_2", "{{$key}}", "{{$value}}"), + {{- end }} {{- end }} {{- end}} {{- end}} {{- range $key, $value := $.default}} - {{- if (isInterfaceSlice $value)}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + {{- if not (definedInList $.exclude_attributes $attributeName) }} + {{- if (isInterfaceSlice $attributeValue)}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test", "{{$attributeName}}.#", "{{len $attributeValue}}"), + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test_2", "{{$attributeName}}.#", "{{len $attributeValue}}"), + {{- range $index, $subvalue := $attributeValue}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test_2", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test", "{{$attributeName}}", "{{$attributeValue}}"), + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test_2", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}} + {{- end }} + {{- end }}), + {{- end }} + {{- else}} + {{- if not (definedInList $.exclude_attributes $key) }} + {{- if (isInterfaceSlice $value)}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test", "{{$key}}.#", "{{len $value}}"), resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test_2", "{{$key}}.#", "{{len $value}}"), - {{- range $index, $subvalue := $value}} + {{- range $index, $subvalue := $value}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test", "{{$key}}.{{$index}}", "{{$subvalue}}"), resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test_2", "{{$key}}.{{$index}}", "{{$subvalue}}"), - {{- end}} - {{- else}} + {{- end}} + {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test", "{{$key}}", "{{$value}}"), resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test_2", "{{$key}}", "{{$value}}"), - {{- end}} + {{- end}} + {{- end }} + {{- end }} {{- end}} {{- range $index, $key := $.read_only}} resource.TestCheckResourceAttrSet("aci_{{$.resourceName}}.allow_test", "{{$key}}"), @@ -67,12 +91,12 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "{{.test_type}}", "{{$.class_version}}") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfig{{$.resourceClassName}}MinDependencyWith{{capitalize .class_name}}AllowExisting, + Config: testConfig{{$.resourceClassName}}Min{{if .class_name}}DependencyWith{{capitalize .class_name}}{{end}}AllowExisting{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, ExpectError: regexp.MustCompile("Object Already Exists"), }, }, @@ -80,12 +104,12 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "{{.test_type}}", "{{$.class_version}}") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfig{{$.resourceClassName}}MinDependencyWith{{capitalize .class_name}}AllowExisting, + Config: testConfig{{$.resourceClassName}}Min{{if .class_name}}DependencyWith{{capitalize .class_name}}{{end}}AllowExisting{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, ExpectNonEmptyPlan: {{.class_in_parent}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := $.resource_required}}{{$contains := definedInMap $key $.default}} @@ -94,13 +118,35 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test", "{{$key}}", "{{getTestTargetDn $.targets $.resourceName $value false $target_classes 0 false}}"), resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test_2", "{{$key}}", "{{getTestTargetDn $.targets $.resourceName $value false $target_classes 0 false}}"), {{- else }} + {{- if not (definedInList $.exclude_attributes $key) }} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test", "{{$key}}", "{{$value}}"), resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test_2", "{{$key}}", "{{$value}}"), + {{- end }} {{- end }} {{- end}} {{- end}} {{- range $key, $value := $.default}} - {{- if (isInterfaceSlice $value)}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + {{- if not (definedInList $.exclude_attributes $attributeName) }} + {{- if (isInterfaceSlice $attributeValue)}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test", "{{$attributeName}}.#", "{{len $attributeValue}}"), + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test_2", "{{$attributeName}}.#", "{{len $attributeValue}}"), + {{- range $index, $subvalue := $attributeValue}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test_2", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test", "{{$attributeName}}", "{{$attributeValue}}"), + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test_2", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}} + {{- end }} + {{- end }}), + {{- end }} + {{- else}} + {{- if not (definedInList $.exclude_attributes $key) }} + {{- if (isInterfaceSlice $value)}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test", "{{$key}}.#", "{{len $value}}"), resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test_2", "{{$key}}.#", "{{len $value}}"), {{- range $index, $subvalue := $value}} @@ -110,7 +156,9 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test", "{{$key}}", "{{$value}}"), resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test_2", "{{$key}}", "{{$value}}"), - {{- end}} + {{- end}} + {{- end}} + {{- end }} {{- end}} {{- range $index, $key := $.read_only}} resource.TestCheckResourceAttrSet("aci_{{$.resourceName}}.allow_test", "{{$key}}"), @@ -122,12 +170,12 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "{{.test_type}}", "{{$.class_version}}") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfig{{$.resourceClassName}}MinDependencyWith{{capitalize .class_name}}, + Config: testConfig{{$.resourceClassName}}Min{{if .class_name}}DependencyWith{{capitalize .class_name}}{{end}}{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, ExpectNonEmptyPlan: {{.class_in_parent}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := $.resource_required}}{{$contains := definedInMap $key $.default}} @@ -135,12 +183,31 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes {{- if eq $key "target_dn" }} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{getTestTargetDn $.targets $.resourceName $value false $target_classes 0 false}}"), {{- else }} + {{- if not (definedInList $.exclude_attributes $key) }} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), {{- end }} {{- end}} + {{- end}} {{- end}} {{- range $key, $value := $.default}} - {{- if (isInterfaceSlice $value)}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + {{- if not (definedInList $.exclude_attributes $attributeName) }} + {{- if (isInterfaceSlice $attributeValue)}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}.#", "{{len $attributeValue}}"), + {{- range $index, $subvalue := $attributeValue}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}} + {{- end}} + {{- end}}), + {{- end}} + {{- else}} + {{- if not (definedInList $.exclude_attributes $key) }} + {{- if (isInterfaceSlice $value)}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.#", "{{len $value}}"), {{- range $index, $subvalue := $value}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.{{$index}}", "{{$subvalue}}"), @@ -148,6 +215,8 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), {{- end}} + {{- end}} + {{- end}} {{- end}} {{- range $index, $key := $.read_only}} resource.TestCheckResourceAttrSet("aci_{{$.resourceName}}.test", "{{$key}}"), @@ -156,7 +225,7 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes }, // Update with all config and verify default APIC values { - Config: testConfig{{$.resourceClassName}}AllDependencyWith{{capitalize .class_name}}, + Config: testConfig{{$.resourceClassName}}All{{ if .class_name}}DependencyWith{{capitalize .class_name}}{{end}}{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, ExpectNonEmptyPlan: {{.class_in_parent}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := $.resource_required}}{{$contains := definedInMap $key $.all}} @@ -164,11 +233,30 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes {{- if eq $key "target_dn" }} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{getTestTargetDn $.targets $.resourceName $value false $target_classes 0 false}}"), {{- else }} - resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), - {{- end }} + {{- if not (definedInList $.exclude_attributes $key) }} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), + {{- end }} + {{- end}} {{- end}} {{- end}} {{- range $key, $value := $.all}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + {{- if not (definedInList $.exclude_attributes $attributeName) }} + {{- if (isInterfaceSlice $attributeValue)}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}.#", "{{len $attributeValue}}"), + {{- range $index, $subvalue := $attributeValue}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}} + {{- end}} + {{- end }}), + {{- end }} + {{- else }} + {{- if not (definedInList $.exclude_attributes $key) }} {{- if (isInterfaceSlice $value)}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.#", "{{len $value}}"), {{- range $index, $subvalue := $value}} @@ -176,7 +264,9 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes {{- end}} {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), + {{- end}} {{- end}} + {{- end}} {{- end}} {{- range $index, $key := $.read_only}} resource.TestCheckResourceAttrSet("aci_{{$.resourceName}}.test", "{{$key}}"), @@ -185,14 +275,16 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes }, // Update with minimum config and verify config is unchanged { - Config: testConfig{{$.resourceClassName}}MinDependencyWith{{capitalize .class_name}}, + Config: testConfig{{$.resourceClassName}}Min{{if .class_name}}DependencyWith{{capitalize .class_name}}{{end}}{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, ExpectNonEmptyPlan: {{.class_in_parent}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := $.resource_required}} {{- if eq $key "target_dn" }} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{getTestTargetDn $.targets $.resourceName $value false $target_classes 0 false}}"), {{- else }} - resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), + {{- if not (definedInList $.exclude_attributes $key) }} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), + {{- end}} {{- end }} {{- end}} {{- range $key, $value := $.all}}{{$contains := definedInMap $key $.all}} @@ -215,18 +307,42 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes }, // Update with empty strings config or default value { - Config: testConfig{{$.resourceClassName}}ResetDependencyWith{{capitalize .class_name}}, + Config: testConfig{{$.resourceClassName}}Reset{{ if .class_name}}DependencyWith{{capitalize .class_name}}{{end}}{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, ExpectNonEmptyPlan: {{.class_in_parent}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := $.resource_required}} {{- if eq $key "target_dn" }} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{getTestTargetDn $.targets $.resourceName $value false $target_classes 0 false}}"), {{- else }} + {{- if not (definedInList $.exclude_attributes $key) }} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), + {{- end }} {{- end }} {{- end}} - {{- range $key, $value := $.default}}{{$contains := definedInMap $key $.resource_required}} + {{- if $.resource_required }} + {{- range $key, $value := $.default}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + {{- $contains := definedInMap $attributeName $.resource_required}} + {{- if not $contains}} + {{- if not (definedInList $.exclude_attributes $attributeName) }} + {{- if (isInterfaceSlice $attributeValue)}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}.#", "{{len $attributeValue}}"), + {{- range $index, $subvalue := $attributeValue}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}} + {{- end}} + {{- end}} + {{- end}}), + {{- end}} + {{- else}} + {{- $contains := definedInMap $key $.resource_required}} {{- if not $contains}} + {{- if not (definedInList $.exclude_attributes $key) }} {{- if (isInterfaceSlice $value)}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.#", "{{len $value}}"), {{- range $index, $subvalue := $value}} @@ -236,7 +352,10 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), {{- end}} {{- end}} + {{- end}} {{- end}} + {{- end}} + {{- end}} {{- range $index, $key := $.read_only}} resource.TestCheckResourceAttrSet("aci_{{$.resourceName}}.test", "{{$key}}"), {{- end}} @@ -247,22 +366,50 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes ResourceName: "aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", ImportState: true, ImportStateVerify: true, + {{- if $.exclude_attributes }} + ImportStateVerifyIgnore: []string{ + {{- range $.exclude_attributes }}"{{.}}",{{- end}} + }, + {{- end}} }, {{- if $.children}} // Update with children { - Config: testConfig{{$.resourceClassName}}ChildrenDependencyWith{{capitalize .class_name}}, + Config: testConfig{{$.resourceClassName}}Children{{ if .class_name}}DependencyWith{{capitalize .class_name}}{{end}}{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, ExpectNonEmptyPlan: {{.class_in_parent}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := $.resource_required}} {{- if eq $key "target_dn" }} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{getTestTargetDn $.targets $.resourceName $value false $target_classes 0 false}}"), {{- else }} + {{- if not (definedInList $.exclude_attributes $key) }} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), {{- end }} {{- end}} - {{- range $key, $value := $.default}}{{$contains := definedInMap $key $.resource_required}} + {{- end }} + {{- range $key, $value := $.default}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + {{- $contains := definedInMap $attributeName $.resource_required}} + {{- if not $contains}} + {{- if not (definedInList $.exclude_attributes $attributeName) }} + {{- if (isInterfaceSlice $attributeValue)}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}.#", "{{len $attributeValue}}"), + {{- range $index, $subvalue := $attributeValue}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}} + {{- end}} + {{- end}} + {{- end}}), + {{- end }} + {{- else}} + {{- $contains := definedInMap $key $.resource_required}} {{- if not $contains}} + {{- if not (definedInList $.exclude_attributes $key) }} {{- if (isInterfaceSlice $value)}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.#", "{{len $value}}"), {{- range $index, $subvalue := $value}} @@ -272,7 +419,9 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), {{- end}} {{- end}} + {{- end }} {{- end}} + {{- end }} {{- range $index, $key := $.read_only}} resource.TestCheckResourceAttrSet("aci_{{$.resourceName}}.test", "{{$key}}"), {{- end}} @@ -280,6 +429,13 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes {{- if eq (len $value) 1}} {{- range $child_index, $child := $value}} {{- range $child_key, $child_value := $child}} + {{- if eq $child_key "version_mismatch" }} + {{- range $version, $attributes := $child_value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$attributeName}}", "{{$attributeValue}}"), + {{- end }}), + {{- end }} + {{- else }} {{- if eq $child_key "target_dn"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_key}}", "{{getTestTargetDn $.child_targets $key $child_value false nil $child_index false }}"), {{- else if ne $child_key "deletable_child"}} @@ -287,13 +443,22 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes {{- end}} {{- end}} {{- end}} + {{- end}} {{- else}} {{- range $child_index, $child := $value}} - {{- range $child_key, $child_value := $child}} + {{- range $child_key, $child_value := $child}} + {{- if eq $child_key "version_mismatch" }} + {{- range $version, $attributes := $child_value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.{{$child_index}}.{{$attributeName}}", "{{$attributeValue}}"), + {{- end }}), + {{- end }} + {{- else }} {{- if eq $child_key "target_dn"}} - resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.{{$child_index}}.{{$child_key}}", "{{getTestTargetDn $.child_targets $key $child_value false nil $child_index false}}"), + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.{{$child_index}}.{{$child_key}}", "{{getTestTargetDn $.child_targets $key $child_value false nil $child_index false}}"), {{- else if ne $child_key "deletable_child"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.{{$child_index}}.{{$child_key}}", "{{$child_value}}"), + {{- end}} {{- end}} {{- end}} {{- end}} @@ -311,17 +476,41 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes ResourceName: "aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", ImportState: true, ImportStateVerify: true, + {{- if $.exclude_attributes }} + ImportStateVerifyIgnore: []string{ + {{- range $.exclude_attributes }}"{{.}}",{{- end}} + }, + {{- end}} }, // Update with children removed from config { - Config: testConfig{{$.resourceClassName}}ChildrenRemoveFromConfigDependencyWith{{capitalize .class_name}}, + Config: testConfig{{$.resourceClassName}}ChildrenRemoveFromConfig{{ if .class_name}}DependencyWith{{capitalize .class_name}}{{end}}{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, ExpectNonEmptyPlan: {{.class_in_parent}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := .min}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), {{- end}} - {{- range $key, $value := .default}}{{$contains := definedInMap $key $.resource_required}} - {{- if not $contains}} + {{- if $.resource_required }} + {{- range $key, $value := .default}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + {{- $contains := definedInMap $attributeName $.resource_required}} + {{- if not $contains}} + {{- if (isInterfaceSlice $attributeValue)}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}.#", "{{len $attributeValue}}"), + {{- range $index, $subvalue := $attributeValue}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}} + {{- end}} + {{- end}}), + {{- end}} + {{- else}} + {{- $contains := definedInMap $key $.resource_required}} + {{- if not $contains}} {{- if (isInterfaceSlice $value)}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.#", "{{len $value}}"), {{- range $index, $subvalue := $value}} @@ -331,7 +520,9 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), {{- end}} {{- end}} + {{- end}} {{- end}} + {{- end}} {{- range $index, $key := $.read_only}} resource.TestCheckResourceAttrSet("aci_{{$.resourceName}}.test", "{{$key}}"), {{- end}} @@ -339,6 +530,13 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes {{- if eq (len $value) 1}} {{- range $child_index, $child := $value}} {{- range $child_key, $child_value := $child}} + {{- if eq $child_key "version_mismatch" }} + {{- range $version, $attributes := $child_value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.{{$attributeName}}", "{{$attributeValue}}"), + {{- end }}), + {{- end }} + {{- else }} {{- if eq $child_key "target_dn"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.{{$child_key}}", "{{getTestTargetDn $.child_targets $key $child_value false nil $child_index false}}"), {{- else if ne $child_key "deletable_child"}} @@ -346,16 +544,25 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes {{- end}} {{- end}} {{- end}} + {{- end}} {{- else}} - {{- range $child_index, $child := $value}} - {{- range $child_key, $child_value := $child}} - {{- if eq $child_key "target_dn"}} - resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.{{$child_index}}.{{$child_key}}", "{{getTestTargetDn $.child_targets $key $child_value false nil $child_index false}}"), - {{- else if ne $child_key "deletable_child"}} + {{- range $child_index, $child := $value}} + {{- range $child_key, $child_value := $child}} + {{- if eq $child_key "version_mismatch" }} + {{- range $version, $attributes := $child_value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.{{$child_index}}.{{$attributeName}}", "{{$attributeValue}}"), + {{- end }}), + {{- end }} + {{- else }} + {{- if eq $child_key "target_dn"}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.{{$child_index}}.{{$child_key}}", "{{getTestTargetDn $.child_targets $key $child_value false nil $child_index false}}"), + {{- else if ne $child_key "deletable_child"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.{{$child_index}}.{{$child_key}}", "{{$child_value}}"), + {{- end}} + {{- end}} {{- end}} {{- end}} - {{- end}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.#", "2"), {{- end}} {{- end}} @@ -363,16 +570,28 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes }, // Update with children first child removed { - Config: testConfig{{$.resourceClassName}}ChildrenRemoveOneDependencyWith{{capitalize .class_name}}, + Config: testConfig{{$.resourceClassName}}ChildrenRemoveOne{{ if .class_name}}DependencyWith{{capitalize .class_name}}{{end}}{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, ExpectNonEmptyPlan: {{.class_in_parent}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := .min}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), {{- end}} - {{- range $key, $value := .default}}{{$contains := definedInMap $key $.resource_required}} + {{- range $key, $value := .default}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + {{- $contains := definedInMap $attributeName $.resource_required}} + {{- if not $contains}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}} + {{- end}}), + {{- end}} + {{- else}} + {{- $contains := definedInMap $key $.resource_required}} {{- if not $contains}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), {{- end}} + {{- end}} {{- end}} {{- range $index, $key := $.read_only}} resource.TestCheckResourceAttrSet("aci_{{$.resourceName}}.test", "{{$key}}"), @@ -381,22 +600,38 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes {{- if eq (len $value) 1}}{{- $child := index $value 0 }} {{- if not $child.deletable_child}} {{- range $child_key, $child_value := $child}} + {{- if eq $child_key "version_mismatch" }} + {{- range $version, $attributes := $child_value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.{{$attributeName}}", "{{$attributeValue}}"), + {{- end }}), + {{- end }} + {{- else }} {{- if eq $child_key "target_dn"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.{{$child_key}}", "{{getTestTargetDn $.child_targets $key $child_value false nil 0 false}}"), {{- else if ne $child_key "deletable_child"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.{{$child_key}}", "{{$child_value}}"), + {{- end}} {{- end}} {{- end}} {{- end}} {{- else}} {{- $child := index $value 1 }} {{- range $child_key, $child_value := $child}} + {{- if eq $child_key "version_mismatch" }} + {{- range $version, $attributes := $child_value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.0.{{$attributeName}}", "{{$attributeValue}}"), + {{- end }}), + {{- end }} + {{- else }} {{- if eq $child_key "target_dn"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.0.{{$child_key}}", "{{getTestTargetDn $.child_targets $key $child_value false nil 1 false}}"), {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.0.{{$child_key}}", "{{$child_value}}"), + {{- end}} + {{- end}} {{- end}} - {{- end}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.#", "1"), {{- end}} {{- end}} @@ -411,8 +646,14 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes knownvalue.MapExact( map[string]knownvalue.Check{ {{- range $child_key, $child_value := $child}} - {{- if ne $child_key "deletable_child"}} - "{{$child_key}}": knownvalue.Null(), + {{- if and (ne $child_key "deletable_child") (ne $child_key "version_mismatch")}} + "{{$child_key}}": knownvalue.Null(), + {{- else if eq $child_key "version_mismatch"}} + {{- range $version, $attributes := $child_value }} + {{- range $attributeName, $attributeValue := $attributes}} + "{{$attributeName}}" : knownvalue.Null(), + {{- end}} + {{- end}} {{- end}} {{- end}} }, @@ -427,16 +668,28 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes }, // Update with all children removed { - Config: testConfig{{$.resourceClassName}}ChildrenRemoveAllDependencyWith{{capitalize .class_name}}, + Config: testConfig{{$.resourceClassName}}ChildrenRemoveAll{{ if .class_name}}DependencyWith{{capitalize .class_name}}{{end}}{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, ExpectNonEmptyPlan: {{.class_in_parent}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := .min}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), {{- end}} - {{- range $key, $value := .default}}{{$contains := definedInMap $key $.resource_required}} + {{- range $key, $value := .default}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + {{- $contains := definedInMap $attributeName $.resource_required}} + {{- if not $contains}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}} + {{- end}}), + {{- end}} + {{- else}} + {{- $contains := definedInMap $key $.resource_required}} {{- if not $contains}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"), {{- end}} + {{- end}} {{- end}} {{- range $index, $key := $.read_only}} resource.TestCheckResourceAttrSet("aci_{{$.resourceName}}.test", "{{$key}}"), @@ -445,8 +698,16 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes {{- if eq (len $value) 1}}{{- $child := index $value 0 }} {{- if not $child.deletable_child}} {{- range $child_key, $child_value := $child}} + {{- if eq $child_key "version_mismatch" }} + {{- range $version, $attributes := $child_value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.{{$attributeName}}", "{{$attributeValue}}"), + {{- end }}), + {{- end }} + {{- else }} {{- if ne $child_key "deletable_child"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.{{$child_key}}", "{{$child_value}}"), + {{- end}} {{- end}} {{- end}} {{- end}} @@ -465,8 +726,14 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes knownvalue.MapExact( map[string]knownvalue.Check{ {{- range $child_key, $child_value := $child}} - {{- if ne $child_key "deletable_child"}} - "{{$child_key}}": knownvalue.Null(), + {{- if and (ne $child_key "deletable_child") (ne $child_key "version_mismatch")}} + "{{$child_key}}": knownvalue.Null(), + {{- else if eq $child_key "version_mismatch"}} + {{- range $version, $attributes := $child_value }} + {{- range $attributeName, $attributeValue := $attributes}} + "{{$attributeName}}" : knownvalue.Null(), + {{- end}} + {{- end}} {{- end}} {{- end}} }, @@ -483,7 +750,7 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes {{- if $.custom_type}} // Update with minimum config and custom type semantic equivalent values { - Config: testConfig{{$.resourceClassName}}CustomTypeDependencyWith{{capitalize .class_name}}, + Config: testConfig{{$.resourceClassName}}CustomTypeDependencyWith{{capitalize .class_name}}{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, ExpectNonEmptyPlan: {{.class_in_parent}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := $.custom_type}} @@ -497,19 +764,19 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes }, {{- end}} }, + CheckDestroy: testCheckResourceDestroy, }) } {{- end}} - {{- else}} func TestAccResource{{.resourceClassName}}(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "{{.test_type}}", "{{.class_version}}") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfig{{.resourceClassName}}MinAllowExisting, + Config: testConfig{{.resourceClassName}}MinAllowExisting{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := $.resource_required}}{{$contains := definedInMap $key $.default}} {{- if not $contains}} @@ -523,8 +790,17 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- end}} {{- end}} {{- range $key, $value := $.default}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test", "{{$attributeName}}", "{{$attributeValue}}"), + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test_2", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}}), + {{- end}} + {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test", "{{$key}}", "{{$value}}"), resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test_2", "{{$key}}", "{{$value}}"), + {{- end}} {{- end}} {{- range $index, $key := $.read_only}} resource.TestCheckResourceAttrSet("aci_{{$.resourceName}}.allow_test", "{{$key}}"), @@ -536,7 +812,7 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "{{.test_type}}", "{{.class_version}}") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -549,12 +825,12 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "{{.test_type}}", "{{.class_version}}") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfig{{.resourceClassName}}MinAllowExisting, + Config: testConfig{{.resourceClassName}}MinAllowExisting{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := $.resource_required}}{{$contains := definedInMap $key $.default}} {{- if not $contains}} @@ -568,8 +844,17 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- end}} {{- end}} {{- range $key, $value := $.default}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test", "{{$attributeName}}", "{{$attributeValue}}"), + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test_2", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}}), + {{- end}} + {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test", "{{$key}}", "{{$value}}"), resource.TestCheckResourceAttr("aci_{{$.resourceName}}.allow_test_2", "{{$key}}", "{{$value}}"), + {{- end}} {{- end}} {{- range $index, $key := $.read_only}} resource.TestCheckResourceAttrSet("aci_{{$.resourceName}}.allow_test", "{{$key}}"), @@ -580,12 +865,12 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "{{.test_type}}", "{{.class_version}}") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfig{{.resourceClassName}}Min, + Config: testConfig{{.resourceClassName}}Min{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := .resource_required}}{{$contains := definedInMap $key $.default}} {{- if not $contains}} @@ -597,6 +882,20 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- end}} {{- end}} {{- range $key, $value := .default}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + {{- if (isInterfaceSlice $attributeValue)}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}.#", "{{len $attributeValue}}"), + {{- range $index, $subvalue := $attributeValue}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}} + {{- end}}), + {{- end}} + {{- else}} {{- if (isInterfaceSlice $value)}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "{{len $value}}"), {{- range $index, $subvalue := $value}} @@ -605,6 +904,7 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"), {{- end}} + {{- end}} {{- end}} {{- range $index, $key := $.read_only}} resource.TestCheckResourceAttrSet("aci_{{$.resourceName}}.test", "{{$key}}"), @@ -613,7 +913,7 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { }, // Update with all config and verify default APIC values { - Config: testConfig{{.resourceClassName}}All, + Config: testConfig{{.resourceClassName}}All{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := .resource_required}}{{$contains := definedInMap $key $.all}} {{- if not $contains}} @@ -625,6 +925,22 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- end}} {{- end}} {{- range $key, $value := .all}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + {{- if not (definedInList $.exclude_attributes $attributeName) }} + {{- if (isInterfaceSlice $attributeValue)}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}.#", "{{len $attributeValue}}"), + {{- range $index, $subvalue := $attributeValue}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}} + {{- end}} + {{- end }}), + {{- end }} + {{- else }} {{- if (isInterfaceSlice $value)}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "{{len $value}}"), {{- range $index, $subvalue := $value}} @@ -632,7 +948,8 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- end}} {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"), - {{- end}} + {{- end}} + {{- end }} {{- end}} {{- range $index, $key := $.read_only}} resource.TestCheckResourceAttrSet("aci_{{$.resourceName}}.test", "{{$key}}"), @@ -641,7 +958,7 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { }, // Update with minimum config and verify config is unchanged { - Config: testConfig{{.resourceClassName}}Min, + Config: testConfig{{.resourceClassName}}Min{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := .resource_required}}{{$contains := definedInMap $key $.all}} {{- if not $contains}} @@ -654,6 +971,22 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- end}} {{- range $key, $value := .all}} {{- if ne $key "annotation"}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + {{- if not (definedInList $.exclude_attributes $attributeName) }} + {{- if (isInterfaceSlice $attributeValue)}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}.#", "{{len $attributeValue}}"), + {{- range $index, $subvalue := $attributeValue}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}} + {{- end}} + {{- end }}), + {{- end }} + {{- else }} {{- if (isInterfaceSlice $value)}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "{{len $value}}"), {{- range $index, $subvalue := $value}} @@ -662,6 +995,7 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"), {{- end}} + {{- end}} {{- else}} {{- range $dkey, $dvalue := $.default}} {{- if eq $dkey "annotation"}} @@ -677,7 +1011,7 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { }, // Update with empty strings config or default value { - Config: testConfig{{.resourceClassName}}Reset, + Config: testConfig{{.resourceClassName}}Reset{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := $.resource_required}} {{- if eq $key "target_dn" }} @@ -686,8 +1020,26 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"), {{- end }} {{- end}} - {{- range $key, $value := $.default}}{{$contains := definedInMap $key $.resource_required}} - {{- if not $contains}} + {{- range $key, $value := $.default}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + {{- $contains := definedInMap $attributeName $.resource_required}} + {{- if not $contains}} + {{- if (isInterfaceSlice $attributeValue)}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}.#", "{{len $attributeValue}}"), + {{- range $index, $subvalue := $attributeValue}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}} + {{- end}} + {{- end}}), + {{- end}} + {{- else}} + {{- $contains := definedInMap $key $.resource_required}} + {{- if not $contains}} {{- if (isInterfaceSlice $value)}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "{{len $value}}"), {{- range $index, $subvalue := $value}} @@ -695,6 +1047,7 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- end}} {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"), + {{- end}} {{- end}} {{- end}} {{- end}} @@ -712,7 +1065,7 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- if $.children}} // Update with children { - Config: testConfig{{.resourceClassName}}Children, + Config: testConfig{{.resourceClassName}}Children{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := .min}} {{- if eq $key "target_dn" }} @@ -721,8 +1074,26 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"), {{- end }} {{- end}} - {{- range $key, $value := .default}}{{$contains := definedInMap $key $.resource_required}} - {{- if not $contains}} + {{- range $key, $value := .default}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + {{- $contains := definedInMap $attributeName $.resource_required}} + {{- if not $contains}} + {{- if (isInterfaceSlice $attributeValue)}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}.#", "{{len $attributeValue}}"), + {{- range $index, $subvalue := $attributeValue}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}} + {{- end}} + {{- end}}), + {{- end}} + {{- else}} + {{- $contains := definedInMap $key $.resource_required}} + {{- if not $contains}} {{- if (isInterfaceSlice $value)}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "{{len $value}}"), {{- range $index, $subvalue := $value}} @@ -732,6 +1103,7 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"), {{- end}} {{- end}} + {{- end}} {{- end}} {{- range $index, $key := $.read_only}} resource.TestCheckResourceAttrSet("aci_{{$.resourceName}}.test", "{{$key}}"), @@ -740,31 +1112,47 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- if eq (len $value) 1}} {{- range $child_index, $child := $value}} {{- range $child_key, $child_value := $child}} + {{- if eq $child_key "version_mismatch" }} + {{- range $version, $attributes := $child_value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$attributeName}}", "{{$attributeValue}}"), + {{- end }}), + {{- end }} + {{- else }} {{- if eq $child_key "target_dn"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_key}}", "{{getTestTargetDn $.child_targets $key $child_value false nil $child_index false}}"), {{- else if ne $child_key "deletable_child"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_key}}", "{{$child_value}}"), + {{- end}} {{- end}} {{- end}} - {{- end}} + {{- end }} {{- else}} {{- range $child_index, $child := $value}} - {{- range $child_key, $child_value := $child}} - {{- 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 ne $child_key "deletable_child"}} - resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_index}}.{{$child_key}}", "{{$child_value}}"), + {{- range $child_key, $child_value := $child}} + {{- if eq $child_key "version_mismatch" }} + {{- range $version, $attributes := $child_value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_index}}.{{$attributeName}}", "{{$attributeValue}}"), + {{- end }}), + {{- end }} + {{- 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 ne $child_key "deletable_child"}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_index}}.{{$child_key}}", "{{$child_value}}"), {{- end}} {{- end}} - {{- end}} + {{- end}} + {{- end}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "{{len $value}}"), + {{- end}} {{- end}} - {{- end}} ), }, // Update with children removed from config { - Config: testConfig{{.resourceClassName}}ChildrenRemoveFromConfig, + Config: testConfig{{.resourceClassName}}ChildrenRemoveFromConfig{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := .min}} {{- if eq $key "target_dn" }} @@ -773,8 +1161,26 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"), {{- end }} {{- end}} - {{- range $key, $value := .default}}{{$contains := definedInMap $key $.resource_required}} - {{- if not $contains}} + {{- range $key, $value := .default}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + {{- $contains := definedInMap $attributeName $.resource_required}} + {{- if not $contains}} + {{- if (isInterfaceSlice $attributeValue)}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}.#", "{{len $attributeValue}}"), + {{- range $index, $subvalue := $attributeValue}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}} + {{- end}} + {{- end}}), + {{- end}} + {{- else}} + {{- $contains := definedInMap $key $.resource_required}} + {{- if not $contains}} {{- if (isInterfaceSlice $value)}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "{{len $value}}"), {{- range $index, $subvalue := $value}} @@ -782,6 +1188,7 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- end}} {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"), + {{- end}} {{- end}} {{- end}} {{- end}} @@ -792,23 +1199,39 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- if eq (len $value) 1}} {{- range $child_index, $child := $value}} {{- range $child_key, $child_value := $child}} + {{- if eq $child_key "version_mismatch" }} + {{- range $version, $attributes := $child_value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$attributeName}}", "{{$attributeValue}}"), + {{- end }}), + {{- end }} + {{- else }} {{- if eq $child_key "target_dn"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_key}}", "{{getTestTargetDn $.child_targets $key $child_value false nil $child_index false}}"), {{- else if ne $child_key "deletable_child"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_key}}", "{{$child_value}}"), + {{- end}} {{- end}} {{- end}} {{- end}} {{- else}} {{- range $child_index, $child := $value}} - {{- range $child_key, $child_value := $child}} - {{- 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 ne $child_key "deletable_child"}} - resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_index}}.{{$child_key}}", "{{$child_value}}"), + {{- range $child_key, $child_value := $child}} + {{- if eq $child_key "version_mismatch" }} + {{- range $version, $attributes := $child_value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_index}}.{{$attributeName}}", "{{$attributeValue}}"), + {{- end }}), + {{- end }} + {{- 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 ne $child_key "deletable_child"}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_index}}.{{$child_key}}", "{{$child_value}}"), + {{- end}} + {{- end}} {{- end}} {{- end}} - {{- end}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "{{len $value}}"), {{- end}} {{- end}} @@ -816,7 +1239,7 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { }, // Update with children first child removed { - Config: testConfig{{.resourceClassName}}ChildrenRemoveOne, + Config: testConfig{{.resourceClassName}}ChildrenRemoveOne{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := .min}} {{- if eq $key "target_dn" }} @@ -825,8 +1248,26 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"), {{- end }} {{- end}} - {{- range $key, $value := .default}}{{$contains := definedInMap $key $.resource_required}} - {{- if not $contains}} + {{- range $key, $value := .default}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + {{- $contains := definedInMap $attributeName $.resource_required}} + {{- if not $contains}} + {{- if (isInterfaceSlice $attributeValue)}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}.#", "{{len $attributeValue}}"), + {{- range $index, $subvalue := $attributeValue}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}} + {{- end}} + {{- end}}), + {{- end}} + {{- else}} + {{- $contains := definedInMap $key $.resource_required}} + {{- if not $contains}} {{- if (isInterfaceSlice $value)}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "{{len $value}}"), {{- range $index, $subvalue := $value}} @@ -835,6 +1276,7 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"), {{- end}} + {{- end}} {{- end}} {{- end}} {{- range $index, $key := $.read_only}} @@ -844,10 +1286,18 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- if eq (len $value) 1}}{{- $child := index $value 0 }} {{- if not $child.deletable_child}} {{- range $child_key, $child_value := $child}} + {{- if eq $child_key "version_mismatch" }} + {{- range $version, $attributes := $child_value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$attributeName}}", "{{$attributeValue}}"), + {{- end }}), + {{- end }} + {{- else }} {{- if eq $child_key "target_dn"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_key}}", "{{getTestTargetDn $.child_targets $key $child_value false nil 1 false}}"), {{- else if ne $child_key "deletable_child"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_key}}", "{{$child_value}}"), + {{- end}} {{- end}} {{- end}} {{- end}} @@ -858,8 +1308,8 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.0.{{$child_key}}", "{{getTestTargetDn $.child_targets $key $child_value false nil 1 false}}"), {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.0.{{$child_key}}", "{{$child_value}}"), + {{- end}} {{- end}} - {{- end}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "1"), {{- end}} {{- end}} @@ -874,8 +1324,14 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { knownvalue.MapExact( map[string]knownvalue.Check{ {{- range $child_key, $child_value := $child}} - {{- if ne $child_key "deletable_child"}} + {{- if and (ne $child_key "deletable_child") (ne $child_key "version_mismatch")}} "{{$child_key}}": knownvalue.Null(), + {{- else if eq $child_key "version_mismatch"}} + {{- range $version, $attributes := $child_value }} + {{- range $attributeName, $attributeValue := $attributes}} + "{{$attributeName}}" : knownvalue.Null(), + {{- end}} + {{- end}} {{- end}} {{- end}} }, @@ -890,7 +1346,7 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { }, // Update with all children removed { - Config: testConfig{{.resourceClassName}}ChildrenRemoveAll, + Config: testConfig{{.resourceClassName}}ChildrenRemoveAll{{if $.version_mismatch}} + testConfigDataSourceSystem{{end}}, Check: resource.ComposeAggregateTestCheckFunc( {{- range $key, $value := .min}} {{- if eq $key "target_dn" }} @@ -899,15 +1355,34 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"), {{- end }} {{- end}} - {{- range $key, $value := .default}}{{$contains := definedInMap $key $.resource_required}} - {{- if not $contains}} - {{- if (isInterfaceSlice $value)}} + {{- range $key, $value := .default}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + {{- $contains := definedInMap $attributeName $.resource_required}} + {{- if not $contains}} + {{- if (isInterfaceSlice $attributeValue)}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}.#", "{{len $attributeValue}}"), + {{- range $index, $subvalue := $attributeValue}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), + {{- end}} + {{- else}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$attributeName}}", "{{$attributeValue}}"), + {{- end}} + {{- end}} + {{- end}}), + {{- end}} + {{- else}} + {{- $contains := definedInMap $key $.resource_required}} + {{- if not $contains}} + {{- if (isInterfaceSlice $value)}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "{{len $value}}"), - {{- range $index, $subvalue := $value}} + {{- range $index, $subvalue := $value}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$index}}", "{{$subvalue}}"), - {{- end}} - {{- else}} + {{- end}} + {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"), + {{- end}} {{- end}} {{- end}} {{- end}} @@ -918,8 +1393,16 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- if eq (len $value) 1}}{{- $child := index $value 0 }} {{- if not $child.deletable_child}} {{- range $child_key, $child_value := $child}} + {{- if eq $child_key "version_mismatch" }} + {{- range $version, $attributes := $child_value }} + composeAggregateTestCheckFuncWithVersion(t,"{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$attributeName}}", "{{$attributeValue}}"), + {{- end }}), + {{- end }} + {{- else }} {{- if ne $child_key "deletable_child"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_key}}", "{{$child_value}}"), + {{- end}} {{- end}} {{- end}} {{- end}} @@ -938,8 +1421,14 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { knownvalue.MapExact( map[string]knownvalue.Check{ {{- range $child_key, $child_value := $child}} - {{- if ne $child_key "deletable_child"}} + {{- if and (ne $child_key "deletable_child") (ne $child_key "version_mismatch")}} "{{$child_key}}": knownvalue.Null(), + {{- else if eq $child_key "version_mismatch"}} + {{- range $version, $attributes := $child_value }} + {{- range $attributeName, $attributeValue := $attributes}} + "{{$attributeName}}" : knownvalue.Null(), + {{- end}} + {{- end}} {{- end}} {{- end}} }, @@ -969,6 +1458,7 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { }, {{- end}} }, + CheckDestroy: testCheckResourceDestroy, }) } {{end}} @@ -979,15 +1469,15 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{ $testIndex := 0 }} const testDependencyConfig{{$.resourceClassName}} = ` {{- range $index, $target := .targets}}{{if not $target.static}} - {{- if ne .parent_dependency "" }} resource "aci_{{$target.target_resource_name}}" "test_{{$target.target_resource_name}}_{{mod $testIndex 2}}" { + {{- if ne $target.parent_dependency_dn_ref ""}} {{$target.parent_dn_key}} = {{$target.parent_dependency_dn_ref}} + {{- end}} {{- range $key, $value := $target.properties}} {{$key}} = "{{$value}}" {{- end}} }{{$testIndex = add $testIndex 1}} - {{- end }} {{- end }}{{- end }} ` {{- end }} @@ -1014,9 +1504,11 @@ resource "aci_{{$target.target_resource_name}}" "test_{{$target.target_resource_ {{- if .parents}} {{- range .parents}}{{$target_classes := .target_classes}} {{ $parentClassName := capitalize .class_name }} -const testConfig{{$.resourceClassName}}MinDependencyWith{{capitalize .class_name}}AllowExisting = {{- if $dependencies }} testDependencyConfig{{$.resourceClassName}} + {{- end }} testConfig{{capitalize .class_name}}Min{{- if ne .parent_dependency ""}}DependencyWith{{capitalize .parent_dependency}}{{if and (ne .parent_dependency_name nil) (ne .parent_dependency_name "")}}{{capitalize .parent_dependency_name }}{{- end }}{{- end}} + ` +const testConfig{{$.resourceClassName}}Min{{if .class_name}}DependencyWith{{capitalize .class_name}}{{- end}}AllowExisting = {{- if $dependencies }} testDependencyConfig{{$.resourceClassName}} + {{- end }} {{if .class_name}}testConfig{{capitalize .class_name}}Min{{- if ne .parent_dependency ""}}DependencyWith{{capitalize .parent_dependency}}{{if and (ne .parent_dependency_name nil) (ne .parent_dependency_name "")}}{{capitalize .parent_dependency_name }}{{- end }}{{- end}} + {{- end}} ` resource "aci_{{$.resourceName}}" "allow_test" { + {{- if ne .parent_dn ""}} parent_dn = {{.parent_dn}} + {{- end}} {{- range $key, $value := $.resource_required}} {{- if eq $key "target_dn" }}{{$attributeValue := getTestTargetDn $.targets $.resourceName $value true $target_classes 0 false}} {{$key}} = {{if containsString $attributeValue "."}}{{$attributeValue}}{{else}}"{{$attributeValue}}"{{end}} @@ -1026,7 +1518,9 @@ resource "aci_{{$.resourceName}}" "allow_test" { {{- end}} } resource "aci_{{$.resourceName}}" "allow_test_2" { + {{- if ne .parent_dn ""}} parent_dn = {{.parent_dn}} + {{- end}} {{- range $key, $value := $.resource_required}} {{- if eq $key "target_dn" }}{{$attributeValue := getTestTargetDn $.targets $.resourceName $value true $target_classes 0 false}} {{$key}} = {{if containsString $attributeValue "."}}{{$attributeValue}}{{else}}"{{$attributeValue}}"{{end}} @@ -1038,9 +1532,11 @@ resource "aci_{{$.resourceName}}" "allow_test_2" { } ` -const testConfig{{$.resourceClassName}}MinDependencyWith{{capitalize .class_name}} = {{- if $dependencies }} testDependencyConfig{{$.resourceClassName}} + {{- end }} testConfig{{capitalize .class_name}}Min{{- if ne .parent_dependency ""}}DependencyWith{{capitalize .parent_dependency}}{{if and (ne .parent_dependency_name nil) (ne .parent_dependency_name "")}}{{capitalize .parent_dependency_name }}{{- end }}{{- end}} + ` +const testConfig{{$.resourceClassName}}Min{{if .class_name}}DependencyWith{{capitalize .class_name}}{{end}} = {{- if $dependencies }} testDependencyConfig{{$.resourceClassName}} + {{- end }} {{if .class_name}}testConfig{{capitalize .class_name}}Min{{- if ne .parent_dependency ""}}DependencyWith{{capitalize .parent_dependency}}{{if and (ne .parent_dependency_name nil) (ne .parent_dependency_name "")}}{{capitalize .parent_dependency_name }}{{- end }}{{- end}} + {{- end}} ` resource "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}" { + {{- if ne .parent_dn ""}} parent_dn = {{.parent_dn}} + {{- end}} {{- range $key, $value := $.resource_required}} {{- if eq $key "target_dn" }}{{$attributeValue := getTestTargetDn $.targets $.resourceName $value true $target_classes 0 false}} {{$key}} = {{if containsString $attributeValue "."}}{{$attributeValue}}{{else}}"{{$attributeValue}}"{{end}} @@ -1051,9 +1547,11 @@ resource "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClas } ` -const testConfig{{$.resourceClassName}}AllDependencyWith{{capitalize .class_name}} = {{- if $dependencies }} testDependencyConfig{{$.resourceClassName}} + {{- end }} testConfig{{capitalize .class_name}}Min{{- if ne .parent_dependency ""}}DependencyWith{{capitalize .parent_dependency}}{{if and (ne .parent_dependency_name nil) (ne .parent_dependency_name "")}}{{capitalize .parent_dependency_name }}{{- end }}{{- end}} + ` +const testConfig{{$.resourceClassName}}All{{ if .class_name}}DependencyWith{{capitalize .class_name}}{{end}} = {{- if $dependencies }} testDependencyConfig{{$.resourceClassName}} + {{- end }} {{if .class_name}}testConfig{{capitalize .class_name}}Min{{- if ne .parent_dependency ""}}DependencyWith{{capitalize .parent_dependency}}{{if and (ne .parent_dependency_name nil) (ne .parent_dependency_name "")}}{{capitalize .parent_dependency_name }}{{- end }}{{- end}} + {{- end}} ` resource "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}" { + {{- if ne .parent_dn ""}} parent_dn = {{.parent_dn}} + {{- end}} {{- range $key, $value := $.resource_required}}{{$contains := definedInMap $key $.all}} {{- if not $contains}} {{- if eq $key "target_dn" }}{{$attributeValue := getTestTargetDn $.targets $.resourceName $value true $target_classes 0 false}} @@ -1064,6 +1562,21 @@ resource "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClas {{- end}} {{- end}} {{- range $key, $value := $.all}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + {{- range $attributeName, $attributeValue := $attributes}} + {{- if (isInterfaceSlice $attributeValue) }} + {{- if lt 0 (len $attributeValue) }} + {{$attributeName}} = provider::aci::compare_versions(data.aci_system.version.version,">=","{{ $version }}") ? [{{range $index, $subvalue := $attributeValue}}{{if lt $index (subtract (len $attributeValue) 1)}}"{{$subvalue}}", {{else}}"{{$subvalue}}"{{end}}{{end}}] : null + {{- else}} + {{$attributeName}} = provider::aci::compare_versions(data.aci_system.version.version,">=","{{ $version }}") ? [] : null + {{- end}} + {{- else}} + {{$attributeName}} = provider::aci::compare_versions(data.aci_system.version.version,">=","{{ $version }}") ? "{{$attributeValue}}" : null + {{- end}} + {{- end }} + {{- end }} + {{- else }} {{- if (isInterfaceSlice $value)}} {{- if lt 0 (len $value)}} {{$key}} = [{{range $index, $subvalue := $value}}{{if lt $index (subtract (len $value) 1)}}"{{$subvalue}}", {{else}}"{{$subvalue}}"{{end}}{{end}}] @@ -1073,13 +1586,16 @@ resource "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClas {{- else}} {{$key}} = "{{$value}}" {{- end}} + {{- end}} {{- end}} } ` -const testConfig{{$.resourceClassName}}ResetDependencyWith{{capitalize .class_name}} = {{- if $dependencies }} testDependencyConfig{{$.resourceClassName}} + {{- end }} testConfig{{capitalize .class_name}}Min{{- if ne .parent_dependency ""}}DependencyWith{{capitalize .parent_dependency}}{{if and (ne .parent_dependency_name nil) (ne .parent_dependency_name "")}}{{capitalize .parent_dependency_name }}{{- end }}{{- end}} + ` +const testConfig{{$.resourceClassName}}Reset{{if .class_name}}DependencyWith{{capitalize .class_name}}{{end}} = {{- if $dependencies }} testDependencyConfig{{$.resourceClassName}} + {{- end }} {{if .class_name}}testConfig{{capitalize .class_name}}Min{{- if ne .parent_dependency ""}}DependencyWith{{capitalize .parent_dependency}}{{if and (ne .parent_dependency_name nil) (ne .parent_dependency_name "")}}{{capitalize .parent_dependency_name }}{{- end }}{{- end}} + {{- end}} ` resource "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}" { +{{- if ne .parent_dn ""}} parent_dn = {{.parent_dn}} + {{- end}} {{- range $key, $value := $.resource_required}}{{$contains := definedInMap $key $.default}} {{- if not $contains}} {{- if eq $key "target_dn" }}{{$attributeValue := getTestTargetDn $.targets $.resourceName $value true $target_classes 0 false}} @@ -1090,6 +1606,21 @@ resource "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClas {{- end}} {{- end}} {{- range $key, $value := $.default}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + {{- range $attributeName, $attributeValue := $attributes}} + {{- if (isInterfaceSlice $attributeValue) }} + {{- if lt 0 (len $attributeValue) }} + {{$attributeName}} = provider::aci::compare_versions(data.aci_system.version.version,">=","{{ $version }}") ? [{{range $index, $subvalue := $attributeValue}}{{if lt $index (subtract (len $attributeValue) 1)}}"{{$subvalue}}", {{else}}"{{$subvalue}}"{{end}}{{end}}] : null + {{- else}} + {{$attributeName}} = provider::aci::compare_versions(data.aci_system.version.version,">=","{{ $version }}") ? [] : null + {{- end}} + {{- else}} + {{$attributeName}} = provider::aci::compare_versions(data.aci_system.version.version,">=","{{ $version }}") ? "{{$attributeValue}}" : null + {{- end}} + {{- end }} + {{- end }} + {{- else }} {{- if (isInterfaceSlice $value)}} {{- if lt 0 (len $value)}} {{$key}} = [{{range $index, $subvalue := $value}}{{if lt $index (subtract (len $value) 1)}}"{{$subvalue}}", {{else}}"{{$subvalue}}"{{end}}{{end}}] @@ -1100,13 +1631,16 @@ resource "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClas {{$key}} = "{{$value}}" {{- end}} {{- end}} + {{- end}} } ` {{- if $.children}} -const testConfig{{$.resourceClassName}}ChildrenDependencyWith{{capitalize .class_name}} = {{- if $dependencies }} testDependencyConfig{{$.resourceClassName}} + {{- end }}{{- if $childDependencies }} testChildDependencyConfig{{$.resourceClassName}} + {{- end }} testConfig{{capitalize .class_name}}Min{{- if ne .parent_dependency ""}}DependencyWith{{capitalize .parent_dependency}}{{if and (ne .parent_dependency_name nil) (ne .parent_dependency_name "")}}{{capitalize .parent_dependency_name }}{{- end }}{{- end}} + ` +const testConfig{{$.resourceClassName}}Children{{ if .class_name}}DependencyWith{{capitalize .class_name}}{{end}} = {{- if $dependencies }} testDependencyConfig{{$.resourceClassName}} + {{- end }}{{- if $childDependencies }} testChildDependencyConfig{{$.resourceClassName}} + {{- end }} {{if .class_name}}testConfig{{capitalize .class_name}}Min{{- if ne .parent_dependency ""}}DependencyWith{{capitalize .parent_dependency}}{{if and (ne .parent_dependency_name nil) (ne .parent_dependency_name "")}}{{capitalize .parent_dependency_name }}{{- end }}{{- end}} + {{- end}} ` resource "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}" { + {{- if ne .parent_dn ""}} parent_dn = {{.parent_dn}} + {{- end}} {{- range $key, $value := $.resource_required}} {{- if eq $key "target_dn" }}{{$attributeValue := getTestTargetDn $.targets $.resourceName $value true $target_classes 0 false}} {{$key}} = {{if containsString $attributeValue "."}}{{$attributeValue}}{{else}}"{{$attributeValue}}"{{end}} @@ -1119,11 +1653,19 @@ resource "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClas {{- $child := index $value 0}} {{$key}} = { {{- range $child_key, $child_value := $child}} + {{- if eq $child_key "version_mismatch" }} + {{- range $version, $attributes := $child_value }} + {{- range $attributeName, $attributeValue := $attributes}} + {{$attributeName}} = provider::aci::compare_versions(data.aci_system.version.version,">=","{{ $version }}") ? "{{$attributeValue}}" : null + {{- end }} + {{- end }} + {{- else }} {{- if eq $child_key "target_dn"}}{{$attributeValue := getTestTargetDn $.child_targets $key $child_value true nil $index false}} {{$child_key}} = {{if containsString $attributeValue "."}}{{$attributeValue}}{{else}}"{{$attributeValue}}"{{end}} {{- else if ne $child_key "deletable_child"}} {{$child_key}} = "{{$child_value}}" {{- end}} + {{- end}} {{- end}}{{ $index = add $index 1 }} } {{- else}} @@ -1131,11 +1673,19 @@ resource "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClas {{- range $child := $value}} { {{- range $child_key, $child_value := $child}} + {{- if eq $child_key "version_mismatch" }} + {{- range $version, $attributes := $child_value }} + {{- range $attributeName, $attributeValue := $attributes}} + {{$attributeName}} = provider::aci::compare_versions(data.aci_system.version.version,">=","{{ $version }}") ? "{{$attributeValue}}" : null + {{- end }} + {{- end }} + {{- else }} {{- if eq $child_key "target_dn"}}{{$attributeValue := getTestTargetDn $.child_targets $key $child_value true nil $index false}} {{$child_key}} = {{if containsString $attributeValue "."}}{{$attributeValue}}{{else}}"{{$attributeValue}}"{{end}} {{- else if ne $child_key "deletable_child"}} {{$child_key}} = "{{$child_value}}" - {{- end}} + {{- end}} + {{- end}} {{- end}}{{ $index = add $index 1 }} }, {{- end}} @@ -1145,9 +1695,11 @@ resource "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClas } ` -const testConfig{{$.resourceClassName}}ChildrenRemoveFromConfigDependencyWith{{capitalize .class_name}} = {{- if $dependencies }} testDependencyConfig{{$.resourceClassName}} + {{- end }}{{- if $childDependencies }} testChildDependencyConfig{{$.resourceClassName}} + {{- end }} testConfig{{capitalize .class_name}}Min{{- if ne .parent_dependency ""}}DependencyWith{{capitalize .parent_dependency}}{{if and (ne .parent_dependency_name nil) (ne .parent_dependency_name "")}}{{capitalize .parent_dependency_name }}{{- end }}{{- end}} + ` +const testConfig{{$.resourceClassName}}ChildrenRemoveFromConfig{{ if .class_name}}DependencyWith{{capitalize .class_name}}{{end}} = {{- if $dependencies }} testDependencyConfig{{$.resourceClassName}} + {{- end }}{{- if $childDependencies }} testChildDependencyConfig{{$.resourceClassName}} + {{- end }} {{if .class_name}}testConfig{{capitalize .class_name}}Min{{- if ne .parent_dependency ""}}DependencyWith{{capitalize .parent_dependency}}{{if and (ne .parent_dependency_name nil) (ne .parent_dependency_name "")}}{{capitalize .parent_dependency_name }}{{- end }}{{- end}} + {{- end}} ` resource "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}" { + {{- if ne .parent_dn ""}} parent_dn = {{.parent_dn}} + {{- end}} {{- range $key, $value := $.resource_required}} {{- if eq $key "target_dn" }}{{$attributeValue := getTestTargetDn $.targets $.resourceName $value true $target_classes 0 false}} {{$key}} = {{if containsString $attributeValue "."}}{{$attributeValue}}{{else}}"{{$attributeValue}}"{{end}} @@ -1158,9 +1710,11 @@ resource "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClas } ` -const testConfig{{$.resourceClassName}}ChildrenRemoveOneDependencyWith{{capitalize .class_name}} = {{- if $dependencies }} testDependencyConfig{{$.resourceClassName}} + {{- end }}{{- if $childDependencies }} testChildDependencyConfig{{$.resourceClassName}} + {{- end }} testConfig{{capitalize .class_name}}Min{{- if ne .parent_dependency ""}}DependencyWith{{capitalize .parent_dependency}}{{if and (ne .parent_dependency_name nil) (ne .parent_dependency_name "")}}{{capitalize .parent_dependency_name }}{{- end }}{{- end}} + ` +const testConfig{{$.resourceClassName}}ChildrenRemoveOne{{ if .class_name}}DependencyWith{{capitalize .class_name}}{{end}} = {{- if $dependencies }} testDependencyConfig{{$.resourceClassName}} + {{- end }}{{- if $childDependencies }} testChildDependencyConfig{{$.resourceClassName}} + {{- end }} {{if .class_name}}testConfig{{capitalize .class_name}}Min{{- if ne .parent_dependency ""}}DependencyWith{{capitalize .parent_dependency}}{{if and (ne .parent_dependency_name nil) (ne .parent_dependency_name "")}}{{capitalize .parent_dependency_name }}{{- end }}{{- end}} + {{- end}} ` resource "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}" { +{{- if ne .parent_dn ""}} parent_dn = {{.parent_dn}} +{{- end}} {{- range $key, $value := $.resource_required}} {{- if eq $key "target_dn" }}{{$attributeValue := getTestTargetDn $.targets $.resourceName $value true $target_classes 0 false}} {{$key}} = {{if containsString $attributeValue "."}}{{$attributeValue}}{{else}}"{{$attributeValue}}"{{end}} @@ -1178,11 +1732,19 @@ resource "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClas {{$key}} = [ {{$child := index $value 1 }} { {{- range $child_key, $child_value := $child}} - {{- if eq $child_key "target_dn"}}{{$attributeValue := getTestTargetDn $.child_targets $key $child_value true nil 1 false}} + {{- if eq $child_key "version_mismatch" }} + {{- range $version, $attributes := $child_value }} + {{- range $attributeName, $attributeValue := $attributes}} + {{$attributeName}} = provider::aci::compare_versions(data.aci_system.version.version,">=","{{ $version }}") ? "{{$attributeValue}}" : null + {{- end }} + {{- end }} + {{- else }} + {{- if eq $child_key "target_dn"}}{{$attributeValue := getTestTargetDn $.child_targets $key $child_value true nil 1 false}} {{$child_key}} = {{if containsString $attributeValue "."}}{{$attributeValue}}{{else}}"{{$attributeValue}}"{{end}} - {{- else }} + {{- else }} {{$child_key}} = "{{$child_value}}" - {{- end}} + {{- end}} + {{- end}} {{- end}} }, ] @@ -1191,9 +1753,11 @@ resource "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClas } ` -const testConfig{{$.resourceClassName}}ChildrenRemoveAllDependencyWith{{capitalize .class_name}} = {{- if $dependencies }} testDependencyConfig{{$.resourceClassName}} + {{- end }}{{- if $childDependencies }} testChildDependencyConfig{{$.resourceClassName}} + {{- end }} testConfig{{capitalize .class_name}}Min{{- if ne .parent_dependency ""}}DependencyWith{{capitalize .parent_dependency}}{{if and (ne .parent_dependency_name nil) (ne .parent_dependency_name "")}}{{capitalize .parent_dependency_name }}{{- end }}{{- end}} + ` +const testConfig{{$.resourceClassName}}ChildrenRemoveAll{{ if .class_name}}DependencyWith{{capitalize .class_name}}{{end}} = {{- if $dependencies }} testDependencyConfig{{$.resourceClassName}} + {{- end }}{{- if $childDependencies }} testChildDependencyConfig{{$.resourceClassName}} + {{- end }} {{if .class_name}}testConfig{{capitalize .class_name}}Min{{- if ne .parent_dependency ""}}DependencyWith{{capitalize .parent_dependency}}{{if and (ne .parent_dependency_name nil) (ne .parent_dependency_name "")}}{{capitalize .parent_dependency_name }}{{- end }}{{- end}} + {{- end}} ` resource "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}" { + {{- if ne .parent_dn ""}} parent_dn = {{.parent_dn}} + {{- end}} {{- range $key, $value := $.resource_required}} {{- if eq $key "target_dn" }}{{$attributeValue := getTestTargetDn $.targets $.resourceName $value true $target_classes 0 false}} {{$key}} = {{if containsString $attributeValue "."}}{{$attributeValue}}{{else}}"{{$attributeValue}}"{{end}} @@ -1256,12 +1820,27 @@ resource "aci_{{$.resourceName}}" "test" { const testConfig{{.resourceClassName}}All = ` resource "aci_{{$.resourceName}}" "test" { - {{- range $key, $value := $.resource_required}}{{$contains := definedInMap $key $.all}} - {{- if not $contains}} +{{- range $key, $value := $.resource_required}}{{$contains := definedInMap $key $.all}} + {{- if not $contains}} {{$key}} = "{{$value}}" {{- end}} {{- end}} {{- range $key, $value := $.all}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + {{- range $attributeName, $attributeValue := $attributes}} + {{- if (isInterfaceSlice $attributeValue) }} + {{- if lt 0 (len $attributeValue) }} + {{$attributeName}} = provider::aci::compare_versions(data.aci_system.version.version,">=","{{ $version }}") ? [{{range $index, $subvalue := $attributeValue}}{{if lt $index (subtract (len $attributeValue) 1)}}"{{$subvalue}}", {{else}}"{{$subvalue}}"{{end}}{{end}}] : null + {{- else}} + {{$attributeName}} = provider::aci::compare_versions(data.aci_system.version.version,">=","{{ $version }}") ? [] : null + {{- end}} + {{- else}} + {{$attributeName}} = provider::aci::compare_versions(data.aci_system.version.version,">=","{{ $version }}") ? "{{$attributeValue}}" : null + {{- end}} + {{- end }} + {{- end }} + {{- else }} {{- if (isInterfaceSlice $value)}} {{- if lt 0 (len $value)}} {{$key}} = [{{range $index, $subvalue := $value}}{{if lt $index (subtract (len $value) 1)}}"{{$subvalue}}", {{else}}"{{$subvalue}}"{{end}}{{end}}] @@ -1271,18 +1850,34 @@ resource "aci_{{$.resourceName}}" "test" { {{- else}} {{$key}} = "{{$value}}" {{- end}} + {{- end}} {{- end}} } ` const testConfig{{.resourceClassName}}Reset = ` resource "aci_{{$.resourceName}}" "test" { - {{- range $key, $value := $.resource_required}}{{$contains := definedInMap $key $.default}} - {{- if not $contains}} +{{- range $key, $value := $.resource_required}}{{$contains := definedInMap $key $.default}} + {{- if not $contains}} {{$key}} = "{{$value}}" {{- end}} {{- end}} {{- range $key, $value := $.default}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} + {{- range $attributeName, $attributeValue := $attributes}} + {{- if (isInterfaceSlice $attributeValue) }} + {{- if lt 0 (len $attributeValue) }} + {{$attributeName}} = provider::aci::compare_versions(data.aci_system.version.version,">=","{{ $version }}") ? [{{range $index, $subvalue := $attributeValue}}{{if lt $index (subtract (len $attributeValue) 1)}}"{{$subvalue}}", {{else}}"{{$subvalue}}"{{end}}{{end}}] : null + {{- else}} + {{$attributeName}} = provider::aci::compare_versions(data.aci_system.version.version,">=","{{ $version }}") ? [] : null + {{- end}} + {{- else}} + {{$attributeName}} = provider::aci::compare_versions(data.aci_system.version.version,">=","{{ $version }}") ? "{{$attributeValue}}" : null + {{- end}} + {{- end }} + {{- end }} + {{- else }} {{- if (isInterfaceSlice $value)}} {{- if lt 0 (len $value)}} {{$key}} = [{{range $index, $subvalue := $value}}{{if lt $index (subtract (len $value) 1)}}"{{$subvalue}}", {{else}}"{{$subvalue}}"{{end}}{{end}}] @@ -1292,6 +1887,7 @@ resource "aci_{{$.resourceName}}" "test" { {{- else}} {{$key}} = "{{$value}}" {{- end}} + {{- end}} {{- end}} } ` @@ -1311,11 +1907,19 @@ resource "aci_{{$.resourceName}}" "test" { {{- $child := index $value 0}} {{$key}} = { {{- range $child_key, $child_value := $child}} + {{- if eq $child_key "version_mismatch" }} + {{- range $version, $attributes := $child_value }} + {{- range $attributeName, $attributeValue := $attributes}} + {{$attributeName}} = provider::aci::compare_versions(data.aci_system.version.version,">=","{{ $version }}") ? "{{$attributeValue}}" : null + {{- end }} + {{- end }} + {{- else }} {{- if eq $child_key "target_dn"}}{{$attributeValue := getTestTargetDn $.child_targets $key $child_value true nil $index false}} {{$child_key}} = {{if containsString $attributeValue "."}}{{$attributeValue}}{{else}}"{{$attributeValue}}"{{end}} {{- else if ne $child_key "deletable_child"}} {{$child_key}} = "{{$child_value}}" {{- end}} + {{- end}} {{- end}}{{ $index = add $index 1 }} } {{- else}} @@ -1323,11 +1927,19 @@ resource "aci_{{$.resourceName}}" "test" { {{- range $child := $value}} { {{- range $child_key, $child_value := $child}} + {{- if eq $child_key "version_mismatch" }} + {{- range $version, $attributes := $child_value }} + {{- range $attributeName, $attributeValue := $attributes}} + {{$attributeName}} = provider::aci::compare_versions(data.aci_system.version.version,">=","{{ $version }}") ? "{{$attributeValue}}" : null + {{- end }} + {{- end }} + {{- else }} {{- if eq $child_key "target_dn"}}{{$attributeValue := getTestTargetDn $.child_targets $key $child_value true nil $index false}} {{$child_key}} = {{if containsString $attributeValue "."}}{{$attributeValue}}{{else}}"{{$attributeValue}}"{{end}} {{- else if ne $child_key "deletable_child"}} {{$child_key}} = "{{$child_value}}" - {{- end}} + {{- end}} + {{- end}} {{- end}}{{ $index = add $index 1 }} }, {{- end}} @@ -1368,11 +1980,19 @@ resource "aci_{{$.resourceName}}" "test" { {{$key}} = [ {{$child := index $value 1 }} { {{- range $child_key, $child_value := $child}} - {{- if eq $child_key "target_dn"}}{{$attributeValue := getTestTargetDn $.child_targets $key $child_value true nil 1 false}} + {{- if eq $child_key "version_mismatch" }} + {{- range $version, $attributes := $child_value }} + {{- range $attributeName, $attributeValue := $attributes}} + {{$attributeName}} = provider::aci::compare_versions(data.aci_system.version.version,">=","{{ $version }}") ? "{{$attributeValue}}" : null + {{- end }} + {{- end }} + {{- else }} + {{- if eq $child_key "target_dn"}}{{$attributeValue := getTestTargetDn $.child_targets $key $child_value true nil 1 false}} {{$child_key}} = {{if containsString $attributeValue "."}}{{$attributeValue}}{{else}}"{{$attributeValue}}"{{end}} - {{- else }} + {{- else }} {{$child_key}} = "{{$child_value}}" - {{- end}} + {{- end}} + {{- end}} {{- end}} }, ] diff --git a/gen/templates/testvars.yaml.tmpl b/gen/templates/testvars.yaml.tmpl index 6b35420e8..4c7ff6374 100644 --- a/gen/templates/testvars.yaml.tmpl +++ b/gen/templates/testvars.yaml.tmpl @@ -2,8 +2,10 @@ # 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). +{{ $versionMismatch := .VersionMismatched}} default: - {{- range .Properties}}{{- if and (not .IgnoreInTest) (not .ReadOnly)}}{{$overwritePropertyName := overwriteProperty .PkgName .SnakeCaseName $.Definitions}} + {{- $versionMismatchExists := false}} + {{- range .Properties}}{{- if keyExists $versionMismatch .RawVersion}}{{$versionMismatchExists = true}}{{- end}}{{- if and (not (keyExists $versionMismatch .RawVersion)) (not .IgnoreInTest) (not .ReadOnly)}}{{$overwritePropertyName := overwriteProperty .PkgName .SnakeCaseName $.Definitions}} {{- if .DefaultValue}} {{- if eq .ValueType "bitmask"}} {{- if lt 0 (len (overwritePropertyValue .PkgName $overwritePropertyName .DefaultValue "default" 0 $.Definitions))}} @@ -30,9 +32,52 @@ default: {{- end}} {{- end}} {{- end}}{{- end}} + {{- if $versionMismatchExists}} + {{- $properties := .Properties }} + version_mismatch: + {{- range $versionMismatchNumber, $propertyNames := $versionMismatch }} + {{- $printedVersionMismatchNumberAll := false }} + {{- range $propertyNames }} + {{- $propertyInMismatch := .}} + {{- range $properties}} + {{- if eq .PropertyName $propertyInMismatch}} + {{- if not $printedVersionMismatchNumberAll }} + {{- $printedVersionMismatchNumberAll = true }} + {{ $versionMismatchNumber }}: + {{- end }} + {{- $overwritePropertyName := overwriteProperty .PkgName .SnakeCaseName $.Definitions}} + {{- if .DefaultValue}} + {{- if eq .ValueType "bitmask"}} + {{- if lt 0 (len (overwritePropertyValue .PkgName $overwritePropertyName .DefaultValue "default" 0 $.Definitions))}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: {{range $index, $value := (overwritePropertyValue .PkgName $overwritePropertyName .DefaultValue "default" 0 $.Definitions)}} + - "{{ $value}}" + {{- end}} + {{- else}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: [] + {{- end}} + {{- else}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: "{{overwritePropertyValue .PkgName $overwritePropertyName .DefaultValue "default" 0 $.Definitions}}" + {{- end}} + {{- else if not .IsNaming}} + {{- if eq .ValueType "bitmask"}} + {{- if lt 0 (len (overwritePropertyValue .PkgName $overwritePropertyName "" "default" 0 $.Definitions))}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: {{range $index, $value := (overwritePropertyValue .PkgName $overwritePropertyName "" "default" 0 $.Definitions)}} + - "{{ $value}}" + {{- end}} + {{- else}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: [] + {{- end}} + {{- else}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: "{{overwritePropertyValue .PkgName $overwritePropertyName "" "default" 0 $.Definitions}}" + {{- end}} + {{- end}} + {{- end}}{{- end}} + {{- end}} + {{- end}} + {{- end}} {{ if .HasNaming }} datasource_non_existing: - {{- range .Properties}}{{- if and (not .IgnoreInTest) (not .ReadOnly)}}{{$testValue := createNonExistingValue .SnakeCaseName}}{{$overwritePropertyName := overwriteProperty .PkgName .SnakeCaseName $.Definitions}} + {{- range .Properties}}{{- if and (not (keyExists $versionMismatch .RawVersion)) (not .IgnoreInTest) (not .ReadOnly)}}{{$testValue := createNonExistingValue .SnakeCaseName}}{{$overwritePropertyName := overwriteProperty .PkgName .SnakeCaseName $.Definitions}} {{- if .IsNaming }} {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: "{{overwritePropertyValue .PkgName $overwritePropertyName $testValue "datasource_non_existing" 0 $.Definitions}}" {{- end}} @@ -72,7 +117,8 @@ read_only: {{- end}} all: - {{- range .Properties}}{{- if and (not .IgnoreInTest) (not .ReadOnly)}}{{$overwritePropertyName := overwriteProperty .PkgName .SnakeCaseName $.Definitions}} + {{- $versionMismatchExists = false}} + {{- range .Properties}}{{- if keyExists $versionMismatch .RawVersion}}{{$versionMismatchExists = true}}{{- end}}{{- if and (not (keyExists $versionMismatch .RawVersion)) (not .IgnoreInTest) (not .ReadOnly)}}{{$overwritePropertyName := overwriteProperty .PkgName .SnakeCaseName $.Definitions}} {{- if overwriteProperty .PkgName .SnakeCaseName $.Definitions | eq "annotation"}} {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: "annotation" {{- else if .DefaultValue}}{{$length := len .ValidValues}} @@ -103,24 +149,137 @@ all: {{- end}} {{- end}} {{- end}}{{- end}} + {{- if $versionMismatchExists}} + {{- $properties := .Properties }} + version_mismatch: + {{- range $versionMismatchNumber, $propertyNames := $versionMismatch }} + {{- $printedVersionMismatchNumberAll := false }} + {{- range $propertyNames }} + {{- $propertyInMismatch := .}} + {{- range $properties}} + {{- if eq .PropertyName $propertyInMismatch}} + {{- if not $printedVersionMismatchNumberAll }} + {{- $printedVersionMismatchNumberAll = true }} + {{ $versionMismatchNumber }}: + {{- end }} + {{- $overwritePropertyName := overwriteProperty .PkgName .SnakeCaseName $.Definitions}} + {{- if .DefaultValue}}{{$length := len .ValidValues}} + {{- if eq .ValueType "bitmask"}} + {{- if lt 0 (len (overwritePropertyValue .PkgName $overwritePropertyName .DefaultValue "all" 0 $.Definitions))}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: {{range $index, $value := (overwritePropertyValue .PkgName $overwritePropertyName .DefaultValue "all" 0 $.Definitions)}} + - "{{ $value}}" + {{- end}} + {{- else}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: [] + {{- end}} + {{- else if eq $length 0}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: "{{overwritePropertyValue .PkgName $overwritePropertyName .DefaultValue "all" 0 $.Definitions}}" + {{- else }}{{$testValue := index .ValidValues 0 }} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: "{{overwritePropertyValue .PkgName $overwritePropertyName $testValue "all" 0 $.Definitions}}" + {{- end}} + {{- else if not .IsNaming}} + {{- if eq .ValueType "bitmask"}} + {{- if lt 0 (len (overwritePropertyValue .PkgName $overwritePropertyName $overwritePropertyName "all" 0 $.Definitions))}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: {{range $index, $value := (overwritePropertyValue .PkgName $overwritePropertyName $overwritePropertyName "all" 0 $.Definitions)}} + - "{{ $value}}" + {{- end}} + {{- else}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: [] + {{- end}} + {{- else}} + {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: "{{overwritePropertyValue .PkgName $overwritePropertyName $overwritePropertyName "all" 0 $.Definitions}}" + {{- end}} + {{- end}} + {{- end}} + {{- end}} + {{- end}} + {{- end}} + {{- end}} {{ if .Children}} children: {{- range $key, $value := .Children}}{{$name := .ResourceName}}{{$child_deletable := .AllowDelete}} {{overwriteProperty .PkgName .ResourceName $.Definitions}}: {{- if or (not .IdentifiedBy) .MaxOneClassAllowed}} - - {{ range .Properties}}{{$overwritePropertyName := overwriteProperty .PkgName .SnakeCaseName $.Definitions}}{{- if and (not .IgnoreInTest) (not .ReadOnly)}}{{$overwritePropertyName}}: {{$length := len .ValidValues}}{{if ne $length 0}}"{{ index .ValidValues 0 }}"{{else if not .IsNaming}}"{{overwritePropertyValue .PkgName $overwritePropertyName $overwritePropertyName "all" 0 $.Definitions }}"{{- else}}"{{lookupChildTestValue .PkgName $.ResourceName .SnakeCaseName $.TestVars 0 $.Definitions}}"{{- end}} + {{- $versionMismatchExists = false}} + - {{ range .Properties}}{{- if keyExists $versionMismatch .RawVersion}}{{$versionMismatchExists = true}}{{- end}}{{$overwritePropertyName := overwriteProperty .PkgName .SnakeCaseName $.Definitions}}{{- if and (not (keyExists $versionMismatch .RawVersion)) (not .IgnoreInTest) (not .ReadOnly)}}{{$overwritePropertyName}}: {{$length := len .ValidValues}}{{if ne $length 0}}"{{ index .ValidValues 0 }}"{{else if not .IsNaming}}"{{overwritePropertyValue .PkgName $overwritePropertyName $overwritePropertyName "all" 0 $.Definitions }}"{{- else}}"{{lookupChildTestValue .PkgName $.ResourceName .SnakeCaseName $.TestVars 0 $.Definitions}}"{{- end}} {{ end}}{{ end}} {{- if $child_deletable -}} deletable_child: true {{- else -}} deletable_child: false {{ end}} + {{- if $versionMismatchExists}} + {{- $properties := .Properties }} + version_mismatch: + {{- range $versionMismatchNumber, $propertyNames := $versionMismatch }} + {{- $printedVersionMismatchNumberChildOne := false }} + {{- range $propertyNames }} + {{- $propertyInMismatch := .}} + {{- range $properties}} + {{- if eq .PropertyName $propertyInMismatch}} + {{- if not $printedVersionMismatchNumberChildOne }} + {{- $printedVersionMismatchNumberChildOne = true }} + {{ $versionMismatchNumber }}: + {{- end }} + {{- $overwritePropertyName := overwriteProperty .PkgName .SnakeCaseName $.Definitions}} + {{$overwritePropertyName}}: {{$length := len .ValidValues}}{{if ne $length 0}}"{{ index .ValidValues 0 }}"{{else if not .IsNaming}}"{{overwritePropertyValue .PkgName $overwritePropertyName $overwritePropertyName "all" 0 $.Definitions }}"{{- else}}"{{lookupChildTestValue .PkgName $.ResourceName .SnakeCaseName $.TestVars 0 $.Definitions}}" + {{- end}} + {{- end}} + {{- end}} + {{- end}} + {{- end}} + {{- end}} {{- else}} - - {{ range .Properties}}{{$overwritePropertyName := overwriteProperty .PkgName .SnakeCaseName $.Definitions}}{{- if and (not .IgnoreInTest) (not .ReadOnly)}}{{$overwritePropertyName}}: {{$length := len .ValidValues}}{{if ne $length 0}}"{{ index .ValidValues 0 }}"{{else if not .IsNaming}}"{{overwritePropertyValue .PkgName $overwritePropertyName $overwritePropertyName "all" 0 $.Definitions }}"{{- else}}"{{lookupChildTestValue .PkgName $.ResourceName .SnakeCaseName $.TestVars 0 $.Definitions}}"{{- end}} + {{- $versionMismatchExists = false}} + - {{ range .Properties}}{{- if keyExists $versionMismatch .RawVersion}}{{$versionMismatchExists = true}}{{- end}}{{$overwritePropertyName := overwriteProperty .PkgName .SnakeCaseName $.Definitions}}{{- if and (not (keyExists $versionMismatch .RawVersion)) (not .IgnoreInTest) (not .ReadOnly)}}{{$overwritePropertyName}}: {{$length := len .ValidValues}}{{if ne $length 0}}"{{ index .ValidValues 0 }}"{{else if not .IsNaming}}"{{overwritePropertyValue .PkgName $overwritePropertyName $overwritePropertyName "all" 0 $.Definitions }}"{{- else}}"{{lookupChildTestValue .PkgName $.ResourceName .SnakeCaseName $.TestVars 0 $.Definitions}}"{{- end}} {{ end}}{{ end}} - - {{ range .Properties}}{{$overwritePropertyName := overwriteProperty .PkgName .SnakeCaseName $.Definitions}}{{- if and (not .IgnoreInTest) (not .ReadOnly)}}{{$overwritePropertyName}}: {{$length := len .ValidValues}}{{if ge $length 2}}"{{ index .ValidValues 1 }}"{{else if not .IsNaming}}"{{overwritePropertyValue .PkgName $overwritePropertyName $overwritePropertyName "default" 0 $.Definitions }}"{{- else}}"{{lookupChildTestValue .PkgName $.ResourceName .SnakeCaseName $.TestVars 1 $.Definitions}}"{{- end}} - {{ end}}{{- end}}{{- end}}{{- end}}{{ end}} -{{- if .ContainedBy}} + {{- if $versionMismatchExists}} + {{- $properties := .Properties }} + version_mismatch: + {{- range $versionMismatchNumber, $propertyNames := $versionMismatch }} + {{- $printedVersionMismatchNumberChildTwo := false }} + {{- range $propertyNames }} + {{- $propertyInMismatch := .}} + {{- range $properties}} + {{- if eq .PropertyName $propertyInMismatch}} + {{- if not $printedVersionMismatchNumberChildTwo }} + {{- $printedVersionMismatchNumberChildTwo = true }} + {{ $versionMismatchNumber }}: + {{- end }} + {{- $overwritePropertyName := overwriteProperty .PkgName .SnakeCaseName $.Definitions}} + {{$overwritePropertyName}}: {{$length := len .ValidValues}}{{if ne $length 0}}"{{ index .ValidValues 0 }}"{{else if not .IsNaming}}"{{overwritePropertyValue .PkgName $overwritePropertyName $overwritePropertyName "all" 0 $.Definitions }}"{{- else}}"{{lookupChildTestValue .PkgName $.ResourceName .SnakeCaseName $.TestVars 0 $.Definitions}}" + {{- end}} + {{- end}} + {{- end}} + {{- end}} + {{- end}} + {{- end}} + {{- $versionMismatchExists = false}} + - {{ range .Properties}}{{- if keyExists $versionMismatch .RawVersion}}{{$versionMismatchExists = true}}{{- end}}{{$overwritePropertyName := overwriteProperty .PkgName .SnakeCaseName $.Definitions}}{{- if and (not (keyExists $versionMismatch .RawVersion)) (not .IgnoreInTest) (not .ReadOnly)}}{{$overwritePropertyName}}: {{$length := len .ValidValues}}{{if ge $length 2}}"{{ index .ValidValues 1 }}"{{else if not .IsNaming}}"{{overwritePropertyValue .PkgName $overwritePropertyName $overwritePropertyName "default" 0 $.Definitions }}"{{- else}}"{{lookupChildTestValue .PkgName $.ResourceName .SnakeCaseName $.TestVars 1 $.Definitions}}"{{- end}} + {{ end}}{{- end}} + {{- if $versionMismatchExists}} + {{- $properties := .Properties }} + version_mismatch: + {{- range $versionMismatchNumber, $propertyNames := $versionMismatch }} + {{- $printedVersionMismatchNumberChildThree := false }} + {{- range $propertyNames }} + {{- $propertyInMismatch := .}} + {{- range $properties}} + {{- if eq .PropertyName $propertyInMismatch}} + {{- if not $printedVersionMismatchNumberChildThree }} + {{- $printedVersionMismatchNumberChildThree = true }} + {{ $versionMismatchNumber }}: + {{- end }} + {{- $overwritePropertyName := overwriteProperty .PkgName .SnakeCaseName $.Definitions}} + {{$overwritePropertyName}}: {{$length := len .ValidValues}}{{if ge $length 2}}"{{ index .ValidValues 1 }}"{{else if not .IsNaming}}"{{overwritePropertyValue .PkgName $overwritePropertyName $overwritePropertyName "default" 0 $.Definitions }}"{{- else}}"{{lookupChildTestValue .PkgName $.ResourceName .SnakeCaseName $.TestVars 1 $.Definitions}}" + {{- end}} + {{- end}} + {{- end}} + {{- end}} + {{- end}} + {{- end}} + {{- end}}{{- end}}{{ end}} +{{- if and .ContainedBy (not .MultiParentFormats)}} parents: {{- $index := 0}}{{- range $key := .DocumentationExamples}}{{$parentDependency := getParentTestDependencies $.PkgName $index $.Definitions}}{{$index = add $index 1}} - class_name: "{{ $key }}" @@ -134,8 +293,9 @@ parents: target_classes: {{- range $parentDependency.target_classes}} - "{{ . }}" - {{- end}} - {{- end}} + {{- end }} + {{- end }} + test_type: {{$.TestType}} {{- end}} {{- if .TestDependencies}} targets: @@ -182,3 +342,64 @@ child_targets: {{- end }} {{- end}} {{- end}} + +{{- if .MultiParentFormats}} +parents: +{{- $topContext := . -}} +{{- range $key, $value := .MultiParentFormats }}{{$parentDependency := getParentTestDependencies $topContext.PkgName 0 $topContext.Definitions}} + - class_name: "{{ $value.ContainedBy }}" + parent_dependency: "{{ $parentDependency.parent_dependency }}" + parent_dn: {{ if eq $key "default" }}""{{ else }}"{{ createParentDnValue $value.ContainedBy "test" $topContext.Definitions }}"{{ end }} + class_in_parent: false + target_classes: + {{- range $parentDependency.target_classes}} + - "{{ . }}" + {{- end}} + {{- $testType := $value.TestType }} + {{- if $testType }} + test_type: {{ $testType }} + {{- else }} + test_type: both + {{- end }} +{{- end }} + +{{- if .TestDependencies}} +targets: + {{- range .TestDependencies }} + - class_name: "{{ .ClassName }}" + target_dn: "{{ .TargetDn }}" + target_dn_ref: "{{ .TargetDnRef }}" + parent_dependency: "{{ .ParentDependency}}" + parent_dependency_dn_ref: "{{.ParentDependencyDnRef}}" + target_resource_name: "{{ .TargetResourceName }}" + relation_resource_name: "{{ .RelationResourceName }}" + parent_dn_key: "{{ .ParentDnKey }}" + properties: + {{- range $key, $value := .Properties}} + {{ $key }}: "{{ $value }}" + {{- end }} + {{- end }} +{{- end }} +{{- end }} + +{{- if or (and (not .ContainedBy) (not .MultiParentFormats)) (and (.ContainedBy) (not .DocumentationExamples) (not .MultiParentFormats)) }} +test_type: {{ .TestType }} +{{- end }} +class_version: {{.ClassVersion}} +{{ $exists_exclude := false -}} +{{- range .Properties }} + {{- if eq .ValueType "password" }} + {{- $exists_exclude = true -}} + {{- end }} +{{- end }} +{{- if $exists_exclude }} +exclude_attributes: + {{- range .Properties }} + {{- if eq .ValueType "password" }} + - "{{ overwriteProperty .PkgName .SnakeCaseName $.Definitions }}" + {{- end }} + {{- end }} +{{- end }} +{{- if gt (len $versionMismatch) 0 }} +version_mismatch: true +{{- end }} \ No newline at end of file diff --git a/gen/testvars/fhsTrustCtrlPol.yaml b/gen/testvars/fhsTrustCtrlPol.yaml index 2f0c7193c..06ad863c0 100644 --- a/gen/testvars/fhsTrustCtrlPol.yaml +++ b/gen/testvars/fhsTrustCtrlPol.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -57,3 +58,5 @@ parents: parent_dependency: "" parent_dn: "aci_tenant.test.id" class_in_parent: false + test_type: both +class_version: 3.0(1k)- diff --git a/gen/testvars/fvAEPg.yaml b/gen/testvars/fvAEPg.yaml index 449664a62..66cb1e47d 100644 --- a/gen/testvars/fvAEPg.yaml +++ b/gen/testvars/fvAEPg.yaml @@ -2,20 +2,23 @@ # 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: "" contract_exception_tag: "" flood_in_encapsulation: "disabled" forwarding_control: "none" - has_multicast_source: "no" useg_epg: "no" match_criteria: "AtleastOne" name_alias: "" intra_epg_isolation: "unenforced" preferred_group_member: "exclude" priority: "unspecified" - admin_state: "no" + version_mismatch: + 4.0(1h): + has_multicast_source: "no" + admin_state: "no" datasource_non_existing: name: "non_existing_name" @@ -39,14 +42,16 @@ all: contract_exception_tag: "contract_exception_tag_1" flood_in_encapsulation: "disabled" forwarding_control: "proxy-arp" - has_multicast_source: "no" useg_epg: "no" match_criteria: "All" name_alias: "name_alias_1" intra_epg_isolation: "enforced" preferred_group_member: "exclude" priority: "level1" - admin_state: "no" + version_mismatch: + 4.0(1h): + has_multicast_source: "no" + admin_state: "no" children: epg_useg_block_statement: @@ -57,9 +62,11 @@ children: name_alias: "name_alias_1" owner_key: "owner_key_1" owner_tag: "owner_tag_1" - precedence: "1" - scope: "scope-bd" deletable_child: true + version_mismatch: + 4.1(1i): + precedence: "1" + scope: "scope-bd" relation_to_application_epg_monitoring_policy: - annotation: "annotation_1" monitoring_policy_name: "monitoring_policy_name_1" @@ -94,9 +101,7 @@ children: relation_to_domains: - annotation: "annotation_1" - binding_type: "dynamicBinding" class_preference: "encap" - custom_epg_name: "custom_epg_name_1" delimiter: "@" encapsulation: "vlan-100" encapsulation_mode: "auto" @@ -106,8 +111,6 @@ children: lag_policy_name: "lag_policy_name_1" netflow_direction: "both" enable_netflow: "disabled" - number_of_ports: "1" - port_allocation: "elastic" primary_encapsulation: "vlan-200" primary_encapsulation_inner: "vlan-300" resolution_immediacy: "immediate" @@ -115,12 +118,16 @@ children: switching_mode: "AVE" target_dn: "target_dn_0" untagged: "no" - vnet_only: "no" + version_mismatch: + 4.0(1h): + binding_type: "dynamicBinding" + number_of_ports: "1" + port_allocation: "elastic" + 4.2(3j): + custom_epg_name: "custom_epg_name_1" - annotation: "annotation_2" - binding_type: "ephemeral" class_preference: "useg" - custom_epg_name: "custom_epg_name_2" delimiter: "" encapsulation: "unknown" encapsulation_mode: "vlan" @@ -130,8 +137,6 @@ children: lag_policy_name: "lag_policy_name_2" netflow_direction: "egress" enable_netflow: "enabled" - number_of_ports: "0" - port_allocation: "fixed" primary_encapsulation: "unknown" primary_encapsulation_inner: "unknown" resolution_immediacy: "lazy" @@ -139,8 +144,14 @@ children: switching_mode: "native" target_dn: "target_dn_1" untagged: "yes" - vnet_only: "yes" + version_mismatch: + 4.0(1h): + binding_type: "ephemeral" + number_of_ports: "0" + port_allocation: "fixed" + 4.2(3j): + custom_epg_name: "custom_epg_name_2" relation_to_data_plane_policing_policy: - annotation: "annotation_1" data_plane_policing_policy_name: "data_plane_policing_policy_name_1" @@ -245,6 +256,7 @@ parents: parent_dependency: "fvTenant" parent_dn: "aci_application_profile.test.id" class_in_parent: false + test_type: apic child_targets: - class_name: "vmmDomP" target_dn: "uni/vmmp-VMware/dom-domain_1" @@ -300,3 +312,6 @@ child_targets: parent_dn_key: "application_profile_dn" properties: name: "epg_3" +class_version: 1.0(1e)- + +version_mismatch: true \ No newline at end of file diff --git a/gen/testvars/fvCrtrn.yaml b/gen/testvars/fvCrtrn.yaml index 071f0a25d..113066237 100644 --- a/gen/testvars/fvCrtrn.yaml +++ b/gen/testvars/fvCrtrn.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -10,8 +11,10 @@ default: name_alias: "" owner_key: "" owner_tag: "" - precedence: "0" - scope: "scope-bd" + version_mismatch: + 4.1(1i): + precedence: "0" + scope: "scope-bd" all: @@ -22,8 +25,10 @@ all: name_alias: "name_alias_1" owner_key: "owner_key_1" owner_tag: "owner_tag_1" - precedence: "1" - scope: "scope-bd" + version_mismatch: + 4.1(1i): + precedence: "1" + scope: "scope-bd" children: annotations: @@ -45,3 +50,7 @@ parents: parent_dependency: "" parent_dn: "aci_application_epg.test.id" class_in_parent: false + test_type: apic +class_version: 1.1(1j)- + +version_mismatch: true \ No newline at end of file diff --git a/gen/testvars/fvDnsAttr.yaml b/gen/testvars/fvDnsAttr.yaml index 23cc9e140..127b4eef4 100644 --- a/gen/testvars/fvDnsAttr.yaml +++ b/gen/testvars/fvDnsAttr.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -47,3 +48,5 @@ parents: parent_dependency: "fvAEPg" parent_dn: "aci_epg_useg_block_statement.test.id" class_in_parent: false + test_type: apic +class_version: 2.3(1e)- diff --git a/gen/testvars/fvESg.yaml b/gen/testvars/fvESg.yaml index b810f0f49..a51b127a1 100644 --- a/gen/testvars/fvESg.yaml +++ b/gen/testvars/fvESg.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -10,7 +11,9 @@ default: name_alias: "" intra_esg_isolation: "unenforced" preferred_group_member: "exclude" - admin_state: "no" + version_mismatch: + 5.2(1g): + admin_state: "no" datasource_non_existing: name: "non_existing_name" @@ -32,7 +35,9 @@ all: name_alias: "name_alias_1" intra_esg_isolation: "enforced" preferred_group_member: "exclude" - admin_state: "no" + version_mismatch: + 5.2(1g): + admin_state: "no" children: relation_to_consumed_contracts: @@ -102,6 +107,7 @@ parents: parent_dependency: "fvTenant" parent_dn: "aci_application_profile.test.id" class_in_parent: false + test_type: apic child_targets: - class_name: "fvESg" target_dn: "uni/tn-test_tenant/ap-test_ap/esg-esg_0" @@ -125,3 +131,6 @@ child_targets: parent_dn_key: "application_profile_dn" properties: name: "esg_1" +class_version: 5.0(1k)- + +version_mismatch: true \ No newline at end of file diff --git a/gen/testvars/fvEpIpTag.yaml b/gen/testvars/fvEpIpTag.yaml index f6089b3d9..0441222c5 100644 --- a/gen/testvars/fvEpIpTag.yaml +++ b/gen/testvars/fvEpIpTag.yaml @@ -2,6 +2,7 @@ # 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" id_attribute: "0" @@ -46,3 +47,5 @@ parents: parent_dependency: "" parent_dn: "aci_tenant.test.id" class_in_parent: false + test_type: apic +class_version: 5.2(1g)- diff --git a/gen/testvars/fvEpMacTag.yaml b/gen/testvars/fvEpMacTag.yaml index 5ac907fd9..bb0446763 100644 --- a/gen/testvars/fvEpMacTag.yaml +++ b/gen/testvars/fvEpMacTag.yaml @@ -2,6 +2,7 @@ # 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" id_attribute: "0" @@ -46,3 +47,5 @@ parents: parent_dependency: "" parent_dn: "aci_tenant.test.id" class_in_parent: false + test_type: apic +class_version: 5.2(1g)- diff --git a/gen/testvars/fvFBRGroup.yaml b/gen/testvars/fvFBRGroup.yaml index d7a4f0795..ae7ee0160 100644 --- a/gen/testvars/fvFBRGroup.yaml +++ b/gen/testvars/fvFBRGroup.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -61,3 +62,5 @@ parents: parent_dependency: "fvTenant" parent_dn: "aci_vrf.test.id" class_in_parent: false + test_type: both +class_version: 5.2(4d)- diff --git a/gen/testvars/fvFBRMember.yaml b/gen/testvars/fvFBRMember.yaml index 14477bfbb..bcb6444d4 100644 --- a/gen/testvars/fvFBRMember.yaml +++ b/gen/testvars/fvFBRMember.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -43,3 +44,5 @@ parents: parent_dependency: "fvCtx" parent_dn: "aci_vrf_fallback_route_group.test.id" class_in_parent: false + test_type: both +class_version: 5.2(4d)- diff --git a/gen/testvars/fvFBRoute.yaml b/gen/testvars/fvFBRoute.yaml index b0d56fd6b..3dcb52ce5 100644 --- a/gen/testvars/fvFBRoute.yaml +++ b/gen/testvars/fvFBRoute.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -43,3 +44,5 @@ parents: parent_dependency: "fvCtx" parent_dn: "aci_vrf_fallback_route_group.test.id" class_in_parent: false + test_type: both +class_version: 5.2(4d)- diff --git a/gen/testvars/fvIdGroupAttr.yaml b/gen/testvars/fvIdGroupAttr.yaml index b37f0226c..ce0ca6dc3 100644 --- a/gen/testvars/fvIdGroupAttr.yaml +++ b/gen/testvars/fvIdGroupAttr.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -47,3 +48,5 @@ parents: parent_dependency: "fvAEPg" parent_dn: "aci_epg_useg_block_statement.test.id" class_in_parent: false + test_type: apic +class_version: 3.2(10e)- diff --git a/gen/testvars/fvIpAttr.yaml b/gen/testvars/fvIpAttr.yaml index a230834c3..dacdf50ab 100644 --- a/gen/testvars/fvIpAttr.yaml +++ b/gen/testvars/fvIpAttr.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -50,3 +51,5 @@ parents: parent_dependency: "fvAEPg" parent_dn: "aci_epg_useg_block_statement.test.id" class_in_parent: false + test_type: apic +class_version: 1.1(1j)- diff --git a/gen/testvars/fvMacAttr.yaml b/gen/testvars/fvMacAttr.yaml index c83fa86c7..9d8325e6c 100644 --- a/gen/testvars/fvMacAttr.yaml +++ b/gen/testvars/fvMacAttr.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -48,3 +49,5 @@ parents: parent_dependency: "fvAEPg" parent_dn: "aci_epg_useg_block_statement.test.id" class_in_parent: false + test_type: apic +class_version: 1.1(1j)- diff --git a/gen/testvars/fvRsCons.yaml b/gen/testvars/fvRsCons.yaml index b7a74742a..f47cd0bc5 100644 --- a/gen/testvars/fvRsCons.yaml +++ b/gen/testvars/fvRsCons.yaml @@ -2,6 +2,7 @@ # 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" priority: "unspecified" @@ -43,7 +44,10 @@ parents: parent_dependency: "fvAp" parent_dn: "aci_application_epg.test.id" class_in_parent: false + test_type: both - class_name: "fvESg" parent_dependency: "fvAp" parent_dn: "aci_endpoint_security_group.test.id" class_in_parent: false + test_type: both +class_version: 1.0(1e)- diff --git a/gen/testvars/fvRsConsIf.yaml b/gen/testvars/fvRsConsIf.yaml index 33e74dbe3..4be226909 100644 --- a/gen/testvars/fvRsConsIf.yaml +++ b/gen/testvars/fvRsConsIf.yaml @@ -2,6 +2,7 @@ # 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" priority: "unspecified" @@ -43,7 +44,10 @@ parents: parent_dependency: "fvAp" parent_dn: "aci_application_epg.test.id" class_in_parent: false + test_type: both - class_name: "fvESg" parent_dependency: "fvAp" parent_dn: "aci_endpoint_security_group.test.id" class_in_parent: false + test_type: both +class_version: 1.0(1e)- diff --git a/gen/testvars/fvRsDomAtt.yaml b/gen/testvars/fvRsDomAtt.yaml index fe6e2c78d..d55d78d1e 100644 --- a/gen/testvars/fvRsDomAtt.yaml +++ b/gen/testvars/fvRsDomAtt.yaml @@ -2,11 +2,10 @@ # 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" - binding_type: "none" class_preference: "encap" - custom_epg_name: "" delimiter: "" encapsulation: "unknown" encapsulation_mode: "auto" @@ -16,15 +15,19 @@ default: lag_policy_name: "" netflow_direction: "both" enable_netflow: "disabled" - number_of_ports: "0" - port_allocation: "none" primary_encapsulation: "unknown" primary_encapsulation_inner: "unknown" resolution_immediacy: "lazy" secondary_encapsulation_inner: "unknown" switching_mode: "native" untagged: "no" - vnet_only: "no" + version_mismatch: + 4.0(1h): + binding_type: "none" + number_of_ports: "0" + port_allocation: "none" + 4.2(3j): + custom_epg_name: "" datasource_non_existing: target_dn: "non_existing_t_dn" @@ -37,9 +40,7 @@ resource_required: all: annotation: "annotation" - binding_type: "dynamicBinding" class_preference: "encap" - custom_epg_name: "custom_epg_name_1" delimiter: "@" encapsulation: "vlan-100" encapsulation_mode: "auto" @@ -49,15 +50,19 @@ all: lag_policy_name: "lag_policy_name_1" netflow_direction: "both" enable_netflow: "disabled" - number_of_ports: "1" - port_allocation: "elastic" primary_encapsulation: "vlan-200" primary_encapsulation_inner: "vlan-300" resolution_immediacy: "immediate" secondary_encapsulation_inner: "vlan-400" switching_mode: "AVE" untagged: "no" - vnet_only: "no" + version_mismatch: + 4.0(1h): + binding_type: "dynamicBinding" + number_of_ports: "1" + port_allocation: "elastic" + 4.2(3j): + custom_epg_name: "custom_epg_name_1" children: annotations: @@ -81,6 +86,7 @@ parents: class_in_parent: false target_classes: - "vmmDomP" + test_type: apic targets: - class_name: "vmmDomP" target_dn: "uni/vmmp-VMware/dom-domain_1" @@ -102,3 +108,6 @@ targets: parent_dn_key: "parent_dn" static: true properties: +class_version: 1.0(1e)- + +version_mismatch: true \ No newline at end of file diff --git a/gen/testvars/fvRsFcPathAtt.yaml b/gen/testvars/fvRsFcPathAtt.yaml index 14b75b753..73188ab87 100644 --- a/gen/testvars/fvRsFcPathAtt.yaml +++ b/gen/testvars/fvRsFcPathAtt.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -45,6 +46,7 @@ parents: class_in_parent: false target_classes: - "fabricPathEp" + test_type: apic targets: - class_name: "fabricPathEp" target_dn: "topology/pod-1/paths-101/pathep-[eth1/1]" @@ -66,3 +68,4 @@ targets: parent_dn_key: "parent_dn" static: true properties: +class_version: 2.0(1m)- diff --git a/gen/testvars/fvRsIntraEpg.yaml b/gen/testvars/fvRsIntraEpg.yaml index 50e6d6792..8211871b4 100644 --- a/gen/testvars/fvRsIntraEpg.yaml +++ b/gen/testvars/fvRsIntraEpg.yaml @@ -2,6 +2,7 @@ # 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" @@ -37,7 +38,10 @@ parents: parent_dependency: "fvAp" parent_dn: "aci_application_epg.test.id" class_in_parent: false + test_type: both - class_name: "fvESg" parent_dependency: "fvAp" parent_dn: "aci_endpoint_security_group.test.id" class_in_parent: false + test_type: both +class_version: 3.0(1k)- diff --git a/gen/testvars/fvRsNodeAtt.yaml b/gen/testvars/fvRsNodeAtt.yaml index 547d2734d..6acfa1014 100644 --- a/gen/testvars/fvRsNodeAtt.yaml +++ b/gen/testvars/fvRsNodeAtt.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -48,6 +49,7 @@ parents: class_in_parent: false target_classes: - "fabricNode" + test_type: apic targets: - class_name: "fabricNode" target_dn: "topology/pod-1/node-101" @@ -69,3 +71,4 @@ targets: parent_dn_key: "parent_dn" static: true properties: +class_version: 1.0(1e)- diff --git a/gen/testvars/fvRsPathAtt.yaml b/gen/testvars/fvRsPathAtt.yaml index 3325e154c..4bb06854d 100644 --- a/gen/testvars/fvRsPathAtt.yaml +++ b/gen/testvars/fvRsPathAtt.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -50,6 +51,7 @@ parents: class_in_parent: false target_classes: - "fabricPathEp" + test_type: apic targets: - class_name: "fabricPathEp" target_dn: "topology/pod-1/paths-101/pathep-[eth1/1]" @@ -71,3 +73,4 @@ targets: parent_dn_key: "parent_dn" static: true properties: +class_version: 1.0(1e)- diff --git a/gen/testvars/fvRsProtBy.yaml b/gen/testvars/fvRsProtBy.yaml index 839e41a70..5d8ca6662 100644 --- a/gen/testvars/fvRsProtBy.yaml +++ b/gen/testvars/fvRsProtBy.yaml @@ -2,6 +2,7 @@ # 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" @@ -37,3 +38,5 @@ parents: parent_dependency: "fvAp" parent_dn: "aci_application_epg.test.id" class_in_parent: false + test_type: both +class_version: 1.0(1e)- diff --git a/gen/testvars/fvRsProv.yaml b/gen/testvars/fvRsProv.yaml index c02c0ea41..4c1e00434 100644 --- a/gen/testvars/fvRsProv.yaml +++ b/gen/testvars/fvRsProv.yaml @@ -2,6 +2,7 @@ # 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" match_criteria: "AtleastOne" @@ -45,7 +46,10 @@ parents: parent_dependency: "fvAp" parent_dn: "aci_application_epg.test.id" class_in_parent: false + test_type: both - class_name: "fvESg" parent_dependency: "fvAp" parent_dn: "aci_endpoint_security_group.test.id" class_in_parent: false + test_type: both +class_version: 1.0(1e)- diff --git a/gen/testvars/fvRsSecInherited.yaml b/gen/testvars/fvRsSecInherited.yaml index 1da67d6d7..ad9bb7d49 100644 --- a/gen/testvars/fvRsSecInherited.yaml +++ b/gen/testvars/fvRsSecInherited.yaml @@ -2,6 +2,7 @@ # 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" @@ -39,12 +40,14 @@ parents: class_in_parent: false target_classes: - "fvAEPg" + test_type: both - class_name: "fvESg" parent_dependency: "fvAp" parent_dn: "aci_endpoint_security_group.test.id" class_in_parent: false target_classes: - "fvESg" + test_type: both targets: - class_name: "fvESg" target_dn: "uni/tn-test_tenant/ap-test_ap/esg-esg_0" @@ -90,3 +93,4 @@ targets: static: false properties: name: "epg_3" +class_version: 2.3(1e)- diff --git a/gen/testvars/fvSCrtrn.yaml b/gen/testvars/fvSCrtrn.yaml index 8885d235c..a82ddee88 100644 --- a/gen/testvars/fvSCrtrn.yaml +++ b/gen/testvars/fvSCrtrn.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -47,7 +48,10 @@ parents: parent_dependency: "fvAEPg" parent_dn: "aci_epg_useg_block_statement.test.id" class_in_parent: false + test_type: apic - class_name: "fvSCrtrn" parent_dependency: "fvCrtrn" parent_dn: "aci_epg_useg_sub_block_statement.test.id" class_in_parent: false + test_type: apic +class_version: 1.2(1i)- diff --git a/gen/testvars/fvVmAttr.yaml b/gen/testvars/fvVmAttr.yaml index b5bcbb294..a0410f598 100644 --- a/gen/testvars/fvVmAttr.yaml +++ b/gen/testvars/fvVmAttr.yaml @@ -2,6 +2,7 @@ # 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" category: "" @@ -56,7 +57,10 @@ parents: parent_dependency: "fvAEPg" parent_dn: "aci_epg_useg_block_statement.test.id" class_in_parent: false + test_type: apic - class_name: "fvSCrtrn" parent_dependency: "fvCrtrn" parent_dn: "aci_epg_useg_sub_block_statement.test.id" class_in_parent: false + test_type: apic +class_version: 1.1(1j)- diff --git a/gen/testvars/infraHPathS.yaml b/gen/testvars/infraHPathS.yaml index 762f04161..27a3f1f72 100644 --- a/gen/testvars/infraHPathS.yaml +++ b/gen/testvars/infraHPathS.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -58,3 +59,5 @@ child_targets: target_dn: "uni/infra/funcprof/accportgrp-access_interface_policy_group" relation_resource_name: "access_interface_policy_group" static: true +test_type: apic +class_version: 1.1(1j)- diff --git a/gen/testvars/l3extConsLbl.yaml b/gen/testvars/l3extConsLbl.yaml index 6d62cb004..05c7d9cfa 100644 --- a/gen/testvars/l3extConsLbl.yaml +++ b/gen/testvars/l3extConsLbl.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -65,6 +66,7 @@ parents: parent_dependency: "" parent_dn: "aci_l3_outside.test.id" class_in_parent: false + test_type: apic child_targets: - class_name: "l3extInstP" target_dn: "uni/tn-test_tenant/out-test_l3_outside/instP-inst_profile_1" @@ -76,3 +78,4 @@ child_targets: target_dn_overwrite_docs: "aci_route_control_profile.example.id" relation_resource_name: "route_control_profile" static: true +class_version: 2.0(1m)- diff --git a/gen/testvars/l3extProvLbl.yaml b/gen/testvars/l3extProvLbl.yaml index f9c2e9229..287554a53 100644 --- a/gen/testvars/l3extProvLbl.yaml +++ b/gen/testvars/l3extProvLbl.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -48,3 +49,5 @@ parents: parent_dn: "aci_l3_outside.test.id" class_in_parent: false parent_dependency_name: "infra" + test_type: apic +class_version: 2.0(1m)- diff --git a/gen/testvars/l3extRsLblToInstP.yaml b/gen/testvars/l3extRsLblToInstP.yaml index 8b415f424..bbcfb3745 100644 --- a/gen/testvars/l3extRsLblToInstP.yaml +++ b/gen/testvars/l3extRsLblToInstP.yaml @@ -2,6 +2,7 @@ # 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" @@ -39,6 +40,7 @@ parents: class_in_parent: false target_classes: - "l3extInstP" + test_type: both targets: - class_name: "l3extInstP" target_dn: "uni/tn-test_tenant/out-test_l3_outside/instP-inst_profile_1" @@ -52,3 +54,4 @@ targets: static: true properties: name: "inst_profile_1" +class_version: 5.0(1k)- diff --git a/gen/testvars/l3extRsLblToProfile.yaml b/gen/testvars/l3extRsLblToProfile.yaml index c1803662c..2abea935b 100644 --- a/gen/testvars/l3extRsLblToProfile.yaml +++ b/gen/testvars/l3extRsLblToProfile.yaml @@ -2,6 +2,7 @@ # 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" direction: "import" @@ -44,6 +45,7 @@ parents: class_in_parent: false target_classes: - "rtctrlProfile" + test_type: both targets: - class_name: "rtctrlProfile" target_dn: "uni/tn-test_tenant/prof-rt_ctrl_profile_1" @@ -57,3 +59,4 @@ targets: static: true properties: name: "rt_ctrl_profile_1" +class_version: 5.0(1k)- diff --git a/gen/testvars/l3extRsOutToFBRGroup.yaml b/gen/testvars/l3extRsOutToFBRGroup.yaml index 9cfd276e2..df86b393b 100644 --- a/gen/testvars/l3extRsOutToFBRGroup.yaml +++ b/gen/testvars/l3extRsOutToFBRGroup.yaml @@ -2,6 +2,7 @@ # 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" @@ -39,6 +40,7 @@ parents: class_in_parent: false target_classes: - "fvFBRGroup" + test_type: apic targets: - class_name: "fvFBRGroup" target_dn: "uni/tn-test_tenant/ctx-test_vrf/fbrg-vrf_fallback_route_group_0" @@ -51,3 +53,4 @@ targets: static: false properties: name: "vrf_fallback_route_group_0" +class_version: 5.2(4d)- diff --git a/gen/testvars/l3extRsRedistributePol.yaml b/gen/testvars/l3extRsRedistributePol.yaml index 47d3604c4..328e1ace6 100644 --- a/gen/testvars/l3extRsRedistributePol.yaml +++ b/gen/testvars/l3extRsRedistributePol.yaml @@ -2,6 +2,7 @@ # 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" source: "direct" @@ -42,3 +43,5 @@ parents: parent_dependency: "fvTenant" parent_dn: "aci_l3_outside.test.id" class_in_parent: true + test_type: apic +class_version: 4.2(1i)- diff --git a/gen/testvars/mgmtInstP.yaml b/gen/testvars/mgmtInstP.yaml index f7bf2d1ae..84ad12a38 100644 --- a/gen/testvars/mgmtInstP.yaml +++ b/gen/testvars/mgmtInstP.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -51,3 +52,5 @@ children: - key: "key_1" value: "test_value" +test_type: both +class_version: 1.0(1e)- diff --git a/gen/testvars/mgmtRsOoBCons.yaml b/gen/testvars/mgmtRsOoBCons.yaml index 965e62c0d..3f5971966 100644 --- a/gen/testvars/mgmtRsOoBCons.yaml +++ b/gen/testvars/mgmtRsOoBCons.yaml @@ -2,6 +2,7 @@ # 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" priority: "unspecified" @@ -43,3 +44,5 @@ parents: parent_dependency: "" parent_dn: "aci_external_management_network_instance_profile.test.id" class_in_parent: false + test_type: both +class_version: 1.0(1e)- diff --git a/gen/testvars/mgmtSubnet.yaml b/gen/testvars/mgmtSubnet.yaml index f42cc8402..39514aaf4 100644 --- a/gen/testvars/mgmtSubnet.yaml +++ b/gen/testvars/mgmtSubnet.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -43,3 +44,5 @@ parents: parent_dependency: "" parent_dn: "aci_external_management_network_instance_profile.test.id" class_in_parent: false + test_type: both +class_version: 1.0(1e)- diff --git a/gen/testvars/mplsNodeSidP.yaml b/gen/testvars/mplsNodeSidP.yaml index 0bde261e0..85454bb11 100644 --- a/gen/testvars/mplsNodeSidP.yaml +++ b/gen/testvars/mplsNodeSidP.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -45,3 +46,5 @@ parents: parent_dependency: "l3extRsNodeL3OutAtt" parent_dn: "aci_l3out_loopback_interface_profile.test.id" class_in_parent: false + test_type: apic +class_version: 5.0(1k)- diff --git a/gen/testvars/netflowExporterPol.yaml b/gen/testvars/netflowExporterPol.yaml index 18b68114d..65b6de52f 100644 --- a/gen/testvars/netflowExporterPol.yaml +++ b/gen/testvars/netflowExporterPol.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -75,6 +76,7 @@ parents: parent_dependency: "" parent_dn: "aci_tenant.test.id" class_in_parent: false + test_type: both child_targets: - class_name: "fvCtx" target_dn: "uni/tn-test_tenant/ctx-test_vrf" @@ -86,3 +88,4 @@ child_targets: target_dn_overwrite_docs: "aci_application_epg.example.id" relation_resource_name: "application_epg" static: true +class_version: 2.2(1k)- diff --git a/gen/testvars/netflowMonitorPol.yaml b/gen/testvars/netflowMonitorPol.yaml index 314aba42b..2f41c2a63 100644 --- a/gen/testvars/netflowMonitorPol.yaml +++ b/gen/testvars/netflowMonitorPol.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -57,3 +58,5 @@ parents: parent_dependency: "" parent_dn: "aci_tenant.test.id" class_in_parent: false + test_type: both +class_version: 2.2(1k)- diff --git a/gen/testvars/netflowRecordPol.yaml b/gen/testvars/netflowRecordPol.yaml index 7049c2098..01a865eb2 100644 --- a/gen/testvars/netflowRecordPol.yaml +++ b/gen/testvars/netflowRecordPol.yaml @@ -2,6 +2,7 @@ # 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" collect_parameters: @@ -54,3 +55,5 @@ parents: parent_dependency: "" parent_dn: "aci_tenant.test.id" class_in_parent: false + test_type: both +class_version: 2.2(1k)- diff --git a/gen/testvars/netflowRsMonitorToExporter.yaml b/gen/testvars/netflowRsMonitorToExporter.yaml index ec61c9810..1ca9bd666 100644 --- a/gen/testvars/netflowRsMonitorToExporter.yaml +++ b/gen/testvars/netflowRsMonitorToExporter.yaml @@ -2,6 +2,7 @@ # 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" @@ -37,3 +38,5 @@ parents: parent_dependency: "fvTenant" parent_dn: "aci_netflow_monitor_policy.test.id" class_in_parent: false + test_type: both +class_version: 2.2(1k)- diff --git a/gen/testvars/pimRouteMapEntry.yaml b/gen/testvars/pimRouteMapEntry.yaml index cbcccebfd..b0b7c51d3 100644 --- a/gen/testvars/pimRouteMapEntry.yaml +++ b/gen/testvars/pimRouteMapEntry.yaml @@ -2,6 +2,7 @@ # 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: action: "permit" annotation: "orchestrator:terraform" @@ -51,3 +52,5 @@ parents: parent_dependency: "fvTenant" parent_dn: "aci_pim_route_map_policy.test.id" class_in_parent: false + test_type: both +class_version: 2.0(1m)- diff --git a/gen/testvars/pimRouteMapPol.yaml b/gen/testvars/pimRouteMapPol.yaml index bbbdbc6fd..7cfa74e5e 100644 --- a/gen/testvars/pimRouteMapPol.yaml +++ b/gen/testvars/pimRouteMapPol.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -45,3 +46,5 @@ parents: parent_dependency: "" parent_dn: "aci_tenant.test.id" class_in_parent: false + test_type: both +class_version: 2.0(1m)- diff --git a/gen/testvars/pkiKeyRing.yaml b/gen/testvars/pkiKeyRing.yaml new file mode 100644 index 000000000..dd1af97e4 --- /dev/null +++ b/gen/testvars/pkiKeyRing.yaml @@ -0,0 +1,95 @@ +# 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: + admin_state: "started" + annotation: "orchestrator:terraform" + certificate: "" + description: "" + key: "" + modulus: "mod2048" + name_alias: "" + owner_key: "" + owner_tag: "" + regenerate: "no" + certificate_authority: "" + version_mismatch: + 6.0(2h): + elliptic_curve: "none" + key_type: "RSA" + +datasource_non_existing: + name: "non_existing_name" + +datasource_required: + name: "test_name" + +resource_required: + name: "test_name" + +all: + admin_state: "completed" + annotation: "annotation" + certificate: "-----BEGIN CERTIFICATE-----\\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\\n-----END CERTIFICATE-----" + description: "description_1" + key: "-----BEGIN PRIVATE KEY-----\\nMIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKIRv+2sbbewm0mj\\nD+6/tpoUymzYIdFsN+gu02teIr/lZi8ipEB514pyhoaerstzboPteWvniLuwq4KQ\\nVTEHgoln7J8EaHCnECViGA61pVx8RkJ99cmCkepspROw3I96zBcm58oXs6+Q/BnD\\n/OWET5sBvR9oTv9GNRVJ1rvSMAEJAgMBAAECgYByu3QO0qF9h7X3JEu0Ld4cKBnB\\ngiQ2uJC/et7KxIJ/LOvw9GopBthyt27KwG1ntBkJpkTuAaQHkyNns7vLkNB0S0IR\\n+owVFEcKYq9VCHTaiQU8TDp24gN+yPTrpRuH8YhDVq5SfVdVuTMgHVQdj4ya4VlF\\nGj+a7+ipxtGiLsVGrQJBAM7p0Fm0xmzi+tBOASUAcVrPLcteFIaTBFwfq16dm/ON\\n00Khla8Et5kMBttTbqbukl8mxFjBEEBlhQqb6EdQQ0sCQQDIhHx1a9diG7y/4DQA\\n4KvR3FCYwP8PBORlSamegzCo+P1OzxiEo0amX7yQMA5UyiP/kUsZrme2JBZgna8S\\np4R7AkEAr7rMhSOPUnMD6V4WgsJ5g1Jp5kqkzBaYoVUUSms5RASz4+cwJVCwTX91\\nY1jcpVIBZmaaY3a0wrx13ajEAa0dOQJBAIpjnb4wqpsEh7VpmJqOdSdGxb1XXfFQ\\nsA0T1OQYqQnFppWwqrxIL+d9pZdiA1ITnNqyvUFBNETqDSOrUHwwb2cCQGArE+vu\\nffPUWQ0j+fiK+covFG8NL7H+26NSGB5+Xsn9uwOGLj7K/YT6CbBtr9hJiuWjM1Al\\n0V4ltlTuu2mTMaw=\\n-----END PRIVATE KEY-----" + modulus: "mod1024" + name_alias: "name_alias_1" + owner_key: "owner_key_1" + owner_tag: "owner_tag_1" + regenerate: "no" + certificate_authority: "test_name" + version_mismatch: + 6.0(2h): + elliptic_curve: "none" + key_type: "RSA" + +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: "" + parent_dependency: "" + parent_dn: "" + class_in_parent: false + target_classes: + - "pkiTp" + test_type: both + - class_name: "fvTenant" + parent_dependency: "" + parent_dn: "aci_tenant.test.id" + class_in_parent: false + target_classes: + - "pkiTp" + test_type: cloud +targets: + - class_name: "pkiTP" + target_dn: "" + target_dn_ref: "" + parent_dependency: "" + parent_dependency_dn_ref: "" + target_resource_name: "certificate_authority" + relation_resource_name: "certificate_authority" + parent_dn_key: "parent_dn" + properties: + certificate_chain: "-----BEGIN CERTIFICATE-----\\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\\n-----END CERTIFICATE-----" + name: "test_name" +class_version: 1.0(1e)- + +exclude_attributes: + - "key" +version_mismatch: true \ No newline at end of file diff --git a/gen/testvars/pkiTP.yaml b/gen/testvars/pkiTP.yaml new file mode 100644 index 000000000..e39604ced --- /dev/null +++ b/gen/testvars/pkiTP.yaml @@ -0,0 +1,60 @@ +# 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" + certificate_chain: "-----BEGIN CERTIFICATE-----\\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\\n-----END CERTIFICATE-----" + description: "" + name_alias: "" + owner_key: "" + owner_tag: "" + +datasource_non_existing: + name: "non_existing_name" + +datasource_required: + name: "test_name" + +resource_required: + certificate_chain: "-----BEGIN CERTIFICATE-----\\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\\n-----END CERTIFICATE-----" + name: "test_name" + +all: + annotation: "annotation" + certificate_chain: "-----BEGIN CERTIFICATE-----\\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\\n-----END CERTIFICATE-----" + description: "description_1" + name_alias: "name_alias_1" + owner_key: "owner_key_1" + owner_tag: "owner_tag_1" + +children: + annotations: + - key: "key_0" + value: "value_1" + + - key: "key_1" + value: "test_value" + + tags: + - key: "key_0" + value: "value_1" + + - key: "key_1" + value: "test_value" + +parents: + - class_name: "" + parent_dependency: "" + parent_dn: "" + class_in_parent: false + target_classes: + test_type: both + - class_name: "fvTenant" + parent_dependency: "" + parent_dn: "aci_tenant.test.id" + class_in_parent: false + target_classes: + test_type: cloud +class_version: 1.0(1e)- diff --git a/gen/testvars/qosCustomPol.yaml b/gen/testvars/qosCustomPol.yaml index bbbdbc6fd..6bdec082c 100644 --- a/gen/testvars/qosCustomPol.yaml +++ b/gen/testvars/qosCustomPol.yaml @@ -2,6 +2,7 @@ # 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: "" @@ -45,3 +46,5 @@ parents: parent_dependency: "" parent_dn: "aci_tenant.test.id" class_in_parent: false + test_type: both +class_version: 1.0(1e)- diff --git a/gen/testvars/qosDppPol.yaml b/gen/testvars/qosDppPol.yaml index dfd8616ac..9e69c329b 100644 --- a/gen/testvars/qosDppPol.yaml +++ b/gen/testvars/qosDppPol.yaml @@ -2,6 +2,7 @@ # 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: admin_state: "disabled" annotation: "orchestrator:terraform" @@ -98,3 +99,5 @@ parents: parent_dependency: "" parent_dn: "aci_tenant.test.id" class_in_parent: false + test_type: both +class_version: 1.2(2g)- diff --git a/gen/testvars/rtctrlProfile.yaml b/gen/testvars/rtctrlProfile.yaml index 1053501ef..c23b41cfe 100644 --- a/gen/testvars/rtctrlProfile.yaml +++ b/gen/testvars/rtctrlProfile.yaml @@ -2,14 +2,17 @@ # 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" - route_map_continue: "no" description: "" name_alias: "" owner_key: "" owner_tag: "" route_control_profile_type: "combinable" + version_mismatch: + 4.2(6d)-4.2(7w),5.1(3e): + route_map_continue: "no" datasource_non_existing: name: "non_existing_name" @@ -22,12 +25,14 @@ resource_required: all: annotation: "annotation" - route_map_continue: "no" description: "description_1" name_alias: "name_alias_1" owner_key: "owner_key_1" owner_tag: "owner_tag_1" route_control_profile_type: "combinable" + version_mismatch: + 4.2(6d)-4.2(7w),5.1(3e): + route_map_continue: "no" children: annotations: @@ -49,7 +54,12 @@ parents: parent_dependency: "" parent_dn: "aci_tenant.test.id" class_in_parent: false + test_type: both - class_name: "l3extOut" parent_dependency: "" parent_dn: "aci_l3_outside.test.id" class_in_parent: false + test_type: both +class_version: 1.0(1e)- + +version_mismatch: true \ No newline at end of file diff --git a/gen/testvars/tagAnnotation.yaml b/gen/testvars/tagAnnotation.yaml index f52b83467..909aa79e1 100644 --- a/gen/testvars/tagAnnotation.yaml +++ b/gen/testvars/tagAnnotation.yaml @@ -2,6 +2,7 @@ # 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: value: "test_value" @@ -23,7 +24,10 @@ parents: parent_dependency: "" parent_dn: "aci_tenant.test.id" class_in_parent: false + test_type: both - class_name: "fvAEPg" parent_dependency: "" parent_dn: "aci_application_epg.test.id" class_in_parent: false + test_type: both +class_version: 3.2(1l)- diff --git a/gen/testvars/tagTag.yaml b/gen/testvars/tagTag.yaml index f52b83467..909aa79e1 100644 --- a/gen/testvars/tagTag.yaml +++ b/gen/testvars/tagTag.yaml @@ -2,6 +2,7 @@ # 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: value: "test_value" @@ -23,7 +24,10 @@ parents: parent_dependency: "" parent_dn: "aci_tenant.test.id" class_in_parent: false + test_type: both - class_name: "fvAEPg" parent_dependency: "" parent_dn: "aci_application_epg.test.id" class_in_parent: false + test_type: both +class_version: 3.2(1l)- diff --git a/gen/testvars/vzOOBBrCP.yaml b/gen/testvars/vzOOBBrCP.yaml index d82020d21..811303381 100644 --- a/gen/testvars/vzOOBBrCP.yaml +++ b/gen/testvars/vzOOBBrCP.yaml @@ -2,16 +2,19 @@ # 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: "" - intent: "install" name_alias: "" owner_key: "" owner_tag: "" priority: "unspecified" scope: "context" target_dscp: "unspecified" + version_mismatch: + 4.2(1i): + intent: "install" datasource_non_existing: name: "non_existing_name" @@ -30,13 +33,15 @@ custom_type: all: annotation: "annotation" description: "description_1" - intent: "estimate_add" name_alias: "name_alias_1" owner_key: "owner_key_1" owner_tag: "owner_tag_1" priority: "level1" scope: "application-profile" target_dscp: "AF11" + version_mismatch: + 4.2(1i): + intent: "estimate_add" children: annotations: @@ -53,3 +58,7 @@ children: - key: "key_1" value: "test_value" +test_type: both +class_version: 1.0(1e)- + +version_mismatch: true \ No newline at end of file diff --git a/go.mod b/go.mod index 71efe06fb..021f85bcd 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/ciscoecosystem/aci-go-client/v2 v2.31.0 github.com/ghodss/yaml v1.0.0 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 + github.com/hashicorp/go-version v1.7.0 github.com/hashicorp/hcl/v2 v2.21.0 github.com/hashicorp/terraform-plugin-framework v1.10.0 github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 @@ -38,7 +39,6 @@ require ( github.com/hashicorp/go-plugin v1.6.0 // indirect github.com/hashicorp/go-retryablehttp v0.7.7 // indirect github.com/hashicorp/go-uuid v1.0.3 // indirect - github.com/hashicorp/go-version v1.7.0 // indirect github.com/hashicorp/hc-install v0.8.0 // indirect github.com/hashicorp/logutils v1.0.0 // indirect github.com/hashicorp/terraform-exec v0.21.0 // indirect diff --git a/internal/provider/data_source_aci_access_interface_override_test.go b/internal/provider/data_source_aci_access_interface_override_test.go index 111cf3ea2..47d1f0121 100644 --- a/internal/provider/data_source_aci_access_interface_override_test.go +++ b/internal/provider/data_source_aci_access_interface_override_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceInfraHPathS(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_annotation_test.go b/internal/provider/data_source_aci_annotation_test.go index 77efa0a62..6b8776b6e 100644 --- a/internal/provider/data_source_aci_annotation_test.go +++ b/internal/provider/data_source_aci_annotation_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceTagAnnotationWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -35,7 +35,7 @@ func TestAccDataSourceTagAnnotationWithFvTenant(t *testing.T) { func TestAccDataSourceTagAnnotationWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_application_epg.go b/internal/provider/data_source_aci_application_epg.go index 85c55a8c0..f52e6b55f 100644 --- a/internal/provider/data_source_aci_application_epg.go +++ b/internal/provider/data_source_aci_application_epg.go @@ -448,10 +448,6 @@ func (d *FvAEPgDataSource) Schema(ctx context.Context, req datasource.SchemaRequ Computed: true, MarkdownDescription: `The untagged status of the Relation To Domain object.`, }, - "vnet_only": schema.StringAttribute{ - Computed: true, - MarkdownDescription: `The VNET only status of the Relation To Domain object.`, - }, }, }, }, diff --git a/internal/provider/data_source_aci_application_epg_test.go b/internal/provider/data_source_aci_application_epg_test.go index bfb52978f..89460beda 100644 --- a/internal/provider/data_source_aci_application_epg_test.go +++ b/internal/provider/data_source_aci_application_epg_test.go @@ -14,32 +14,33 @@ import ( func TestAccDataSourceFvAEPgWithFvAp(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testConfigFvAEPgDataSourceDependencyWithFvAp, + Config: testConfigFvAEPgDataSourceDependencyWithFvAp + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.aci_application_epg.test", "name", "test_name"), - resource.TestCheckResourceAttr("data.aci_application_epg.test", "admin_state", "no"), resource.TestCheckResourceAttr("data.aci_application_epg.test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("data.aci_application_epg.test", "contract_exception_tag", ""), resource.TestCheckResourceAttr("data.aci_application_epg.test", "description", ""), resource.TestCheckResourceAttr("data.aci_application_epg.test", "flood_in_encapsulation", "disabled"), resource.TestCheckResourceAttr("data.aci_application_epg.test", "forwarding_control", "none"), - resource.TestCheckResourceAttr("data.aci_application_epg.test", "has_multicast_source", "no"), resource.TestCheckResourceAttr("data.aci_application_epg.test", "intra_epg_isolation", "unenforced"), resource.TestCheckResourceAttr("data.aci_application_epg.test", "match_criteria", "AtleastOne"), resource.TestCheckResourceAttr("data.aci_application_epg.test", "name_alias", ""), resource.TestCheckResourceAttr("data.aci_application_epg.test", "preferred_group_member", "exclude"), resource.TestCheckResourceAttr("data.aci_application_epg.test", "priority", "unspecified"), resource.TestCheckResourceAttr("data.aci_application_epg.test", "useg_epg", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.0(1h)", ">", + resource.TestCheckResourceAttr("data.aci_application_epg.test", "admin_state", "no"), + resource.TestCheckResourceAttr("data.aci_application_epg.test", "has_multicast_source", "no")), resource.TestCheckResourceAttrSet("data.aci_application_epg.test", "pc_tag"), ), }, { - Config: testConfigFvAEPgNotExistingFvAp, + Config: testConfigFvAEPgNotExistingFvAp + testConfigDataSourceSystem, ExpectError: regexp.MustCompile("Failed to read aci_application_epg data source"), }, }, diff --git a/internal/provider/data_source_aci_certificate_authority.go b/internal/provider/data_source_aci_certificate_authority.go new file mode 100644 index 000000000..353d89832 --- /dev/null +++ b/internal/provider/data_source_aci_certificate_authority.go @@ -0,0 +1,174 @@ +// 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/basetypes" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var _ datasource.DataSource = &PkiTPDataSource{} + +func NewPkiTPDataSource() datasource.DataSource { + return &PkiTPDataSource{} +} + +// PkiTPDataSource defines the data source implementation. +type PkiTPDataSource struct { + client *client.Client +} + +func (d *PkiTPDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + tflog.Debug(ctx, "Start metadata of datasource: aci_certificate_authority") + resp.TypeName = req.ProviderTypeName + "_certificate_authority" + tflog.Debug(ctx, "End metadata of datasource: aci_certificate_authority") +} + +func (d *PkiTPDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + tflog.Debug(ctx, "Start schema of datasource: aci_certificate_authority") + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: "The certificate_authority datasource for the 'pkiTP' class", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + MarkdownDescription: "The distinguished name (DN) of the Certificate Authority object.", + }, + "parent_dn": schema.StringAttribute{ + Optional: true, + MarkdownDescription: "The distinguished name (DN) of the parent object.", + }, + "annotation": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The annotation of the Certificate Authority object.`, + }, + "certificate_chain": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The PEM-encoded chain of trust from the trustpoint to a trusted root authority.`, + }, + "description": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The description of the Certificate Authority object.`, + }, + "name": schema.StringAttribute{ + Required: true, + MarkdownDescription: `The name of the Certificate Authority object.`, + }, + "name_alias": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The name alias of the Certificate Authority object.`, + }, + "owner_key": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The key for enabling clients to own their data for entity correlation.`, + }, + "owner_tag": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `A tag for enabling clients to add their own data. For example, to indicate who created this object.`, + }, + "annotations": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "key": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The key used to uniquely identify this configuration object.`, + }, + "value": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The value of the property.`, + }, + }, + }, + }, + "tags": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "key": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The key used to uniquely identify this configuration object.`, + }, + "value": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The value of the property.`, + }, + }, + }, + }, + }, + } + tflog.Debug(ctx, "End schema of datasource: aci_certificate_authority") +} + +func (d *PkiTPDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + tflog.Debug(ctx, "Start configure of datasource: aci_certificate_authority") + // 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_certificate_authority") +} + +func (d *PkiTPDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + tflog.Debug(ctx, "Start read of datasource: aci_certificate_authority") + var data *PkiTPResourceModel + + // Read Terraform configuration data into the model + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + if data.ParentDn.IsNull() || data.ParentDn.IsUnknown() { + data.ParentDn = basetypes.NewStringValue("uni/userext/pkiext") + } + + setPkiTPId(ctx, data) + + // Create a copy of the Id for when not found during getAndSetPkiTPAttributes + cachedId := data.Id.ValueString() + + tflog.Debug(ctx, fmt.Sprintf("Read of datasource aci_certificate_authority with id '%s'", data.Id.ValueString())) + + getAndSetPkiTPAttributes(ctx, &resp.Diagnostics, d.client, data) + + if data.Id.IsNull() { + resp.Diagnostics.AddError( + "Failed to read aci_certificate_authority data source", + fmt.Sprintf("The aci_certificate_authority 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_certificate_authority with id '%s'", data.Id.ValueString())) +} diff --git a/internal/provider/data_source_aci_certificate_authority_test.go b/internal/provider/data_source_aci_certificate_authority_test.go new file mode 100644 index 000000000..72583c879 --- /dev/null +++ b/internal/provider/data_source_aci_certificate_authority_test.go @@ -0,0 +1,92 @@ +// 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 TestAccDataSourcePkiTP(t *testing.T) { + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testConfigPkiTPDataSource, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.aci_certificate_authority.test", "name", "test_name"), + resource.TestCheckResourceAttr("data.aci_certificate_authority.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("data.aci_certificate_authority.test", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("data.aci_certificate_authority.test", "description", ""), + resource.TestCheckResourceAttr("data.aci_certificate_authority.test", "name_alias", ""), + resource.TestCheckResourceAttr("data.aci_certificate_authority.test", "owner_key", ""), + resource.TestCheckResourceAttr("data.aci_certificate_authority.test", "owner_tag", ""), + ), + }, + { + Config: testConfigPkiTPNotExisting, + ExpectError: regexp.MustCompile("Failed to read aci_certificate_authority data source"), + }, + }, + }) +} +func TestAccDataSourcePkiTPWithFvTenant(t *testing.T) { + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "cloud", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testConfigPkiTPDataSourceDependencyWithFvTenant, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.aci_certificate_authority.test", "name", "test_name"), + resource.TestCheckResourceAttr("data.aci_certificate_authority.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("data.aci_certificate_authority.test", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("data.aci_certificate_authority.test", "description", ""), + resource.TestCheckResourceAttr("data.aci_certificate_authority.test", "name_alias", ""), + resource.TestCheckResourceAttr("data.aci_certificate_authority.test", "owner_key", ""), + resource.TestCheckResourceAttr("data.aci_certificate_authority.test", "owner_tag", ""), + ), + }, + { + Config: testConfigPkiTPNotExistingFvTenant, + ExpectError: regexp.MustCompile("Failed to read aci_certificate_authority data source"), + }, + }, + }) +} + +const testConfigPkiTPDataSource = testConfigPkiTPMin + ` +data "aci_certificate_authority" "test" { + name = "test_name" + depends_on = [aci_certificate_authority.test] +} +` + +const testConfigPkiTPNotExisting = testConfigPkiTPMin + ` +data "aci_certificate_authority" "test_non_existing" { + name = "non_existing_name" +} +` +const testConfigPkiTPDataSourceDependencyWithFvTenant = testConfigPkiTPMinDependencyWithFvTenant + ` +data "aci_certificate_authority" "test" { + parent_dn = aci_tenant.test.id + name = "test_name" + depends_on = [aci_certificate_authority.test] +} +` + +const testConfigPkiTPNotExistingFvTenant = testConfigFvTenantMin + ` +data "aci_certificate_authority" "test_non_existing" { + parent_dn = aci_tenant.test.id + name = "non_existing_name" +} +` diff --git a/internal/provider/data_source_aci_custom_qos_policy_test.go b/internal/provider/data_source_aci_custom_qos_policy_test.go index 011d2ea7c..9e7615360 100644 --- a/internal/provider/data_source_aci_custom_qos_policy_test.go +++ b/internal/provider/data_source_aci_custom_qos_policy_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceQosCustomPolWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_data_plane_policing_policy_test.go b/internal/provider/data_source_aci_data_plane_policing_policy_test.go index aa23d88f6..53d73f9e7 100644 --- a/internal/provider/data_source_aci_data_plane_policing_policy_test.go +++ b/internal/provider/data_source_aci_data_plane_policing_policy_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceQosDppPolWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.2(2g)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_endpoint_security_group_test.go b/internal/provider/data_source_aci_endpoint_security_group_test.go index 63d74de7a..343ec16e5 100644 --- a/internal/provider/data_source_aci_endpoint_security_group_test.go +++ b/internal/provider/data_source_aci_endpoint_security_group_test.go @@ -14,15 +14,14 @@ import ( func TestAccDataSourceFvESgWithFvAp(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testConfigFvESgDataSourceDependencyWithFvAp, + Config: testConfigFvESgDataSourceDependencyWithFvAp + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.aci_endpoint_security_group.test", "name", "test_name"), - resource.TestCheckResourceAttr("data.aci_endpoint_security_group.test", "admin_state", "no"), resource.TestCheckResourceAttr("data.aci_endpoint_security_group.test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("data.aci_endpoint_security_group.test", "description", ""), resource.TestCheckResourceAttr("data.aci_endpoint_security_group.test", "exception_tag", ""), @@ -30,11 +29,13 @@ func TestAccDataSourceFvESgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("data.aci_endpoint_security_group.test", "match_criteria", "AtleastOne"), resource.TestCheckResourceAttr("data.aci_endpoint_security_group.test", "name_alias", ""), resource.TestCheckResourceAttr("data.aci_endpoint_security_group.test", "preferred_group_member", "exclude"), + composeAggregateTestCheckFuncWithVersion(t, "5.2(1g)", ">", + resource.TestCheckResourceAttr("data.aci_endpoint_security_group.test", "admin_state", "no")), resource.TestCheckResourceAttrSet("data.aci_endpoint_security_group.test", "pc_tag"), ), }, { - Config: testConfigFvESgNotExistingFvAp, + Config: testConfigFvESgNotExistingFvAp + testConfigDataSourceSystem, ExpectError: regexp.MustCompile("Failed to read aci_endpoint_security_group data source"), }, }, diff --git a/internal/provider/data_source_aci_endpoint_tag_ip_test.go b/internal/provider/data_source_aci_endpoint_tag_ip_test.go index 66a4eff33..3a4581e3c 100644 --- a/internal/provider/data_source_aci_endpoint_tag_ip_test.go +++ b/internal/provider/data_source_aci_endpoint_tag_ip_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvEpIpTagWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.2(1g)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_endpoint_tag_mac_test.go b/internal/provider/data_source_aci_endpoint_tag_mac_test.go index 9390118cd..872a739d0 100644 --- a/internal/provider/data_source_aci_endpoint_tag_mac_test.go +++ b/internal/provider/data_source_aci_endpoint_tag_mac_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvEpMacTagWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.2(1g)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_epg_useg_ad_group_attribute_test.go b/internal/provider/data_source_aci_epg_useg_ad_group_attribute_test.go index 9684f1b32..34c84303f 100644 --- a/internal/provider/data_source_aci_epg_useg_ad_group_attribute_test.go +++ b/internal/provider/data_source_aci_epg_useg_ad_group_attribute_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvIdGroupAttrWithFvCrtrn(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "3.2(10e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_epg_useg_block_statement_test.go b/internal/provider/data_source_aci_epg_useg_block_statement_test.go index f0300d3e0..047315507 100644 --- a/internal/provider/data_source_aci_epg_useg_block_statement_test.go +++ b/internal/provider/data_source_aci_epg_useg_block_statement_test.go @@ -14,11 +14,11 @@ import ( func TestAccDataSourceFvCrtrnWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testConfigFvCrtrnDataSourceDependencyWithFvAEPg, + Config: testConfigFvCrtrnDataSourceDependencyWithFvAEPg + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.aci_epg_useg_block_statement.test", "annotation", "orchestrator:terraform"), @@ -28,12 +28,13 @@ func TestAccDataSourceFvCrtrnWithFvAEPg(t *testing.T) { resource.TestCheckResourceAttr("data.aci_epg_useg_block_statement.test", "name_alias", ""), resource.TestCheckResourceAttr("data.aci_epg_useg_block_statement.test", "owner_key", ""), resource.TestCheckResourceAttr("data.aci_epg_useg_block_statement.test", "owner_tag", ""), - resource.TestCheckResourceAttr("data.aci_epg_useg_block_statement.test", "precedence", "0"), - resource.TestCheckResourceAttr("data.aci_epg_useg_block_statement.test", "scope", "scope-bd"), + composeAggregateTestCheckFuncWithVersion(t, "4.1(1i)", ">", + resource.TestCheckResourceAttr("data.aci_epg_useg_block_statement.test", "precedence", "0"), + resource.TestCheckResourceAttr("data.aci_epg_useg_block_statement.test", "scope", "scope-bd")), ), }, { - Config: testConfigFvCrtrnNotExistingFvAEPg, + Config: testConfigFvCrtrnNotExistingFvAEPg + testConfigDataSourceSystem, ExpectError: regexp.MustCompile("Failed to read aci_epg_useg_block_statement data source"), }, }, diff --git a/internal/provider/data_source_aci_epg_useg_dns_attribute_test.go b/internal/provider/data_source_aci_epg_useg_dns_attribute_test.go index 0e44bd12c..259cc82be 100644 --- a/internal/provider/data_source_aci_epg_useg_dns_attribute_test.go +++ b/internal/provider/data_source_aci_epg_useg_dns_attribute_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvDnsAttrWithFvCrtrn(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.3(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_epg_useg_ip_attribute_test.go b/internal/provider/data_source_aci_epg_useg_ip_attribute_test.go index dbb43d0c8..fd8770802 100644 --- a/internal/provider/data_source_aci_epg_useg_ip_attribute_test.go +++ b/internal/provider/data_source_aci_epg_useg_ip_attribute_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvIpAttrWithFvCrtrn(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_epg_useg_mac_attribute_test.go b/internal/provider/data_source_aci_epg_useg_mac_attribute_test.go index a93801104..2c1efd468 100644 --- a/internal/provider/data_source_aci_epg_useg_mac_attribute_test.go +++ b/internal/provider/data_source_aci_epg_useg_mac_attribute_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvMacAttrWithFvCrtrn(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_epg_useg_sub_block_statement_test.go b/internal/provider/data_source_aci_epg_useg_sub_block_statement_test.go index dfb59e62f..b2b8b5a2d 100644 --- a/internal/provider/data_source_aci_epg_useg_sub_block_statement_test.go +++ b/internal/provider/data_source_aci_epg_useg_sub_block_statement_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvSCrtrnWithFvCrtrn(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.2(1i)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -40,7 +40,7 @@ func TestAccDataSourceFvSCrtrnWithFvCrtrn(t *testing.T) { func TestAccDataSourceFvSCrtrnWithFvSCrtrn(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.2(1i)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_epg_useg_vm_attribute_test.go b/internal/provider/data_source_aci_epg_useg_vm_attribute_test.go index 5713d5023..2b79abc9b 100644 --- a/internal/provider/data_source_aci_epg_useg_vm_attribute_test.go +++ b/internal/provider/data_source_aci_epg_useg_vm_attribute_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvVmAttrWithFvCrtrn(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -44,7 +44,7 @@ func TestAccDataSourceFvVmAttrWithFvCrtrn(t *testing.T) { func TestAccDataSourceFvVmAttrWithFvSCrtrn(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_external_management_network_instance_profile_test.go b/internal/provider/data_source_aci_external_management_network_instance_profile_test.go index 1665c3708..e90157d88 100644 --- a/internal/provider/data_source_aci_external_management_network_instance_profile_test.go +++ b/internal/provider/data_source_aci_external_management_network_instance_profile_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceMgmtInstP(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_external_management_network_subnet_test.go b/internal/provider/data_source_aci_external_management_network_subnet_test.go index cdfbaf8ae..202614fe0 100644 --- a/internal/provider/data_source_aci_external_management_network_subnet_test.go +++ b/internal/provider/data_source_aci_external_management_network_subnet_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceMgmtSubnetWithMgmtInstP(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_key_ring.go b/internal/provider/data_source_aci_key_ring.go new file mode 100644 index 000000000..200b97baa --- /dev/null +++ b/internal/provider/data_source_aci_key_ring.go @@ -0,0 +1,202 @@ +// 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/basetypes" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var _ datasource.DataSource = &PkiKeyRingDataSource{} + +func NewPkiKeyRingDataSource() datasource.DataSource { + return &PkiKeyRingDataSource{} +} + +// PkiKeyRingDataSource defines the data source implementation. +type PkiKeyRingDataSource struct { + client *client.Client +} + +func (d *PkiKeyRingDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + tflog.Debug(ctx, "Start metadata of datasource: aci_key_ring") + resp.TypeName = req.ProviderTypeName + "_key_ring" + tflog.Debug(ctx, "End metadata of datasource: aci_key_ring") +} + +func (d *PkiKeyRingDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + tflog.Debug(ctx, "Start schema of datasource: aci_key_ring") + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: "The key_ring datasource for the 'pkiKeyRing' class", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + MarkdownDescription: "The distinguished name (DN) of the Key Ring object.", + }, + "parent_dn": schema.StringAttribute{ + Optional: true, + MarkdownDescription: "The distinguished name (DN) of the parent object.", + }, + "admin_state": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The current administrative state of the certificate request process.`, + }, + "annotation": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The annotation of the Key Ring object.`, + }, + "certificate": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `A certificate contains a device's public key along with signed information verifying the identity of the device.`, + }, + "description": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The description of the Key Ring object.`, + }, + "elliptic_curve": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The elliptic curve used by the provided key.`, + }, + "key": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The private key of the certificate. This sensitive value is excluded from the resource's lifecycle configuration and is not tracked by Terraform.`, + }, + "key_type": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The type used by the provided key.`, + }, + "modulus": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The length of the encryption keys. A longer key length increases the difficulty of breaking the key.`, + }, + "name": schema.StringAttribute{ + Required: true, + MarkdownDescription: `The name of the Key Ring object.`, + }, + "name_alias": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The name alias of the Key Ring 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.`, + }, + "regenerate": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `Forces regeneration of the keypair. Each PKI device holds a pair of asymmetric Rivest-Shamir-Adleman (RSA) or Elliptic Curve Cryptography (ECC) encryption keys, one kept private and one made public, stored in an internal key ring.`, + }, + "certificate_authority": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The certificate of the Certificate Authority (CA) that issued the certificate provided in the 'certificate' attribute. The CA can be a root CA, an intermediate CA, or a trust anchor in a chain of trust leading to a root CA.`, + }, + "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_key_ring") +} + +func (d *PkiKeyRingDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + tflog.Debug(ctx, "Start configure of datasource: aci_key_ring") + // 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_key_ring") +} + +func (d *PkiKeyRingDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + tflog.Debug(ctx, "Start read of datasource: aci_key_ring") + var data *PkiKeyRingResourceModel + + // Read Terraform configuration data into the model + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + if data.ParentDn.IsNull() || data.ParentDn.IsUnknown() { + data.ParentDn = basetypes.NewStringValue("uni/userext/pkiext") + } + + setPkiKeyRingId(ctx, data) + + // Create a copy of the Id for when not found during getAndSetPkiKeyRingAttributes + cachedId := data.Id.ValueString() + + tflog.Debug(ctx, fmt.Sprintf("Read of datasource aci_key_ring with id '%s'", data.Id.ValueString())) + + getAndSetPkiKeyRingAttributes(ctx, &resp.Diagnostics, d.client, data) + + if data.Id.IsNull() { + resp.Diagnostics.AddError( + "Failed to read aci_key_ring data source", + fmt.Sprintf("The aci_key_ring 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_key_ring with id '%s'", data.Id.ValueString())) +} diff --git a/internal/provider/data_source_aci_key_ring_test.go b/internal/provider/data_source_aci_key_ring_test.go new file mode 100644 index 000000000..cf2fb0cc6 --- /dev/null +++ b/internal/provider/data_source_aci_key_ring_test.go @@ -0,0 +1,106 @@ +// 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 TestAccDataSourcePkiKeyRing(t *testing.T) { + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testConfigPkiKeyRingDataSource + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.aci_key_ring.test", "name", "test_name"), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "admin_state", "started"), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "certificate", ""), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "certificate_authority", ""), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "description", ""), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "modulus", "mod2048"), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "name_alias", ""), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "owner_key", ""), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "owner_tag", ""), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "regenerate", "no"), + composeAggregateTestCheckFuncWithVersion(t, "6.0(2h)", ">", + resource.TestCheckResourceAttr("data.aci_key_ring.test", "elliptic_curve", "none"), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "key_type", "RSA")), + ), + }, + { + Config: testConfigPkiKeyRingNotExisting + testConfigDataSourceSystem, + ExpectError: regexp.MustCompile("Failed to read aci_key_ring data source"), + }, + }, + }) +} +func TestAccDataSourcePkiKeyRingWithFvTenant(t *testing.T) { + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "cloud", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testConfigPkiKeyRingDataSourceDependencyWithFvTenant + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.aci_key_ring.test", "name", "test_name"), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "admin_state", "started"), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "certificate", ""), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "certificate_authority", ""), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "description", ""), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "modulus", "mod2048"), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "name_alias", ""), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "owner_key", ""), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "owner_tag", ""), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "regenerate", "no"), + composeAggregateTestCheckFuncWithVersion(t, "6.0(2h)", ">", + resource.TestCheckResourceAttr("data.aci_key_ring.test", "elliptic_curve", "none"), + resource.TestCheckResourceAttr("data.aci_key_ring.test", "key_type", "RSA")), + ), + }, + { + Config: testConfigPkiKeyRingNotExistingFvTenant + testConfigDataSourceSystem, + ExpectError: regexp.MustCompile("Failed to read aci_key_ring data source"), + }, + }, + }) +} + +const testConfigPkiKeyRingDataSource = testConfigPkiKeyRingMin + ` +data "aci_key_ring" "test" { + name = "test_name" + depends_on = [aci_key_ring.test] +} +` + +const testConfigPkiKeyRingNotExisting = testConfigPkiKeyRingMin + ` +data "aci_key_ring" "test_non_existing" { + name = "non_existing_name" +} +` +const testConfigPkiKeyRingDataSourceDependencyWithFvTenant = testConfigPkiKeyRingMinDependencyWithFvTenant + ` +data "aci_key_ring" "test" { + parent_dn = aci_tenant.test.id + name = "test_name" + depends_on = [aci_key_ring.test] +} +` + +const testConfigPkiKeyRingNotExistingFvTenant = testConfigFvTenantMin + ` +data "aci_key_ring" "test_non_existing" { + parent_dn = aci_tenant.test.id + name = "non_existing_name" +} +` diff --git a/internal/provider/data_source_aci_l3out_consumer_label_test.go b/internal/provider/data_source_aci_l3out_consumer_label_test.go index 5811e8648..0bd85c052 100644 --- a/internal/provider/data_source_aci_l3out_consumer_label_test.go +++ b/internal/provider/data_source_aci_l3out_consumer_label_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceL3extConsLblWithL3extOut(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_l3out_node_sid_profile_test.go b/internal/provider/data_source_aci_l3out_node_sid_profile_test.go index 29634bab1..4b878dfa7 100644 --- a/internal/provider/data_source_aci_l3out_node_sid_profile_test.go +++ b/internal/provider/data_source_aci_l3out_node_sid_profile_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceMplsNodeSidPWithL3extLoopBackIfP(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_l3out_provider_label_test.go b/internal/provider/data_source_aci_l3out_provider_label_test.go index a37b73b5e..1e40bfeb8 100644 --- a/internal/provider/data_source_aci_l3out_provider_label_test.go +++ b/internal/provider/data_source_aci_l3out_provider_label_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceL3extProvLblWithL3extOut(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_l3out_redistribute_policy_test.go b/internal/provider/data_source_aci_l3out_redistribute_policy_test.go index 48ba80197..d21f88373 100644 --- a/internal/provider/data_source_aci_l3out_redistribute_policy_test.go +++ b/internal/provider/data_source_aci_l3out_redistribute_policy_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceL3extRsRedistributePolWithL3extOut(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "4.2(1i)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_netflow_exporter_policy_test.go b/internal/provider/data_source_aci_netflow_exporter_policy_test.go index d6e74532d..5c5791ad4 100644 --- a/internal/provider/data_source_aci_netflow_exporter_policy_test.go +++ b/internal/provider/data_source_aci_netflow_exporter_policy_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceNetflowExporterPolWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_netflow_monitor_policy_test.go b/internal/provider/data_source_aci_netflow_monitor_policy_test.go index 5cfc3948a..e5daafc15 100644 --- a/internal/provider/data_source_aci_netflow_monitor_policy_test.go +++ b/internal/provider/data_source_aci_netflow_monitor_policy_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceNetflowMonitorPolWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_netflow_record_policy_test.go b/internal/provider/data_source_aci_netflow_record_policy_test.go index ecfaf204f..4f35596ee 100644 --- a/internal/provider/data_source_aci_netflow_record_policy_test.go +++ b/internal/provider/data_source_aci_netflow_record_policy_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceNetflowRecordPolWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_out_of_band_contract_test.go b/internal/provider/data_source_aci_out_of_band_contract_test.go index f39e800f7..3e89f47db 100644 --- a/internal/provider/data_source_aci_out_of_band_contract_test.go +++ b/internal/provider/data_source_aci_out_of_band_contract_test.go @@ -14,25 +14,26 @@ import ( func TestAccDataSourceVzOOBBrCP(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testConfigVzOOBBrCPDataSource, + Config: testConfigVzOOBBrCPDataSource + testConfigDataSourceSystem, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.aci_out_of_band_contract.test", "annotation", "annotation"), resource.TestCheckResourceAttr("data.aci_out_of_band_contract.test", "description", "description_1"), - resource.TestCheckResourceAttr("data.aci_out_of_band_contract.test", "intent", "estimate_add"), resource.TestCheckResourceAttr("data.aci_out_of_band_contract.test", "name_alias", "name_alias_1"), resource.TestCheckResourceAttr("data.aci_out_of_band_contract.test", "owner_key", "owner_key_1"), resource.TestCheckResourceAttr("data.aci_out_of_band_contract.test", "owner_tag", "owner_tag_1"), resource.TestCheckResourceAttr("data.aci_out_of_band_contract.test", "priority", "level1"), resource.TestCheckResourceAttr("data.aci_out_of_band_contract.test", "scope", "application-profile"), resource.TestCheckResourceAttr("data.aci_out_of_band_contract.test", "target_dscp", "AF11"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)", ">", + resource.TestCheckResourceAttr("data.aci_out_of_band_contract.test", "intent", "estimate_add")), ), }, { - Config: testConfigVzOOBBrCPNotExisting, + Config: testConfigVzOOBBrCPNotExisting + testConfigDataSourceSystem, ExpectError: regexp.MustCompile("Failed to read aci_out_of_band_contract data source"), }, }, diff --git a/internal/provider/data_source_aci_pim_route_map_entry_test.go b/internal/provider/data_source_aci_pim_route_map_entry_test.go index 777403a1e..b53cd935c 100644 --- a/internal/provider/data_source_aci_pim_route_map_entry_test.go +++ b/internal/provider/data_source_aci_pim_route_map_entry_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourcePimRouteMapEntryWithPimRouteMapPol(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_pim_route_map_policy_test.go b/internal/provider/data_source_aci_pim_route_map_policy_test.go index 0220f8f03..3df68d9d6 100644 --- a/internal/provider/data_source_aci_pim_route_map_policy_test.go +++ b/internal/provider/data_source_aci_pim_route_map_policy_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourcePimRouteMapPolWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_relation_from_l3out_consumer_label_to_external_epg_test.go b/internal/provider/data_source_aci_relation_from_l3out_consumer_label_to_external_epg_test.go index 7032b3c90..e8c799a45 100644 --- a/internal/provider/data_source_aci_relation_from_l3out_consumer_label_to_external_epg_test.go +++ b/internal/provider/data_source_aci_relation_from_l3out_consumer_label_to_external_epg_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceL3extRsLblToInstPWithL3extConsLbl(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_relation_from_l3out_consumer_label_to_route_control_profile_test.go b/internal/provider/data_source_aci_relation_from_l3out_consumer_label_to_route_control_profile_test.go index 617c240e9..a3b3edb1a 100644 --- a/internal/provider/data_source_aci_relation_from_l3out_consumer_label_to_route_control_profile_test.go +++ b/internal/provider/data_source_aci_relation_from_l3out_consumer_label_to_route_control_profile_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceL3extRsLblToProfileWithL3extConsLbl(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_relation_to_consumed_contract_test.go b/internal/provider/data_source_aci_relation_to_consumed_contract_test.go index 15cab183f..2cdfc4a66 100644 --- a/internal/provider/data_source_aci_relation_to_consumed_contract_test.go +++ b/internal/provider/data_source_aci_relation_to_consumed_contract_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvRsConsWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -36,7 +36,7 @@ func TestAccDataSourceFvRsConsWithFvAEPg(t *testing.T) { func TestAccDataSourceFvRsConsWithFvESg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_relation_to_consumed_out_of_band_contract_test.go b/internal/provider/data_source_aci_relation_to_consumed_out_of_band_contract_test.go index e3bc93845..21e992094 100644 --- a/internal/provider/data_source_aci_relation_to_consumed_out_of_band_contract_test.go +++ b/internal/provider/data_source_aci_relation_to_consumed_out_of_band_contract_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceMgmtRsOoBConsWithMgmtInstP(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_relation_to_contract_master_test.go b/internal/provider/data_source_aci_relation_to_contract_master_test.go index af13936d4..399995c3a 100644 --- a/internal/provider/data_source_aci_relation_to_contract_master_test.go +++ b/internal/provider/data_source_aci_relation_to_contract_master_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvRsSecInheritedWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.3(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -35,7 +35,7 @@ func TestAccDataSourceFvRsSecInheritedWithFvAEPg(t *testing.T) { func TestAccDataSourceFvRsSecInheritedWithFvESg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.3(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_relation_to_domain.go b/internal/provider/data_source_aci_relation_to_domain.go index 557e80707..1de8c9216 100644 --- a/internal/provider/data_source_aci_relation_to_domain.go +++ b/internal/provider/data_source_aci_relation_to_domain.go @@ -148,10 +148,6 @@ func (d *FvRsDomAttDataSource) Schema(ctx context.Context, req datasource.Schema Computed: true, MarkdownDescription: `The untagged status of the Relation To Domain object.`, }, - "vnet_only": schema.StringAttribute{ - Computed: true, - MarkdownDescription: `The VNET only status of the Relation To Domain object.`, - }, "annotations": schema.SetNestedAttribute{ MarkdownDescription: ``, Computed: true, diff --git a/internal/provider/data_source_aci_relation_to_domain_test.go b/internal/provider/data_source_aci_relation_to_domain_test.go index e79de2bdc..fcf9bd5d6 100644 --- a/internal/provider/data_source_aci_relation_to_domain_test.go +++ b/internal/provider/data_source_aci_relation_to_domain_test.go @@ -14,18 +14,16 @@ import ( func TestAccDataSourceFvRsDomAttWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testConfigFvRsDomAttDataSourceDependencyWithFvAEPg, + Config: testConfigFvRsDomAttDataSourceDependencyWithFvAEPg + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "target_dn", "uni/vmmp-VMware/dom-domain_1"), resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "annotation", "orchestrator:terraform"), - resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "binding_type", "none"), resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "class_preference", "encap"), - resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "custom_epg_name", ""), resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "delimiter", ""), resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "deployment_immediacy", "lazy"), resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "enable_netflow", "disabled"), @@ -35,19 +33,22 @@ func TestAccDataSourceFvRsDomAttWithFvAEPg(t *testing.T) { resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "epg_cos_pref", "disabled"), resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "lag_policy_name", ""), resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "netflow_direction", "both"), - resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "number_of_ports", "0"), - resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "port_allocation", "none"), resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "primary_encapsulation", "unknown"), resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "primary_encapsulation_inner", "unknown"), resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "resolution_immediacy", "lazy"), resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "secondary_encapsulation_inner", "unknown"), resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "switching_mode", "native"), resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "untagged", "no"), - resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "vnet_only", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.0(1h)", ">", + resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "binding_type", "none"), + resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "number_of_ports", "0"), + resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "port_allocation", "none")), + composeAggregateTestCheckFuncWithVersion(t, "4.2(3j)", ">", + resource.TestCheckResourceAttr("data.aci_relation_to_domain.test", "custom_epg_name", "")), ), }, { - Config: testConfigFvRsDomAttNotExistingFvAEPg, + Config: testConfigFvRsDomAttNotExistingFvAEPg + testConfigDataSourceSystem, ExpectError: regexp.MustCompile("Failed to read aci_relation_to_domain data source"), }, }, diff --git a/internal/provider/data_source_aci_relation_to_fibre_channel_path_test.go b/internal/provider/data_source_aci_relation_to_fibre_channel_path_test.go index 46eb676b0..42c5db70b 100644 --- a/internal/provider/data_source_aci_relation_to_fibre_channel_path_test.go +++ b/internal/provider/data_source_aci_relation_to_fibre_channel_path_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvRsFcPathAttWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_relation_to_imported_contract_test.go b/internal/provider/data_source_aci_relation_to_imported_contract_test.go index a63066e2c..39e36473a 100644 --- a/internal/provider/data_source_aci_relation_to_imported_contract_test.go +++ b/internal/provider/data_source_aci_relation_to_imported_contract_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvRsConsIfWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -36,7 +36,7 @@ func TestAccDataSourceFvRsConsIfWithFvAEPg(t *testing.T) { func TestAccDataSourceFvRsConsIfWithFvESg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_relation_to_intra_epg_contract_test.go b/internal/provider/data_source_aci_relation_to_intra_epg_contract_test.go index 617798ccd..ae313b8f8 100644 --- a/internal/provider/data_source_aci_relation_to_intra_epg_contract_test.go +++ b/internal/provider/data_source_aci_relation_to_intra_epg_contract_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvRsIntraEpgWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -35,7 +35,7 @@ func TestAccDataSourceFvRsIntraEpgWithFvAEPg(t *testing.T) { func TestAccDataSourceFvRsIntraEpgWithFvESg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_relation_to_netflow_exporter_test.go b/internal/provider/data_source_aci_relation_to_netflow_exporter_test.go index cbb1f515b..1d3cdc34f 100644 --- a/internal/provider/data_source_aci_relation_to_netflow_exporter_test.go +++ b/internal/provider/data_source_aci_relation_to_netflow_exporter_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceNetflowRsMonitorToExporterWithNetflowMonitorPol(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_relation_to_provided_contract_test.go b/internal/provider/data_source_aci_relation_to_provided_contract_test.go index 0331bab61..9aa069dd2 100644 --- a/internal/provider/data_source_aci_relation_to_provided_contract_test.go +++ b/internal/provider/data_source_aci_relation_to_provided_contract_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvRsProvWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -37,7 +37,7 @@ func TestAccDataSourceFvRsProvWithFvAEPg(t *testing.T) { func TestAccDataSourceFvRsProvWithFvESg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_relation_to_static_leaf_test.go b/internal/provider/data_source_aci_relation_to_static_leaf_test.go index 22160c77f..fd2692b3a 100644 --- a/internal/provider/data_source_aci_relation_to_static_leaf_test.go +++ b/internal/provider/data_source_aci_relation_to_static_leaf_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvRsNodeAttWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_relation_to_static_path_test.go b/internal/provider/data_source_aci_relation_to_static_path_test.go index 7409c6b96..cdb7976d9 100644 --- a/internal/provider/data_source_aci_relation_to_static_path_test.go +++ b/internal/provider/data_source_aci_relation_to_static_path_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvRsPathAttWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_relation_to_taboo_contract_test.go b/internal/provider/data_source_aci_relation_to_taboo_contract_test.go index 50c3eba9d..783b4323b 100644 --- a/internal/provider/data_source_aci_relation_to_taboo_contract_test.go +++ b/internal/provider/data_source_aci_relation_to_taboo_contract_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvRsProtByWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_relation_to_vrf_fallback_route_group_test.go b/internal/provider/data_source_aci_relation_to_vrf_fallback_route_group_test.go index 4eda76267..ac00fe05a 100644 --- a/internal/provider/data_source_aci_relation_to_vrf_fallback_route_group_test.go +++ b/internal/provider/data_source_aci_relation_to_vrf_fallback_route_group_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceL3extRsOutToFBRGroupWithL3extOut(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_rest_managed_test.go b/internal/provider/data_source_aci_rest_managed_test.go index 8455cb080..30c344433 100644 --- a/internal/provider/data_source_aci_rest_managed_test.go +++ b/internal/provider/data_source_aci_rest_managed_test.go @@ -9,7 +9,7 @@ import ( func TestAccDataSourceAciRestManaged_tenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(7g)") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_route_control_profile_test.go b/internal/provider/data_source_aci_route_control_profile_test.go index d296b222c..f0607013e 100644 --- a/internal/provider/data_source_aci_route_control_profile_test.go +++ b/internal/provider/data_source_aci_route_control_profile_test.go @@ -14,11 +14,11 @@ import ( func TestAccDataSourceRtctrlProfileWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testConfigRtctrlProfileDataSourceDependencyWithFvTenant, + Config: testConfigRtctrlProfileDataSourceDependencyWithFvTenant + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.aci_route_control_profile.test", "name", "test_name"), @@ -28,11 +28,12 @@ func TestAccDataSourceRtctrlProfileWithFvTenant(t *testing.T) { resource.TestCheckResourceAttr("data.aci_route_control_profile.test", "owner_key", ""), resource.TestCheckResourceAttr("data.aci_route_control_profile.test", "owner_tag", ""), resource.TestCheckResourceAttr("data.aci_route_control_profile.test", "route_control_profile_type", "combinable"), - resource.TestCheckResourceAttr("data.aci_route_control_profile.test", "route_map_continue", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(6d)-4.2(7w),5.1(3e)", ">", + resource.TestCheckResourceAttr("data.aci_route_control_profile.test", "route_map_continue", "no")), ), }, { - Config: testConfigRtctrlProfileNotExistingFvTenant, + Config: testConfigRtctrlProfileNotExistingFvTenant + testConfigDataSourceSystem, ExpectError: regexp.MustCompile("Failed to read aci_route_control_profile data source"), }, }, @@ -41,11 +42,11 @@ func TestAccDataSourceRtctrlProfileWithFvTenant(t *testing.T) { func TestAccDataSourceRtctrlProfileWithL3extOut(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testConfigRtctrlProfileDataSourceDependencyWithL3extOut, + Config: testConfigRtctrlProfileDataSourceDependencyWithL3extOut + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.aci_route_control_profile.test", "name", "test_name"), @@ -55,11 +56,12 @@ func TestAccDataSourceRtctrlProfileWithL3extOut(t *testing.T) { resource.TestCheckResourceAttr("data.aci_route_control_profile.test", "owner_key", ""), resource.TestCheckResourceAttr("data.aci_route_control_profile.test", "owner_tag", ""), resource.TestCheckResourceAttr("data.aci_route_control_profile.test", "route_control_profile_type", "combinable"), - resource.TestCheckResourceAttr("data.aci_route_control_profile.test", "route_map_continue", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(6d)-4.2(7w),5.1(3e)", ">", + resource.TestCheckResourceAttr("data.aci_route_control_profile.test", "route_map_continue", "no")), ), }, { - Config: testConfigRtctrlProfileNotExistingL3extOut, + Config: testConfigRtctrlProfileNotExistingL3extOut + testConfigDataSourceSystem, ExpectError: regexp.MustCompile("Failed to read aci_route_control_profile data source"), }, }, diff --git a/internal/provider/data_source_aci_system_test.go b/internal/provider/data_source_aci_system_test.go index 8073c11f5..99adf64c0 100644 --- a/internal/provider/data_source_aci_system_test.go +++ b/internal/provider/data_source_aci_system_test.go @@ -13,7 +13,7 @@ import ( func TestAccDataSourceTopSystem(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_tag_test.go b/internal/provider/data_source_aci_tag_test.go index dcdbafeef..09abdd964 100644 --- a/internal/provider/data_source_aci_tag_test.go +++ b/internal/provider/data_source_aci_tag_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceTagTagWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -35,7 +35,7 @@ func TestAccDataSourceTagTagWithFvTenant(t *testing.T) { func TestAccDataSourceTagTagWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_trust_control_policy_test.go b/internal/provider/data_source_aci_trust_control_policy_test.go index bfda656ab..cb00b4827 100644 --- a/internal/provider/data_source_aci_trust_control_policy_test.go +++ b/internal/provider/data_source_aci_trust_control_policy_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFhsTrustCtrlPolWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_vrf_fallback_route_group_member_test.go b/internal/provider/data_source_aci_vrf_fallback_route_group_member_test.go index 54f9fb60f..5cffe4b8d 100644 --- a/internal/provider/data_source_aci_vrf_fallback_route_group_member_test.go +++ b/internal/provider/data_source_aci_vrf_fallback_route_group_member_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvFBRMemberWithFvFBRGroup(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_vrf_fallback_route_group_test.go b/internal/provider/data_source_aci_vrf_fallback_route_group_test.go index c01f15411..9a16d74ab 100644 --- a/internal/provider/data_source_aci_vrf_fallback_route_group_test.go +++ b/internal/provider/data_source_aci_vrf_fallback_route_group_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvFBRGroupWithFvCtx(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/data_source_aci_vrf_fallback_route_test.go b/internal/provider/data_source_aci_vrf_fallback_route_test.go index 7e7a89729..0cad14d86 100644 --- a/internal/provider/data_source_aci_vrf_fallback_route_test.go +++ b/internal/provider/data_source_aci_vrf_fallback_route_test.go @@ -14,7 +14,7 @@ import ( func TestAccDataSourceFvFBRouteWithFvFBRGroup(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/function_compare_versions.go b/internal/provider/function_compare_versions.go new file mode 100644 index 000000000..127eef5ef --- /dev/null +++ b/internal/provider/function_compare_versions.go @@ -0,0 +1,204 @@ +package provider + +import ( + "context" + "errors" + "fmt" + "regexp" + "strconv" + + "github.com/hashicorp/terraform-plugin-framework/function" +) + +// Ensure the implementation satisfies the desired interfaces. +var _ function.Function = CompareVersionsFunction{} + +func NewCompareVersionsFunction() function.Function { + return &CompareVersionsFunction{} +} + +type CompareVersionsFunction struct{} + +func (f CompareVersionsFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { + resp.Name = "compare_versions" +} + +func (f CompareVersionsFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { + resp.Definition = function.Definition{ + Summary: "Compare two version strings", + Description: "Given two APIC version strings and a comparison operator, returns a boolean result of the comparison.", + + Parameters: []function.Parameter{ + function.StringParameter{ + Name: "version1", + Description: "First version string", + }, + function.StringParameter{ + Name: "operator", + Description: "Comparison operator", + Validators: []function.StringParameterValidator{oneOf("==", "!=", ">", "<", ">=", "<=")}, + }, + function.StringParameter{ + Name: "version2", + Description: "Second version string", + }, + }, + Return: function.BoolReturn{}, + } +} + +func (f CompareVersionsFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { + var version1, version2, operator string + + resp.Error = function.ConcatFuncErrors(req.Arguments.Get(ctx, &version1, &operator, &version2)) + if resp.Error != nil { + return + } + + result, err := CompareVersions(version1, version2, operator) + if err != nil { + resp.Error = function.NewFuncError(err.Error()) + return + } + + resp.Error = function.ConcatFuncErrors(resp.Result.Set(ctx, result)) +} + +type Version struct { + Major int + Minor int + Patch int + Tag int +} + +type VersionResult struct { + Version *Version + Error string +} + +func ParseVersion(rawVersion string) VersionResult { + versionRegex := regexp.MustCompile(`(\d+)\.(\d+)\((\d+)([a-z])\)`) + matches := versionRegex.FindStringSubmatch(rawVersion) + if matches == nil { + return VersionResult{Error: "unknown"} + } + major, _ := strconv.Atoi(matches[1]) + minor, _ := strconv.Atoi(matches[2]) + patch, _ := strconv.Atoi(matches[3]) + tag := int(matches[4][0]) + + return VersionResult{Version: &Version{Major: major, Minor: minor, Patch: patch, Tag: tag}} + +} + +func IsVersionGreater(v1, v2 Version) bool { + if v1.Major != v2.Major { + return v1.Major > v2.Major + } else if v1.Minor != v2.Minor { + return v1.Minor > v2.Minor + } else if v1.Patch != v2.Patch { + return v1.Patch > v2.Patch + } + return v1.Tag > v2.Tag +} + +func IsVersionEqual(v1, v2 Version) bool { + return v1.Major == v2.Major && v1.Minor == v2.Minor && v1.Patch == v2.Patch && v1.Tag == v2.Tag +} + +func IsVersionNotEqual(v1, v2 Version) bool { + return !IsVersionEqual(v1, v2) +} + +func IsVersionLesser(v1, v2 Version) bool { + if v1.Major != v2.Major { + return v1.Major < v2.Major + } else if v1.Minor != v2.Minor { + return v1.Minor < v2.Minor + } else if v1.Patch != v2.Patch { + return v1.Patch < v2.Patch + } + return v1.Tag < v2.Tag +} + +func IsVersionGreaterOrEqual(v1, v2 Version) bool { + return IsVersionGreater(v1, v2) || IsVersionEqual(v1, v2) +} + +func IsVersionLessOrEqual(v1, v2 Version) bool { + return IsVersionLesser(v1, v2) || IsVersionEqual(v1, v2) +} + +func CompareVersions(version1, version2, operator string) (bool, error) { + versionResult1 := ParseVersion(version1) + if versionResult1.Error == "unknown" { + return false, errors.New(fmt.Sprintf("Invalid APIC version provided: %s", version1)) + } + + versionResult2 := ParseVersion(version2) + if versionResult2.Error == "unknown" { + return false, errors.New(fmt.Sprintf("Invalid APIC version provided: %s", version2)) + } + + v1 := *versionResult1.Version + v2 := *versionResult2.Version + + var result bool + switch operator { + case "==": + result = IsVersionEqual(v1, v2) + case "!=": + result = IsVersionNotEqual(v1, v2) + case ">": + result = IsVersionGreater(v1, v2) + case "<": + result = IsVersionLesser(v1, v2) + case ">=": + result = IsVersionGreaterOrEqual(v1, v2) + case "<=": + result = IsVersionLessOrEqual(v1, v2) + default: + return false, errors.New(fmt.Sprintf("Invalid operator: %s", operator)) + } + + return result, nil +} + +var _ function.StringParameterValidator = oneOfValidator{} + +type oneOfValidator struct { + AllowedValues []string +} + +func (v oneOfValidator) Description(ctx context.Context) string { + return fmt.Sprintf("value must be one of %v", v.AllowedValues) +} + +func (v oneOfValidator) MarkdownDescription(ctx context.Context) string { + return fmt.Sprintf("value must be one of `%v`", v.AllowedValues) +} + +func (v oneOfValidator) ValidateParameterString(ctx context.Context, req function.StringParameterValidatorRequest, resp *function.StringParameterValidatorResponse) { + + if req.Value.IsUnknown() || req.Value.IsNull() { + return + } + + value := req.Value.ValueString() + for _, allowedValue := range v.AllowedValues { + if value == allowedValue { + return + } + } + + resp.Error = function.NewArgumentFuncError( + req.ArgumentPosition, + fmt.Sprintf("Invalid Value: Value must be one of %v, got: %s.", v.AllowedValues, value), + ) +} + +func oneOf(values ...string) oneOfValidator { + return oneOfValidator{ + AllowedValues: values, + } +} diff --git a/internal/provider/function_compare_versions_test.go b/internal/provider/function_compare_versions_test.go new file mode 100644 index 000000000..486e55e53 --- /dev/null +++ b/internal/provider/function_compare_versions_test.go @@ -0,0 +1,71 @@ +package provider + +import ( + "testing" + + "github.com/hashicorp/go-version" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/tfversion" +) + +func TestCompareVersionsFunction(t *testing.T) { + t.Parallel() + + resource.UnitTest(t, resource.TestCase{ + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBelow(version.Must(version.NewVersion("1.8.0"))), + }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactoriesFunction, + Steps: []resource.TestStep{ + { + Config: ` + output "test_equal" { + value = provider::aci::compare_versions("1.0(0a)", "==", "1.0(0a)") + } + output "test_greater" { + value = provider::aci::compare_versions("1.1(0a)", ">", "1.0(0a)") + } + output "test_lesser" { + value = provider::aci::compare_versions("1.0(0a)", "<", "1.1(0a)") + } + output "test_not_equal" { + value = provider::aci::compare_versions("1.0(0a)", "!=", "1.1(0a)") + } + output "test_greater_or_equal" { + value = provider::aci::compare_versions("1.1(0a)", ">=", "1.0(0a)") + } + output "test_less_or_equal" { + value = provider::aci::compare_versions("1.0(0a)", "<=", "1.1(0a)") + } + output "test_not_equal_false" { + value = provider::aci::compare_versions("1.0(0a)", "!=", "1.0(0a)") + } + output "test_greater_false" { + value = provider::aci::compare_versions("1.0(0a)", ">", "1.1(0a)") + } + output "test_lesser_false" { + value = provider::aci::compare_versions("1.1(0a)", "<", "1.0(0a)") + } + output "test_greater_or_equal_false" { + value = provider::aci::compare_versions("1.0(0a)", ">=", "1.1(0a)") + } + output "test_less_or_equal_false" { + value = provider::aci::compare_versions("1.1(0a)", "<=", "1.0(0a)") + }`, + Check: resource.ComposeAggregateTestCheckFunc( + CheckOutputBool("test_equal", true), + CheckOutputBool("test_greater", true), + CheckOutputBool("test_lesser", true), + CheckOutputBool("test_not_equal", true), + CheckOutputBool("test_greater_or_equal", true), + CheckOutputBool("test_less_or_equal", true), + CheckOutputBool("test_not_equal_false", false), + CheckOutputBool("test_greater_false", false), + CheckOutputBool("test_lesser_false", false), + CheckOutputBool("test_greater_or_equal_false", false), + CheckOutputBool("test_less_or_equal_false", false), + ), + }, + }, + }) +} diff --git a/internal/provider/provider.go b/internal/provider/provider.go index ff04aca37..ac8e231ff 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -23,6 +23,7 @@ import ( // temporary unused until muxing is removed // "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/function" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" ) @@ -32,6 +33,7 @@ var globalAllowExistingOnCreate bool // Ensure AciProvider satisfies various provider interfaces. var _ provider.Provider = &AciProvider{} +var _ provider.ProviderWithFunctions = &AciProvider{} // AciProvider defines the provider implementation. type AciProvider struct { @@ -246,6 +248,8 @@ func (p *AciProvider) Resources(ctx context.Context) []func() resource.Resource NewNetflowRsMonitorToExporterResource, NewPimRouteMapEntryResource, NewPimRouteMapPolResource, + NewPkiKeyRingResource, + NewPkiTPResource, NewQosCustomPolResource, NewQosDppPolResource, NewRtctrlProfileResource, @@ -300,6 +304,8 @@ func (p *AciProvider) DataSources(ctx context.Context) []func() datasource.DataS NewNetflowRsMonitorToExporterDataSource, NewPimRouteMapEntryDataSource, NewPimRouteMapPolDataSource, + NewPkiKeyRingDataSource, + NewPkiTPDataSource, NewQosCustomPolDataSource, NewQosDppPolDataSource, NewRtctrlProfileDataSource, @@ -433,3 +439,9 @@ func stringToInt(resp *provider.ConfigureResponse, attributeName, stringValue st } return intValue } + +func (p *AciProvider) Functions(ctx context.Context) []func() function.Function { + return []func() function.Function{ + NewCompareVersionsFunction, + } +} diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go index 7c9f8d223..5eee644ab 100644 --- a/internal/provider/provider_test.go +++ b/internal/provider/provider_test.go @@ -2,16 +2,24 @@ package provider import ( "context" + "errors" + "fmt" "os" "strconv" + "strings" + "sync" "testing" "github.com/CiscoDevNet/terraform-provider-aci/v2/aci" + "github.com/ciscoecosystem/aci-go-client/v2/client" + "github.com/ciscoecosystem/aci-go-client/v2/container" "github.com/hashicorp/terraform-plugin-framework/providerserver" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-mux/tf5to6server" "github.com/hashicorp/terraform-plugin-mux/tf6muxserver" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" ) var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){ @@ -44,28 +52,154 @@ var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServe }, } -func testAccPreCheck(t *testing.T) { +var testAccProtoV6ProviderFactoriesFunction = map[string]func() (tfprotov6.ProviderServer, error){ + "aci": providerserver.NewProtocol6WithError(New("test")()), +} + +var ( + aciClientTest *client.Client + aciClientTestOnce sync.Once +) + +func getACIClientTest(t *testing.T) *client.Client { + aciClientTestOnce.Do(func() { + var aci_url, aci_username, aci_password string + if v := os.Getenv("ACI_USERNAME"); v == "" { + t.Fatal("ACI_USERNAME must be set for acceptance tests") + } else { + aci_username = v + } + if v := os.Getenv("ACI_PASSWORD"); v == "" { + t.Fatal("ACI_PASSWORD must be set for acceptance tests") + } else { + aci_password = v + } + if v := os.Getenv("ACI_URL"); v == "" { + t.Fatal("ACI_URL must be set for acceptance tests") + } else { + aci_url = v + } + if v := os.Getenv("ACI_VAL_REL_DN"); v == "" { + t.Fatal("ACI_VAL_REL_DN must be set for acceptance tests") + boolValue, err := strconv.ParseBool(v) + if err != nil || boolValue == true { + t.Fatal("ACI_VAL_REL_DN must be a 'false' boolean value") + } + } + + aciClientTest = client.NewClient(aci_url, aci_username, client.Password(aci_password), client.Insecure(true), client.MaxRetries(2)) + }) + return aciClientTest +} + +func testAccPreCheck(t *testing.T, testType string, testApplicableFromVersion string) { // globalAnnotation is explicitly set here, as the provider initialization in acceptance tests differs from the standard initialization process. setGlobalAnnotation(basetypes.NewStringNull(), "ACI_ANNOTATION") - if v := os.Getenv("ACI_USERNAME"); v == "" { - t.Fatal("ACI_USERNAME must be set for acceptance tests") + if testType == "cloud" { + t.Skip("[WARNING] Test skipped because it is not supported on an on-prem APIC") } - if v := os.Getenv("ACI_PASSWORD"); v == "" { - t.Fatal("ACI_PASSWORD must be set for acceptance tests") + + infoController, err := getACIClientTest(t).GetViaURL("/api/node/class/firmwareCtrlrRunning.json") + if err != nil { + t.Fatalf("Error fetching APIC controller information: %v", err) } - if v := os.Getenv("ACI_URL"); v == "" { - t.Fatal("ACI_URL must be set for acceptance tests") + apicVersion := extractControllerVersion(infoController) + // TODO process the version when it has ranges associated with it + if apicVersion != strings.TrimSuffix(testApplicableFromVersion, "-") { + if IsVersionGreater(*ParseVersion(testApplicableFromVersion).Version, *ParseVersion(apicVersion).Version) { + t.Skip("[WARNING] Test skipped because it is not supported on APIC version:", apicVersion) + } } - if v := os.Getenv("ACI_VAL_REL_DN"); v == "" { - t.Fatal("ACI_VAL_REL_DN must be set for acceptance tests") - boolValue, err := strconv.ParseBool(v) - if err != nil || boolValue == true { - t.Fatal("ACI_VAL_REL_DN must be a 'false' boolean value") + +} + +func composeAggregateTestCheckFuncWithVersion(t *testing.T, propertyVersion string, operator string, checks ...resource.TestCheckFunc) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources["data.aci_system.version"] + + if !ok { + return fmt.Errorf("data source aci_system was not found in the test configuration") + } + + apicVersion := rs.Primary.Attributes["version"] + + var result []error + + comparisonResult, err := CompareVersions(apicVersion, propertyVersion, operator) + if err != nil { + return fmt.Errorf("Failed to compare versions in the test check function: %w", err) } + + if !comparisonResult { + t.Logf("[WARNING] Test for checking the resource attribute value skipped due to version incompatibility between Property version: %s and APIC version: %s.", propertyVersion, apicVersion) + return nil + } + + for i, check := range checks { + if err := check(s); err != nil { + result = append(result, fmt.Errorf("Check %d/%d error: %w", i+1, len(checks), err)) + } + + } + return errors.Join(result...) } } +func extractControllerVersion(requestData *container.Container) string { + classReadInfo := requestData.Search("imdata").Search("firmwareCtrlrRunning").Data().([]interface{}) + if len(classReadInfo) == 1 { + attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) + for attributeName, attributeValue := range attributes { + if attributeName == "version" { + return attributeValue.(string) + } + } + } + return "" +} + +func testCheckResourceDestroy(s *terraform.State) error { + aciClient := getACIClientTest(nil) + for name, rs := range s.RootModule().Resources { + if strings.HasPrefix(name, "aci_") { + _, err := aciClient.Get(rs.Primary.ID) + if err != nil { + if strings.Contains(err.Error(), "Error retrieving Object: Object may not exist") { + continue + } else { + return fmt.Errorf("error checking if resource '%s' with ID '%s' still exists: %s", name, rs.Primary.ID, err) + } + } + return fmt.Errorf("terraform destroy was unsuccessful. The resource '%s' with ID '%s' still exists", name, rs.Primary.ID) + } + } + return nil +} + func setEnvVariable(t *testing.T, key, value string) { t.Setenv(key, value) } + +func CheckOutputBool(name string, value bool) resource.TestCheckFunc { + return func(s *terraform.State) error { + ms := s.RootModule() + rs, ok := ms.Outputs[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + boolValue, err := strconv.ParseBool(rs.Value.(string)) + if err != nil { + return fmt.Errorf("Error Parsing value: %s", err) + } + if boolValue != value { + return fmt.Errorf( + "Output '%s': expected %#v, got %#v", + name, + value, + rs.Value) + } + + return nil + } +} diff --git a/internal/provider/resource_aci_access_interface_override.go b/internal/provider/resource_aci_access_interface_override.go index 11f1fcee7..554fed6d7 100644 --- a/internal/provider/resource_aci_access_interface_override.go +++ b/internal/provider/resource_aci_access_interface_override.go @@ -465,6 +465,7 @@ func (r *InfraHPathSResource) Create(ctx context.Context, req resource.CreateReq } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -585,7 +586,7 @@ func (r *InfraHPathSResource) ImportState(ctx context.Context, req resource.Impo func getAndSetInfraHPathSAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *InfraHPathSResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "infraHPathS,infraRsHPathAtt,infraRsPathToAccBaseGrp,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyInfraHPathSResourceModel() + readData := getEmptyInfraHPathSResourceModel() if diags.HasError() { return @@ -596,26 +597,26 @@ func getAndSetInfraHPathSAttributes(ctx context.Context, diags *diag.Diagnostics attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setInfraHPathSParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setInfraHPathSParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerKey" { - data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerTag" { - data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) } } InfraRsHPathAttInfraHPathSList := make([]InfraRsHPathAttInfraHPathSResourceModel, 0) @@ -681,22 +682,22 @@ func getAndSetInfraHPathSAttributes(ctx context.Context, diags *diag.Diagnostics } if len(InfraRsHPathAttInfraHPathSList) == 1 { infraRsHPathAttObject, _ := types.ObjectValueFrom(ctx, InfraRsHPathAttInfraHPathSType, InfraRsHPathAttInfraHPathSList[0]) - data.InfraRsHPathAtt = infraRsHPathAttObject + readData.InfraRsHPathAtt = infraRsHPathAttObject } else { infraRsHPathAttObject, _ := types.ObjectValueFrom(ctx, InfraRsHPathAttInfraHPathSType, getEmptyInfraRsHPathAttInfraHPathSResourceModel()) - data.InfraRsHPathAtt = infraRsHPathAttObject + readData.InfraRsHPathAtt = infraRsHPathAttObject } if len(InfraRsPathToAccBaseGrpInfraHPathSList) == 1 { infraRsPathToAccBaseGrpObject, _ := types.ObjectValueFrom(ctx, InfraRsPathToAccBaseGrpInfraHPathSType, InfraRsPathToAccBaseGrpInfraHPathSList[0]) - data.InfraRsPathToAccBaseGrp = infraRsPathToAccBaseGrpObject + readData.InfraRsPathToAccBaseGrp = infraRsPathToAccBaseGrpObject } else { infraRsPathToAccBaseGrpObject, _ := types.ObjectValueFrom(ctx, InfraRsPathToAccBaseGrpInfraHPathSType, getEmptyInfraRsPathToAccBaseGrpInfraHPathSResourceModel()) - data.InfraRsPathToAccBaseGrp = infraRsPathToAccBaseGrpObject + readData.InfraRsPathToAccBaseGrp = infraRsPathToAccBaseGrpObject } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationInfraHPathSList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagInfraHPathSList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationInfraHPathSList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagInfraHPathSList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -704,8 +705,9 @@ func getAndSetInfraHPathSAttributes(ctx context.Context, diags *diag.Diagnostics ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getInfraHPathSRn(ctx context.Context, data *InfraHPathSResourceModel) string { @@ -921,7 +923,6 @@ func getInfraHPathSCreateJsonPayload(ctx context.Context, diags *diag.Diagnostic if !data.OwnerTag.IsNull() && !data.OwnerTag.IsUnknown() { payloadMap["attributes"].(map[string]string)["ownerTag"] = data.OwnerTag.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"infraHPathS": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_access_interface_override_test.go b/internal/provider/resource_aci_access_interface_override_test.go index d7e4e94a1..e6b1ac3b0 100644 --- a/internal/provider/resource_aci_access_interface_override_test.go +++ b/internal/provider/resource_aci_access_interface_override_test.go @@ -17,7 +17,7 @@ import ( func TestAccResourceInfraHPathS(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -43,7 +43,7 @@ func TestAccResourceInfraHPathS(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -56,7 +56,7 @@ func TestAccResourceInfraHPathS(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -81,7 +81,7 @@ func TestAccResourceInfraHPathS(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -259,6 +259,7 @@ func TestAccResourceInfraHPathS(t *testing.T) { }, }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_annotation.go b/internal/provider/resource_aci_annotation.go index f35aad4bc..0954dfb73 100644 --- a/internal/provider/resource_aci_annotation.go +++ b/internal/provider/resource_aci_annotation.go @@ -180,6 +180,7 @@ func (r *TagAnnotationResource) Create(ctx context.Context, req resource.CreateR } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -286,7 +287,7 @@ func (r *TagAnnotationResource) ImportState(ctx context.Context, req resource.Im func getAndSetTagAnnotationAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *TagAnnotationResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "GET", nil) - *data = *getEmptyTagAnnotationResourceModel() + readData := getEmptyTagAnnotationResourceModel() if diags.HasError() { return @@ -297,14 +298,14 @@ func getAndSetTagAnnotationAttributes(ctx context.Context, diags *diag.Diagnosti attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setTagAnnotationParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setTagAnnotationParentDn(ctx, attributeValue.(string), readData) } if attributeName == "key" { - data.Key = basetypes.NewStringValue(attributeValue.(string)) + readData.Key = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "value" { - data.Value = basetypes.NewStringValue(attributeValue.(string)) + readData.Value = basetypes.NewStringValue(attributeValue.(string)) } } } else { @@ -314,8 +315,9 @@ func getAndSetTagAnnotationAttributes(ctx context.Context, diags *diag.Diagnosti ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getTagAnnotationRn(ctx context.Context, data *TagAnnotationResourceModel) string { @@ -362,7 +364,6 @@ func getTagAnnotationCreateJsonPayload(ctx context.Context, diags *diag.Diagnost if !data.Value.IsNull() && !data.Value.IsUnknown() { payloadMap["attributes"].(map[string]string)["value"] = data.Value.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"tagAnnotation": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_annotation_test.go b/internal/provider/resource_aci_annotation_test.go index 4489c8617..8c5b58774 100644 --- a/internal/provider/resource_aci_annotation_test.go +++ b/internal/provider/resource_aci_annotation_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceTagAnnotationWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -33,7 +33,7 @@ func TestAccResourceTagAnnotationWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -46,7 +46,7 @@ func TestAccResourceTagAnnotationWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -64,7 +64,7 @@ func TestAccResourceTagAnnotationWithFvTenant(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -110,12 +110,13 @@ func TestAccResourceTagAnnotationWithFvTenant(t *testing.T) { ImportStateVerify: true, }, }, + CheckDestroy: testCheckResourceDestroy, }) } func TestAccResourceTagAnnotationWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -134,7 +135,7 @@ func TestAccResourceTagAnnotationWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -147,7 +148,7 @@ func TestAccResourceTagAnnotationWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -165,7 +166,7 @@ func TestAccResourceTagAnnotationWithFvAEPg(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -211,6 +212,7 @@ func TestAccResourceTagAnnotationWithFvAEPg(t *testing.T) { ImportStateVerify: true, }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_application_epg.go b/internal/provider/resource_aci_application_epg.go index 40a416254..bf62a57ec 100644 --- a/internal/provider/resource_aci_application_epg.go +++ b/internal/provider/resource_aci_application_epg.go @@ -193,7 +193,6 @@ func getEmptyFvAEPgResourceModel() *FvAEPgResourceModel { "switching_mode": types.StringType, "target_dn": types.StringType, "untagged": types.StringType, - "vnet_only": types.StringType, }, }), FvRsDppPol: types.ObjectNull(map[string]attr.Type{ @@ -450,7 +449,6 @@ type FvRsDomAttFvAEPgResourceModel struct { SwitchingMode types.String `tfsdk:"switching_mode"` TDn types.String `tfsdk:"target_dn"` Untagged types.String `tfsdk:"untagged"` - VnetOnly types.String `tfsdk:"vnet_only"` } func getEmptyFvRsDomAttFvAEPgResourceModel() FvRsDomAttFvAEPgResourceModel { @@ -480,7 +478,6 @@ func getEmptyFvRsDomAttFvAEPgResourceModel() FvRsDomAttFvAEPgResourceModel { SwitchingMode: basetypes.NewStringNull(), TDn: basetypes.NewStringNull(), Untagged: basetypes.NewStringNull(), - VnetOnly: basetypes.NewStringNull(), } } @@ -1057,7 +1054,6 @@ func (r *FvAEPgResource) UpgradeState(ctx context.Context) map[int64]resource.St "switching_mode": basetypes.StringType{}, "target_dn": basetypes.StringType{}, "untagged": basetypes.StringType{}, - "vnet_only": basetypes.StringType{}, }, }, ) @@ -3300,17 +3296,6 @@ func (r *FvAEPgResource) Schema(ctx context.Context, req resource.SchemaRequest, }, MarkdownDescription: `The untagged status of the Relation To Domain object.`, }, - "vnet_only": schema.StringAttribute{ - Optional: true, - Computed: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - }, - Validators: []validator.String{ - stringvalidator.OneOf("no", "yes"), - }, - MarkdownDescription: `The VNET only status of the Relation To Domain object.`, - }, }, }, }, @@ -3995,6 +3980,7 @@ func (r *FvAEPgResource) Create(ctx context.Context, req resource.CreateRequest, } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -4171,7 +4157,7 @@ func (r *FvAEPgResource) ImportState(ctx context.Context, req resource.ImportSta func getAndSetFvAEPgAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvAEPgResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvAEPg,fvCrtrn,fvRsAEPgMonPol,fvRsBd,fvRsCons,fvRsConsIf,fvRsCustQosPol,fvRsDomAtt,fvRsDppPol,fvRsFcPathAtt,fvRsIntraEpg,fvRsNodeAtt,fvRsPathAtt,fvRsProtBy,fvRsProv,fvRsSecInherited,fvRsTrustCtrl,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvAEPgResourceModel() + readData := getEmptyFvAEPgResourceModel() if diags.HasError() { return @@ -4182,55 +4168,55 @@ func getAndSetFvAEPgAttributes(ctx context.Context, diags *diag.Diagnostics, cli attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvAEPgParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvAEPgParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "exceptionTag" { - data.ExceptionTag = basetypes.NewStringValue(attributeValue.(string)) + readData.ExceptionTag = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "floodOnEncap" { - data.FloodOnEncap = basetypes.NewStringValue(attributeValue.(string)) + readData.FloodOnEncap = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "fwdCtrl" && attributeValue.(string) == "" { - data.FwdCtrl = basetypes.NewStringValue("none") + readData.FwdCtrl = basetypes.NewStringValue("none") } else if attributeName == "fwdCtrl" { - data.FwdCtrl = basetypes.NewStringValue(attributeValue.(string)) + readData.FwdCtrl = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "hasMcastSource" { - data.HasMcastSource = basetypes.NewStringValue(attributeValue.(string)) + readData.HasMcastSource = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "isAttrBasedEPg" { - data.IsAttrBasedEPg = basetypes.NewStringValue(attributeValue.(string)) + readData.IsAttrBasedEPg = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "matchT" { - data.MatchT = basetypes.NewStringValue(attributeValue.(string)) + readData.MatchT = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "pcEnfPref" { - data.PcEnfPref = basetypes.NewStringValue(attributeValue.(string)) + readData.PcEnfPref = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "pcTag" { - data.PcTag = basetypes.NewStringValue(attributeValue.(string)) + readData.PcTag = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "prefGrMemb" { - data.PrefGrMemb = basetypes.NewStringValue(attributeValue.(string)) + readData.PrefGrMemb = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "prio" { - data.Prio = customTypes.NewFvAEPgPrioStringValue(attributeValue.(string)) + readData.Prio = customTypes.NewFvAEPgPrioStringValue(attributeValue.(string)) } if attributeName == "shutdown" { - data.Shutdown = basetypes.NewStringValue(attributeValue.(string)) + readData.Shutdown = basetypes.NewStringValue(attributeValue.(string)) } } FvCrtrnFvAEPgList := make([]FvCrtrnFvAEPgResourceModel, 0) @@ -4438,9 +4424,6 @@ func getAndSetFvAEPgAttributes(ctx context.Context, diags *diag.Diagnostics, cli if childAttributeName == "untagged" { FvRsDomAttFvAEPg.Untagged = basetypes.NewStringValue(childAttributeValue.(string)) } - if childAttributeName == "vnetOnly" { - FvRsDomAttFvAEPg.VnetOnly = basetypes.NewStringValue(childAttributeValue.(string)) - } } FvRsDomAttFvAEPgList = append(FvRsDomAttFvAEPgList, FvRsDomAttFvAEPg) } @@ -4623,71 +4606,71 @@ func getAndSetFvAEPgAttributes(ctx context.Context, diags *diag.Diagnostics, cli } if len(FvCrtrnFvAEPgList) == 1 { fvCrtrnObject, _ := types.ObjectValueFrom(ctx, FvCrtrnFvAEPgType, FvCrtrnFvAEPgList[0]) - data.FvCrtrn = fvCrtrnObject + readData.FvCrtrn = fvCrtrnObject } else { fvCrtrnObject, _ := types.ObjectValueFrom(ctx, FvCrtrnFvAEPgType, getEmptyFvCrtrnFvAEPgResourceModel()) - data.FvCrtrn = fvCrtrnObject + readData.FvCrtrn = fvCrtrnObject } if len(FvRsAEPgMonPolFvAEPgList) == 1 { fvRsAEPgMonPolObject, _ := types.ObjectValueFrom(ctx, FvRsAEPgMonPolFvAEPgType, FvRsAEPgMonPolFvAEPgList[0]) - data.FvRsAEPgMonPol = fvRsAEPgMonPolObject + readData.FvRsAEPgMonPol = fvRsAEPgMonPolObject } else { fvRsAEPgMonPolObject, _ := types.ObjectValueFrom(ctx, FvRsAEPgMonPolFvAEPgType, getEmptyFvRsAEPgMonPolFvAEPgResourceModel()) - data.FvRsAEPgMonPol = fvRsAEPgMonPolObject + readData.FvRsAEPgMonPol = fvRsAEPgMonPolObject } if len(FvRsBdFvAEPgList) == 1 { fvRsBdObject, _ := types.ObjectValueFrom(ctx, FvRsBdFvAEPgType, FvRsBdFvAEPgList[0]) - data.FvRsBd = fvRsBdObject + readData.FvRsBd = fvRsBdObject } else { fvRsBdObject, _ := types.ObjectValueFrom(ctx, FvRsBdFvAEPgType, getEmptyFvRsBdFvAEPgResourceModel()) - data.FvRsBd = fvRsBdObject + readData.FvRsBd = fvRsBdObject } - fvRsConsSet, _ := types.SetValueFrom(ctx, data.FvRsCons.ElementType(ctx), FvRsConsFvAEPgList) - data.FvRsCons = fvRsConsSet - fvRsConsIfSet, _ := types.SetValueFrom(ctx, data.FvRsConsIf.ElementType(ctx), FvRsConsIfFvAEPgList) - data.FvRsConsIf = fvRsConsIfSet + fvRsConsSet, _ := types.SetValueFrom(ctx, readData.FvRsCons.ElementType(ctx), FvRsConsFvAEPgList) + readData.FvRsCons = fvRsConsSet + fvRsConsIfSet, _ := types.SetValueFrom(ctx, readData.FvRsConsIf.ElementType(ctx), FvRsConsIfFvAEPgList) + readData.FvRsConsIf = fvRsConsIfSet if len(FvRsCustQosPolFvAEPgList) == 1 { fvRsCustQosPolObject, _ := types.ObjectValueFrom(ctx, FvRsCustQosPolFvAEPgType, FvRsCustQosPolFvAEPgList[0]) - data.FvRsCustQosPol = fvRsCustQosPolObject + readData.FvRsCustQosPol = fvRsCustQosPolObject } else { fvRsCustQosPolObject, _ := types.ObjectValueFrom(ctx, FvRsCustQosPolFvAEPgType, getEmptyFvRsCustQosPolFvAEPgResourceModel()) - data.FvRsCustQosPol = fvRsCustQosPolObject + readData.FvRsCustQosPol = fvRsCustQosPolObject } - fvRsDomAttSet, _ := types.SetValueFrom(ctx, data.FvRsDomAtt.ElementType(ctx), FvRsDomAttFvAEPgList) - data.FvRsDomAtt = fvRsDomAttSet + fvRsDomAttSet, _ := types.SetValueFrom(ctx, readData.FvRsDomAtt.ElementType(ctx), FvRsDomAttFvAEPgList) + readData.FvRsDomAtt = fvRsDomAttSet if len(FvRsDppPolFvAEPgList) == 1 { fvRsDppPolObject, _ := types.ObjectValueFrom(ctx, FvRsDppPolFvAEPgType, FvRsDppPolFvAEPgList[0]) - data.FvRsDppPol = fvRsDppPolObject + readData.FvRsDppPol = fvRsDppPolObject } else { fvRsDppPolObject, _ := types.ObjectValueFrom(ctx, FvRsDppPolFvAEPgType, getEmptyFvRsDppPolFvAEPgResourceModel()) - data.FvRsDppPol = fvRsDppPolObject - } - fvRsFcPathAttSet, _ := types.SetValueFrom(ctx, data.FvRsFcPathAtt.ElementType(ctx), FvRsFcPathAttFvAEPgList) - data.FvRsFcPathAtt = fvRsFcPathAttSet - fvRsIntraEpgSet, _ := types.SetValueFrom(ctx, data.FvRsIntraEpg.ElementType(ctx), FvRsIntraEpgFvAEPgList) - data.FvRsIntraEpg = fvRsIntraEpgSet - fvRsNodeAttSet, _ := types.SetValueFrom(ctx, data.FvRsNodeAtt.ElementType(ctx), FvRsNodeAttFvAEPgList) - data.FvRsNodeAtt = fvRsNodeAttSet - fvRsPathAttSet, _ := types.SetValueFrom(ctx, data.FvRsPathAtt.ElementType(ctx), FvRsPathAttFvAEPgList) - data.FvRsPathAtt = fvRsPathAttSet - fvRsProtBySet, _ := types.SetValueFrom(ctx, data.FvRsProtBy.ElementType(ctx), FvRsProtByFvAEPgList) - data.FvRsProtBy = fvRsProtBySet - fvRsProvSet, _ := types.SetValueFrom(ctx, data.FvRsProv.ElementType(ctx), FvRsProvFvAEPgList) - data.FvRsProv = fvRsProvSet - fvRsSecInheritedSet, _ := types.SetValueFrom(ctx, data.FvRsSecInherited.ElementType(ctx), FvRsSecInheritedFvAEPgList) - data.FvRsSecInherited = fvRsSecInheritedSet + readData.FvRsDppPol = fvRsDppPolObject + } + fvRsFcPathAttSet, _ := types.SetValueFrom(ctx, readData.FvRsFcPathAtt.ElementType(ctx), FvRsFcPathAttFvAEPgList) + readData.FvRsFcPathAtt = fvRsFcPathAttSet + fvRsIntraEpgSet, _ := types.SetValueFrom(ctx, readData.FvRsIntraEpg.ElementType(ctx), FvRsIntraEpgFvAEPgList) + readData.FvRsIntraEpg = fvRsIntraEpgSet + fvRsNodeAttSet, _ := types.SetValueFrom(ctx, readData.FvRsNodeAtt.ElementType(ctx), FvRsNodeAttFvAEPgList) + readData.FvRsNodeAtt = fvRsNodeAttSet + fvRsPathAttSet, _ := types.SetValueFrom(ctx, readData.FvRsPathAtt.ElementType(ctx), FvRsPathAttFvAEPgList) + readData.FvRsPathAtt = fvRsPathAttSet + fvRsProtBySet, _ := types.SetValueFrom(ctx, readData.FvRsProtBy.ElementType(ctx), FvRsProtByFvAEPgList) + readData.FvRsProtBy = fvRsProtBySet + fvRsProvSet, _ := types.SetValueFrom(ctx, readData.FvRsProv.ElementType(ctx), FvRsProvFvAEPgList) + readData.FvRsProv = fvRsProvSet + fvRsSecInheritedSet, _ := types.SetValueFrom(ctx, readData.FvRsSecInherited.ElementType(ctx), FvRsSecInheritedFvAEPgList) + readData.FvRsSecInherited = fvRsSecInheritedSet if len(FvRsTrustCtrlFvAEPgList) == 1 { fvRsTrustCtrlObject, _ := types.ObjectValueFrom(ctx, FvRsTrustCtrlFvAEPgType, FvRsTrustCtrlFvAEPgList[0]) - data.FvRsTrustCtrl = fvRsTrustCtrlObject + readData.FvRsTrustCtrl = fvRsTrustCtrlObject } else { fvRsTrustCtrlObject, _ := types.ObjectValueFrom(ctx, FvRsTrustCtrlFvAEPgType, getEmptyFvRsTrustCtrlFvAEPgResourceModel()) - data.FvRsTrustCtrl = fvRsTrustCtrlObject + readData.FvRsTrustCtrl = fvRsTrustCtrlObject } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvAEPgList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvAEPgList) - data.TagTag = tagTagSet - setFvAEPgLegacyAttributes(ctx, diags, data, classReadInfo) + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvAEPgList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvAEPgList) + readData.TagTag = tagTagSet + setFvAEPgLegacyAttributes(ctx, diags, readData, classReadInfo) } else { diags.AddError( "too many results in response", @@ -4695,8 +4678,9 @@ func getAndSetFvAEPgAttributes(ctx context.Context, diags *diag.Diagnostics, cli ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvAEPgRn(ctx context.Context, data *FvAEPgResourceModel) string { @@ -5019,9 +5003,6 @@ func getFvAEPgFvRsDomAttChildPayloads(ctx context.Context, diags *diag.Diagnosti if !fvRsDomAtt.Untagged.IsUnknown() && !fvRsDomAtt.Untagged.IsNull() { childMap["attributes"]["untagged"] = fvRsDomAtt.Untagged.ValueString() } - if !fvRsDomAtt.VnetOnly.IsUnknown() && !fvRsDomAtt.VnetOnly.IsNull() { - childMap["attributes"]["vnetOnly"] = fvRsDomAtt.VnetOnly.ValueString() - } childPayloads = append(childPayloads, map[string]interface{}{"fvRsDomAtt": childMap}) fvRsDomAttIdentifier := FvRsDomAttIdentifier{} fvRsDomAttIdentifier.TDn = fvRsDomAtt.TDn @@ -5666,7 +5647,6 @@ func getFvAEPgCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, cr if !data.Shutdown.IsNull() && !data.Shutdown.IsUnknown() { payloadMap["attributes"].(map[string]string)["shutdown"] = data.Shutdown.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvAEPg": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_application_epg_test.go b/internal/provider/resource_aci_application_epg_test.go index fce05ad0b..72d298725 100644 --- a/internal/provider/resource_aci_application_epg_test.go +++ b/internal/provider/resource_aci_application_epg_test.go @@ -17,18 +17,16 @@ import ( func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigFvAEPgMinDependencyWithFvApAllowExisting, + Config: testConfigFvAEPgMinDependencyWithFvApAllowExisting + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_application_epg.allow_test", "name", "test_name"), resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "name", "test_name"), - resource.TestCheckResourceAttr("aci_application_epg.allow_test", "admin_state", "no"), - resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "admin_state", "no"), resource.TestCheckResourceAttr("aci_application_epg.allow_test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_application_epg.allow_test", "contract_exception_tag", ""), @@ -39,8 +37,6 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "flood_in_encapsulation", "disabled"), resource.TestCheckResourceAttr("aci_application_epg.allow_test", "forwarding_control", "none"), resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "forwarding_control", "none"), - resource.TestCheckResourceAttr("aci_application_epg.allow_test", "has_multicast_source", "no"), - resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "has_multicast_source", "no"), resource.TestCheckResourceAttr("aci_application_epg.allow_test", "intra_epg_isolation", "unenforced"), resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "intra_epg_isolation", "unenforced"), resource.TestCheckResourceAttr("aci_application_epg.allow_test", "match_criteria", "AtleastOne"), @@ -53,6 +49,11 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "priority", "unspecified"), resource.TestCheckResourceAttr("aci_application_epg.allow_test", "useg_epg", "no"), resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "useg_epg", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.0(1h)", ">", + resource.TestCheckResourceAttr("aci_application_epg.allow_test", "admin_state", "no"), + resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "admin_state", "no"), + resource.TestCheckResourceAttr("aci_application_epg.allow_test", "has_multicast_source", "no"), + resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "has_multicast_source", "no")), resource.TestCheckResourceAttrSet("aci_application_epg.allow_test", "pc_tag"), ), }, @@ -61,12 +62,12 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigFvAEPgMinDependencyWithFvApAllowExisting, + Config: testConfigFvAEPgMinDependencyWithFvApAllowExisting + testConfigDataSourceSystem, ExpectError: regexp.MustCompile("Object Already Exists"), }, }, @@ -74,18 +75,16 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigFvAEPgMinDependencyWithFvApAllowExisting, + Config: testConfigFvAEPgMinDependencyWithFvApAllowExisting + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_application_epg.allow_test", "name", "test_name"), resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "name", "test_name"), - resource.TestCheckResourceAttr("aci_application_epg.allow_test", "admin_state", "no"), - resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "admin_state", "no"), resource.TestCheckResourceAttr("aci_application_epg.allow_test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_application_epg.allow_test", "contract_exception_tag", ""), @@ -96,8 +95,6 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "flood_in_encapsulation", "disabled"), resource.TestCheckResourceAttr("aci_application_epg.allow_test", "forwarding_control", "none"), resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "forwarding_control", "none"), - resource.TestCheckResourceAttr("aci_application_epg.allow_test", "has_multicast_source", "no"), - resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "has_multicast_source", "no"), resource.TestCheckResourceAttr("aci_application_epg.allow_test", "intra_epg_isolation", "unenforced"), resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "intra_epg_isolation", "unenforced"), resource.TestCheckResourceAttr("aci_application_epg.allow_test", "match_criteria", "AtleastOne"), @@ -110,6 +107,11 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "priority", "unspecified"), resource.TestCheckResourceAttr("aci_application_epg.allow_test", "useg_epg", "no"), resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "useg_epg", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.0(1h)", ">", + resource.TestCheckResourceAttr("aci_application_epg.allow_test", "admin_state", "no"), + resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "admin_state", "no"), + resource.TestCheckResourceAttr("aci_application_epg.allow_test", "has_multicast_source", "no"), + resource.TestCheckResourceAttr("aci_application_epg.allow_test_2", "has_multicast_source", "no")), resource.TestCheckResourceAttrSet("aci_application_epg.allow_test", "pc_tag"), resource.TestCheckResourceAttrSet("aci_application_epg.allow_test_2", "pc_tag"), ), @@ -118,56 +120,58 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigFvAEPgMinDependencyWithFvAp, + Config: testConfigFvAEPgMinDependencyWithFvAp + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_application_epg.test", "name", "test_name"), - resource.TestCheckResourceAttr("aci_application_epg.test", "admin_state", "no"), resource.TestCheckResourceAttr("aci_application_epg.test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_application_epg.test", "contract_exception_tag", ""), resource.TestCheckResourceAttr("aci_application_epg.test", "description", ""), resource.TestCheckResourceAttr("aci_application_epg.test", "flood_in_encapsulation", "disabled"), resource.TestCheckResourceAttr("aci_application_epg.test", "forwarding_control", "none"), - resource.TestCheckResourceAttr("aci_application_epg.test", "has_multicast_source", "no"), resource.TestCheckResourceAttr("aci_application_epg.test", "intra_epg_isolation", "unenforced"), resource.TestCheckResourceAttr("aci_application_epg.test", "match_criteria", "AtleastOne"), resource.TestCheckResourceAttr("aci_application_epg.test", "name_alias", ""), resource.TestCheckResourceAttr("aci_application_epg.test", "preferred_group_member", "exclude"), resource.TestCheckResourceAttr("aci_application_epg.test", "priority", "unspecified"), resource.TestCheckResourceAttr("aci_application_epg.test", "useg_epg", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.0(1h)", ">", + resource.TestCheckResourceAttr("aci_application_epg.test", "admin_state", "no"), + resource.TestCheckResourceAttr("aci_application_epg.test", "has_multicast_source", "no")), resource.TestCheckResourceAttrSet("aci_application_epg.test", "pc_tag"), ), }, // Update with all config and verify default APIC values { - Config: testConfigFvAEPgAllDependencyWithFvAp, + Config: testConfigFvAEPgAllDependencyWithFvAp + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_application_epg.test", "name", "test_name"), - resource.TestCheckResourceAttr("aci_application_epg.test", "admin_state", "no"), resource.TestCheckResourceAttr("aci_application_epg.test", "annotation", "annotation"), resource.TestCheckResourceAttr("aci_application_epg.test", "contract_exception_tag", "contract_exception_tag_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "description", "description_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "flood_in_encapsulation", "disabled"), resource.TestCheckResourceAttr("aci_application_epg.test", "forwarding_control", "proxy-arp"), - resource.TestCheckResourceAttr("aci_application_epg.test", "has_multicast_source", "no"), resource.TestCheckResourceAttr("aci_application_epg.test", "intra_epg_isolation", "enforced"), resource.TestCheckResourceAttr("aci_application_epg.test", "match_criteria", "All"), resource.TestCheckResourceAttr("aci_application_epg.test", "name_alias", "name_alias_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "preferred_group_member", "exclude"), resource.TestCheckResourceAttr("aci_application_epg.test", "priority", "level1"), resource.TestCheckResourceAttr("aci_application_epg.test", "useg_epg", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.0(1h)", ">", + resource.TestCheckResourceAttr("aci_application_epg.test", "admin_state", "no"), + resource.TestCheckResourceAttr("aci_application_epg.test", "has_multicast_source", "no")), resource.TestCheckResourceAttrSet("aci_application_epg.test", "pc_tag"), ), }, // Update with minimum config and verify config is unchanged { - Config: testConfigFvAEPgMinDependencyWithFvAp, + Config: testConfigFvAEPgMinDependencyWithFvAp + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_application_epg.test", "name", "test_name"), @@ -176,23 +180,24 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { }, // Update with empty strings config or default value { - Config: testConfigFvAEPgResetDependencyWithFvAp, + Config: testConfigFvAEPgResetDependencyWithFvAp + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_application_epg.test", "name", "test_name"), - resource.TestCheckResourceAttr("aci_application_epg.test", "admin_state", "no"), resource.TestCheckResourceAttr("aci_application_epg.test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_application_epg.test", "contract_exception_tag", ""), resource.TestCheckResourceAttr("aci_application_epg.test", "description", ""), resource.TestCheckResourceAttr("aci_application_epg.test", "flood_in_encapsulation", "disabled"), resource.TestCheckResourceAttr("aci_application_epg.test", "forwarding_control", "none"), - resource.TestCheckResourceAttr("aci_application_epg.test", "has_multicast_source", "no"), resource.TestCheckResourceAttr("aci_application_epg.test", "intra_epg_isolation", "unenforced"), resource.TestCheckResourceAttr("aci_application_epg.test", "match_criteria", "AtleastOne"), resource.TestCheckResourceAttr("aci_application_epg.test", "name_alias", ""), resource.TestCheckResourceAttr("aci_application_epg.test", "preferred_group_member", "exclude"), resource.TestCheckResourceAttr("aci_application_epg.test", "priority", "unspecified"), resource.TestCheckResourceAttr("aci_application_epg.test", "useg_epg", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.0(1h)", ">", + resource.TestCheckResourceAttr("aci_application_epg.test", "admin_state", "no"), + resource.TestCheckResourceAttr("aci_application_epg.test", "has_multicast_source", "no")), resource.TestCheckResourceAttrSet("aci_application_epg.test", "pc_tag"), ), }, @@ -204,23 +209,24 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { }, // Update with children { - Config: testConfigFvAEPgChildrenDependencyWithFvAp, + Config: testConfigFvAEPgChildrenDependencyWithFvAp + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_application_epg.test", "name", "test_name"), - resource.TestCheckResourceAttr("aci_application_epg.test", "admin_state", "no"), resource.TestCheckResourceAttr("aci_application_epg.test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_application_epg.test", "contract_exception_tag", ""), resource.TestCheckResourceAttr("aci_application_epg.test", "description", ""), resource.TestCheckResourceAttr("aci_application_epg.test", "flood_in_encapsulation", "disabled"), resource.TestCheckResourceAttr("aci_application_epg.test", "forwarding_control", "none"), - resource.TestCheckResourceAttr("aci_application_epg.test", "has_multicast_source", "no"), resource.TestCheckResourceAttr("aci_application_epg.test", "intra_epg_isolation", "unenforced"), resource.TestCheckResourceAttr("aci_application_epg.test", "match_criteria", "AtleastOne"), resource.TestCheckResourceAttr("aci_application_epg.test", "name_alias", ""), resource.TestCheckResourceAttr("aci_application_epg.test", "preferred_group_member", "exclude"), resource.TestCheckResourceAttr("aci_application_epg.test", "priority", "unspecified"), resource.TestCheckResourceAttr("aci_application_epg.test", "useg_epg", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.0(1h)", ">", + resource.TestCheckResourceAttr("aci_application_epg.test", "admin_state", "no"), + resource.TestCheckResourceAttr("aci_application_epg.test", "has_multicast_source", "no")), resource.TestCheckResourceAttrSet("aci_application_epg.test", "pc_tag"), resource.TestCheckResourceAttr("aci_application_epg.test", "annotations.0.key", "key_0"), resource.TestCheckResourceAttr("aci_application_epg.test", "annotations.0.value", "value_1"), @@ -233,8 +239,9 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_application_epg.test", "epg_useg_block_statement.name_alias", "name_alias_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "epg_useg_block_statement.owner_key", "owner_key_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "epg_useg_block_statement.owner_tag", "owner_tag_1"), - resource.TestCheckResourceAttr("aci_application_epg.test", "epg_useg_block_statement.precedence", "1"), - resource.TestCheckResourceAttr("aci_application_epg.test", "epg_useg_block_statement.scope", "scope-bd"), + composeAggregateTestCheckFuncWithVersion(t, "4.1(1i)", ">", + resource.TestCheckResourceAttr("aci_application_epg.test", "epg_useg_block_statement.precedence", "1"), + resource.TestCheckResourceAttr("aci_application_epg.test", "epg_useg_block_statement.scope", "scope-bd")), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_application_epg_monitoring_policy.annotation", "annotation_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_application_epg_monitoring_policy.monitoring_policy_name", "monitoring_policy_name_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_bridge_domain.annotation", "annotation_1"), @@ -254,9 +261,7 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_data_plane_policing_policy.annotation", "annotation_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_data_plane_policing_policy.data_plane_policing_policy_name", "data_plane_policing_policy_name_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.annotation", "annotation_1"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.binding_type", "dynamicBinding"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.class_preference", "encap"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.custom_epg_name", "custom_epg_name_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.delimiter", "@"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.deployment_immediacy", "immediate"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.enable_netflow", "disabled"), @@ -266,8 +271,6 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.epg_cos_pref", "disabled"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.lag_policy_name", "lag_policy_name_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.netflow_direction", "both"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.number_of_ports", "1"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.port_allocation", "elastic"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.primary_encapsulation", "vlan-200"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.primary_encapsulation_inner", "vlan-300"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.resolution_immediacy", "immediate"), @@ -275,11 +278,14 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.switching_mode", "AVE"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.target_dn", "uni/vmmp-VMware/dom-domain_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.untagged", "no"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.vnet_only", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.0(1h)", ">", + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.binding_type", "dynamicBinding"), + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.number_of_ports", "1"), + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.port_allocation", "elastic")), + composeAggregateTestCheckFuncWithVersion(t, "4.2(3j)", ">", + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.custom_epg_name", "custom_epg_name_1")), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.annotation", "annotation_2"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.binding_type", "ephemeral"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.class_preference", "useg"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.custom_epg_name", "custom_epg_name_2"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.delimiter", ""), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.deployment_immediacy", "lazy"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.enable_netflow", "enabled"), @@ -289,8 +295,6 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.epg_cos_pref", "enabled"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.lag_policy_name", "lag_policy_name_2"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.netflow_direction", "egress"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.number_of_ports", "0"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.port_allocation", "fixed"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.primary_encapsulation", "unknown"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.primary_encapsulation_inner", "unknown"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.resolution_immediacy", "lazy"), @@ -298,7 +302,12 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.switching_mode", "native"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.target_dn", "uni/vmmp-VMware/dom-domain_2"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.untagged", "yes"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.vnet_only", "yes"), + composeAggregateTestCheckFuncWithVersion(t, "4.0(1h)", ">", + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.binding_type", "ephemeral"), + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.number_of_ports", "0"), + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.port_allocation", "fixed")), + composeAggregateTestCheckFuncWithVersion(t, "4.2(3j)", ">", + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.custom_epg_name", "custom_epg_name_2")), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_fibre_channel_paths.0.annotation", "annotation_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_fibre_channel_paths.0.description", "description_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_fibre_channel_paths.0.target_dn", "topology/pod-1/paths-101/pathep-[eth1/1]"), @@ -378,7 +387,7 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { }, // Update with children removed from config { - Config: testConfigFvAEPgChildrenRemoveFromConfigDependencyWithFvAp, + Config: testConfigFvAEPgChildrenRemoveFromConfigDependencyWithFvAp + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("aci_application_epg.test", "pc_tag"), @@ -394,8 +403,9 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_application_epg.test", "epg_useg_block_statement.name_alias", "name_alias_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "epg_useg_block_statement.owner_key", "owner_key_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "epg_useg_block_statement.owner_tag", "owner_tag_1"), - resource.TestCheckResourceAttr("aci_application_epg.test", "epg_useg_block_statement.precedence", "1"), - resource.TestCheckResourceAttr("aci_application_epg.test", "epg_useg_block_statement.scope", "scope-bd"), + composeAggregateTestCheckFuncWithVersion(t, "4.1(1i)", ">", + resource.TestCheckResourceAttr("aci_application_epg.test", "epg_useg_block_statement.precedence", "1"), + resource.TestCheckResourceAttr("aci_application_epg.test", "epg_useg_block_statement.scope", "scope-bd")), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_application_epg_monitoring_policy.annotation", "annotation_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_application_epg_monitoring_policy.monitoring_policy_name", "monitoring_policy_name_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_bridge_domain.annotation", "annotation_1"), @@ -417,9 +427,7 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_data_plane_policing_policy.annotation", "annotation_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_data_plane_policing_policy.data_plane_policing_policy_name", "data_plane_policing_policy_name_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.annotation", "annotation_1"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.binding_type", "dynamicBinding"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.class_preference", "encap"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.custom_epg_name", "custom_epg_name_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.delimiter", "@"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.deployment_immediacy", "immediate"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.enable_netflow", "disabled"), @@ -429,8 +437,6 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.epg_cos_pref", "disabled"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.lag_policy_name", "lag_policy_name_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.netflow_direction", "both"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.number_of_ports", "1"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.port_allocation", "elastic"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.primary_encapsulation", "vlan-200"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.primary_encapsulation_inner", "vlan-300"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.resolution_immediacy", "immediate"), @@ -438,11 +444,14 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.switching_mode", "AVE"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.target_dn", "uni/vmmp-VMware/dom-domain_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.untagged", "no"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.vnet_only", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.0(1h)", ">", + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.binding_type", "dynamicBinding"), + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.number_of_ports", "1"), + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.port_allocation", "elastic")), + composeAggregateTestCheckFuncWithVersion(t, "4.2(3j)", ">", + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.custom_epg_name", "custom_epg_name_1")), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.annotation", "annotation_2"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.binding_type", "ephemeral"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.class_preference", "useg"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.custom_epg_name", "custom_epg_name_2"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.delimiter", ""), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.deployment_immediacy", "lazy"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.enable_netflow", "enabled"), @@ -452,8 +461,6 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.epg_cos_pref", "enabled"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.lag_policy_name", "lag_policy_name_2"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.netflow_direction", "egress"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.number_of_ports", "0"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.port_allocation", "fixed"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.primary_encapsulation", "unknown"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.primary_encapsulation_inner", "unknown"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.resolution_immediacy", "lazy"), @@ -461,7 +468,12 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.switching_mode", "native"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.target_dn", "uni/vmmp-VMware/dom-domain_2"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.untagged", "yes"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.vnet_only", "yes"), + composeAggregateTestCheckFuncWithVersion(t, "4.0(1h)", ">", + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.binding_type", "ephemeral"), + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.number_of_ports", "0"), + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.port_allocation", "fixed")), + composeAggregateTestCheckFuncWithVersion(t, "4.2(3j)", ">", + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.1.custom_epg_name", "custom_epg_name_2")), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.#", "2"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_fibre_channel_paths.0.annotation", "annotation_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_fibre_channel_paths.0.description", "description_1"), @@ -539,7 +551,7 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { }, // Update with children first child removed { - Config: testConfigFvAEPgChildrenRemoveOneDependencyWithFvAp, + Config: testConfigFvAEPgChildrenRemoveOneDependencyWithFvAp + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("aci_application_epg.test", "pc_tag"), @@ -558,9 +570,7 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_custom_qos_policy.annotation", "annotation_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_custom_qos_policy.custom_qos_policy_name", "custom_qos_policy_name_1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.annotation", "annotation_2"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.binding_type", "ephemeral"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.class_preference", "useg"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.custom_epg_name", "custom_epg_name_2"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.delimiter", ""), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.deployment_immediacy", "lazy"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.enable_netflow", "enabled"), @@ -570,8 +580,6 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.epg_cos_pref", "enabled"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.lag_policy_name", "lag_policy_name_2"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.netflow_direction", "egress"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.number_of_ports", "0"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.port_allocation", "fixed"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.primary_encapsulation", "unknown"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.primary_encapsulation_inner", "unknown"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.resolution_immediacy", "lazy"), @@ -579,7 +587,12 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.switching_mode", "native"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.target_dn", "uni/vmmp-VMware/dom-domain_2"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.untagged", "yes"), - resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.vnet_only", "yes"), + composeAggregateTestCheckFuncWithVersion(t, "4.0(1h)", ">", + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.binding_type", "ephemeral"), + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.number_of_ports", "0"), + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.port_allocation", "fixed")), + composeAggregateTestCheckFuncWithVersion(t, "4.2(3j)", ">", + resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.0.custom_epg_name", "custom_epg_name_2")), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_domains.#", "1"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_fibre_channel_paths.0.annotation", "annotation_2"), resource.TestCheckResourceAttr("aci_application_epg.test", "relation_to_fibre_channel_paths.0.description", "description_2"), @@ -669,7 +682,7 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { }, // Update with all children removed { - Config: testConfigFvAEPgChildrenRemoveAllDependencyWithFvAp, + Config: testConfigFvAEPgChildrenRemoveAllDependencyWithFvAp + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("aci_application_epg.test", "pc_tag"), @@ -738,7 +751,7 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { }, // Update with minimum config and custom type semantic equivalent values { - Config: testConfigFvAEPgCustomTypeDependencyWithFvAp, + Config: testConfigFvAEPgCustomTypeDependencyWithFvAp + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_application_epg.test", "name", "test_name"), @@ -746,6 +759,7 @@ func TestAccResourceFvAEPgWithFvAp(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } @@ -783,19 +797,19 @@ const testConfigFvAEPgAllDependencyWithFvAp = testConfigFvApMinDependencyWithFvT resource "aci_application_epg" "test" { parent_dn = aci_application_profile.test.id name = "test_name" - admin_state = "no" annotation = "annotation" contract_exception_tag = "contract_exception_tag_1" description = "description_1" flood_in_encapsulation = "disabled" forwarding_control = "proxy-arp" - has_multicast_source = "no" intra_epg_isolation = "enforced" match_criteria = "All" name_alias = "name_alias_1" preferred_group_member = "exclude" priority = "level1" useg_epg = "no" + admin_state = provider::aci::compare_versions(data.aci_system.version.version,">=","4.0(1h)") ? "no" : null + has_multicast_source = provider::aci::compare_versions(data.aci_system.version.version,">=","4.0(1h)") ? "no" : null } ` @@ -803,19 +817,19 @@ const testConfigFvAEPgResetDependencyWithFvAp = testConfigFvApMinDependencyWithF resource "aci_application_epg" "test" { parent_dn = aci_application_profile.test.id name = "test_name" - admin_state = "no" annotation = "orchestrator:terraform" contract_exception_tag = "" description = "" flood_in_encapsulation = "disabled" forwarding_control = "none" - has_multicast_source = "no" intra_epg_isolation = "unenforced" match_criteria = "AtleastOne" name_alias = "" preferred_group_member = "exclude" priority = "unspecified" useg_epg = "no" + admin_state = provider::aci::compare_versions(data.aci_system.version.version,">=","4.0(1h)") ? "no" : null + has_multicast_source = provider::aci::compare_versions(data.aci_system.version.version,">=","4.0(1h)") ? "no" : null } ` const testConfigFvAEPgChildrenDependencyWithFvAp = testChildDependencyConfigFvAEPg + testConfigFvApMinDependencyWithFvTenant + ` @@ -840,8 +854,8 @@ resource "aci_application_epg" "test" { name_alias = "name_alias_1" owner_key = "owner_key_1" owner_tag = "owner_tag_1" - precedence = "1" - scope = "scope-bd" + precedence = provider::aci::compare_versions(data.aci_system.version.version,">=","4.1(1i)") ? "1" : null + scope = provider::aci::compare_versions(data.aci_system.version.version,">=","4.1(1i)") ? "scope-bd" : null } relation_to_application_epg_monitoring_policy = { annotation = "annotation_1" @@ -884,9 +898,7 @@ resource "aci_application_epg" "test" { relation_to_domains = [ { annotation = "annotation_1" - binding_type = "dynamicBinding" class_preference = "encap" - custom_epg_name = "custom_epg_name_1" delimiter = "@" deployment_immediacy = "immediate" enable_netflow = "disabled" @@ -896,8 +908,6 @@ resource "aci_application_epg" "test" { epg_cos_pref = "disabled" lag_policy_name = "lag_policy_name_1" netflow_direction = "both" - number_of_ports = "1" - port_allocation = "elastic" primary_encapsulation = "vlan-200" primary_encapsulation_inner = "vlan-300" resolution_immediacy = "immediate" @@ -905,13 +915,14 @@ resource "aci_application_epg" "test" { switching_mode = "AVE" target_dn = "uni/vmmp-VMware/dom-domain_1" untagged = "no" - vnet_only = "no" + binding_type = provider::aci::compare_versions(data.aci_system.version.version,">=","4.0(1h)") ? "dynamicBinding" : null + number_of_ports = provider::aci::compare_versions(data.aci_system.version.version,">=","4.0(1h)") ? "1" : null + port_allocation = provider::aci::compare_versions(data.aci_system.version.version,">=","4.0(1h)") ? "elastic" : null + custom_epg_name = provider::aci::compare_versions(data.aci_system.version.version,">=","4.2(3j)") ? "custom_epg_name_1" : null }, { annotation = "annotation_2" - binding_type = "ephemeral" class_preference = "useg" - custom_epg_name = "custom_epg_name_2" delimiter = "" deployment_immediacy = "lazy" enable_netflow = "enabled" @@ -921,8 +932,6 @@ resource "aci_application_epg" "test" { epg_cos_pref = "enabled" lag_policy_name = "lag_policy_name_2" netflow_direction = "egress" - number_of_ports = "0" - port_allocation = "fixed" primary_encapsulation = "unknown" primary_encapsulation_inner = "unknown" resolution_immediacy = "lazy" @@ -930,7 +939,10 @@ resource "aci_application_epg" "test" { switching_mode = "native" target_dn = "uni/vmmp-VMware/dom-domain_2" untagged = "yes" - vnet_only = "yes" + binding_type = provider::aci::compare_versions(data.aci_system.version.version,">=","4.0(1h)") ? "ephemeral" : null + number_of_ports = provider::aci::compare_versions(data.aci_system.version.version,">=","4.0(1h)") ? "0" : null + port_allocation = provider::aci::compare_versions(data.aci_system.version.version,">=","4.0(1h)") ? "fixed" : null + custom_epg_name = provider::aci::compare_versions(data.aci_system.version.version,">=","4.2(3j)") ? "custom_epg_name_2" : null }, ] relation_to_fibre_channel_paths = [ @@ -1086,9 +1098,7 @@ resource "aci_application_epg" "test" { relation_to_domains = [ { annotation = "annotation_2" - binding_type = "ephemeral" class_preference = "useg" - custom_epg_name = "custom_epg_name_2" delimiter = "" deployment_immediacy = "lazy" enable_netflow = "enabled" @@ -1098,8 +1108,6 @@ resource "aci_application_epg" "test" { epg_cos_pref = "enabled" lag_policy_name = "lag_policy_name_2" netflow_direction = "egress" - number_of_ports = "0" - port_allocation = "fixed" primary_encapsulation = "unknown" primary_encapsulation_inner = "unknown" resolution_immediacy = "lazy" @@ -1107,7 +1115,10 @@ resource "aci_application_epg" "test" { switching_mode = "native" target_dn = "uni/vmmp-VMware/dom-domain_2" untagged = "yes" - vnet_only = "yes" + binding_type = provider::aci::compare_versions(data.aci_system.version.version,">=","4.0(1h)") ? "ephemeral" : null + number_of_ports = provider::aci::compare_versions(data.aci_system.version.version,">=","4.0(1h)") ? "0" : null + port_allocation = provider::aci::compare_versions(data.aci_system.version.version,">=","4.0(1h)") ? "fixed" : null + custom_epg_name = provider::aci::compare_versions(data.aci_system.version.version,">=","4.2(3j)") ? "custom_epg_name_2" : null }, ] relation_to_fibre_channel_paths = [ diff --git a/internal/provider/resource_aci_certificate_authority.go b/internal/provider/resource_aci_certificate_authority.go new file mode 100644 index 000000000..f5c087c11 --- /dev/null +++ b/internal/provider/resource_aci_certificate_authority.go @@ -0,0 +1,793 @@ +// 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" + "reflect" + "strings" + + "github.com/ciscoecosystem/aci-go-client/v2/client" + "github.com/ciscoecosystem/aci-go-client/v2/container" + "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/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 = &PkiTPResource{} +var _ resource.ResourceWithImportState = &PkiTPResource{} + +func NewPkiTPResource() resource.Resource { + return &PkiTPResource{} +} + +// PkiTPResource defines the resource implementation. +type PkiTPResource struct { + client *client.Client +} + +// PkiTPResourceModel describes the resource data model. +type PkiTPResourceModel struct { + Id types.String `tfsdk:"id"` + ParentDn types.String `tfsdk:"parent_dn"` + Annotation types.String `tfsdk:"annotation"` + CertChain types.String `tfsdk:"certificate_chain"` + 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"` + TagAnnotation types.Set `tfsdk:"annotations"` + TagTag types.Set `tfsdk:"tags"` +} + +func getEmptyPkiTPResourceModel() *PkiTPResourceModel { + return &PkiTPResourceModel{ + Id: basetypes.NewStringNull(), + ParentDn: basetypes.NewStringNull(), + Annotation: basetypes.NewStringNull(), + CertChain: basetypes.NewStringNull(), + Descr: basetypes.NewStringNull(), + Name: basetypes.NewStringNull(), + NameAlias: basetypes.NewStringNull(), + OwnerKey: basetypes.NewStringNull(), + OwnerTag: basetypes.NewStringNull(), + TagAnnotation: types.SetNull(types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "key": types.StringType, + "value": types.StringType, + }, + }), + TagTag: types.SetNull(types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "key": types.StringType, + "value": types.StringType, + }, + }), + } +} + +// TagAnnotationPkiTPResourceModel describes the resource data model for the children without relation ships. +type TagAnnotationPkiTPResourceModel struct { + Key types.String `tfsdk:"key"` + Value types.String `tfsdk:"value"` +} + +func getEmptyTagAnnotationPkiTPResourceModel() TagAnnotationPkiTPResourceModel { + return TagAnnotationPkiTPResourceModel{ + Key: basetypes.NewStringNull(), + Value: basetypes.NewStringNull(), + } +} + +// TagTagPkiTPResourceModel describes the resource data model for the children without relation ships. +type TagTagPkiTPResourceModel struct { + Key types.String `tfsdk:"key"` + Value types.String `tfsdk:"value"` +} + +func getEmptyTagTagPkiTPResourceModel() TagTagPkiTPResourceModel { + return TagTagPkiTPResourceModel{ + Key: basetypes.NewStringNull(), + Value: basetypes.NewStringNull(), + } +} + +type PkiTPIdentifier struct { + Name types.String +} + +func (r *PkiTPResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if !req.Plan.Raw.IsNull() { + var planData, stateData *PkiTPResourceModel + 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() { + setPkiTPId(ctx, planData) + } + + if stateData == nil && !globalAllowExistingOnCreate && !planData.Id.IsUnknown() && !planData.Id.IsNull() { + CheckDn(ctx, &resp.Diagnostics, r.client, "pkiTP", planData.Id.ValueString()) + if resp.Diagnostics.HasError() { + return + } + } + + resp.Diagnostics.Append(resp.Plan.Set(ctx, &planData)...) + } +} + +func (r *PkiTPResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + tflog.Debug(ctx, "Start metadata of resource: aci_certificate_authority") + resp.TypeName = req.ProviderTypeName + "_certificate_authority" + tflog.Debug(ctx, "End metadata of resource: aci_certificate_authority") +} + +func (r *PkiTPResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + tflog.Debug(ctx, "Start schema of resource: aci_certificate_authority") + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: "The certificate_authority resource for the 'pkiTP' class", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + MarkdownDescription: "The distinguished name (DN) of the Certificate Authority object.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "parent_dn": schema.StringAttribute{ + Optional: true, + Computed: true, + Default: stringdefault.StaticString("uni/userext/pkiext"), + 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 Certificate Authority object.`, + }, + "certificate_chain": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `The PEM-encoded chain of trust from the trustpoint to a trusted root authority.`, + }, + "description": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `The description of the Certificate Authority object.`, + }, + "name": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + stringplanmodifier.RequiresReplace(), + }, + MarkdownDescription: `The name of the Certificate Authority object.`, + }, + "name_alias": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `The name alias of the Certificate Authority object.`, + }, + "owner_key": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `The key for enabling clients to own their data for entity correlation.`, + }, + "owner_tag": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `A tag for enabling clients to add their own data. For example, to indicate who created this object.`, + }, + "annotations": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Set{ + setplanmodifier.UseStateForUnknown(), + }, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "key": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The key used to uniquely identify this configuration object.`, + }, + "value": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The value of the property.`, + }, + }, + }, + }, + "tags": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Set{ + setplanmodifier.UseStateForUnknown(), + }, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "key": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The key used to uniquely identify this configuration object.`, + }, + "value": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The value of the property.`, + }, + }, + }, + }, + }, + } + tflog.Debug(ctx, "End schema of resource: aci_certificate_authority") +} + +func (r *PkiTPResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + tflog.Debug(ctx, "Start configure of resource: aci_certificate_authority") + // 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_certificate_authority") +} + +func (r *PkiTPResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + tflog.Debug(ctx, "Start create of resource: aci_certificate_authority") + // On create retrieve information on current state prior to making any changes in order to determine child delete operations + var stateData *PkiTPResourceModel + resp.Diagnostics.Append(req.Plan.Get(ctx, &stateData)...) + if stateData.Id.IsUnknown() || stateData.Id.IsNull() { + setPkiTPId(ctx, stateData) + } + getAndSetPkiTPAttributes(ctx, &resp.Diagnostics, r.client, stateData) + if !globalAllowExistingOnCreate && !stateData.Id.IsNull() { + resp.Diagnostics.AddError( + "Object Already Exists", + fmt.Sprintf("The pkiTP object with DN '%s' already exists.", stateData.Id.ValueString()), + ) + return + } + + var data *PkiTPResourceModel + + // 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() { + setPkiTPId(ctx, data) + } + + tflog.Debug(ctx, fmt.Sprintf("Create of resource aci_certificate_authority with id '%s'", data.Id.ValueString())) + + var tagAnnotationPlan, tagAnnotationState []TagAnnotationPkiTPResourceModel + data.TagAnnotation.ElementsAs(ctx, &tagAnnotationPlan, false) + stateData.TagAnnotation.ElementsAs(ctx, &tagAnnotationState, false) + var tagTagPlan, tagTagState []TagTagPkiTPResourceModel + data.TagTag.ElementsAs(ctx, &tagTagPlan, false) + stateData.TagTag.ElementsAs(ctx, &tagTagState, false) + jsonPayload := getPkiTPCreateJsonPayload(ctx, &resp.Diagnostics, true, data, tagAnnotationPlan, tagAnnotationState, tagTagPlan, tagTagState) + + if resp.Diagnostics.HasError() { + return + } + + wrapperClassMap := map[string]string{"uni/userext/pkiext": "", "certstore": "cloudCertStore"} + for rnPrepend, wrapperClass := range wrapperClassMap { + if strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass != "" { + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s%s.json", strings.Split(data.Id.ValueString(), rnPrepend)[0], rnPrepend), "POST", jsonPayload) + break + } else if strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass == "" { + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + break + } + } + + if resp.Diagnostics.HasError() { + return + } + + getAndSetPkiTPAttributes(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_certificate_authority with id '%s'", data.Id.ValueString())) +} + +func (r *PkiTPResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + tflog.Debug(ctx, "Start read of resource: aci_certificate_authority") + var data *PkiTPResourceModel + + // 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_certificate_authority with id '%s'", data.Id.ValueString())) + + getAndSetPkiTPAttributes(ctx, &resp.Diagnostics, r.client, data) + + // Save updated data into Terraform state + if data.Id.IsNull() { + var emptyData *PkiTPResourceModel + 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_certificate_authority with id '%s'", data.Id.ValueString())) +} + +func (r *PkiTPResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + tflog.Debug(ctx, "Start update of resource: aci_certificate_authority") + var data *PkiTPResourceModel + var stateData *PkiTPResourceModel + + // 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_certificate_authority with id '%s'", data.Id.ValueString())) + + var tagAnnotationPlan, tagAnnotationState []TagAnnotationPkiTPResourceModel + data.TagAnnotation.ElementsAs(ctx, &tagAnnotationPlan, false) + stateData.TagAnnotation.ElementsAs(ctx, &tagAnnotationState, false) + var tagTagPlan, tagTagState []TagTagPkiTPResourceModel + data.TagTag.ElementsAs(ctx, &tagTagPlan, false) + stateData.TagTag.ElementsAs(ctx, &tagTagState, false) + jsonPayload := getPkiTPCreateJsonPayload(ctx, &resp.Diagnostics, false, data, tagAnnotationPlan, tagAnnotationState, tagTagPlan, tagTagState) + + if resp.Diagnostics.HasError() { + return + } + + wrapperClassMap := map[string]string{ + "uni/userext/pkiext": "", + "certstore": "cloudCertStore", + } + for rnPrepend, wrapperClass := range wrapperClassMap { + if strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass != "" { + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s%s.json", strings.Split(data.Id.ValueString(), rnPrepend)[0], rnPrepend), "POST", jsonPayload) + break + } else if strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass == "" { + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + break + } + } + + if resp.Diagnostics.HasError() { + return + } + + getAndSetPkiTPAttributes(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_certificate_authority with id '%s'", data.Id.ValueString())) +} + +func (r *PkiTPResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + tflog.Debug(ctx, "Start delete of resource: aci_certificate_authority") + var data *PkiTPResourceModel + + // 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_certificate_authority with id '%s'", data.Id.ValueString())) + jsonPayload := GetDeleteJsonPayload(ctx, &resp.Diagnostics, "pkiTP", 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_certificate_authority with id '%s'", data.Id.ValueString())) +} + +func (r *PkiTPResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + tflog.Debug(ctx, "Start import state of resource: aci_certificate_authority") + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + + var stateData *PkiTPResourceModel + resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_certificate_authority with id '%s'", stateData.Id.ValueString())) + + tflog.Debug(ctx, "End import of state resource: aci_certificate_authority") +} + +func getAndSetPkiTPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *PkiTPResourceModel) { + requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "pkiTP,tagAnnotation,tagTag"), "GET", nil) + + readData := getEmptyPkiTPResourceModel() + + if diags.HasError() { + return + } + if requestData.Search("imdata").Search("pkiTP").Data() != nil { + classReadInfo := requestData.Search("imdata").Search("pkiTP").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)) + setPkiTPParentDn(ctx, attributeValue.(string), readData) + } + if attributeName == "annotation" { + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "certChain" { + readData.CertChain = 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)) + } + } + TagAnnotationPkiTPList := make([]TagAnnotationPkiTPResourceModel, 0) + TagTagPkiTPList := make([]TagTagPkiTPResourceModel, 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" { + TagAnnotationPkiTP := getEmptyTagAnnotationPkiTPResourceModel() + for childAttributeName, childAttributeValue := range childAttributes { + if childAttributeName == "key" { + TagAnnotationPkiTP.Key = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "value" { + TagAnnotationPkiTP.Value = basetypes.NewStringValue(childAttributeValue.(string)) + } + } + TagAnnotationPkiTPList = append(TagAnnotationPkiTPList, TagAnnotationPkiTP) + } + if childClassName == "tagTag" { + TagTagPkiTP := getEmptyTagTagPkiTPResourceModel() + for childAttributeName, childAttributeValue := range childAttributes { + if childAttributeName == "key" { + TagTagPkiTP.Key = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "value" { + TagTagPkiTP.Value = basetypes.NewStringValue(childAttributeValue.(string)) + } + } + TagTagPkiTPList = append(TagTagPkiTPList, TagTagPkiTP) + } + } + } + } + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationPkiTPList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagPkiTPList) + readData.TagTag = tagTagSet + } else { + diags.AddError( + "too many results in response", + fmt.Sprintf("%v matches returned for class 'pkiTP'. Please report this issue to the provider developers.", len(classReadInfo)), + ) + } + } else { + readData.Id = basetypes.NewStringNull() + } + *data = *readData +} + +func getPkiTPRn(ctx context.Context, data *PkiTPResourceModel) string { + rn := "tp-{name}" + for _, identifier := range []string{"name"} { + fieldName := fmt.Sprintf("%s%s", strings.ToUpper(identifier[:1]), identifier[1:]) + fieldValue := reflect.ValueOf(data).Elem().FieldByName(fieldName).Interface().(basetypes.StringValue).ValueString() + rn = strings.ReplaceAll(rn, fmt.Sprintf("{%s}", identifier), fieldValue) + } + return rn +} + +func setPkiTPParentDn(ctx context.Context, dn string, data *PkiTPResourceModel) { + 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 + } + } + parentDn := dn[:rnIndex] + rnMap := map[string]string{ + "tn": "certstore", + } + for parentIdentifier, rnPrepend := range rnMap { + if strings.Contains(parentDn, parentIdentifier) { + parentDn = parentDn[:strings.Index(parentDn, fmt.Sprintf("/%s", rnPrepend))] + break + } + } + data.ParentDn = basetypes.NewStringValue(parentDn) +} + +func setPkiTPId(ctx context.Context, data *PkiTPResourceModel) { + rn := getPkiTPRn(ctx, data) + parentDn := data.ParentDn.ValueString() + rnMap := map[string]string{ + "tn": "certstore", + } + id := fmt.Sprintf("%s/%s", parentDn, rn) + for parentIdentifier, rnPrepend := range rnMap { + if strings.Contains(parentDn, parentIdentifier) { + id = fmt.Sprintf("%s/%s/%s", parentDn, rnPrepend, rn) + break + } + } + data.Id = types.StringValue(id) +} + +func getPkiTPTagAnnotationChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *PkiTPResourceModel, tagAnnotationPlan, tagAnnotationState []TagAnnotationPkiTPResourceModel) []map[string]interface{} { + + childPayloads := []map[string]interface{}{} + if !data.TagAnnotation.IsUnknown() { + tagAnnotationIdentifiers := []TagAnnotationIdentifier{} + for _, tagAnnotation := range tagAnnotationPlan { + childMap := map[string]map[string]interface{}{"attributes": {}} + if !tagAnnotation.Key.IsUnknown() && !tagAnnotation.Key.IsNull() { + childMap["attributes"]["key"] = tagAnnotation.Key.ValueString() + } + if !tagAnnotation.Value.IsUnknown() && !tagAnnotation.Value.IsNull() { + childMap["attributes"]["value"] = tagAnnotation.Value.ValueString() + } + childPayloads = append(childPayloads, map[string]interface{}{"tagAnnotation": childMap}) + tagAnnotationIdentifier := TagAnnotationIdentifier{} + tagAnnotationIdentifier.Key = tagAnnotation.Key + tagAnnotationIdentifiers = append(tagAnnotationIdentifiers, tagAnnotationIdentifier) + } + for _, tagAnnotation := range tagAnnotationState { + delete := true + for _, tagAnnotationIdentifier := range tagAnnotationIdentifiers { + if tagAnnotationIdentifier.Key == tagAnnotation.Key { + delete = false + break + } + } + if delete { + childMap := map[string]map[string]interface{}{"attributes": {}} + childMap["attributes"]["status"] = "deleted" + childMap["attributes"]["key"] = tagAnnotation.Key.ValueString() + childPayloads = append(childPayloads, map[string]interface{}{"tagAnnotation": childMap}) + } + } + } else { + data.TagAnnotation = types.SetNull(data.TagAnnotation.ElementType(ctx)) + } + + return childPayloads +} +func getPkiTPTagTagChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *PkiTPResourceModel, tagTagPlan, tagTagState []TagTagPkiTPResourceModel) []map[string]interface{} { + + childPayloads := []map[string]interface{}{} + if !data.TagTag.IsUnknown() { + tagTagIdentifiers := []TagTagIdentifier{} + for _, tagTag := range tagTagPlan { + childMap := map[string]map[string]interface{}{"attributes": {}} + if !tagTag.Key.IsUnknown() && !tagTag.Key.IsNull() { + childMap["attributes"]["key"] = tagTag.Key.ValueString() + } + if !tagTag.Value.IsUnknown() && !tagTag.Value.IsNull() { + childMap["attributes"]["value"] = tagTag.Value.ValueString() + } + childPayloads = append(childPayloads, map[string]interface{}{"tagTag": childMap}) + tagTagIdentifier := TagTagIdentifier{} + tagTagIdentifier.Key = tagTag.Key + tagTagIdentifiers = append(tagTagIdentifiers, tagTagIdentifier) + } + for _, tagTag := range tagTagState { + delete := true + for _, tagTagIdentifier := range tagTagIdentifiers { + if tagTagIdentifier.Key == tagTag.Key { + delete = false + break + } + } + if delete { + childMap := map[string]map[string]interface{}{"attributes": {}} + childMap["attributes"]["status"] = "deleted" + childMap["attributes"]["key"] = tagTag.Key.ValueString() + childPayloads = append(childPayloads, map[string]interface{}{"tagTag": childMap}) + } + } + } else { + data.TagTag = types.SetNull(data.TagTag.ElementType(ctx)) + } + + return childPayloads +} + +func getPkiTPCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, createType bool, data *PkiTPResourceModel, tagAnnotationPlan, tagAnnotationState []TagAnnotationPkiTPResourceModel, tagTagPlan, tagTagState []TagTagPkiTPResourceModel) *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 := getPkiTPTagAnnotationChildPayloads(ctx, diags, data, tagAnnotationPlan, tagAnnotationState) + if TagAnnotationchildPayloads == nil { + return nil + } + childPayloads = append(childPayloads, TagAnnotationchildPayloads...) + + TagTagchildPayloads := getPkiTPTagTagChildPayloads(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.CertChain.IsNull() && !data.CertChain.IsUnknown() { + payloadMap["attributes"].(map[string]string)["certChain"] = data.CertChain.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() + } + wrapperClassMap := map[string]string{ + "uni/userext/pkiext": "", + "certstore": "cloudCertStore", + } + + var payload []byte + var err error + for rnPrepend, wrapperClass := range wrapperClassMap { + if strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass != "" && createType { + wrapperPayloadMap := map[string]interface{}{ + wrapperClass: map[string]interface{}{ + "attributes": map[string]interface{}{}, + "children": []interface{}{map[string]interface{}{"pkiTP": payloadMap}}, + }, + } + payload, err = json.Marshal(wrapperPayloadMap) + break + } else if (strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass == "") || !createType { + payload, err = json.Marshal(map[string]interface{}{"pkiTP": payloadMap}) + break + } + } + 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_certificate_authority_test.go b/internal/provider/resource_aci_certificate_authority_test.go new file mode 100644 index 000000000..23bf511b3 --- /dev/null +++ b/internal/provider/resource_aci_certificate_authority_test.go @@ -0,0 +1,648 @@ +// 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 TestAccResourcePkiTP(t *testing.T) { + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigPkiTPMinAllowExisting, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "name", "test_name"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "description", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "description", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "name_alias", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "owner_key", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "owner_tag", ""), + ), + }, + }, + }) + + setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigPkiTPMinAllowExisting, + ExpectError: regexp.MustCompile("Object Already Exists"), + }, + }, + }) + + setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigPkiTPMinAllowExisting, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "name", "test_name"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "description", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "description", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "name_alias", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "owner_key", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "owner_tag", ""), + ), + }, + }, + }) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigPkiTPMin, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "description", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "owner_tag", ""), + ), + }, + // Update with all config and verify default APIC values + { + Config: testConfigPkiTPAll, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotation", "annotation"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "description", "description_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "name_alias", "name_alias_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "owner_key", "owner_key_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "owner_tag", "owner_tag_1"), + ), + }, + // Update with minimum config and verify config is unchanged + { + Config: testConfigPkiTPMin, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.test", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "name", "test_name"), + ), + }, + // Update with empty strings config or default value + { + Config: testConfigPkiTPReset, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.test", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "description", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "owner_tag", ""), + ), + }, + // Import testing + { + ResourceName: "aci_certificate_authority.test", + ImportState: true, + ImportStateVerify: true, + }, + // Update with children + { + Config: testConfigPkiTPChildren, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.test", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "description", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.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_certificate_authority.test", + ImportState: true, + ImportStateVerify: true, + }, + // Update with children removed from config + { + Config: testConfigPkiTPChildrenRemoveFromConfig, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.#", "2"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.#", "2"), + ), + }, + // Update with children first child removed + { + Config: testConfigPkiTPChildrenRemoveOne, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.0.value", "test_value"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.#", "1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.0.value", "test_value"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.#", "1"), + ), + }, + // Update with all children removed + { + Config: testConfigPkiTPChildrenRemoveAll, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.#", "0"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.#", "0"), + ), + }, + }, + CheckDestroy: testCheckResourceDestroy, + }) +} +func TestAccResourcePkiTPWithFvTenant(t *testing.T) { + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "cloud", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigPkiTPMinDependencyWithFvTenantAllowExisting, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "name", "test_name"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "description", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "description", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "name_alias", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "owner_key", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "owner_tag", ""), + ), + }, + }, + }) + + setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "cloud", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigPkiTPMinDependencyWithFvTenantAllowExisting, + ExpectError: regexp.MustCompile("Object Already Exists"), + }, + }, + }) + + setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "cloud", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigPkiTPMinDependencyWithFvTenantAllowExisting, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "name", "test_name"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "description", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "description", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "name_alias", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "owner_key", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.allow_test_2", "owner_tag", ""), + ), + }, + }, + }) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "cloud", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigPkiTPMinDependencyWithFvTenant, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "description", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "owner_tag", ""), + ), + }, + // Update with all config and verify default APIC values + { + Config: testConfigPkiTPAllDependencyWithFvTenant, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotation", "annotation"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "description", "description_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "name_alias", "name_alias_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "owner_key", "owner_key_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "owner_tag", "owner_tag_1"), + ), + }, + // Update with minimum config and verify config is unchanged + { + Config: testConfigPkiTPMinDependencyWithFvTenant, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.test", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "name", "test_name"), + ), + }, + // Update with empty strings config or default value + { + Config: testConfigPkiTPResetDependencyWithFvTenant, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.test", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "description", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "owner_tag", ""), + ), + }, + // Import testing + { + ResourceName: "aci_certificate_authority.test", + ImportState: true, + ImportStateVerify: true, + }, + // Update with children + { + Config: testConfigPkiTPChildrenDependencyWithFvTenant, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.test", "certificate_chain", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "description", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.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_certificate_authority.test", + ImportState: true, + ImportStateVerify: true, + }, + // Update with children removed from config + { + Config: testConfigPkiTPChildrenRemoveFromConfigDependencyWithFvTenant, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.#", "2"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.#", "2"), + ), + }, + // Update with children first child removed + { + Config: testConfigPkiTPChildrenRemoveOneDependencyWithFvTenant, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.0.value", "test_value"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.#", "1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.0.value", "test_value"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.#", "1"), + ), + }, + // Update with all children removed + { + Config: testConfigPkiTPChildrenRemoveAllDependencyWithFvTenant, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_certificate_authority.test", "annotations.#", "0"), + resource.TestCheckResourceAttr("aci_certificate_authority.test", "tags.#", "0"), + ), + }, + }, + CheckDestroy: testCheckResourceDestroy, + }) +} + +const testConfigPkiTPMinAllowExisting = ` +resource "aci_certificate_authority" "allow_test" { + certificate_chain = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + name = "test_name" +} +resource "aci_certificate_authority" "allow_test_2" { + certificate_chain = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + name = "test_name" + depends_on = [aci_certificate_authority.allow_test] +} +` + +const testConfigPkiTPMin = ` +resource "aci_certificate_authority" "test" { + certificate_chain = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + name = "test_name" +} +` + +const testConfigPkiTPAll = ` +resource "aci_certificate_authority" "test" { + name = "test_name" + annotation = "annotation" + certificate_chain = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + description = "description_1" + name_alias = "name_alias_1" + owner_key = "owner_key_1" + owner_tag = "owner_tag_1" +} +` + +const testConfigPkiTPReset = ` +resource "aci_certificate_authority" "test" { + name = "test_name" + annotation = "orchestrator:terraform" + certificate_chain = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + description = "" + name_alias = "" + owner_key = "" + owner_tag = "" +} +` +const testConfigPkiTPChildren = ` +resource "aci_certificate_authority" "test" { + certificate_chain = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + 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 testConfigPkiTPChildrenRemoveFromConfig = ` +resource "aci_certificate_authority" "test" { + certificate_chain = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + name = "test_name" +} +` + +const testConfigPkiTPChildrenRemoveOne = ` +resource "aci_certificate_authority" "test" { + certificate_chain = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + name = "test_name" + annotations = [ + { + key = "key_1" + value = "test_value" + }, + ] + tags = [ + { + key = "key_1" + value = "test_value" + }, + ] +} +` + +const testConfigPkiTPChildrenRemoveAll = ` +resource "aci_certificate_authority" "test" { + certificate_chain = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + name = "test_name" + annotations = [] + tags = [] +} +` + +const testConfigPkiTPMinDependencyWithFvTenantAllowExisting = testConfigFvTenantMin + ` +resource "aci_certificate_authority" "allow_test" { + parent_dn = aci_tenant.test.id + certificate_chain = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + name = "test_name" +} +resource "aci_certificate_authority" "allow_test_2" { + parent_dn = aci_tenant.test.id + certificate_chain = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + name = "test_name" + depends_on = [aci_certificate_authority.allow_test] +} +` + +const testConfigPkiTPMinDependencyWithFvTenant = testConfigFvTenantMin + ` +resource "aci_certificate_authority" "test" { + parent_dn = aci_tenant.test.id + certificate_chain = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + name = "test_name" +} +` + +const testConfigPkiTPAllDependencyWithFvTenant = testConfigFvTenantMin + ` +resource "aci_certificate_authority" "test" { + parent_dn = aci_tenant.test.id + name = "test_name" + annotation = "annotation" + certificate_chain = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + description = "description_1" + name_alias = "name_alias_1" + owner_key = "owner_key_1" + owner_tag = "owner_tag_1" +} +` + +const testConfigPkiTPResetDependencyWithFvTenant = testConfigFvTenantMin + ` +resource "aci_certificate_authority" "test" { + parent_dn = aci_tenant.test.id + name = "test_name" + annotation = "orchestrator:terraform" + certificate_chain = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + description = "" + name_alias = "" + owner_key = "" + owner_tag = "" +} +` +const testConfigPkiTPChildrenDependencyWithFvTenant = testConfigFvTenantMin + ` +resource "aci_certificate_authority" "test" { + parent_dn = aci_tenant.test.id + certificate_chain = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + 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 testConfigPkiTPChildrenRemoveFromConfigDependencyWithFvTenant = testConfigFvTenantMin + ` +resource "aci_certificate_authority" "test" { + parent_dn = aci_tenant.test.id + certificate_chain = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + name = "test_name" +} +` + +const testConfigPkiTPChildrenRemoveOneDependencyWithFvTenant = testConfigFvTenantMin + ` +resource "aci_certificate_authority" "test" { + parent_dn = aci_tenant.test.id + certificate_chain = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + name = "test_name" + annotations = [ + { + key = "key_1" + value = "test_value" + }, + ] + tags = [ + { + key = "key_1" + value = "test_value" + }, + ] +} +` + +const testConfigPkiTPChildrenRemoveAllDependencyWithFvTenant = testConfigFvTenantMin + ` +resource "aci_certificate_authority" "test" { + parent_dn = aci_tenant.test.id + certificate_chain = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + name = "test_name" + annotations = [] + tags = [] +} +` diff --git a/internal/provider/resource_aci_custom_qos_policy.go b/internal/provider/resource_aci_custom_qos_policy.go index f439e24b3..e829fe128 100644 --- a/internal/provider/resource_aci_custom_qos_policy.go +++ b/internal/provider/resource_aci_custom_qos_policy.go @@ -341,6 +341,7 @@ func (r *QosCustomPolResource) Create(ctx context.Context, req resource.CreateRe } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -455,7 +456,7 @@ func (r *QosCustomPolResource) ImportState(ctx context.Context, req resource.Imp func getAndSetQosCustomPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *QosCustomPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "qosCustomPol,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyQosCustomPolResourceModel() + readData := getEmptyQosCustomPolResourceModel() if diags.HasError() { return @@ -466,26 +467,26 @@ func getAndSetQosCustomPolAttributes(ctx context.Context, diags *diag.Diagnostic attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setQosCustomPolParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setQosCustomPolParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerKey" { - data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerTag" { - data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationQosCustomPolList := make([]TagAnnotationQosCustomPolResourceModel, 0) @@ -523,10 +524,10 @@ func getAndSetQosCustomPolAttributes(ctx context.Context, diags *diag.Diagnostic } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationQosCustomPolList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagQosCustomPolList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationQosCustomPolList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagQosCustomPolList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -534,8 +535,9 @@ func getAndSetQosCustomPolAttributes(ctx context.Context, diags *diag.Diagnostic ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getQosCustomPolRn(ctx context.Context, data *QosCustomPolResourceModel) string { @@ -688,7 +690,6 @@ func getQosCustomPolCreateJsonPayload(ctx context.Context, diags *diag.Diagnosti if !data.OwnerTag.IsNull() && !data.OwnerTag.IsUnknown() { payloadMap["attributes"].(map[string]string)["ownerTag"] = data.OwnerTag.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"qosCustomPol": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_custom_qos_policy_test.go b/internal/provider/resource_aci_custom_qos_policy_test.go index 22d9732ea..791188ba0 100644 --- a/internal/provider/resource_aci_custom_qos_policy_test.go +++ b/internal/provider/resource_aci_custom_qos_policy_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceQosCustomPolWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -41,7 +41,7 @@ func TestAccResourceQosCustomPolWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -54,7 +54,7 @@ func TestAccResourceQosCustomPolWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -80,7 +80,7 @@ func TestAccResourceQosCustomPolWithFvTenant(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -208,6 +208,7 @@ func TestAccResourceQosCustomPolWithFvTenant(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_data_plane_policing_policy.go b/internal/provider/resource_aci_data_plane_policing_policy.go index 5b635277c..7f4575a60 100644 --- a/internal/provider/resource_aci_data_plane_policing_policy.go +++ b/internal/provider/resource_aci_data_plane_policing_policy.go @@ -667,6 +667,7 @@ func (r *QosDppPolResource) Create(ctx context.Context, req resource.CreateReque } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -781,7 +782,7 @@ func (r *QosDppPolResource) ImportState(ctx context.Context, req resource.Import func getAndSetQosDppPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *QosDppPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "qosDppPol,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyQosDppPolResourceModel() + readData := getEmptyQosDppPolResourceModel() if diags.HasError() { return @@ -792,89 +793,89 @@ func getAndSetQosDppPolAttributes(ctx context.Context, diags *diag.Diagnostics, attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setQosDppPolParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setQosDppPolParentDn(ctx, attributeValue.(string), readData) } if attributeName == "adminSt" { - data.AdminSt = basetypes.NewStringValue(attributeValue.(string)) + readData.AdminSt = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "be" { - data.Be = customTypes.NewQosDppPolBeStringValue(attributeValue.(string)) + readData.Be = customTypes.NewQosDppPolBeStringValue(attributeValue.(string)) } if attributeName == "beUnit" { - data.BeUnit = basetypes.NewStringValue(attributeValue.(string)) + readData.BeUnit = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "burst" { - data.Burst = customTypes.NewQosDppPolBurstStringValue(attributeValue.(string)) + readData.Burst = customTypes.NewQosDppPolBurstStringValue(attributeValue.(string)) } if attributeName == "burstUnit" { - data.BurstUnit = basetypes.NewStringValue(attributeValue.(string)) + readData.BurstUnit = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "conformAction" { - data.ConformAction = basetypes.NewStringValue(attributeValue.(string)) + readData.ConformAction = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "conformMarkCos" { - data.ConformMarkCos = customTypes.NewQosDppPolConformMarkCosStringValue(attributeValue.(string)) + readData.ConformMarkCos = customTypes.NewQosDppPolConformMarkCosStringValue(attributeValue.(string)) } if attributeName == "conformMarkDscp" { - data.ConformMarkDscp = customTypes.NewQosDppPolConformMarkDscpStringValue(attributeValue.(string)) + readData.ConformMarkDscp = customTypes.NewQosDppPolConformMarkDscpStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "exceedAction" { - data.ExceedAction = basetypes.NewStringValue(attributeValue.(string)) + readData.ExceedAction = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "exceedMarkCos" { - data.ExceedMarkCos = customTypes.NewQosDppPolExceedMarkCosStringValue(attributeValue.(string)) + readData.ExceedMarkCos = customTypes.NewQosDppPolExceedMarkCosStringValue(attributeValue.(string)) } if attributeName == "exceedMarkDscp" { - data.ExceedMarkDscp = customTypes.NewQosDppPolExceedMarkDscpStringValue(attributeValue.(string)) + readData.ExceedMarkDscp = customTypes.NewQosDppPolExceedMarkDscpStringValue(attributeValue.(string)) } if attributeName == "mode" { - data.Mode = basetypes.NewStringValue(attributeValue.(string)) + readData.Mode = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerKey" { - data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerTag" { - data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "pir" { - data.Pir = basetypes.NewStringValue(attributeValue.(string)) + readData.Pir = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "pirUnit" { - data.PirUnit = basetypes.NewStringValue(attributeValue.(string)) + readData.PirUnit = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "rate" { - data.Rate = basetypes.NewStringValue(attributeValue.(string)) + readData.Rate = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "rateUnit" { - data.RateUnit = basetypes.NewStringValue(attributeValue.(string)) + readData.RateUnit = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "sharingMode" { - data.SharingMode = basetypes.NewStringValue(attributeValue.(string)) + readData.SharingMode = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "type" { - data.Type = basetypes.NewStringValue(attributeValue.(string)) + readData.Type = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "violateAction" { - data.ViolateAction = basetypes.NewStringValue(attributeValue.(string)) + readData.ViolateAction = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "violateMarkCos" { - data.ViolateMarkCos = customTypes.NewQosDppPolViolateMarkCosStringValue(attributeValue.(string)) + readData.ViolateMarkCos = customTypes.NewQosDppPolViolateMarkCosStringValue(attributeValue.(string)) } if attributeName == "violateMarkDscp" { - data.ViolateMarkDscp = customTypes.NewQosDppPolViolateMarkDscpStringValue(attributeValue.(string)) + readData.ViolateMarkDscp = customTypes.NewQosDppPolViolateMarkDscpStringValue(attributeValue.(string)) } } TagAnnotationQosDppPolList := make([]TagAnnotationQosDppPolResourceModel, 0) @@ -912,10 +913,10 @@ func getAndSetQosDppPolAttributes(ctx context.Context, diags *diag.Diagnostics, } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationQosDppPolList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagQosDppPolList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationQosDppPolList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagQosDppPolList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -923,8 +924,9 @@ func getAndSetQosDppPolAttributes(ctx context.Context, diags *diag.Diagnostics, ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getQosDppPolRn(ctx context.Context, data *QosDppPolResourceModel) string { @@ -1140,7 +1142,6 @@ func getQosDppPolCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, if !data.ViolateMarkDscp.IsNull() && !data.ViolateMarkDscp.IsUnknown() { payloadMap["attributes"].(map[string]string)["violateMarkDscp"] = data.ViolateMarkDscp.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"qosDppPol": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_data_plane_policing_policy_test.go b/internal/provider/resource_aci_data_plane_policing_policy_test.go index baf1bd17c..47210cb0e 100644 --- a/internal/provider/resource_aci_data_plane_policing_policy_test.go +++ b/internal/provider/resource_aci_data_plane_policing_policy_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceQosDppPolWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.2(2g)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -83,7 +83,7 @@ func TestAccResourceQosDppPolWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.2(2g)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -96,7 +96,7 @@ func TestAccResourceQosDppPolWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.2(2g)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -164,7 +164,7 @@ func TestAccResourceQosDppPolWithFvTenant(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.2(2g)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -392,6 +392,7 @@ func TestAccResourceQosDppPolWithFvTenant(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_endpoint_security_group.go b/internal/provider/resource_aci_endpoint_security_group.go index 42e94397c..d4d764c01 100644 --- a/internal/provider/resource_aci_endpoint_security_group.go +++ b/internal/provider/resource_aci_endpoint_security_group.go @@ -1762,6 +1762,7 @@ func (r *FvESgResource) Create(ctx context.Context, req resource.CreateRequest, } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -1901,7 +1902,7 @@ func (r *FvESgResource) ImportState(ctx context.Context, req resource.ImportStat func getAndSetFvESgAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvESgResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvESg,fvRsCons,fvRsConsIf,fvRsIntraEpg,fvRsProv,fvRsScope,fvRsSecInherited,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvESgResourceModel() + readData := getEmptyFvESgResourceModel() if diags.HasError() { return @@ -1912,38 +1913,38 @@ func getAndSetFvESgAttributes(ctx context.Context, diags *diag.Diagnostics, clie attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvESgParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvESgParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "exceptionTag" { - data.ExceptionTag = basetypes.NewStringValue(attributeValue.(string)) + readData.ExceptionTag = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "matchT" { - data.MatchT = basetypes.NewStringValue(attributeValue.(string)) + readData.MatchT = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "pcEnfPref" { - data.PcEnfPref = basetypes.NewStringValue(attributeValue.(string)) + readData.PcEnfPref = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "pcTag" { - data.PcTag = basetypes.NewStringValue(attributeValue.(string)) + readData.PcTag = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "prefGrMemb" { - data.PrefGrMemb = basetypes.NewStringValue(attributeValue.(string)) + readData.PrefGrMemb = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "shutdown" { - data.Shutdown = basetypes.NewStringValue(attributeValue.(string)) + readData.Shutdown = basetypes.NewStringValue(attributeValue.(string)) } } FvRsConsFvESgList := make([]FvRsConsFvESgResourceModel, 0) @@ -2071,28 +2072,28 @@ func getAndSetFvESgAttributes(ctx context.Context, diags *diag.Diagnostics, clie } } } - fvRsConsSet, _ := types.SetValueFrom(ctx, data.FvRsCons.ElementType(ctx), FvRsConsFvESgList) - data.FvRsCons = fvRsConsSet - fvRsConsIfSet, _ := types.SetValueFrom(ctx, data.FvRsConsIf.ElementType(ctx), FvRsConsIfFvESgList) - data.FvRsConsIf = fvRsConsIfSet - fvRsIntraEpgSet, _ := types.SetValueFrom(ctx, data.FvRsIntraEpg.ElementType(ctx), FvRsIntraEpgFvESgList) - data.FvRsIntraEpg = fvRsIntraEpgSet - fvRsProvSet, _ := types.SetValueFrom(ctx, data.FvRsProv.ElementType(ctx), FvRsProvFvESgList) - data.FvRsProv = fvRsProvSet + fvRsConsSet, _ := types.SetValueFrom(ctx, readData.FvRsCons.ElementType(ctx), FvRsConsFvESgList) + readData.FvRsCons = fvRsConsSet + fvRsConsIfSet, _ := types.SetValueFrom(ctx, readData.FvRsConsIf.ElementType(ctx), FvRsConsIfFvESgList) + readData.FvRsConsIf = fvRsConsIfSet + fvRsIntraEpgSet, _ := types.SetValueFrom(ctx, readData.FvRsIntraEpg.ElementType(ctx), FvRsIntraEpgFvESgList) + readData.FvRsIntraEpg = fvRsIntraEpgSet + fvRsProvSet, _ := types.SetValueFrom(ctx, readData.FvRsProv.ElementType(ctx), FvRsProvFvESgList) + readData.FvRsProv = fvRsProvSet if len(FvRsScopeFvESgList) == 1 { fvRsScopeObject, _ := types.ObjectValueFrom(ctx, FvRsScopeFvESgType, FvRsScopeFvESgList[0]) - data.FvRsScope = fvRsScopeObject + readData.FvRsScope = fvRsScopeObject } else { fvRsScopeObject, _ := types.ObjectValueFrom(ctx, FvRsScopeFvESgType, getEmptyFvRsScopeFvESgResourceModel()) - data.FvRsScope = fvRsScopeObject + readData.FvRsScope = fvRsScopeObject } - fvRsSecInheritedSet, _ := types.SetValueFrom(ctx, data.FvRsSecInherited.ElementType(ctx), FvRsSecInheritedFvESgList) - data.FvRsSecInherited = fvRsSecInheritedSet - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvESgList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvESgList) - data.TagTag = tagTagSet - setFvESgLegacyAttributes(ctx, diags, data, classReadInfo) + fvRsSecInheritedSet, _ := types.SetValueFrom(ctx, readData.FvRsSecInherited.ElementType(ctx), FvRsSecInheritedFvESgList) + readData.FvRsSecInherited = fvRsSecInheritedSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvESgList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvESgList) + readData.TagTag = tagTagSet + setFvESgLegacyAttributes(ctx, diags, readData, classReadInfo) } else { diags.AddError( "too many results in response", @@ -2100,8 +2101,9 @@ func getAndSetFvESgAttributes(ctx context.Context, diags *diag.Diagnostics, clie ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvESgRn(ctx context.Context, data *FvESgResourceModel) string { @@ -2539,7 +2541,6 @@ func getFvESgCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, cre if !data.Shutdown.IsNull() && !data.Shutdown.IsUnknown() { payloadMap["attributes"].(map[string]string)["shutdown"] = data.Shutdown.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvESg": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_endpoint_security_group_test.go b/internal/provider/resource_aci_endpoint_security_group_test.go index 831a2076c..116c922a1 100644 --- a/internal/provider/resource_aci_endpoint_security_group_test.go +++ b/internal/provider/resource_aci_endpoint_security_group_test.go @@ -14,18 +14,16 @@ import ( func TestAccResourceFvESgWithFvAp(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigFvESgMinDependencyWithFvApAllowExisting, + Config: testConfigFvESgMinDependencyWithFvApAllowExisting + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test", "name", "test_name"), resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test_2", "name", "test_name"), - resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test", "admin_state", "no"), - resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test_2", "admin_state", "no"), resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test_2", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test", "description", ""), @@ -40,6 +38,9 @@ func TestAccResourceFvESgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test_2", "name_alias", ""), resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test", "preferred_group_member", "exclude"), resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test_2", "preferred_group_member", "exclude"), + composeAggregateTestCheckFuncWithVersion(t, "5.2(1g)", ">", + resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test", "admin_state", "no"), + resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test_2", "admin_state", "no")), resource.TestCheckResourceAttrSet("aci_endpoint_security_group.allow_test", "pc_tag"), ), }, @@ -48,12 +49,12 @@ func TestAccResourceFvESgWithFvAp(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigFvESgMinDependencyWithFvApAllowExisting, + Config: testConfigFvESgMinDependencyWithFvApAllowExisting + testConfigDataSourceSystem, ExpectError: regexp.MustCompile("Object Already Exists"), }, }, @@ -61,18 +62,16 @@ func TestAccResourceFvESgWithFvAp(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigFvESgMinDependencyWithFvApAllowExisting, + Config: testConfigFvESgMinDependencyWithFvApAllowExisting + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test", "name", "test_name"), resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test_2", "name", "test_name"), - resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test", "admin_state", "no"), - resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test_2", "admin_state", "no"), resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test_2", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test", "description", ""), @@ -87,6 +86,9 @@ func TestAccResourceFvESgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test_2", "name_alias", ""), resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test", "preferred_group_member", "exclude"), resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test_2", "preferred_group_member", "exclude"), + composeAggregateTestCheckFuncWithVersion(t, "5.2(1g)", ">", + resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test", "admin_state", "no"), + resource.TestCheckResourceAttr("aci_endpoint_security_group.allow_test_2", "admin_state", "no")), resource.TestCheckResourceAttrSet("aci_endpoint_security_group.allow_test", "pc_tag"), resource.TestCheckResourceAttrSet("aci_endpoint_security_group.allow_test_2", "pc_tag"), ), @@ -95,16 +97,15 @@ func TestAccResourceFvESgWithFvAp(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigFvESgMinDependencyWithFvAp, + Config: testConfigFvESgMinDependencyWithFvAp + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "name", "test_name"), - resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "admin_state", "no"), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "description", ""), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "exception_tag", ""), @@ -112,16 +113,17 @@ func TestAccResourceFvESgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "match_criteria", "AtleastOne"), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "name_alias", ""), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "preferred_group_member", "exclude"), + composeAggregateTestCheckFuncWithVersion(t, "5.2(1g)", ">", + resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "admin_state", "no")), resource.TestCheckResourceAttrSet("aci_endpoint_security_group.test", "pc_tag"), ), }, // Update with all config and verify default APIC values { - Config: testConfigFvESgAllDependencyWithFvAp, + Config: testConfigFvESgAllDependencyWithFvAp + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "name", "test_name"), - resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "admin_state", "no"), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "annotation", "annotation"), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "description", "description_1"), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "exception_tag", "exception_tag_1"), @@ -129,12 +131,14 @@ func TestAccResourceFvESgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "match_criteria", "All"), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "name_alias", "name_alias_1"), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "preferred_group_member", "exclude"), + composeAggregateTestCheckFuncWithVersion(t, "5.2(1g)", ">", + resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "admin_state", "no")), resource.TestCheckResourceAttrSet("aci_endpoint_security_group.test", "pc_tag"), ), }, // Update with minimum config and verify config is unchanged { - Config: testConfigFvESgMinDependencyWithFvAp, + Config: testConfigFvESgMinDependencyWithFvAp + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "name", "test_name"), @@ -143,11 +147,10 @@ func TestAccResourceFvESgWithFvAp(t *testing.T) { }, // Update with empty strings config or default value { - Config: testConfigFvESgResetDependencyWithFvAp, + Config: testConfigFvESgResetDependencyWithFvAp + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "name", "test_name"), - resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "admin_state", "no"), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "description", ""), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "exception_tag", ""), @@ -155,6 +158,8 @@ func TestAccResourceFvESgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "match_criteria", "AtleastOne"), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "name_alias", ""), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "preferred_group_member", "exclude"), + composeAggregateTestCheckFuncWithVersion(t, "5.2(1g)", ">", + resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "admin_state", "no")), resource.TestCheckResourceAttrSet("aci_endpoint_security_group.test", "pc_tag"), ), }, @@ -166,11 +171,10 @@ func TestAccResourceFvESgWithFvAp(t *testing.T) { }, // Update with children { - Config: testConfigFvESgChildrenDependencyWithFvAp, + Config: testConfigFvESgChildrenDependencyWithFvAp + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "name", "test_name"), - resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "admin_state", "no"), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "description", ""), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "exception_tag", ""), @@ -178,6 +182,8 @@ func TestAccResourceFvESgWithFvAp(t *testing.T) { resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "match_criteria", "AtleastOne"), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "name_alias", ""), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "preferred_group_member", "exclude"), + composeAggregateTestCheckFuncWithVersion(t, "5.2(1g)", ">", + resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "admin_state", "no")), resource.TestCheckResourceAttrSet("aci_endpoint_security_group.test", "pc_tag"), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "annotations.0.key", "key_0"), resource.TestCheckResourceAttr("aci_endpoint_security_group.test", "annotations.0.value", "value_1"), @@ -232,7 +238,7 @@ func TestAccResourceFvESgWithFvAp(t *testing.T) { }, // Update with children removed from config { - Config: testConfigFvESgChildrenRemoveFromConfigDependencyWithFvAp, + Config: testConfigFvESgChildrenRemoveFromConfigDependencyWithFvAp + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("aci_endpoint_security_group.test", "pc_tag"), @@ -285,7 +291,7 @@ func TestAccResourceFvESgWithFvAp(t *testing.T) { }, // Update with children first child removed { - Config: testConfigFvESgChildrenRemoveOneDependencyWithFvAp, + Config: testConfigFvESgChildrenRemoveOneDependencyWithFvAp + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("aci_endpoint_security_group.test", "pc_tag"), @@ -320,7 +326,7 @@ func TestAccResourceFvESgWithFvAp(t *testing.T) { }, // Update with all children removed { - Config: testConfigFvESgChildrenRemoveAllDependencyWithFvAp, + Config: testConfigFvESgChildrenRemoveAllDependencyWithFvAp + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("aci_endpoint_security_group.test", "pc_tag"), @@ -336,6 +342,7 @@ func TestAccResourceFvESgWithFvAp(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } @@ -373,7 +380,6 @@ const testConfigFvESgAllDependencyWithFvAp = testConfigFvApMinDependencyWithFvTe resource "aci_endpoint_security_group" "test" { parent_dn = aci_application_profile.test.id name = "test_name" - admin_state = "no" annotation = "annotation" description = "description_1" exception_tag = "exception_tag_1" @@ -381,6 +387,7 @@ resource "aci_endpoint_security_group" "test" { match_criteria = "All" name_alias = "name_alias_1" preferred_group_member = "exclude" + admin_state = provider::aci::compare_versions(data.aci_system.version.version,">=","5.2(1g)") ? "no" : null } ` @@ -388,7 +395,6 @@ const testConfigFvESgResetDependencyWithFvAp = testConfigFvApMinDependencyWithFv resource "aci_endpoint_security_group" "test" { parent_dn = aci_application_profile.test.id name = "test_name" - admin_state = "no" annotation = "orchestrator:terraform" description = "" exception_tag = "" @@ -396,6 +402,7 @@ resource "aci_endpoint_security_group" "test" { match_criteria = "AtleastOne" name_alias = "" preferred_group_member = "exclude" + admin_state = provider::aci::compare_versions(data.aci_system.version.version,">=","5.2(1g)") ? "no" : null } ` const testConfigFvESgChildrenDependencyWithFvAp = testChildDependencyConfigFvESg + testConfigFvApMinDependencyWithFvTenant + ` diff --git a/internal/provider/resource_aci_endpoint_tag_ip.go b/internal/provider/resource_aci_endpoint_tag_ip.go index e91a43b3b..635fe9b67 100644 --- a/internal/provider/resource_aci_endpoint_tag_ip.go +++ b/internal/provider/resource_aci_endpoint_tag_ip.go @@ -342,6 +342,7 @@ func (r *FvEpIpTagResource) Create(ctx context.Context, req resource.CreateReque } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -456,7 +457,7 @@ func (r *FvEpIpTagResource) ImportState(ctx context.Context, req resource.Import func getAndSetFvEpIpTagAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvEpIpTagResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvEpIpTag,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvEpIpTagResourceModel() + readData := getEmptyFvEpIpTagResourceModel() if diags.HasError() { return @@ -467,26 +468,26 @@ func getAndSetFvEpIpTagAttributes(ctx context.Context, diags *diag.Diagnostics, attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvEpIpTagParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvEpIpTagParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ctxName" { - data.CtxName = basetypes.NewStringValue(attributeValue.(string)) + readData.CtxName = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "id" { - data.FvEpIpTagId = basetypes.NewStringValue(attributeValue.(string)) + readData.FvEpIpTagId = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ip" { - data.Ip = basetypes.NewStringValue(attributeValue.(string)) + readData.Ip = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvEpIpTagList := make([]TagAnnotationFvEpIpTagResourceModel, 0) @@ -524,10 +525,10 @@ func getAndSetFvEpIpTagAttributes(ctx context.Context, diags *diag.Diagnostics, } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvEpIpTagList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvEpIpTagList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvEpIpTagList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvEpIpTagList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -535,8 +536,9 @@ func getAndSetFvEpIpTagAttributes(ctx context.Context, diags *diag.Diagnostics, ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvEpIpTagRn(ctx context.Context, data *FvEpIpTagResourceModel) string { @@ -691,7 +693,6 @@ func getFvEpIpTagCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, if !data.NameAlias.IsNull() && !data.NameAlias.IsUnknown() { payloadMap["attributes"].(map[string]string)["nameAlias"] = data.NameAlias.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvEpIpTag": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_endpoint_tag_ip_test.go b/internal/provider/resource_aci_endpoint_tag_ip_test.go index d384c4009..a48f8c3c4 100644 --- a/internal/provider/resource_aci_endpoint_tag_ip_test.go +++ b/internal/provider/resource_aci_endpoint_tag_ip_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFvEpIpTagWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.2(1g)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -41,7 +41,7 @@ func TestAccResourceFvEpIpTagWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.2(1g)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -54,7 +54,7 @@ func TestAccResourceFvEpIpTagWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.2(1g)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -80,7 +80,7 @@ func TestAccResourceFvEpIpTagWithFvTenant(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.2(1g)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -209,6 +209,7 @@ func TestAccResourceFvEpIpTagWithFvTenant(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_endpoint_tag_mac.go b/internal/provider/resource_aci_endpoint_tag_mac.go index d2fbe0468..5bf94e68e 100644 --- a/internal/provider/resource_aci_endpoint_tag_mac.go +++ b/internal/provider/resource_aci_endpoint_tag_mac.go @@ -342,6 +342,7 @@ func (r *FvEpMacTagResource) Create(ctx context.Context, req resource.CreateRequ } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -456,7 +457,7 @@ func (r *FvEpMacTagResource) ImportState(ctx context.Context, req resource.Impor func getAndSetFvEpMacTagAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvEpMacTagResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvEpMacTag,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvEpMacTagResourceModel() + readData := getEmptyFvEpMacTagResourceModel() if diags.HasError() { return @@ -467,26 +468,26 @@ func getAndSetFvEpMacTagAttributes(ctx context.Context, diags *diag.Diagnostics, attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvEpMacTagParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvEpMacTagParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "bdName" { - data.BdName = basetypes.NewStringValue(attributeValue.(string)) + readData.BdName = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "id" { - data.FvEpMacTagId = basetypes.NewStringValue(attributeValue.(string)) + readData.FvEpMacTagId = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "mac" { - data.Mac = basetypes.NewStringValue(attributeValue.(string)) + readData.Mac = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvEpMacTagList := make([]TagAnnotationFvEpMacTagResourceModel, 0) @@ -524,10 +525,10 @@ func getAndSetFvEpMacTagAttributes(ctx context.Context, diags *diag.Diagnostics, } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvEpMacTagList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvEpMacTagList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvEpMacTagList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvEpMacTagList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -535,8 +536,9 @@ func getAndSetFvEpMacTagAttributes(ctx context.Context, diags *diag.Diagnostics, ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvEpMacTagRn(ctx context.Context, data *FvEpMacTagResourceModel) string { @@ -691,7 +693,6 @@ func getFvEpMacTagCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics if !data.NameAlias.IsNull() && !data.NameAlias.IsUnknown() { payloadMap["attributes"].(map[string]string)["nameAlias"] = data.NameAlias.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvEpMacTag": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_endpoint_tag_mac_test.go b/internal/provider/resource_aci_endpoint_tag_mac_test.go index f666d3217..acc74c19a 100644 --- a/internal/provider/resource_aci_endpoint_tag_mac_test.go +++ b/internal/provider/resource_aci_endpoint_tag_mac_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFvEpMacTagWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.2(1g)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -41,7 +41,7 @@ func TestAccResourceFvEpMacTagWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.2(1g)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -54,7 +54,7 @@ func TestAccResourceFvEpMacTagWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.2(1g)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -80,7 +80,7 @@ func TestAccResourceFvEpMacTagWithFvTenant(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.2(1g)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -209,6 +209,7 @@ func TestAccResourceFvEpMacTagWithFvTenant(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_epg_useg_ad_group_attribute.go b/internal/provider/resource_aci_epg_useg_ad_group_attribute.go index b207cc0ae..cc7d4aa7a 100644 --- a/internal/provider/resource_aci_epg_useg_ad_group_attribute.go +++ b/internal/provider/resource_aci_epg_useg_ad_group_attribute.go @@ -352,6 +352,7 @@ func (r *FvIdGroupAttrResource) Create(ctx context.Context, req resource.CreateR } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -466,7 +467,7 @@ func (r *FvIdGroupAttrResource) ImportState(ctx context.Context, req resource.Im func getAndSetFvIdGroupAttrAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvIdGroupAttrResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvIdGroupAttr,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvIdGroupAttrResourceModel() + readData := getEmptyFvIdGroupAttrResourceModel() if diags.HasError() { return @@ -477,29 +478,29 @@ func getAndSetFvIdGroupAttrAttributes(ctx context.Context, diags *diag.Diagnosti attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvIdGroupAttrParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvIdGroupAttrParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerKey" { - data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerTag" { - data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "selector" { - data.Selector = basetypes.NewStringValue(attributeValue.(string)) + readData.Selector = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvIdGroupAttrList := make([]TagAnnotationFvIdGroupAttrResourceModel, 0) @@ -537,10 +538,10 @@ func getAndSetFvIdGroupAttrAttributes(ctx context.Context, diags *diag.Diagnosti } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvIdGroupAttrList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvIdGroupAttrList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvIdGroupAttrList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvIdGroupAttrList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -548,8 +549,9 @@ func getAndSetFvIdGroupAttrAttributes(ctx context.Context, diags *diag.Diagnosti ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvIdGroupAttrRn(ctx context.Context, data *FvIdGroupAttrResourceModel) string { @@ -705,7 +707,6 @@ func getFvIdGroupAttrCreateJsonPayload(ctx context.Context, diags *diag.Diagnost if !data.Selector.IsNull() && !data.Selector.IsUnknown() { payloadMap["attributes"].(map[string]string)["selector"] = data.Selector.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvIdGroupAttr": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_epg_useg_ad_group_attribute_test.go b/internal/provider/resource_aci_epg_useg_ad_group_attribute_test.go index ead6422fe..2303669ca 100644 --- a/internal/provider/resource_aci_epg_useg_ad_group_attribute_test.go +++ b/internal/provider/resource_aci_epg_useg_ad_group_attribute_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFvIdGroupAttrWithFvCrtrn(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "3.2(10e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -43,7 +43,7 @@ func TestAccResourceFvIdGroupAttrWithFvCrtrn(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "3.2(10e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -56,7 +56,7 @@ func TestAccResourceFvIdGroupAttrWithFvCrtrn(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "3.2(10e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -84,7 +84,7 @@ func TestAccResourceFvIdGroupAttrWithFvCrtrn(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "3.2(10e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -216,6 +216,7 @@ func TestAccResourceFvIdGroupAttrWithFvCrtrn(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_epg_useg_block_statement.go b/internal/provider/resource_aci_epg_useg_block_statement.go index 2aec3c938..09b195059 100644 --- a/internal/provider/resource_aci_epg_useg_block_statement.go +++ b/internal/provider/resource_aci_epg_useg_block_statement.go @@ -376,6 +376,7 @@ func (r *FvCrtrnResource) Create(ctx context.Context, req resource.CreateRequest } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -490,7 +491,7 @@ func (r *FvCrtrnResource) ImportState(ctx context.Context, req resource.ImportSt func getAndSetFvCrtrnAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvCrtrnResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvCrtrn,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvCrtrnResourceModel() + readData := getEmptyFvCrtrnResourceModel() if diags.HasError() { return @@ -501,35 +502,35 @@ func getAndSetFvCrtrnAttributes(ctx context.Context, diags *diag.Diagnostics, cl attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvCrtrnParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvCrtrnParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "match" { - data.Match = basetypes.NewStringValue(attributeValue.(string)) + readData.Match = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerKey" { - data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerTag" { - data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "prec" { - data.Prec = basetypes.NewStringValue(attributeValue.(string)) + readData.Prec = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "scope" { - data.Scope = basetypes.NewStringValue(attributeValue.(string)) + readData.Scope = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvCrtrnList := make([]TagAnnotationFvCrtrnResourceModel, 0) @@ -567,10 +568,10 @@ func getAndSetFvCrtrnAttributes(ctx context.Context, diags *diag.Diagnostics, cl } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvCrtrnList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvCrtrnList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvCrtrnList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvCrtrnList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -578,8 +579,9 @@ func getAndSetFvCrtrnAttributes(ctx context.Context, diags *diag.Diagnostics, cl ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvCrtrnRn(ctx context.Context, data *FvCrtrnResourceModel) string { @@ -735,7 +737,6 @@ func getFvCrtrnCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, c if !data.Scope.IsNull() && !data.Scope.IsUnknown() { payloadMap["attributes"].(map[string]string)["scope"] = data.Scope.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvCrtrn": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_epg_useg_block_statement_test.go b/internal/provider/resource_aci_epg_useg_block_statement_test.go index ea22b568c..43a6d7d61 100644 --- a/internal/provider/resource_aci_epg_useg_block_statement_test.go +++ b/internal/provider/resource_aci_epg_useg_block_statement_test.go @@ -14,12 +14,12 @@ import ( func TestAccResourceFvCrtrnWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigFvCrtrnMinDependencyWithFvAEPgAllowExisting, + Config: testConfigFvCrtrnMinDependencyWithFvAEPgAllowExisting + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test", "annotation", "orchestrator:terraform"), @@ -36,10 +36,11 @@ func TestAccResourceFvCrtrnWithFvAEPg(t *testing.T) { resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test_2", "owner_key", ""), resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test", "owner_tag", ""), resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test_2", "owner_tag", ""), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test", "precedence", "0"), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test_2", "precedence", "0"), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test", "scope", "scope-bd"), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test_2", "scope", "scope-bd"), + composeAggregateTestCheckFuncWithVersion(t, "4.1(1i)", ">", + resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test", "precedence", "0"), + resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test_2", "precedence", "0"), + resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test", "scope", "scope-bd"), + resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test_2", "scope", "scope-bd")), ), }, }, @@ -47,12 +48,12 @@ func TestAccResourceFvCrtrnWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigFvCrtrnMinDependencyWithFvAEPgAllowExisting, + Config: testConfigFvCrtrnMinDependencyWithFvAEPgAllowExisting + testConfigDataSourceSystem, ExpectError: regexp.MustCompile("Object Already Exists"), }, }, @@ -60,12 +61,12 @@ func TestAccResourceFvCrtrnWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigFvCrtrnMinDependencyWithFvAEPgAllowExisting, + Config: testConfigFvCrtrnMinDependencyWithFvAEPgAllowExisting + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test", "annotation", "orchestrator:terraform"), @@ -82,22 +83,23 @@ func TestAccResourceFvCrtrnWithFvAEPg(t *testing.T) { resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test_2", "owner_key", ""), resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test", "owner_tag", ""), resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test_2", "owner_tag", ""), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test", "precedence", "0"), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test_2", "precedence", "0"), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test", "scope", "scope-bd"), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test_2", "scope", "scope-bd"), + composeAggregateTestCheckFuncWithVersion(t, "4.1(1i)", ">", + resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test", "precedence", "0"), + resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test_2", "precedence", "0"), + resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test", "scope", "scope-bd"), + resource.TestCheckResourceAttr("aci_epg_useg_block_statement.allow_test_2", "scope", "scope-bd")), ), }, }, }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigFvCrtrnMinDependencyWithFvAEPg, + Config: testConfigFvCrtrnMinDependencyWithFvAEPg + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "annotation", "orchestrator:terraform"), @@ -107,13 +109,14 @@ func TestAccResourceFvCrtrnWithFvAEPg(t *testing.T) { resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "name_alias", ""), resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "owner_key", ""), resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "owner_tag", ""), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "precedence", "0"), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "scope", "scope-bd"), + composeAggregateTestCheckFuncWithVersion(t, "4.1(1i)", ">", + resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "precedence", "0"), + resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "scope", "scope-bd")), ), }, // Update with all config and verify default APIC values { - Config: testConfigFvCrtrnAllDependencyWithFvAEPg, + Config: testConfigFvCrtrnAllDependencyWithFvAEPg + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "annotation", "annotation"), @@ -123,31 +126,22 @@ func TestAccResourceFvCrtrnWithFvAEPg(t *testing.T) { resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "name_alias", "name_alias_1"), resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "owner_key", "owner_key_1"), resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "owner_tag", "owner_tag_1"), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "precedence", "1"), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "scope", "scope-bd"), + composeAggregateTestCheckFuncWithVersion(t, "4.1(1i)", ">", + resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "precedence", "1"), + resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "scope", "scope-bd")), ), }, // Update with minimum config and verify config is unchanged { - Config: testConfigFvCrtrnMinDependencyWithFvAEPg, + Config: testConfigFvCrtrnMinDependencyWithFvAEPg + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc(), }, // Update with empty strings config or default value { - Config: testConfigFvCrtrnResetDependencyWithFvAEPg, + Config: testConfigFvCrtrnResetDependencyWithFvAEPg + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "annotation", "orchestrator:terraform"), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "description", ""), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "match", "any"), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "name", ""), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "name_alias", ""), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "owner_key", ""), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "owner_tag", ""), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "precedence", "0"), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "scope", "scope-bd"), - ), + Check: resource.ComposeAggregateTestCheckFunc(), }, // Import testing { @@ -157,7 +151,7 @@ func TestAccResourceFvCrtrnWithFvAEPg(t *testing.T) { }, // Update with children { - Config: testConfigFvCrtrnChildrenDependencyWithFvAEPg, + Config: testConfigFvCrtrnChildrenDependencyWithFvAEPg + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "annotation", "orchestrator:terraform"), @@ -167,8 +161,9 @@ func TestAccResourceFvCrtrnWithFvAEPg(t *testing.T) { resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "name_alias", ""), resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "owner_key", ""), resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "owner_tag", ""), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "precedence", "0"), - resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "scope", "scope-bd"), + composeAggregateTestCheckFuncWithVersion(t, "4.1(1i)", ">", + resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "precedence", "0"), + resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "scope", "scope-bd")), resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "annotations.0.key", "key_0"), resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "annotations.0.value", "value_1"), resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "annotations.1.key", "key_1"), @@ -192,7 +187,7 @@ func TestAccResourceFvCrtrnWithFvAEPg(t *testing.T) { }, // Update with children removed from config { - Config: testConfigFvCrtrnChildrenRemoveFromConfigDependencyWithFvAEPg, + Config: testConfigFvCrtrnChildrenRemoveFromConfigDependencyWithFvAEPg + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "annotations.0.key", "key_0"), @@ -209,7 +204,7 @@ func TestAccResourceFvCrtrnWithFvAEPg(t *testing.T) { }, // Update with children first child removed { - Config: testConfigFvCrtrnChildrenRemoveOneDependencyWithFvAEPg, + Config: testConfigFvCrtrnChildrenRemoveOneDependencyWithFvAEPg + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "annotations.0.key", "key_1"), @@ -222,7 +217,7 @@ func TestAccResourceFvCrtrnWithFvAEPg(t *testing.T) { }, // Update with all children removed { - Config: testConfigFvCrtrnChildrenRemoveAllDependencyWithFvAEPg, + Config: testConfigFvCrtrnChildrenRemoveAllDependencyWithFvAEPg + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_epg_useg_block_statement.test", "annotations.#", "0"), @@ -230,6 +225,7 @@ func TestAccResourceFvCrtrnWithFvAEPg(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } @@ -259,8 +255,8 @@ resource "aci_epg_useg_block_statement" "test" { name_alias = "name_alias_1" owner_key = "owner_key_1" owner_tag = "owner_tag_1" - precedence = "1" - scope = "scope-bd" + precedence = provider::aci::compare_versions(data.aci_system.version.version,">=","4.1(1i)") ? "1" : null + scope = provider::aci::compare_versions(data.aci_system.version.version,">=","4.1(1i)") ? "scope-bd" : null } ` @@ -274,8 +270,8 @@ resource "aci_epg_useg_block_statement" "test" { name_alias = "" owner_key = "" owner_tag = "" - precedence = "0" - scope = "scope-bd" + precedence = provider::aci::compare_versions(data.aci_system.version.version,">=","4.1(1i)") ? "0" : null + scope = provider::aci::compare_versions(data.aci_system.version.version,">=","4.1(1i)") ? "scope-bd" : null } ` const testConfigFvCrtrnChildrenDependencyWithFvAEPg = testConfigFvAEPgMin + ` diff --git a/internal/provider/resource_aci_epg_useg_dns_attribute.go b/internal/provider/resource_aci_epg_useg_dns_attribute.go index 7ff6a5da9..4d6fabb58 100644 --- a/internal/provider/resource_aci_epg_useg_dns_attribute.go +++ b/internal/provider/resource_aci_epg_useg_dns_attribute.go @@ -352,6 +352,7 @@ func (r *FvDnsAttrResource) Create(ctx context.Context, req resource.CreateReque } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -466,7 +467,7 @@ func (r *FvDnsAttrResource) ImportState(ctx context.Context, req resource.Import func getAndSetFvDnsAttrAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvDnsAttrResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvDnsAttr,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvDnsAttrResourceModel() + readData := getEmptyFvDnsAttrResourceModel() if diags.HasError() { return @@ -477,29 +478,29 @@ func getAndSetFvDnsAttrAttributes(ctx context.Context, diags *diag.Diagnostics, attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvDnsAttrParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvDnsAttrParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "filter" { - data.Filter = basetypes.NewStringValue(attributeValue.(string)) + readData.Filter = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerKey" { - data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerTag" { - data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvDnsAttrList := make([]TagAnnotationFvDnsAttrResourceModel, 0) @@ -537,10 +538,10 @@ func getAndSetFvDnsAttrAttributes(ctx context.Context, diags *diag.Diagnostics, } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvDnsAttrList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvDnsAttrList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvDnsAttrList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvDnsAttrList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -548,8 +549,9 @@ func getAndSetFvDnsAttrAttributes(ctx context.Context, diags *diag.Diagnostics, ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvDnsAttrRn(ctx context.Context, data *FvDnsAttrResourceModel) string { @@ -705,7 +707,6 @@ func getFvDnsAttrCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, if !data.OwnerTag.IsNull() && !data.OwnerTag.IsUnknown() { payloadMap["attributes"].(map[string]string)["ownerTag"] = data.OwnerTag.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvDnsAttr": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_epg_useg_dns_attribute_test.go b/internal/provider/resource_aci_epg_useg_dns_attribute_test.go index 4c87a10fd..0b05550d0 100644 --- a/internal/provider/resource_aci_epg_useg_dns_attribute_test.go +++ b/internal/provider/resource_aci_epg_useg_dns_attribute_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFvDnsAttrWithFvCrtrn(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.3(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -43,7 +43,7 @@ func TestAccResourceFvDnsAttrWithFvCrtrn(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.3(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -56,7 +56,7 @@ func TestAccResourceFvDnsAttrWithFvCrtrn(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.3(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -84,7 +84,7 @@ func TestAccResourceFvDnsAttrWithFvCrtrn(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.3(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -216,6 +216,7 @@ func TestAccResourceFvDnsAttrWithFvCrtrn(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_epg_useg_ip_attribute.go b/internal/provider/resource_aci_epg_useg_ip_attribute.go index 223ccc876..0788be715 100644 --- a/internal/provider/resource_aci_epg_useg_ip_attribute.go +++ b/internal/provider/resource_aci_epg_useg_ip_attribute.go @@ -367,6 +367,7 @@ func (r *FvIpAttrResource) Create(ctx context.Context, req resource.CreateReques } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -481,7 +482,7 @@ func (r *FvIpAttrResource) ImportState(ctx context.Context, req resource.ImportS func getAndSetFvIpAttrAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvIpAttrResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvIpAttr,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvIpAttrResourceModel() + readData := getEmptyFvIpAttrResourceModel() if diags.HasError() { return @@ -492,32 +493,32 @@ func getAndSetFvIpAttrAttributes(ctx context.Context, diags *diag.Diagnostics, c attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvIpAttrParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvIpAttrParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ip" { - data.Ip = basetypes.NewStringValue(attributeValue.(string)) + readData.Ip = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerKey" { - data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerTag" { - data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "usefvSubnet" { - data.UsefvSubnet = basetypes.NewStringValue(attributeValue.(string)) + readData.UsefvSubnet = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvIpAttrList := make([]TagAnnotationFvIpAttrResourceModel, 0) @@ -555,10 +556,10 @@ func getAndSetFvIpAttrAttributes(ctx context.Context, diags *diag.Diagnostics, c } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvIpAttrList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvIpAttrList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvIpAttrList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvIpAttrList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -566,8 +567,9 @@ func getAndSetFvIpAttrAttributes(ctx context.Context, diags *diag.Diagnostics, c ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvIpAttrRn(ctx context.Context, data *FvIpAttrResourceModel) string { @@ -726,7 +728,6 @@ func getFvIpAttrCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, if !data.UsefvSubnet.IsNull() && !data.UsefvSubnet.IsUnknown() { payloadMap["attributes"].(map[string]string)["usefvSubnet"] = data.UsefvSubnet.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvIpAttr": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_epg_useg_ip_attribute_test.go b/internal/provider/resource_aci_epg_useg_ip_attribute_test.go index 78a3dedcc..09327e576 100644 --- a/internal/provider/resource_aci_epg_useg_ip_attribute_test.go +++ b/internal/provider/resource_aci_epg_useg_ip_attribute_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFvIpAttrWithFvCrtrn(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -45,7 +45,7 @@ func TestAccResourceFvIpAttrWithFvCrtrn(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -58,7 +58,7 @@ func TestAccResourceFvIpAttrWithFvCrtrn(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -88,7 +88,7 @@ func TestAccResourceFvIpAttrWithFvCrtrn(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -225,6 +225,7 @@ func TestAccResourceFvIpAttrWithFvCrtrn(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_epg_useg_mac_attribute.go b/internal/provider/resource_aci_epg_useg_mac_attribute.go index 19144cb50..0a6fc9049 100644 --- a/internal/provider/resource_aci_epg_useg_mac_attribute.go +++ b/internal/provider/resource_aci_epg_useg_mac_attribute.go @@ -351,6 +351,7 @@ func (r *FvMacAttrResource) Create(ctx context.Context, req resource.CreateReque } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -465,7 +466,7 @@ func (r *FvMacAttrResource) ImportState(ctx context.Context, req resource.Import func getAndSetFvMacAttrAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvMacAttrResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvMacAttr,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvMacAttrResourceModel() + readData := getEmptyFvMacAttrResourceModel() if diags.HasError() { return @@ -476,29 +477,29 @@ func getAndSetFvMacAttrAttributes(ctx context.Context, diags *diag.Diagnostics, attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvMacAttrParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvMacAttrParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "mac" { - data.Mac = basetypes.NewStringValue(attributeValue.(string)) + readData.Mac = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerKey" { - data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerTag" { - data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvMacAttrList := make([]TagAnnotationFvMacAttrResourceModel, 0) @@ -536,10 +537,10 @@ func getAndSetFvMacAttrAttributes(ctx context.Context, diags *diag.Diagnostics, } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvMacAttrList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvMacAttrList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvMacAttrList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvMacAttrList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -547,8 +548,9 @@ func getAndSetFvMacAttrAttributes(ctx context.Context, diags *diag.Diagnostics, ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvMacAttrRn(ctx context.Context, data *FvMacAttrResourceModel) string { @@ -704,7 +706,6 @@ func getFvMacAttrCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, if !data.OwnerTag.IsNull() && !data.OwnerTag.IsUnknown() { payloadMap["attributes"].(map[string]string)["ownerTag"] = data.OwnerTag.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvMacAttr": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_epg_useg_mac_attribute_test.go b/internal/provider/resource_aci_epg_useg_mac_attribute_test.go index ae33c8ac9..36ada02a3 100644 --- a/internal/provider/resource_aci_epg_useg_mac_attribute_test.go +++ b/internal/provider/resource_aci_epg_useg_mac_attribute_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFvMacAttrWithFvCrtrn(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -43,7 +43,7 @@ func TestAccResourceFvMacAttrWithFvCrtrn(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -56,7 +56,7 @@ func TestAccResourceFvMacAttrWithFvCrtrn(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -84,7 +84,7 @@ func TestAccResourceFvMacAttrWithFvCrtrn(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -217,6 +217,7 @@ func TestAccResourceFvMacAttrWithFvCrtrn(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_epg_useg_sub_block_statement.go b/internal/provider/resource_aci_epg_useg_sub_block_statement.go index ce88b1af6..f00c05b54 100644 --- a/internal/provider/resource_aci_epg_useg_sub_block_statement.go +++ b/internal/provider/resource_aci_epg_useg_sub_block_statement.go @@ -357,6 +357,7 @@ func (r *FvSCrtrnResource) Create(ctx context.Context, req resource.CreateReques } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -471,7 +472,7 @@ func (r *FvSCrtrnResource) ImportState(ctx context.Context, req resource.ImportS func getAndSetFvSCrtrnAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvSCrtrnResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvSCrtrn,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvSCrtrnResourceModel() + readData := getEmptyFvSCrtrnResourceModel() if diags.HasError() { return @@ -482,29 +483,29 @@ func getAndSetFvSCrtrnAttributes(ctx context.Context, diags *diag.Diagnostics, c attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvSCrtrnParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvSCrtrnParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "match" { - data.Match = basetypes.NewStringValue(attributeValue.(string)) + readData.Match = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerKey" { - data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerTag" { - data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvSCrtrnList := make([]TagAnnotationFvSCrtrnResourceModel, 0) @@ -542,10 +543,10 @@ func getAndSetFvSCrtrnAttributes(ctx context.Context, diags *diag.Diagnostics, c } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvSCrtrnList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvSCrtrnList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvSCrtrnList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvSCrtrnList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -553,8 +554,9 @@ func getAndSetFvSCrtrnAttributes(ctx context.Context, diags *diag.Diagnostics, c ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvSCrtrnRn(ctx context.Context, data *FvSCrtrnResourceModel) string { @@ -710,7 +712,6 @@ func getFvSCrtrnCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, if !data.OwnerTag.IsNull() && !data.OwnerTag.IsUnknown() { payloadMap["attributes"].(map[string]string)["ownerTag"] = data.OwnerTag.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvSCrtrn": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_epg_useg_sub_block_statement_test.go b/internal/provider/resource_aci_epg_useg_sub_block_statement_test.go index d3c5d2039..33e4d5530 100644 --- a/internal/provider/resource_aci_epg_useg_sub_block_statement_test.go +++ b/internal/provider/resource_aci_epg_useg_sub_block_statement_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFvSCrtrnWithFvCrtrn(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.2(1i)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -43,7 +43,7 @@ func TestAccResourceFvSCrtrnWithFvCrtrn(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.2(1i)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -56,7 +56,7 @@ func TestAccResourceFvSCrtrnWithFvCrtrn(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.2(1i)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -84,7 +84,7 @@ func TestAccResourceFvSCrtrnWithFvCrtrn(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.2(1i)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -216,12 +216,13 @@ func TestAccResourceFvSCrtrnWithFvCrtrn(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } func TestAccResourceFvSCrtrnWithFvSCrtrn(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.2(1i)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -250,7 +251,7 @@ func TestAccResourceFvSCrtrnWithFvSCrtrn(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.2(1i)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -263,7 +264,7 @@ func TestAccResourceFvSCrtrnWithFvSCrtrn(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.2(1i)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -291,7 +292,7 @@ func TestAccResourceFvSCrtrnWithFvSCrtrn(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.2(1i)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -423,6 +424,7 @@ func TestAccResourceFvSCrtrnWithFvSCrtrn(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_epg_useg_vm_attribute.go b/internal/provider/resource_aci_epg_useg_vm_attribute.go index 3dfbc1bea..91a49c21a 100644 --- a/internal/provider/resource_aci_epg_useg_vm_attribute.go +++ b/internal/provider/resource_aci_epg_useg_vm_attribute.go @@ -403,6 +403,7 @@ func (r *FvVmAttrResource) Create(ctx context.Context, req resource.CreateReques } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -517,7 +518,7 @@ func (r *FvVmAttrResource) ImportState(ctx context.Context, req resource.ImportS func getAndSetFvVmAttrAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvVmAttrResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvVmAttr,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvVmAttrResourceModel() + readData := getEmptyFvVmAttrResourceModel() if diags.HasError() { return @@ -528,41 +529,41 @@ func getAndSetFvVmAttrAttributes(ctx context.Context, diags *diag.Diagnostics, c attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvVmAttrParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvVmAttrParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "category" { - data.Category = basetypes.NewStringValue(attributeValue.(string)) + readData.Category = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "labelName" { - data.LabelName = basetypes.NewStringValue(attributeValue.(string)) + readData.LabelName = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "operator" { - data.Operator = basetypes.NewStringValue(attributeValue.(string)) + readData.Operator = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerKey" { - data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerTag" { - data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "type" { - data.Type = basetypes.NewStringValue(attributeValue.(string)) + readData.Type = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "value" { - data.Value = basetypes.NewStringValue(attributeValue.(string)) + readData.Value = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvVmAttrList := make([]TagAnnotationFvVmAttrResourceModel, 0) @@ -600,10 +601,10 @@ func getAndSetFvVmAttrAttributes(ctx context.Context, diags *diag.Diagnostics, c } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvVmAttrList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvVmAttrList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvVmAttrList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvVmAttrList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -611,8 +612,9 @@ func getAndSetFvVmAttrAttributes(ctx context.Context, diags *diag.Diagnostics, c ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvVmAttrRn(ctx context.Context, data *FvVmAttrResourceModel) string { @@ -780,7 +782,6 @@ func getFvVmAttrCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, if !data.Value.IsNull() && !data.Value.IsUnknown() { payloadMap["attributes"].(map[string]string)["value"] = data.Value.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvVmAttr": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_epg_useg_vm_attribute_test.go b/internal/provider/resource_aci_epg_useg_vm_attribute_test.go index 50adb1f8e..f76a59b02 100644 --- a/internal/provider/resource_aci_epg_useg_vm_attribute_test.go +++ b/internal/provider/resource_aci_epg_useg_vm_attribute_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFvVmAttrWithFvCrtrn(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -51,7 +51,7 @@ func TestAccResourceFvVmAttrWithFvCrtrn(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -64,7 +64,7 @@ func TestAccResourceFvVmAttrWithFvCrtrn(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -100,7 +100,7 @@ func TestAccResourceFvVmAttrWithFvCrtrn(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -249,12 +249,13 @@ func TestAccResourceFvVmAttrWithFvCrtrn(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } func TestAccResourceFvVmAttrWithFvSCrtrn(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -291,7 +292,7 @@ func TestAccResourceFvVmAttrWithFvSCrtrn(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -304,7 +305,7 @@ func TestAccResourceFvVmAttrWithFvSCrtrn(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -340,7 +341,7 @@ func TestAccResourceFvVmAttrWithFvSCrtrn(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.1(1j)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -489,6 +490,7 @@ func TestAccResourceFvVmAttrWithFvSCrtrn(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_external_management_network_instance_profile.go b/internal/provider/resource_aci_external_management_network_instance_profile.go index 6a5e6d950..beb1e1847 100644 --- a/internal/provider/resource_aci_external_management_network_instance_profile.go +++ b/internal/provider/resource_aci_external_management_network_instance_profile.go @@ -399,6 +399,7 @@ func (r *MgmtInstPResource) Create(ctx context.Context, req resource.CreateReque } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -516,7 +517,7 @@ func (r *MgmtInstPResource) ImportState(ctx context.Context, req resource.Import func getAndSetMgmtInstPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *MgmtInstPResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "mgmtInstP,mgmtRsOoBCons,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyMgmtInstPResourceModel() + readData := getEmptyMgmtInstPResourceModel() if diags.HasError() { return @@ -527,22 +528,22 @@ func getAndSetMgmtInstPAttributes(ctx context.Context, diags *diag.Diagnostics, attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "prio" { - data.Prio = customTypes.NewMgmtInstPPrioStringValue(attributeValue.(string)) + readData.Prio = customTypes.NewMgmtInstPPrioStringValue(attributeValue.(string)) } } MgmtRsOoBConsMgmtInstPList := make([]MgmtRsOoBConsMgmtInstPResourceModel, 0) @@ -596,12 +597,12 @@ func getAndSetMgmtInstPAttributes(ctx context.Context, diags *diag.Diagnostics, } } } - mgmtRsOoBConsSet, _ := types.SetValueFrom(ctx, data.MgmtRsOoBCons.ElementType(ctx), MgmtRsOoBConsMgmtInstPList) - data.MgmtRsOoBCons = mgmtRsOoBConsSet - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationMgmtInstPList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagMgmtInstPList) - data.TagTag = tagTagSet + mgmtRsOoBConsSet, _ := types.SetValueFrom(ctx, readData.MgmtRsOoBCons.ElementType(ctx), MgmtRsOoBConsMgmtInstPList) + readData.MgmtRsOoBCons = mgmtRsOoBConsSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationMgmtInstPList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagMgmtInstPList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -609,8 +610,9 @@ func getAndSetMgmtInstPAttributes(ctx context.Context, diags *diag.Diagnostics, ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getMgmtInstPRn(ctx context.Context, data *MgmtInstPResourceModel) string { @@ -794,7 +796,6 @@ func getMgmtInstPCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, if !data.Prio.IsNull() && !data.Prio.IsUnknown() { payloadMap["attributes"].(map[string]string)["prio"] = data.Prio.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"mgmtInstP": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_external_management_network_instance_profile_test.go b/internal/provider/resource_aci_external_management_network_instance_profile_test.go index a28ef0948..98c4bfd8e 100644 --- a/internal/provider/resource_aci_external_management_network_instance_profile_test.go +++ b/internal/provider/resource_aci_external_management_network_instance_profile_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceMgmtInstP(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -38,7 +38,7 @@ func TestAccResourceMgmtInstP(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -51,7 +51,7 @@ func TestAccResourceMgmtInstP(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -74,7 +74,7 @@ func TestAccResourceMgmtInstP(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -223,6 +223,7 @@ func TestAccResourceMgmtInstP(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_external_management_network_subnet.go b/internal/provider/resource_aci_external_management_network_subnet.go index c875e5b6e..d1a2bdd9f 100644 --- a/internal/provider/resource_aci_external_management_network_subnet.go +++ b/internal/provider/resource_aci_external_management_network_subnet.go @@ -330,6 +330,7 @@ func (r *MgmtSubnetResource) Create(ctx context.Context, req resource.CreateRequ } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -444,7 +445,7 @@ func (r *MgmtSubnetResource) ImportState(ctx context.Context, req resource.Impor func getAndSetMgmtSubnetAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *MgmtSubnetResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "mgmtSubnet,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyMgmtSubnetResourceModel() + readData := getEmptyMgmtSubnetResourceModel() if diags.HasError() { return @@ -455,23 +456,23 @@ func getAndSetMgmtSubnetAttributes(ctx context.Context, diags *diag.Diagnostics, attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setMgmtSubnetParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setMgmtSubnetParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ip" { - data.Ip = basetypes.NewStringValue(attributeValue.(string)) + readData.Ip = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationMgmtSubnetList := make([]TagAnnotationMgmtSubnetResourceModel, 0) @@ -509,10 +510,10 @@ func getAndSetMgmtSubnetAttributes(ctx context.Context, diags *diag.Diagnostics, } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationMgmtSubnetList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagMgmtSubnetList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationMgmtSubnetList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagMgmtSubnetList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -520,8 +521,9 @@ func getAndSetMgmtSubnetAttributes(ctx context.Context, diags *diag.Diagnostics, ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getMgmtSubnetRn(ctx context.Context, data *MgmtSubnetResourceModel) string { @@ -671,7 +673,6 @@ func getMgmtSubnetCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics if !data.NameAlias.IsNull() && !data.NameAlias.IsUnknown() { payloadMap["attributes"].(map[string]string)["nameAlias"] = data.NameAlias.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"mgmtSubnet": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_external_management_network_subnet_test.go b/internal/provider/resource_aci_external_management_network_subnet_test.go index 4f721ffc7..c8094c05a 100644 --- a/internal/provider/resource_aci_external_management_network_subnet_test.go +++ b/internal/provider/resource_aci_external_management_network_subnet_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceMgmtSubnetWithMgmtInstP(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -39,7 +39,7 @@ func TestAccResourceMgmtSubnetWithMgmtInstP(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -52,7 +52,7 @@ func TestAccResourceMgmtSubnetWithMgmtInstP(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -76,7 +76,7 @@ func TestAccResourceMgmtSubnetWithMgmtInstP(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -200,6 +200,7 @@ func TestAccResourceMgmtSubnetWithMgmtInstP(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_key_ring.go b/internal/provider/resource_aci_key_ring.go new file mode 100644 index 000000000..b68911190 --- /dev/null +++ b/internal/provider/resource_aci_key_ring.go @@ -0,0 +1,933 @@ +// 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" + "reflect" + "strings" + + "github.com/ciscoecosystem/aci-go-client/v2/client" + "github.com/ciscoecosystem/aci-go-client/v2/container" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var _ resource.Resource = &PkiKeyRingResource{} +var _ resource.ResourceWithImportState = &PkiKeyRingResource{} + +func NewPkiKeyRingResource() resource.Resource { + return &PkiKeyRingResource{} +} + +// PkiKeyRingResource defines the resource implementation. +type PkiKeyRingResource struct { + client *client.Client +} + +// PkiKeyRingResourceModel describes the resource data model. +type PkiKeyRingResourceModel struct { + Id types.String `tfsdk:"id"` + ParentDn types.String `tfsdk:"parent_dn"` + AdminState types.String `tfsdk:"admin_state"` + Annotation types.String `tfsdk:"annotation"` + Cert types.String `tfsdk:"certificate"` + Descr types.String `tfsdk:"description"` + EccCurve types.String `tfsdk:"elliptic_curve"` + Key types.String `tfsdk:"key"` + KeyType types.String `tfsdk:"key_type"` + Modulus types.String `tfsdk:"modulus"` + Name types.String `tfsdk:"name"` + NameAlias types.String `tfsdk:"name_alias"` + OwnerKey types.String `tfsdk:"owner_key"` + OwnerTag types.String `tfsdk:"owner_tag"` + Regen types.String `tfsdk:"regenerate"` + Tp types.String `tfsdk:"certificate_authority"` + TagAnnotation types.Set `tfsdk:"annotations"` + TagTag types.Set `tfsdk:"tags"` +} + +func getEmptyPkiKeyRingResourceModel() *PkiKeyRingResourceModel { + return &PkiKeyRingResourceModel{ + Id: basetypes.NewStringNull(), + ParentDn: basetypes.NewStringNull(), + AdminState: basetypes.NewStringNull(), + Annotation: basetypes.NewStringNull(), + Cert: basetypes.NewStringNull(), + Descr: basetypes.NewStringNull(), + EccCurve: basetypes.NewStringNull(), + Key: basetypes.NewStringNull(), + KeyType: basetypes.NewStringNull(), + Modulus: basetypes.NewStringNull(), + Name: basetypes.NewStringNull(), + NameAlias: basetypes.NewStringNull(), + OwnerKey: basetypes.NewStringNull(), + OwnerTag: basetypes.NewStringNull(), + Regen: basetypes.NewStringNull(), + Tp: 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, + }, + }), + } +} + +// TagAnnotationPkiKeyRingResourceModel describes the resource data model for the children without relation ships. +type TagAnnotationPkiKeyRingResourceModel struct { + Key types.String `tfsdk:"key"` + Value types.String `tfsdk:"value"` +} + +func getEmptyTagAnnotationPkiKeyRingResourceModel() TagAnnotationPkiKeyRingResourceModel { + return TagAnnotationPkiKeyRingResourceModel{ + Key: basetypes.NewStringNull(), + Value: basetypes.NewStringNull(), + } +} + +// TagTagPkiKeyRingResourceModel describes the resource data model for the children without relation ships. +type TagTagPkiKeyRingResourceModel struct { + Key types.String `tfsdk:"key"` + Value types.String `tfsdk:"value"` +} + +func getEmptyTagTagPkiKeyRingResourceModel() TagTagPkiKeyRingResourceModel { + return TagTagPkiKeyRingResourceModel{ + Key: basetypes.NewStringNull(), + Value: basetypes.NewStringNull(), + } +} + +type PkiKeyRingIdentifier struct { + Name types.String +} + +func (r *PkiKeyRingResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if !req.Plan.Raw.IsNull() { + var planData, stateData *PkiKeyRingResourceModel + 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() { + setPkiKeyRingId(ctx, planData) + } + + if stateData == nil && !globalAllowExistingOnCreate && !planData.Id.IsUnknown() && !planData.Id.IsNull() { + CheckDn(ctx, &resp.Diagnostics, r.client, "pkiKeyRing", planData.Id.ValueString()) + if resp.Diagnostics.HasError() { + return + } + } + + resp.Diagnostics.Append(resp.Plan.Set(ctx, &planData)...) + } +} + +func (r *PkiKeyRingResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + tflog.Debug(ctx, "Start metadata of resource: aci_key_ring") + resp.TypeName = req.ProviderTypeName + "_key_ring" + tflog.Debug(ctx, "End metadata of resource: aci_key_ring") +} + +func (r *PkiKeyRingResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + tflog.Debug(ctx, "Start schema of resource: aci_key_ring") + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: "The key_ring resource for the 'pkiKeyRing' class", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + MarkdownDescription: "The distinguished name (DN) of the Key Ring object.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "parent_dn": schema.StringAttribute{ + Optional: true, + Computed: true, + Default: stringdefault.StaticString("uni/userext/pkiext"), + MarkdownDescription: "The distinguished name (DN) of the parent object.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + stringplanmodifier.RequiresReplace(), + }, + }, + "admin_state": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + Validators: []validator.String{ + stringvalidator.OneOf("completed", "created", "reqCreated", "started", "tpSet"), + }, + MarkdownDescription: `The current administrative state of the certificate request process.`, + }, + "annotation": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + Default: stringdefault.StaticString(globalAnnotation), + MarkdownDescription: `The annotation of the Key Ring object.`, + }, + "certificate": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `A certificate contains a device's public key along with signed information verifying the identity of the device.`, + }, + "description": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `The description of the Key Ring object.`, + }, + "elliptic_curve": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + Validators: []validator.String{ + stringvalidator.OneOf("none", "prime256v1", "secp384r1", "secp521r1"), + }, + MarkdownDescription: `The elliptic curve used by the provided key.`, + }, + "key": schema.StringAttribute{ + Optional: true, + Sensitive: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `The private key of the certificate. This sensitive value is excluded from the resource's lifecycle configuration and is not tracked by Terraform.`, + }, + "key_type": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + Validators: []validator.String{ + stringvalidator.OneOf("ECC", "RSA", "indeterminate"), + }, + MarkdownDescription: `The type used by the provided key.`, + }, + "modulus": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + Validators: []validator.String{ + stringvalidator.OneOf("mod1024", "mod1536", "mod2048", "mod3072", "mod4096", "mod512", "none"), + }, + MarkdownDescription: `The length of the encryption keys. A longer key length increases the difficulty of breaking the key.`, + }, + "name": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + stringplanmodifier.RequiresReplace(), + }, + MarkdownDescription: `The name of the Key Ring object.`, + }, + "name_alias": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `The name alias of the Key Ring 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.`, + }, + "regenerate": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + Validators: []validator.String{ + stringvalidator.OneOf("no", "yes"), + }, + MarkdownDescription: `Forces regeneration of the keypair. Each PKI device holds a pair of asymmetric Rivest-Shamir-Adleman (RSA) or Elliptic Curve Cryptography (ECC) encryption keys, one kept private and one made public, stored in an internal key ring.`, + }, + "certificate_authority": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), + }, + MarkdownDescription: `The certificate of the Certificate Authority (CA) that issued the certificate provided in the 'certificate' attribute. The CA can be a root CA, an intermediate CA, or a trust anchor in a chain of trust leading to a root CA.`, + }, + "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_key_ring") +} + +func (r *PkiKeyRingResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + tflog.Debug(ctx, "Start configure of resource: aci_key_ring") + // 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_key_ring") +} + +func (r *PkiKeyRingResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + tflog.Debug(ctx, "Start create of resource: aci_key_ring") + // On create retrieve information on current state prior to making any changes in order to determine child delete operations + var stateData *PkiKeyRingResourceModel + resp.Diagnostics.Append(req.Plan.Get(ctx, &stateData)...) + if stateData.Id.IsUnknown() || stateData.Id.IsNull() { + setPkiKeyRingId(ctx, stateData) + } + getAndSetPkiKeyRingAttributes(ctx, &resp.Diagnostics, r.client, stateData) + if !globalAllowExistingOnCreate && !stateData.Id.IsNull() { + resp.Diagnostics.AddError( + "Object Already Exists", + fmt.Sprintf("The pkiKeyRing object with DN '%s' already exists.", stateData.Id.ValueString()), + ) + return + } + + var data *PkiKeyRingResourceModel + + // 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() { + setPkiKeyRingId(ctx, data) + } + + tflog.Debug(ctx, fmt.Sprintf("Create of resource aci_key_ring with id '%s'", data.Id.ValueString())) + + var tagAnnotationPlan, tagAnnotationState []TagAnnotationPkiKeyRingResourceModel + data.TagAnnotation.ElementsAs(ctx, &tagAnnotationPlan, false) + stateData.TagAnnotation.ElementsAs(ctx, &tagAnnotationState, false) + var tagTagPlan, tagTagState []TagTagPkiKeyRingResourceModel + data.TagTag.ElementsAs(ctx, &tagTagPlan, false) + stateData.TagTag.ElementsAs(ctx, &tagTagState, false) + jsonPayload := getPkiKeyRingCreateJsonPayload(ctx, &resp.Diagnostics, true, data, tagAnnotationPlan, tagAnnotationState, tagTagPlan, tagTagState) + + if resp.Diagnostics.HasError() { + return + } + + wrapperClassMap := map[string]string{"uni/userext/pkiext": "", "certstore": "cloudCertStore"} + for rnPrepend, wrapperClass := range wrapperClassMap { + if strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass != "" { + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s%s.json", strings.Split(data.Id.ValueString(), rnPrepend)[0], rnPrepend), "POST", jsonPayload) + break + } else if strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass == "" { + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + break + } + } + + if resp.Diagnostics.HasError() { + return + } + + getAndSetPkiKeyRingAttributes(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_key_ring with id '%s'", data.Id.ValueString())) +} + +func (r *PkiKeyRingResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + tflog.Debug(ctx, "Start read of resource: aci_key_ring") + var data *PkiKeyRingResourceModel + + // 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_key_ring with id '%s'", data.Id.ValueString())) + + getAndSetPkiKeyRingAttributes(ctx, &resp.Diagnostics, r.client, data) + + // Save updated data into Terraform state + if data.Id.IsNull() { + var emptyData *PkiKeyRingResourceModel + 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_key_ring with id '%s'", data.Id.ValueString())) +} + +func (r *PkiKeyRingResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + tflog.Debug(ctx, "Start update of resource: aci_key_ring") + var data *PkiKeyRingResourceModel + var stateData *PkiKeyRingResourceModel + + // 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_key_ring with id '%s'", data.Id.ValueString())) + + var tagAnnotationPlan, tagAnnotationState []TagAnnotationPkiKeyRingResourceModel + data.TagAnnotation.ElementsAs(ctx, &tagAnnotationPlan, false) + stateData.TagAnnotation.ElementsAs(ctx, &tagAnnotationState, false) + var tagTagPlan, tagTagState []TagTagPkiKeyRingResourceModel + data.TagTag.ElementsAs(ctx, &tagTagPlan, false) + stateData.TagTag.ElementsAs(ctx, &tagTagState, false) + jsonPayload := getPkiKeyRingCreateJsonPayload(ctx, &resp.Diagnostics, false, data, tagAnnotationPlan, tagAnnotationState, tagTagPlan, tagTagState) + + if resp.Diagnostics.HasError() { + return + } + + wrapperClassMap := map[string]string{ + "uni/userext/pkiext": "", + "certstore": "cloudCertStore", + } + for rnPrepend, wrapperClass := range wrapperClassMap { + if strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass != "" { + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s%s.json", strings.Split(data.Id.ValueString(), rnPrepend)[0], rnPrepend), "POST", jsonPayload) + break + } else if strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass == "" { + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + break + } + } + + if resp.Diagnostics.HasError() { + return + } + + getAndSetPkiKeyRingAttributes(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_key_ring with id '%s'", data.Id.ValueString())) +} + +func (r *PkiKeyRingResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + tflog.Debug(ctx, "Start delete of resource: aci_key_ring") + var data *PkiKeyRingResourceModel + + // 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_key_ring with id '%s'", data.Id.ValueString())) + jsonPayload := GetDeleteJsonPayload(ctx, &resp.Diagnostics, "pkiKeyRing", 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_key_ring with id '%s'", data.Id.ValueString())) +} + +func (r *PkiKeyRingResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + tflog.Debug(ctx, "Start import state of resource: aci_key_ring") + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + + var stateData *PkiKeyRingResourceModel + resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_key_ring with id '%s'", stateData.Id.ValueString())) + + tflog.Debug(ctx, "End import of state resource: aci_key_ring") +} + +func getAndSetPkiKeyRingAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *PkiKeyRingResourceModel) { + requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "pkiKeyRing,tagAnnotation,tagTag"), "GET", nil) + + readData := getEmptyPkiKeyRingResourceModel() + + if diags.HasError() { + return + } + if requestData.Search("imdata").Search("pkiKeyRing").Data() != nil { + classReadInfo := requestData.Search("imdata").Search("pkiKeyRing").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)) + setPkiKeyRingParentDn(ctx, attributeValue.(string), readData) + } + if attributeName == "adminState" { + readData.AdminState = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "annotation" { + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "cert" { + readData.Cert = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "descr" { + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "eccCurve" && attributeValue.(string) == "" { + readData.EccCurve = basetypes.NewStringValue("none") + } else if attributeName == "eccCurve" { + readData.EccCurve = basetypes.NewStringValue(attributeValue.(string)) + } + // Sensitive attributes are not returned by the APIC, so they are explicitly set to their current state values. + readData.Key = data.Key + if attributeName == "keyType" { + readData.KeyType = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "modulus" && attributeValue.(string) == "" { + readData.Modulus = basetypes.NewStringValue("none") + } else if attributeName == "modulus" { + readData.Modulus = 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)) + } + if attributeName == "regen" { + readData.Regen = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "tp" { + readData.Tp = basetypes.NewStringValue(attributeValue.(string)) + } + } + TagAnnotationPkiKeyRingList := make([]TagAnnotationPkiKeyRingResourceModel, 0) + TagTagPkiKeyRingList := make([]TagTagPkiKeyRingResourceModel, 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" { + TagAnnotationPkiKeyRing := getEmptyTagAnnotationPkiKeyRingResourceModel() + for childAttributeName, childAttributeValue := range childAttributes { + if childAttributeName == "key" { + TagAnnotationPkiKeyRing.Key = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "value" { + TagAnnotationPkiKeyRing.Value = basetypes.NewStringValue(childAttributeValue.(string)) + } + } + TagAnnotationPkiKeyRingList = append(TagAnnotationPkiKeyRingList, TagAnnotationPkiKeyRing) + } + if childClassName == "tagTag" { + TagTagPkiKeyRing := getEmptyTagTagPkiKeyRingResourceModel() + for childAttributeName, childAttributeValue := range childAttributes { + if childAttributeName == "key" { + TagTagPkiKeyRing.Key = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "value" { + TagTagPkiKeyRing.Value = basetypes.NewStringValue(childAttributeValue.(string)) + } + } + TagTagPkiKeyRingList = append(TagTagPkiKeyRingList, TagTagPkiKeyRing) + } + } + } + } + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationPkiKeyRingList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagPkiKeyRingList) + readData.TagTag = tagTagSet + } else { + diags.AddError( + "too many results in response", + fmt.Sprintf("%v matches returned for class 'pkiKeyRing'. Please report this issue to the provider developers.", len(classReadInfo)), + ) + } + } else { + readData.Id = basetypes.NewStringNull() + } + *data = *readData +} + +func getPkiKeyRingRn(ctx context.Context, data *PkiKeyRingResourceModel) string { + rn := "keyring-{name}" + for _, identifier := range []string{"name"} { + fieldName := fmt.Sprintf("%s%s", strings.ToUpper(identifier[:1]), identifier[1:]) + fieldValue := reflect.ValueOf(data).Elem().FieldByName(fieldName).Interface().(basetypes.StringValue).ValueString() + rn = strings.ReplaceAll(rn, fmt.Sprintf("{%s}", identifier), fieldValue) + } + return rn +} + +func setPkiKeyRingParentDn(ctx context.Context, dn string, data *PkiKeyRingResourceModel) { + 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 + } + } + parentDn := dn[:rnIndex] + rnMap := map[string]string{ + "tn": "certstore", + } + for parentIdentifier, rnPrepend := range rnMap { + if strings.Contains(parentDn, parentIdentifier) { + parentDn = parentDn[:strings.Index(parentDn, fmt.Sprintf("/%s", rnPrepend))] + break + } + } + data.ParentDn = basetypes.NewStringValue(parentDn) +} + +func setPkiKeyRingId(ctx context.Context, data *PkiKeyRingResourceModel) { + rn := getPkiKeyRingRn(ctx, data) + parentDn := data.ParentDn.ValueString() + rnMap := map[string]string{ + "tn": "certstore", + } + id := fmt.Sprintf("%s/%s", parentDn, rn) + for parentIdentifier, rnPrepend := range rnMap { + if strings.Contains(parentDn, parentIdentifier) { + id = fmt.Sprintf("%s/%s/%s", parentDn, rnPrepend, rn) + break + } + } + data.Id = types.StringValue(id) +} + +func getPkiKeyRingTagAnnotationChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *PkiKeyRingResourceModel, tagAnnotationPlan, tagAnnotationState []TagAnnotationPkiKeyRingResourceModel) []map[string]interface{} { + + childPayloads := []map[string]interface{}{} + if !data.TagAnnotation.IsUnknown() { + tagAnnotationIdentifiers := []TagAnnotationIdentifier{} + for _, tagAnnotation := range tagAnnotationPlan { + childMap := map[string]map[string]interface{}{"attributes": {}} + if !tagAnnotation.Key.IsUnknown() && !tagAnnotation.Key.IsNull() { + childMap["attributes"]["key"] = tagAnnotation.Key.ValueString() + } + if !tagAnnotation.Value.IsUnknown() && !tagAnnotation.Value.IsNull() { + childMap["attributes"]["value"] = tagAnnotation.Value.ValueString() + } + childPayloads = append(childPayloads, map[string]interface{}{"tagAnnotation": childMap}) + tagAnnotationIdentifier := TagAnnotationIdentifier{} + tagAnnotationIdentifier.Key = tagAnnotation.Key + tagAnnotationIdentifiers = append(tagAnnotationIdentifiers, tagAnnotationIdentifier) + } + for _, tagAnnotation := range tagAnnotationState { + delete := true + for _, tagAnnotationIdentifier := range tagAnnotationIdentifiers { + if tagAnnotationIdentifier.Key == tagAnnotation.Key { + delete = false + break + } + } + if delete { + childMap := map[string]map[string]interface{}{"attributes": {}} + childMap["attributes"]["status"] = "deleted" + childMap["attributes"]["key"] = tagAnnotation.Key.ValueString() + childPayloads = append(childPayloads, map[string]interface{}{"tagAnnotation": childMap}) + } + } + } else { + data.TagAnnotation = types.SetNull(data.TagAnnotation.ElementType(ctx)) + } + + return childPayloads +} +func getPkiKeyRingTagTagChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *PkiKeyRingResourceModel, tagTagPlan, tagTagState []TagTagPkiKeyRingResourceModel) []map[string]interface{} { + + childPayloads := []map[string]interface{}{} + if !data.TagTag.IsUnknown() { + tagTagIdentifiers := []TagTagIdentifier{} + for _, tagTag := range tagTagPlan { + childMap := map[string]map[string]interface{}{"attributes": {}} + if !tagTag.Key.IsUnknown() && !tagTag.Key.IsNull() { + childMap["attributes"]["key"] = tagTag.Key.ValueString() + } + if !tagTag.Value.IsUnknown() && !tagTag.Value.IsNull() { + childMap["attributes"]["value"] = tagTag.Value.ValueString() + } + childPayloads = append(childPayloads, map[string]interface{}{"tagTag": childMap}) + tagTagIdentifier := TagTagIdentifier{} + tagTagIdentifier.Key = tagTag.Key + tagTagIdentifiers = append(tagTagIdentifiers, tagTagIdentifier) + } + for _, tagTag := range tagTagState { + delete := true + for _, tagTagIdentifier := range tagTagIdentifiers { + if tagTagIdentifier.Key == tagTag.Key { + delete = false + break + } + } + if delete { + childMap := map[string]map[string]interface{}{"attributes": {}} + childMap["attributes"]["status"] = "deleted" + childMap["attributes"]["key"] = tagTag.Key.ValueString() + childPayloads = append(childPayloads, map[string]interface{}{"tagTag": childMap}) + } + } + } else { + data.TagTag = types.SetNull(data.TagTag.ElementType(ctx)) + } + + return childPayloads +} + +func getPkiKeyRingCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, createType bool, data *PkiKeyRingResourceModel, tagAnnotationPlan, tagAnnotationState []TagAnnotationPkiKeyRingResourceModel, tagTagPlan, tagTagState []TagTagPkiKeyRingResourceModel) *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 := getPkiKeyRingTagAnnotationChildPayloads(ctx, diags, data, tagAnnotationPlan, tagAnnotationState) + if TagAnnotationchildPayloads == nil { + return nil + } + childPayloads = append(childPayloads, TagAnnotationchildPayloads...) + + TagTagchildPayloads := getPkiKeyRingTagTagChildPayloads(ctx, diags, data, tagTagPlan, tagTagState) + if TagTagchildPayloads == nil { + return nil + } + childPayloads = append(childPayloads, TagTagchildPayloads...) + + payloadMap["children"] = childPayloads + if !data.AdminState.IsNull() && !data.AdminState.IsUnknown() { + payloadMap["attributes"].(map[string]string)["adminState"] = data.AdminState.ValueString() + } + if !data.Annotation.IsNull() && !data.Annotation.IsUnknown() { + payloadMap["attributes"].(map[string]string)["annotation"] = data.Annotation.ValueString() + } + if !data.Cert.IsNull() && !data.Cert.IsUnknown() { + payloadMap["attributes"].(map[string]string)["cert"] = data.Cert.ValueString() + } + if !data.Descr.IsNull() && !data.Descr.IsUnknown() { + payloadMap["attributes"].(map[string]string)["descr"] = data.Descr.ValueString() + } + if !data.EccCurve.IsNull() && !data.EccCurve.IsUnknown() { + payloadMap["attributes"].(map[string]string)["eccCurve"] = data.EccCurve.ValueString() + } + if !data.Key.IsNull() && !data.Key.IsUnknown() { + payloadMap["attributes"].(map[string]string)["key"] = data.Key.ValueString() + } + if !data.KeyType.IsNull() && !data.KeyType.IsUnknown() { + payloadMap["attributes"].(map[string]string)["keyType"] = data.KeyType.ValueString() + } + if !data.Modulus.IsNull() && !data.Modulus.IsUnknown() { + payloadMap["attributes"].(map[string]string)["modulus"] = data.Modulus.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() + } + if !data.Regen.IsNull() && !data.Regen.IsUnknown() { + payloadMap["attributes"].(map[string]string)["regen"] = data.Regen.ValueString() + } + if !data.Tp.IsNull() && !data.Tp.IsUnknown() { + payloadMap["attributes"].(map[string]string)["tp"] = data.Tp.ValueString() + } + wrapperClassMap := map[string]string{ + "uni/userext/pkiext": "", + "certstore": "cloudCertStore", + } + + var payload []byte + var err error + for rnPrepend, wrapperClass := range wrapperClassMap { + if strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass != "" && createType { + wrapperPayloadMap := map[string]interface{}{ + wrapperClass: map[string]interface{}{ + "attributes": map[string]interface{}{}, + "children": []interface{}{map[string]interface{}{"pkiKeyRing": payloadMap}}, + }, + } + payload, err = json.Marshal(wrapperPayloadMap) + break + } else if (strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass == "") || !createType { + payload, err = json.Marshal(map[string]interface{}{"pkiKeyRing": payloadMap}) + break + } + } + 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_key_ring_test.go b/internal/provider/resource_aci_key_ring_test.go new file mode 100644 index 000000000..774f5d6f7 --- /dev/null +++ b/internal/provider/resource_aci_key_ring_test.go @@ -0,0 +1,779 @@ +// 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 TestAccResourcePkiKeyRing(t *testing.T) { + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigPkiKeyRingMinAllowExisting + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "name", "test_name"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "admin_state", "started"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "admin_state", "started"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "certificate", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "certificate", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "certificate_authority", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "certificate_authority", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "description", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "description", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "modulus", "mod2048"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "modulus", "mod2048"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "name_alias", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "owner_key", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "regenerate", "no"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "regenerate", "no"), + composeAggregateTestCheckFuncWithVersion(t, "6.0(2h)", ">", + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "elliptic_curve", "none"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "elliptic_curve", "none"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "key_type", "RSA"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "key_type", "RSA")), + ), + }, + }, + }) + + setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigPkiKeyRingMinAllowExisting + testConfigDataSourceSystem, + ExpectError: regexp.MustCompile("Object Already Exists"), + }, + }, + }) + + setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigPkiKeyRingMinAllowExisting + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "name", "test_name"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "admin_state", "started"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "admin_state", "started"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "certificate", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "certificate", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "certificate_authority", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "certificate_authority", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "description", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "description", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "modulus", "mod2048"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "modulus", "mod2048"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "name_alias", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "owner_key", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "regenerate", "no"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "regenerate", "no"), + composeAggregateTestCheckFuncWithVersion(t, "6.0(2h)", ">", + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "elliptic_curve", "none"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "elliptic_curve", "none"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "key_type", "RSA"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "key_type", "RSA")), + ), + }, + }, + }) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigPkiKeyRingMin + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_key_ring.test", "admin_state", "started"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_key_ring.test", "certificate", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "certificate_authority", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "description", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "modulus", "mod2048"), + resource.TestCheckResourceAttr("aci_key_ring.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "regenerate", "no"), + composeAggregateTestCheckFuncWithVersion(t, "6.0(2h)", ">", + resource.TestCheckResourceAttr("aci_key_ring.test", "elliptic_curve", "none"), + resource.TestCheckResourceAttr("aci_key_ring.test", "key_type", "RSA")), + ), + }, + // Update with all config and verify default APIC values + { + Config: testConfigPkiKeyRingAll + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_key_ring.test", "admin_state", "completed"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotation", "annotation"), + resource.TestCheckResourceAttr("aci_key_ring.test", "certificate", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_key_ring.test", "certificate_authority", "test_name"), + resource.TestCheckResourceAttr("aci_key_ring.test", "description", "description_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "modulus", "mod1024"), + resource.TestCheckResourceAttr("aci_key_ring.test", "name_alias", "name_alias_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "owner_key", "owner_key_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "owner_tag", "owner_tag_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "regenerate", "no"), + composeAggregateTestCheckFuncWithVersion(t, "6.0(2h)", ">", + resource.TestCheckResourceAttr("aci_key_ring.test", "elliptic_curve", "none"), + resource.TestCheckResourceAttr("aci_key_ring.test", "key_type", "RSA")), + ), + }, + // Update with minimum config and verify config is unchanged + { + Config: testConfigPkiKeyRingMin + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.test", "name", "test_name"), + ), + }, + // Update with empty strings config or default value + { + Config: testConfigPkiKeyRingReset + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_key_ring.test", "admin_state", "started"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_key_ring.test", "certificate", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "certificate_authority", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "description", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "modulus", "mod2048"), + resource.TestCheckResourceAttr("aci_key_ring.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "regenerate", "no"), + composeAggregateTestCheckFuncWithVersion(t, "6.0(2h)", ">", + resource.TestCheckResourceAttr("aci_key_ring.test", "elliptic_curve", "none"), + resource.TestCheckResourceAttr("aci_key_ring.test", "key_type", "RSA")), + ), + }, + // Import testing + { + ResourceName: "aci_key_ring.test", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"key"}, + }, + // Update with children + { + Config: testConfigPkiKeyRingChildren + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_key_ring.test", "admin_state", "started"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_key_ring.test", "certificate", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "certificate_authority", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "description", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "modulus", "mod2048"), + resource.TestCheckResourceAttr("aci_key_ring.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "regenerate", "no"), + composeAggregateTestCheckFuncWithVersion(t, "6.0(2h)", ">", + resource.TestCheckResourceAttr("aci_key_ring.test", "elliptic_curve", "none"), + resource.TestCheckResourceAttr("aci_key_ring.test", "key_type", "RSA")), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_key_ring.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_key_ring.test", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"key"}, + }, + // Update with children removed from config + { + Config: testConfigPkiKeyRingChildrenRemoveFromConfig + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.#", "2"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.#", "2"), + ), + }, + // Update with children first child removed + { + Config: testConfigPkiKeyRingChildrenRemoveOne + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.0.value", "test_value"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.#", "1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.0.value", "test_value"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.#", "1"), + ), + }, + // Update with all children removed + { + Config: testConfigPkiKeyRingChildrenRemoveAll + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.#", "0"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.#", "0"), + ), + }, + }, + CheckDestroy: testCheckResourceDestroy, + }) +} +func TestAccResourcePkiKeyRingWithFvTenant(t *testing.T) { + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "cloud", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigPkiKeyRingMinDependencyWithFvTenantAllowExisting + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "name", "test_name"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "admin_state", "started"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "admin_state", "started"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "certificate", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "certificate", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "certificate_authority", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "certificate_authority", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "description", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "description", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "modulus", "mod2048"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "modulus", "mod2048"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "name_alias", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "owner_key", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "regenerate", "no"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "regenerate", "no"), + composeAggregateTestCheckFuncWithVersion(t, "6.0(2h)", ">", + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "elliptic_curve", "none"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "elliptic_curve", "none"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "key_type", "RSA"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "key_type", "RSA")), + ), + }, + }, + }) + + setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "cloud", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigPkiKeyRingMinDependencyWithFvTenantAllowExisting + testConfigDataSourceSystem, + ExpectError: regexp.MustCompile("Object Already Exists"), + }, + }, + }) + + setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "cloud", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigPkiKeyRingMinDependencyWithFvTenantAllowExisting + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "name", "test_name"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "admin_state", "started"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "admin_state", "started"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "certificate", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "certificate", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "certificate_authority", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "certificate_authority", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "description", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "description", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "modulus", "mod2048"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "modulus", "mod2048"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "name_alias", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "owner_key", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "regenerate", "no"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "regenerate", "no"), + composeAggregateTestCheckFuncWithVersion(t, "6.0(2h)", ">", + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "elliptic_curve", "none"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "elliptic_curve", "none"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test", "key_type", "RSA"), + resource.TestCheckResourceAttr("aci_key_ring.allow_test_2", "key_type", "RSA")), + ), + }, + }, + }) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t, "cloud", "1.0(1e)-") }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigPkiKeyRingMinDependencyWithFvTenant + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_key_ring.test", "admin_state", "started"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_key_ring.test", "certificate", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "certificate_authority", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "description", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "modulus", "mod2048"), + resource.TestCheckResourceAttr("aci_key_ring.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "regenerate", "no"), + composeAggregateTestCheckFuncWithVersion(t, "6.0(2h)", ">", + resource.TestCheckResourceAttr("aci_key_ring.test", "elliptic_curve", "none"), + resource.TestCheckResourceAttr("aci_key_ring.test", "key_type", "RSA")), + ), + }, + // Update with all config and verify default APIC values + { + Config: testConfigPkiKeyRingAllDependencyWithFvTenant + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_key_ring.test", "admin_state", "completed"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotation", "annotation"), + resource.TestCheckResourceAttr("aci_key_ring.test", "certificate", "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----"), + resource.TestCheckResourceAttr("aci_key_ring.test", "certificate_authority", "test_name"), + resource.TestCheckResourceAttr("aci_key_ring.test", "description", "description_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "modulus", "mod1024"), + resource.TestCheckResourceAttr("aci_key_ring.test", "name_alias", "name_alias_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "owner_key", "owner_key_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "owner_tag", "owner_tag_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "regenerate", "no"), + composeAggregateTestCheckFuncWithVersion(t, "6.0(2h)", ">", + resource.TestCheckResourceAttr("aci_key_ring.test", "elliptic_curve", "none"), + resource.TestCheckResourceAttr("aci_key_ring.test", "key_type", "RSA")), + ), + }, + // Update with minimum config and verify config is unchanged + { + Config: testConfigPkiKeyRingMinDependencyWithFvTenant + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.test", "name", "test_name"), + ), + }, + // Update with empty strings config or default value + { + Config: testConfigPkiKeyRingResetDependencyWithFvTenant + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_key_ring.test", "admin_state", "started"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_key_ring.test", "certificate", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "certificate_authority", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "description", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "modulus", "mod2048"), + resource.TestCheckResourceAttr("aci_key_ring.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "regenerate", "no"), + composeAggregateTestCheckFuncWithVersion(t, "6.0(2h)", ">", + resource.TestCheckResourceAttr("aci_key_ring.test", "elliptic_curve", "none"), + resource.TestCheckResourceAttr("aci_key_ring.test", "key_type", "RSA")), + ), + }, + // Import testing + { + ResourceName: "aci_key_ring.test", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"key"}, + }, + // Update with children + { + Config: testConfigPkiKeyRingChildrenDependencyWithFvTenant + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.test", "name", "test_name"), + resource.TestCheckResourceAttr("aci_key_ring.test", "admin_state", "started"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_key_ring.test", "certificate", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "certificate_authority", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "description", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "modulus", "mod2048"), + resource.TestCheckResourceAttr("aci_key_ring.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_key_ring.test", "regenerate", "no"), + composeAggregateTestCheckFuncWithVersion(t, "6.0(2h)", ">", + resource.TestCheckResourceAttr("aci_key_ring.test", "elliptic_curve", "none"), + resource.TestCheckResourceAttr("aci_key_ring.test", "key_type", "RSA")), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_key_ring.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_key_ring.test", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"key"}, + }, + // Update with children removed from config + { + Config: testConfigPkiKeyRingChildrenRemoveFromConfigDependencyWithFvTenant + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.#", "2"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.1.value", "test_value"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.#", "2"), + ), + }, + // Update with children first child removed + { + Config: testConfigPkiKeyRingChildrenRemoveOneDependencyWithFvTenant + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.0.value", "test_value"), + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.#", "1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.0.value", "test_value"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.#", "1"), + ), + }, + // Update with all children removed + { + Config: testConfigPkiKeyRingChildrenRemoveAllDependencyWithFvTenant + testConfigDataSourceSystem, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_key_ring.test", "annotations.#", "0"), + resource.TestCheckResourceAttr("aci_key_ring.test", "tags.#", "0"), + ), + }, + }, + CheckDestroy: testCheckResourceDestroy, + }) +} + +const testDependencyConfigPkiKeyRing = ` +resource "aci_certificate_authority" "test_certificate_authority_0" { + certificate_chain = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + name = "test_name" +} +` + +const testConfigPkiKeyRingMinAllowExisting = testDependencyConfigPkiKeyRing + ` +resource "aci_key_ring" "allow_test" { + name = "test_name" +} +resource "aci_key_ring" "allow_test_2" { + name = "test_name" + depends_on = [aci_key_ring.allow_test] +} +` + +const testConfigPkiKeyRingMin = testDependencyConfigPkiKeyRing + ` +resource "aci_key_ring" "test" { + name = "test_name" +} +` + +const testConfigPkiKeyRingAll = testDependencyConfigPkiKeyRing + ` +resource "aci_key_ring" "test" { + name = "test_name" + admin_state = "completed" + annotation = "annotation" + certificate = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + certificate_authority = "test_name" + description = "description_1" + key = "-----BEGIN PRIVATE KEY-----\nMIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKIRv+2sbbewm0mj\nD+6/tpoUymzYIdFsN+gu02teIr/lZi8ipEB514pyhoaerstzboPteWvniLuwq4KQ\nVTEHgoln7J8EaHCnECViGA61pVx8RkJ99cmCkepspROw3I96zBcm58oXs6+Q/BnD\n/OWET5sBvR9oTv9GNRVJ1rvSMAEJAgMBAAECgYByu3QO0qF9h7X3JEu0Ld4cKBnB\ngiQ2uJC/et7KxIJ/LOvw9GopBthyt27KwG1ntBkJpkTuAaQHkyNns7vLkNB0S0IR\n+owVFEcKYq9VCHTaiQU8TDp24gN+yPTrpRuH8YhDVq5SfVdVuTMgHVQdj4ya4VlF\nGj+a7+ipxtGiLsVGrQJBAM7p0Fm0xmzi+tBOASUAcVrPLcteFIaTBFwfq16dm/ON\n00Khla8Et5kMBttTbqbukl8mxFjBEEBlhQqb6EdQQ0sCQQDIhHx1a9diG7y/4DQA\n4KvR3FCYwP8PBORlSamegzCo+P1OzxiEo0amX7yQMA5UyiP/kUsZrme2JBZgna8S\np4R7AkEAr7rMhSOPUnMD6V4WgsJ5g1Jp5kqkzBaYoVUUSms5RASz4+cwJVCwTX91\nY1jcpVIBZmaaY3a0wrx13ajEAa0dOQJBAIpjnb4wqpsEh7VpmJqOdSdGxb1XXfFQ\nsA0T1OQYqQnFppWwqrxIL+d9pZdiA1ITnNqyvUFBNETqDSOrUHwwb2cCQGArE+vu\nffPUWQ0j+fiK+covFG8NL7H+26NSGB5+Xsn9uwOGLj7K/YT6CbBtr9hJiuWjM1Al\n0V4ltlTuu2mTMaw=\n-----END PRIVATE KEY-----" + modulus = "mod1024" + name_alias = "name_alias_1" + owner_key = "owner_key_1" + owner_tag = "owner_tag_1" + regenerate = "no" + elliptic_curve = provider::aci::compare_versions(data.aci_system.version.version,">=","6.0(2h)") ? "none" : null + key_type = provider::aci::compare_versions(data.aci_system.version.version,">=","6.0(2h)") ? "RSA" : null +} +` + +const testConfigPkiKeyRingReset = testDependencyConfigPkiKeyRing + ` +resource "aci_key_ring" "test" { + name = "test_name" + admin_state = "started" + annotation = "orchestrator:terraform" + certificate = "" + certificate_authority = "" + description = "" + key = "" + modulus = "mod2048" + name_alias = "" + owner_key = "" + owner_tag = "" + regenerate = "no" + elliptic_curve = provider::aci::compare_versions(data.aci_system.version.version,">=","6.0(2h)") ? "none" : null + key_type = provider::aci::compare_versions(data.aci_system.version.version,">=","6.0(2h)") ? "RSA" : null +} +` +const testConfigPkiKeyRingChildren = testDependencyConfigPkiKeyRing + ` +resource "aci_key_ring" "test" { + name = "test_name" + annotations = [ + { + key = "key_0" + value = "value_1" + }, + { + key = "key_1" + value = "test_value" + }, + ] + tags = [ + { + key = "key_0" + value = "value_1" + }, + { + key = "key_1" + value = "test_value" + }, + ] +} +` + +const testConfigPkiKeyRingChildrenRemoveFromConfig = testDependencyConfigPkiKeyRing + ` +resource "aci_key_ring" "test" { + name = "test_name" +} +` + +const testConfigPkiKeyRingChildrenRemoveOne = testDependencyConfigPkiKeyRing + ` +resource "aci_key_ring" "test" { + name = "test_name" + annotations = [ + { + key = "key_1" + value = "test_value" + }, + ] + tags = [ + { + key = "key_1" + value = "test_value" + }, + ] +} +` + +const testConfigPkiKeyRingChildrenRemoveAll = testDependencyConfigPkiKeyRing + ` +resource "aci_key_ring" "test" { + name = "test_name" + annotations = [] + tags = [] +} +` + +const testConfigPkiKeyRingMinDependencyWithFvTenantAllowExisting = testDependencyConfigPkiKeyRing + testConfigFvTenantMin + ` +resource "aci_key_ring" "allow_test" { + parent_dn = aci_tenant.test.id + name = "test_name" +} +resource "aci_key_ring" "allow_test_2" { + parent_dn = aci_tenant.test.id + name = "test_name" + depends_on = [aci_key_ring.allow_test] +} +` + +const testConfigPkiKeyRingMinDependencyWithFvTenant = testDependencyConfigPkiKeyRing + testConfigFvTenantMin + ` +resource "aci_key_ring" "test" { + parent_dn = aci_tenant.test.id + name = "test_name" +} +` + +const testConfigPkiKeyRingAllDependencyWithFvTenant = testDependencyConfigPkiKeyRing + testConfigFvTenantMin + ` +resource "aci_key_ring" "test" { + parent_dn = aci_tenant.test.id + name = "test_name" + admin_state = "completed" + annotation = "annotation" + certificate = "-----BEGIN CERTIFICATE-----\nMIICODCCAaGgAwIBAgIJAIt8XMntue0VMA0GCSqGSIb3DQEBCwUAMDQxDjAMBgNV\nBAMMBUFkbWluMRUwEwYDVQQKDAxZb3VyIENvbXBhbnkxCzAJBgNVBAYTAlVTMCAX\nDTE4MDEwOTAwNTk0NFoYDzIxMTcxMjE2MDA1OTQ0WjA0MQ4wDAYDVQQDDAVBZG1p\nbjEVMBMGA1UECgwMWW91ciBDb21wYW55MQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n9w0BAQEFAAOBjQAwgYkCgYEAohG/7axtt7CbSaMP7r+2mhTKbNgh0Ww36C7Ta14i\nv+VmLyKkQHnXinKGhp6uy3Nug+15a+eIu7CrgpBVMQeCiWfsnwRocKcQJWIYDrWl\nXHxGQn31yYKR6mylE7Dcj3rMFybnyhezr5D8GcP85YRPmwG9H2hO/0Y1FUnWu9Iw\nAQkCAwEAAaNQME4wHQYDVR0OBBYEFD0jLXfpkrU/ChzRvfruRs/fy1VXMB8GA1Ud\nIwQYMBaAFD0jLXfpkrU/ChzRvfruRs/fy1VXMAwGA1UdEwQFMAMBAf8wDQYJKoZI\nhvcNAQELBQADgYEAOmvre+5tgZ0+F3DgsfxNQqLTrGiBgGCIymPkP/cBXXkNuJyl\n3ac7tArHQc7WEA4U2R2rZbEq8FC3UJJm4nUVtCPvEh3G9OhN2xwYev79yt6pIn/l\nKU0Td2OpVyo0eLqjoX5u2G90IBWzhyjFbo+CcKMrSVKj1YOdG0E3OuiJf00=\n-----END CERTIFICATE-----" + certificate_authority = "test_name" + description = "description_1" + key = "-----BEGIN PRIVATE KEY-----\nMIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKIRv+2sbbewm0mj\nD+6/tpoUymzYIdFsN+gu02teIr/lZi8ipEB514pyhoaerstzboPteWvniLuwq4KQ\nVTEHgoln7J8EaHCnECViGA61pVx8RkJ99cmCkepspROw3I96zBcm58oXs6+Q/BnD\n/OWET5sBvR9oTv9GNRVJ1rvSMAEJAgMBAAECgYByu3QO0qF9h7X3JEu0Ld4cKBnB\ngiQ2uJC/et7KxIJ/LOvw9GopBthyt27KwG1ntBkJpkTuAaQHkyNns7vLkNB0S0IR\n+owVFEcKYq9VCHTaiQU8TDp24gN+yPTrpRuH8YhDVq5SfVdVuTMgHVQdj4ya4VlF\nGj+a7+ipxtGiLsVGrQJBAM7p0Fm0xmzi+tBOASUAcVrPLcteFIaTBFwfq16dm/ON\n00Khla8Et5kMBttTbqbukl8mxFjBEEBlhQqb6EdQQ0sCQQDIhHx1a9diG7y/4DQA\n4KvR3FCYwP8PBORlSamegzCo+P1OzxiEo0amX7yQMA5UyiP/kUsZrme2JBZgna8S\np4R7AkEAr7rMhSOPUnMD6V4WgsJ5g1Jp5kqkzBaYoVUUSms5RASz4+cwJVCwTX91\nY1jcpVIBZmaaY3a0wrx13ajEAa0dOQJBAIpjnb4wqpsEh7VpmJqOdSdGxb1XXfFQ\nsA0T1OQYqQnFppWwqrxIL+d9pZdiA1ITnNqyvUFBNETqDSOrUHwwb2cCQGArE+vu\nffPUWQ0j+fiK+covFG8NL7H+26NSGB5+Xsn9uwOGLj7K/YT6CbBtr9hJiuWjM1Al\n0V4ltlTuu2mTMaw=\n-----END PRIVATE KEY-----" + modulus = "mod1024" + name_alias = "name_alias_1" + owner_key = "owner_key_1" + owner_tag = "owner_tag_1" + regenerate = "no" + elliptic_curve = provider::aci::compare_versions(data.aci_system.version.version,">=","6.0(2h)") ? "none" : null + key_type = provider::aci::compare_versions(data.aci_system.version.version,">=","6.0(2h)") ? "RSA" : null +} +` + +const testConfigPkiKeyRingResetDependencyWithFvTenant = testDependencyConfigPkiKeyRing + testConfigFvTenantMin + ` +resource "aci_key_ring" "test" { + parent_dn = aci_tenant.test.id + name = "test_name" + admin_state = "started" + annotation = "orchestrator:terraform" + certificate = "" + certificate_authority = "" + description = "" + key = "" + modulus = "mod2048" + name_alias = "" + owner_key = "" + owner_tag = "" + regenerate = "no" + elliptic_curve = provider::aci::compare_versions(data.aci_system.version.version,">=","6.0(2h)") ? "none" : null + key_type = provider::aci::compare_versions(data.aci_system.version.version,">=","6.0(2h)") ? "RSA" : null +} +` +const testConfigPkiKeyRingChildrenDependencyWithFvTenant = testDependencyConfigPkiKeyRing + testConfigFvTenantMin + ` +resource "aci_key_ring" "test" { + parent_dn = aci_tenant.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 testConfigPkiKeyRingChildrenRemoveFromConfigDependencyWithFvTenant = testDependencyConfigPkiKeyRing + testConfigFvTenantMin + ` +resource "aci_key_ring" "test" { + parent_dn = aci_tenant.test.id + name = "test_name" +} +` + +const testConfigPkiKeyRingChildrenRemoveOneDependencyWithFvTenant = testDependencyConfigPkiKeyRing + testConfigFvTenantMin + ` +resource "aci_key_ring" "test" { + parent_dn = aci_tenant.test.id + name = "test_name" + annotations = [ + { + key = "key_1" + value = "test_value" + }, + ] + tags = [ + { + key = "key_1" + value = "test_value" + }, + ] +} +` + +const testConfigPkiKeyRingChildrenRemoveAllDependencyWithFvTenant = testDependencyConfigPkiKeyRing + testConfigFvTenantMin + ` +resource "aci_key_ring" "test" { + parent_dn = aci_tenant.test.id + name = "test_name" + annotations = [] + tags = [] +} +` diff --git a/internal/provider/resource_aci_l3out_consumer_label.go b/internal/provider/resource_aci_l3out_consumer_label.go index 7ee428243..91171f5d7 100644 --- a/internal/provider/resource_aci_l3out_consumer_label.go +++ b/internal/provider/resource_aci_l3out_consumer_label.go @@ -485,6 +485,7 @@ func (r *L3extConsLblResource) Create(ctx context.Context, req resource.CreateRe } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -605,7 +606,7 @@ func (r *L3extConsLblResource) ImportState(ctx context.Context, req resource.Imp func getAndSetL3extConsLblAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *L3extConsLblResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "l3extConsLbl,l3extRsLblToInstP,l3extRsLblToProfile,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyL3extConsLblResourceModel() + readData := getEmptyL3extConsLblResourceModel() if diags.HasError() { return @@ -616,32 +617,32 @@ func getAndSetL3extConsLblAttributes(ctx context.Context, diags *diag.Diagnostic attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setL3extConsLblParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setL3extConsLblParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "owner" { - data.Owner = basetypes.NewStringValue(attributeValue.(string)) + readData.Owner = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerKey" { - data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerTag" { - data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "tag" { - data.Tag = basetypes.NewStringValue(attributeValue.(string)) + readData.Tag = basetypes.NewStringValue(attributeValue.(string)) } } L3extRsLblToInstPL3extConsLblList := make([]L3extRsLblToInstPL3extConsLblResourceModel, 0) @@ -708,14 +709,14 @@ func getAndSetL3extConsLblAttributes(ctx context.Context, diags *diag.Diagnostic } } } - l3extRsLblToInstPSet, _ := types.SetValueFrom(ctx, data.L3extRsLblToInstP.ElementType(ctx), L3extRsLblToInstPL3extConsLblList) - data.L3extRsLblToInstP = l3extRsLblToInstPSet - l3extRsLblToProfileSet, _ := types.SetValueFrom(ctx, data.L3extRsLblToProfile.ElementType(ctx), L3extRsLblToProfileL3extConsLblList) - data.L3extRsLblToProfile = l3extRsLblToProfileSet - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationL3extConsLblList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagL3extConsLblList) - data.TagTag = tagTagSet + l3extRsLblToInstPSet, _ := types.SetValueFrom(ctx, readData.L3extRsLblToInstP.ElementType(ctx), L3extRsLblToInstPL3extConsLblList) + readData.L3extRsLblToInstP = l3extRsLblToInstPSet + l3extRsLblToProfileSet, _ := types.SetValueFrom(ctx, readData.L3extRsLblToProfile.ElementType(ctx), L3extRsLblToProfileL3extConsLblList) + readData.L3extRsLblToProfile = l3extRsLblToProfileSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationL3extConsLblList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagL3extConsLblList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -723,8 +724,9 @@ func getAndSetL3extConsLblAttributes(ctx context.Context, diags *diag.Diagnostic ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getL3extConsLblRn(ctx context.Context, data *L3extConsLblResourceModel) string { @@ -983,7 +985,6 @@ func getL3extConsLblCreateJsonPayload(ctx context.Context, diags *diag.Diagnosti if !data.Tag.IsNull() && !data.Tag.IsUnknown() { payloadMap["attributes"].(map[string]string)["tag"] = data.Tag.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"l3extConsLbl": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_l3out_consumer_label_test.go b/internal/provider/resource_aci_l3out_consumer_label_test.go index f158f0e83..800d6c795 100644 --- a/internal/provider/resource_aci_l3out_consumer_label_test.go +++ b/internal/provider/resource_aci_l3out_consumer_label_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceL3extConsLblWithL3extOut(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -45,7 +45,7 @@ func TestAccResourceL3extConsLblWithL3extOut(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -58,7 +58,7 @@ func TestAccResourceL3extConsLblWithL3extOut(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -88,7 +88,7 @@ func TestAccResourceL3extConsLblWithL3extOut(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -255,6 +255,7 @@ func TestAccResourceL3extConsLblWithL3extOut(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_l3out_node_sid_profile.go b/internal/provider/resource_aci_l3out_node_sid_profile.go index 6daa01ff4..627cb19c1 100644 --- a/internal/provider/resource_aci_l3out_node_sid_profile.go +++ b/internal/provider/resource_aci_l3out_node_sid_profile.go @@ -341,6 +341,7 @@ func (r *MplsNodeSidPResource) Create(ctx context.Context, req resource.CreateRe } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -455,7 +456,7 @@ func (r *MplsNodeSidPResource) ImportState(ctx context.Context, req resource.Imp func getAndSetMplsNodeSidPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *MplsNodeSidPResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "mplsNodeSidP,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyMplsNodeSidPResourceModel() + readData := getEmptyMplsNodeSidPResourceModel() if diags.HasError() { return @@ -466,26 +467,26 @@ func getAndSetMplsNodeSidPAttributes(ctx context.Context, diags *diag.Diagnostic attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setMplsNodeSidPParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setMplsNodeSidPParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "loopbackAddr" { - data.LoopbackAddr = basetypes.NewStringValue(attributeValue.(string)) + readData.LoopbackAddr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "sidoffset" { - data.Sidoffset = basetypes.NewStringValue(attributeValue.(string)) + readData.Sidoffset = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationMplsNodeSidPList := make([]TagAnnotationMplsNodeSidPResourceModel, 0) @@ -523,10 +524,10 @@ func getAndSetMplsNodeSidPAttributes(ctx context.Context, diags *diag.Diagnostic } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationMplsNodeSidPList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagMplsNodeSidPList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationMplsNodeSidPList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagMplsNodeSidPList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -534,8 +535,9 @@ func getAndSetMplsNodeSidPAttributes(ctx context.Context, diags *diag.Diagnostic ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getMplsNodeSidPRn(ctx context.Context, data *MplsNodeSidPResourceModel) string { @@ -688,7 +690,6 @@ func getMplsNodeSidPCreateJsonPayload(ctx context.Context, diags *diag.Diagnosti if !data.Sidoffset.IsNull() && !data.Sidoffset.IsUnknown() { payloadMap["attributes"].(map[string]string)["sidoffset"] = data.Sidoffset.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"mplsNodeSidP": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_l3out_node_sid_profile_test.go b/internal/provider/resource_aci_l3out_node_sid_profile_test.go index abd2b3586..5c47289ad 100644 --- a/internal/provider/resource_aci_l3out_node_sid_profile_test.go +++ b/internal/provider/resource_aci_l3out_node_sid_profile_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceMplsNodeSidPWithL3extLoopBackIfP(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -41,7 +41,7 @@ func TestAccResourceMplsNodeSidPWithL3extLoopBackIfP(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -54,7 +54,7 @@ func TestAccResourceMplsNodeSidPWithL3extLoopBackIfP(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -80,7 +80,7 @@ func TestAccResourceMplsNodeSidPWithL3extLoopBackIfP(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -208,6 +208,7 @@ func TestAccResourceMplsNodeSidPWithL3extLoopBackIfP(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_l3out_provider_label.go b/internal/provider/resource_aci_l3out_provider_label.go index f1cdbf498..c3054d5c1 100644 --- a/internal/provider/resource_aci_l3out_provider_label.go +++ b/internal/provider/resource_aci_l3out_provider_label.go @@ -357,6 +357,7 @@ func (r *L3extProvLblResource) Create(ctx context.Context, req resource.CreateRe } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -471,7 +472,7 @@ func (r *L3extProvLblResource) ImportState(ctx context.Context, req resource.Imp func getAndSetL3extProvLblAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *L3extProvLblResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "l3extProvLbl,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyL3extProvLblResourceModel() + readData := getEmptyL3extProvLblResourceModel() if diags.HasError() { return @@ -482,29 +483,29 @@ func getAndSetL3extProvLblAttributes(ctx context.Context, diags *diag.Diagnostic attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setL3extProvLblParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setL3extProvLblParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerKey" { - data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerTag" { - data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "tag" { - data.Tag = basetypes.NewStringValue(attributeValue.(string)) + readData.Tag = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationL3extProvLblList := make([]TagAnnotationL3extProvLblResourceModel, 0) @@ -542,10 +543,10 @@ func getAndSetL3extProvLblAttributes(ctx context.Context, diags *diag.Diagnostic } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationL3extProvLblList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagL3extProvLblList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationL3extProvLblList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagL3extProvLblList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -553,8 +554,9 @@ func getAndSetL3extProvLblAttributes(ctx context.Context, diags *diag.Diagnostic ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getL3extProvLblRn(ctx context.Context, data *L3extProvLblResourceModel) string { @@ -710,7 +712,6 @@ func getL3extProvLblCreateJsonPayload(ctx context.Context, diags *diag.Diagnosti if !data.Tag.IsNull() && !data.Tag.IsUnknown() { payloadMap["attributes"].(map[string]string)["tag"] = data.Tag.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"l3extProvLbl": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_l3out_provider_label_test.go b/internal/provider/resource_aci_l3out_provider_label_test.go index 191ab4fde..0c46a04c6 100644 --- a/internal/provider/resource_aci_l3out_provider_label_test.go +++ b/internal/provider/resource_aci_l3out_provider_label_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceL3extProvLblWithL3extOut(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -43,7 +43,7 @@ func TestAccResourceL3extProvLblWithL3extOut(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -56,7 +56,7 @@ func TestAccResourceL3extProvLblWithL3extOut(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -84,7 +84,7 @@ func TestAccResourceL3extProvLblWithL3extOut(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -216,6 +216,7 @@ func TestAccResourceL3extProvLblWithL3extOut(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_l3out_redistribute_policy.go b/internal/provider/resource_aci_l3out_redistribute_policy.go index b550e76e1..a5ed0de64 100644 --- a/internal/provider/resource_aci_l3out_redistribute_policy.go +++ b/internal/provider/resource_aci_l3out_redistribute_policy.go @@ -314,6 +314,7 @@ func (r *L3extRsRedistributePolResource) Create(ctx context.Context, req resourc } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -428,7 +429,7 @@ func (r *L3extRsRedistributePolResource) ImportState(ctx context.Context, req re func getAndSetL3extRsRedistributePolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *L3extRsRedistributePolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "l3extRsRedistributePol,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyL3extRsRedistributePolResourceModel() + readData := getEmptyL3extRsRedistributePolResourceModel() if diags.HasError() { return @@ -439,17 +440,17 @@ func getAndSetL3extRsRedistributePolAttributes(ctx context.Context, diags *diag. attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setL3extRsRedistributePolParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setL3extRsRedistributePolParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "src" { - data.Src = basetypes.NewStringValue(attributeValue.(string)) + readData.Src = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "tnRtctrlProfileName" { - data.TnRtctrlProfileName = basetypes.NewStringValue(attributeValue.(string)) + readData.TnRtctrlProfileName = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationL3extRsRedistributePolList := make([]TagAnnotationL3extRsRedistributePolResourceModel, 0) @@ -487,10 +488,10 @@ func getAndSetL3extRsRedistributePolAttributes(ctx context.Context, diags *diag. } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationL3extRsRedistributePolList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagL3extRsRedistributePolList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationL3extRsRedistributePolList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagL3extRsRedistributePolList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -498,8 +499,9 @@ func getAndSetL3extRsRedistributePolAttributes(ctx context.Context, diags *diag. ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getL3extRsRedistributePolRn(ctx context.Context, data *L3extRsRedistributePolResourceModel) string { @@ -643,7 +645,6 @@ func getL3extRsRedistributePolCreateJsonPayload(ctx context.Context, diags *diag if !data.TnRtctrlProfileName.IsNull() && !data.TnRtctrlProfileName.IsUnknown() { payloadMap["attributes"].(map[string]string)["tnRtctrlProfileName"] = data.TnRtctrlProfileName.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"l3extRsRedistributePol": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_l3out_redistribute_policy_test.go b/internal/provider/resource_aci_l3out_redistribute_policy_test.go index e97b63c81..d6cf2d292 100644 --- a/internal/provider/resource_aci_l3out_redistribute_policy_test.go +++ b/internal/provider/resource_aci_l3out_redistribute_policy_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceL3extRsRedistributePolWithL3extOut(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "4.2(1i)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -35,7 +35,7 @@ func TestAccResourceL3extRsRedistributePolWithL3extOut(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "4.2(1i)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -48,7 +48,7 @@ func TestAccResourceL3extRsRedistributePolWithL3extOut(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "4.2(1i)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -68,7 +68,7 @@ func TestAccResourceL3extRsRedistributePolWithL3extOut(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "4.2(1i)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -185,6 +185,7 @@ func TestAccResourceL3extRsRedistributePolWithL3extOut(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_netflow_exporter_policy.go b/internal/provider/resource_aci_netflow_exporter_policy.go index 765d0bc5e..907050f5d 100644 --- a/internal/provider/resource_aci_netflow_exporter_policy.go +++ b/internal/provider/resource_aci_netflow_exporter_policy.go @@ -549,6 +549,7 @@ func (r *NetflowExporterPolResource) Create(ctx context.Context, req resource.Cr } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -669,7 +670,7 @@ func (r *NetflowExporterPolResource) ImportState(ctx context.Context, req resour func getAndSetNetflowExporterPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *NetflowExporterPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "netflowExporterPol,netflowRsExporterToCtx,netflowRsExporterToEPg,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyNetflowExporterPolResourceModel() + readData := getEmptyNetflowExporterPolResourceModel() if diags.HasError() { return @@ -680,44 +681,44 @@ func getAndSetNetflowExporterPolAttributes(ctx context.Context, diags *diag.Diag attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setNetflowExporterPolParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setNetflowExporterPolParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "dscp" { - data.Dscp = customTypes.NewNetflowExporterPolDscpStringValue(attributeValue.(string)) + readData.Dscp = customTypes.NewNetflowExporterPolDscpStringValue(attributeValue.(string)) } if attributeName == "dstAddr" { - data.DstAddr = basetypes.NewStringValue(attributeValue.(string)) + readData.DstAddr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "dstPort" { - data.DstPort = customTypes.NewNetflowExporterPolDstPortStringValue(attributeValue.(string)) + readData.DstPort = customTypes.NewNetflowExporterPolDstPortStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerKey" { - data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerTag" { - data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "sourceIpType" { - data.SourceIpType = basetypes.NewStringValue(attributeValue.(string)) + readData.SourceIpType = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "srcAddr" { - data.SrcAddr = basetypes.NewStringValue(attributeValue.(string)) + readData.SrcAddr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ver" { - data.Ver = basetypes.NewStringValue(attributeValue.(string)) + readData.Ver = basetypes.NewStringValue(attributeValue.(string)) } } NetflowRsExporterToCtxNetflowExporterPolList := make([]NetflowRsExporterToCtxNetflowExporterPolResourceModel, 0) @@ -783,22 +784,22 @@ func getAndSetNetflowExporterPolAttributes(ctx context.Context, diags *diag.Diag } if len(NetflowRsExporterToCtxNetflowExporterPolList) == 1 { netflowRsExporterToCtxObject, _ := types.ObjectValueFrom(ctx, NetflowRsExporterToCtxNetflowExporterPolType, NetflowRsExporterToCtxNetflowExporterPolList[0]) - data.NetflowRsExporterToCtx = netflowRsExporterToCtxObject + readData.NetflowRsExporterToCtx = netflowRsExporterToCtxObject } else { netflowRsExporterToCtxObject, _ := types.ObjectValueFrom(ctx, NetflowRsExporterToCtxNetflowExporterPolType, getEmptyNetflowRsExporterToCtxNetflowExporterPolResourceModel()) - data.NetflowRsExporterToCtx = netflowRsExporterToCtxObject + readData.NetflowRsExporterToCtx = netflowRsExporterToCtxObject } if len(NetflowRsExporterToEPgNetflowExporterPolList) == 1 { netflowRsExporterToEPgObject, _ := types.ObjectValueFrom(ctx, NetflowRsExporterToEPgNetflowExporterPolType, NetflowRsExporterToEPgNetflowExporterPolList[0]) - data.NetflowRsExporterToEPg = netflowRsExporterToEPgObject + readData.NetflowRsExporterToEPg = netflowRsExporterToEPgObject } else { netflowRsExporterToEPgObject, _ := types.ObjectValueFrom(ctx, NetflowRsExporterToEPgNetflowExporterPolType, getEmptyNetflowRsExporterToEPgNetflowExporterPolResourceModel()) - data.NetflowRsExporterToEPg = netflowRsExporterToEPgObject + readData.NetflowRsExporterToEPg = netflowRsExporterToEPgObject } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationNetflowExporterPolList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagNetflowExporterPolList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationNetflowExporterPolList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagNetflowExporterPolList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -806,8 +807,9 @@ func getAndSetNetflowExporterPolAttributes(ctx context.Context, diags *diag.Diag ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getNetflowExporterPolRn(ctx context.Context, data *NetflowExporterPolResourceModel) string { @@ -1040,7 +1042,6 @@ func getNetflowExporterPolCreateJsonPayload(ctx context.Context, diags *diag.Dia if !data.Ver.IsNull() && !data.Ver.IsUnknown() { payloadMap["attributes"].(map[string]string)["ver"] = data.Ver.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"netflowExporterPol": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_netflow_exporter_policy_test.go b/internal/provider/resource_aci_netflow_exporter_policy_test.go index e051df08b..c401afc56 100644 --- a/internal/provider/resource_aci_netflow_exporter_policy_test.go +++ b/internal/provider/resource_aci_netflow_exporter_policy_test.go @@ -17,7 +17,7 @@ import ( func TestAccResourceNetflowExporterPolWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -56,7 +56,7 @@ func TestAccResourceNetflowExporterPolWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -69,7 +69,7 @@ func TestAccResourceNetflowExporterPolWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -107,7 +107,7 @@ func TestAccResourceNetflowExporterPolWithFvTenant(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -322,6 +322,7 @@ func TestAccResourceNetflowExporterPolWithFvTenant(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_netflow_monitor_policy.go b/internal/provider/resource_aci_netflow_monitor_policy.go index 0bfe6610f..01e19105a 100644 --- a/internal/provider/resource_aci_netflow_monitor_policy.go +++ b/internal/provider/resource_aci_netflow_monitor_policy.go @@ -630,6 +630,7 @@ func (r *NetflowMonitorPolResource) Create(ctx context.Context, req resource.Cre } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -757,7 +758,7 @@ func (r *NetflowMonitorPolResource) ImportState(ctx context.Context, req resourc func getAndSetNetflowMonitorPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *NetflowMonitorPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "netflowMonitorPol,netflowRsMonitorToExporter,netflowRsMonitorToRecord,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyNetflowMonitorPolResourceModel() + readData := getEmptyNetflowMonitorPolResourceModel() if diags.HasError() { return @@ -768,26 +769,26 @@ func getAndSetNetflowMonitorPolAttributes(ctx context.Context, diags *diag.Diagn attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setNetflowMonitorPolParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setNetflowMonitorPolParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerKey" { - data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerTag" { - data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) } } NetflowRsMonitorToExporterNetflowMonitorPolList := make([]NetflowRsMonitorToExporterNetflowMonitorPolResourceModel, 0) @@ -851,19 +852,19 @@ func getAndSetNetflowMonitorPolAttributes(ctx context.Context, diags *diag.Diagn } } } - netflowRsMonitorToExporterSet, _ := types.SetValueFrom(ctx, data.NetflowRsMonitorToExporter.ElementType(ctx), NetflowRsMonitorToExporterNetflowMonitorPolList) - data.NetflowRsMonitorToExporter = netflowRsMonitorToExporterSet + netflowRsMonitorToExporterSet, _ := types.SetValueFrom(ctx, readData.NetflowRsMonitorToExporter.ElementType(ctx), NetflowRsMonitorToExporterNetflowMonitorPolList) + readData.NetflowRsMonitorToExporter = netflowRsMonitorToExporterSet if len(NetflowRsMonitorToRecordNetflowMonitorPolList) == 1 { netflowRsMonitorToRecordObject, _ := types.ObjectValueFrom(ctx, NetflowRsMonitorToRecordNetflowMonitorPolType, NetflowRsMonitorToRecordNetflowMonitorPolList[0]) - data.NetflowRsMonitorToRecord = netflowRsMonitorToRecordObject + readData.NetflowRsMonitorToRecord = netflowRsMonitorToRecordObject } else { netflowRsMonitorToRecordObject, _ := types.ObjectValueFrom(ctx, NetflowRsMonitorToRecordNetflowMonitorPolType, getEmptyNetflowRsMonitorToRecordNetflowMonitorPolResourceModel()) - data.NetflowRsMonitorToRecord = netflowRsMonitorToRecordObject + readData.NetflowRsMonitorToRecord = netflowRsMonitorToRecordObject } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationNetflowMonitorPolList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagNetflowMonitorPolList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationNetflowMonitorPolList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagNetflowMonitorPolList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -871,8 +872,9 @@ func getAndSetNetflowMonitorPolAttributes(ctx context.Context, diags *diag.Diagn ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getNetflowMonitorPolRn(ctx context.Context, data *NetflowMonitorPolResourceModel) string { @@ -1101,7 +1103,6 @@ func getNetflowMonitorPolCreateJsonPayload(ctx context.Context, diags *diag.Diag if !data.OwnerTag.IsNull() && !data.OwnerTag.IsUnknown() { payloadMap["attributes"].(map[string]string)["ownerTag"] = data.OwnerTag.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"netflowMonitorPol": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_netflow_monitor_policy_test.go b/internal/provider/resource_aci_netflow_monitor_policy_test.go index 8fc442d82..829df93f8 100644 --- a/internal/provider/resource_aci_netflow_monitor_policy_test.go +++ b/internal/provider/resource_aci_netflow_monitor_policy_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceNetflowMonitorPolWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -41,7 +41,7 @@ func TestAccResourceNetflowMonitorPolWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -54,7 +54,7 @@ func TestAccResourceNetflowMonitorPolWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -80,7 +80,7 @@ func TestAccResourceNetflowMonitorPolWithFvTenant(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -229,6 +229,7 @@ func TestAccResourceNetflowMonitorPolWithFvTenant(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_netflow_record_policy.go b/internal/provider/resource_aci_netflow_record_policy.go index 20e90868c..7db636671 100644 --- a/internal/provider/resource_aci_netflow_record_policy.go +++ b/internal/provider/resource_aci_netflow_record_policy.go @@ -187,6 +187,7 @@ func (r *NetflowRecordPolResource) Schema(ctx context.Context, req resource.Sche Computed: true, PlanModifiers: []planmodifier.Set{ setplanmodifier.UseStateForUnknown(), + SetToSetNullWhenStateIsNullPlanIsUnknownDuringUpdate(), }, Validators: []validator.Set{ setvalidator.SizeAtMost(8), @@ -211,6 +212,7 @@ func (r *NetflowRecordPolResource) Schema(ctx context.Context, req resource.Sche Computed: true, PlanModifiers: []planmodifier.Set{ setplanmodifier.UseStateForUnknown(), + SetToSetNullWhenStateIsNullPlanIsUnknownDuringUpdate(), }, Validators: []validator.Set{ setvalidator.SizeAtMost(14), @@ -380,6 +382,7 @@ func (r *NetflowRecordPolResource) Create(ctx context.Context, req resource.Crea } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -494,7 +497,7 @@ func (r *NetflowRecordPolResource) ImportState(ctx context.Context, req resource func getAndSetNetflowRecordPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *NetflowRecordPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "netflowRecordPol,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyNetflowRecordPolResourceModel() + readData := getEmptyNetflowRecordPolResourceModel() if diags.HasError() { return @@ -505,42 +508,42 @@ func getAndSetNetflowRecordPolAttributes(ctx context.Context, diags *diag.Diagno attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setNetflowRecordPolParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setNetflowRecordPolParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "collect" { collectList := make([]string, 0) if attributeValue.(string) != "" { collectList = strings.Split(attributeValue.(string), ",") } - collectSet, _ := types.SetValueFrom(ctx, data.Collect.ElementType(ctx), collectList) - data.Collect = collectSet + collectSet, _ := types.SetValueFrom(ctx, readData.Collect.ElementType(ctx), collectList) + readData.Collect = collectSet } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "match" { matchList := make([]string, 0) if attributeValue.(string) != "" { matchList = strings.Split(attributeValue.(string), ",") } - matchSet, _ := types.SetValueFrom(ctx, data.Match.ElementType(ctx), matchList) - data.Match = matchSet + matchSet, _ := types.SetValueFrom(ctx, readData.Match.ElementType(ctx), matchList) + readData.Match = matchSet } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerKey" { - data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerTag" { - data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationNetflowRecordPolList := make([]TagAnnotationNetflowRecordPolResourceModel, 0) @@ -578,10 +581,10 @@ func getAndSetNetflowRecordPolAttributes(ctx context.Context, diags *diag.Diagno } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationNetflowRecordPolList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagNetflowRecordPolList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationNetflowRecordPolList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagNetflowRecordPolList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -589,8 +592,9 @@ func getAndSetNetflowRecordPolAttributes(ctx context.Context, diags *diag.Diagno ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getNetflowRecordPolRn(ctx context.Context, data *NetflowRecordPolResourceModel) string { @@ -753,7 +757,6 @@ func getNetflowRecordPolCreateJsonPayload(ctx context.Context, diags *diag.Diagn if !data.OwnerTag.IsNull() && !data.OwnerTag.IsUnknown() { payloadMap["attributes"].(map[string]string)["ownerTag"] = data.OwnerTag.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"netflowRecordPol": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_netflow_record_policy_test.go b/internal/provider/resource_aci_netflow_record_policy_test.go index bde206058..51227f00a 100644 --- a/internal/provider/resource_aci_netflow_record_policy_test.go +++ b/internal/provider/resource_aci_netflow_record_policy_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceNetflowRecordPolWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -47,7 +47,7 @@ func TestAccResourceNetflowRecordPolWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -60,7 +60,7 @@ func TestAccResourceNetflowRecordPolWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -92,7 +92,7 @@ func TestAccResourceNetflowRecordPolWithFvTenant(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -235,6 +235,7 @@ func TestAccResourceNetflowRecordPolWithFvTenant(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_out_of_band_contract.go b/internal/provider/resource_aci_out_of_band_contract.go index fcab7ba5d..899354a06 100644 --- a/internal/provider/resource_aci_out_of_band_contract.go +++ b/internal/provider/resource_aci_out_of_band_contract.go @@ -399,6 +399,7 @@ func (r *VzOOBBrCPResource) Create(ctx context.Context, req resource.CreateReque } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -513,7 +514,7 @@ func (r *VzOOBBrCPResource) ImportState(ctx context.Context, req resource.Import func getAndSetVzOOBBrCPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *VzOOBBrCPResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "vzOOBBrCP,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyVzOOBBrCPResourceModel() + readData := getEmptyVzOOBBrCPResourceModel() if diags.HasError() { return @@ -524,37 +525,37 @@ func getAndSetVzOOBBrCPAttributes(ctx context.Context, diags *diag.Diagnostics, attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "intent" { - data.Intent = basetypes.NewStringValue(attributeValue.(string)) + readData.Intent = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerKey" { - data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerTag" { - data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "prio" { - data.Prio = customTypes.NewVzOOBBrCPPrioStringValue(attributeValue.(string)) + readData.Prio = customTypes.NewVzOOBBrCPPrioStringValue(attributeValue.(string)) } if attributeName == "scope" { - data.Scope = basetypes.NewStringValue(attributeValue.(string)) + readData.Scope = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "targetDscp" { - data.TargetDscp = customTypes.NewVzOOBBrCPTargetDscpStringValue(attributeValue.(string)) + readData.TargetDscp = customTypes.NewVzOOBBrCPTargetDscpStringValue(attributeValue.(string)) } } TagAnnotationVzOOBBrCPList := make([]TagAnnotationVzOOBBrCPResourceModel, 0) @@ -592,10 +593,10 @@ func getAndSetVzOOBBrCPAttributes(ctx context.Context, diags *diag.Diagnostics, } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationVzOOBBrCPList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagVzOOBBrCPList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationVzOOBBrCPList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagVzOOBBrCPList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -603,8 +604,9 @@ func getAndSetVzOOBBrCPAttributes(ctx context.Context, diags *diag.Diagnostics, ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getVzOOBBrCPRn(ctx context.Context, data *VzOOBBrCPResourceModel) string { @@ -753,7 +755,6 @@ func getVzOOBBrCPCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, if !data.TargetDscp.IsNull() && !data.TargetDscp.IsUnknown() { payloadMap["attributes"].(map[string]string)["targetDscp"] = data.TargetDscp.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"vzOOBBrCP": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_out_of_band_contract_test.go b/internal/provider/resource_aci_out_of_band_contract_test.go index 8c20a117b..3a0b6b191 100644 --- a/internal/provider/resource_aci_out_of_band_contract_test.go +++ b/internal/provider/resource_aci_out_of_band_contract_test.go @@ -14,12 +14,12 @@ import ( func TestAccResourceVzOOBBrCP(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigVzOOBBrCPMinAllowExisting, + Config: testConfigVzOOBBrCPMinAllowExisting + testConfigDataSourceSystem, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "name", "test_name"), resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "name", "test_name"), @@ -27,8 +27,6 @@ func TestAccResourceVzOOBBrCP(t *testing.T) { resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "description", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "description", ""), - resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "intent", "install"), - resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "intent", "install"), resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "name_alias", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "name_alias", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "owner_key", ""), @@ -41,6 +39,9 @@ func TestAccResourceVzOOBBrCP(t *testing.T) { resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "scope", "context"), resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "target_dscp", "unspecified"), resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "target_dscp", "unspecified"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)", ">", + resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "intent", "install"), + resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "intent", "install")), ), }, }, @@ -48,7 +49,7 @@ func TestAccResourceVzOOBBrCP(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -61,12 +62,12 @@ func TestAccResourceVzOOBBrCP(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigVzOOBBrCPMinAllowExisting, + Config: testConfigVzOOBBrCPMinAllowExisting + testConfigDataSourceSystem, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "name", "test_name"), resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "name", "test_name"), @@ -74,8 +75,6 @@ func TestAccResourceVzOOBBrCP(t *testing.T) { resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "description", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "description", ""), - resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "intent", "install"), - resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "intent", "install"), resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "name_alias", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "name_alias", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "owner_key", ""), @@ -88,77 +87,84 @@ func TestAccResourceVzOOBBrCP(t *testing.T) { resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "scope", "context"), resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "target_dscp", "unspecified"), resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "target_dscp", "unspecified"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)", ">", + resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "intent", "install"), + resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "intent", "install")), ), }, }, }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigVzOOBBrCPMin, + Config: testConfigVzOOBBrCPMin + testConfigDataSourceSystem, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name", "test_name"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "description", ""), - resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "install"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name_alias", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_key", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_tag", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "priority", "unspecified"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "scope", "context"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "target_dscp", "unspecified"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)", ">", + resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "install")), ), }, // Update with all config and verify default APIC values { - Config: testConfigVzOOBBrCPAll, + Config: testConfigVzOOBBrCPAll + testConfigDataSourceSystem, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name", "test_name"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotation", "annotation"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "description", "description_1"), - resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "estimate_add"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name_alias", "name_alias_1"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_key", "owner_key_1"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_tag", "owner_tag_1"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "priority", "level1"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "scope", "application-profile"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "target_dscp", "AF11"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)", ">", + resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "estimate_add")), ), }, // Update with minimum config and verify config is unchanged { - Config: testConfigVzOOBBrCPMin, + Config: testConfigVzOOBBrCPMin + testConfigDataSourceSystem, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name", "test_name"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "description", "description_1"), - resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "estimate_add"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name_alias", "name_alias_1"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_key", "owner_key_1"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_tag", "owner_tag_1"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "priority", "level1"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "scope", "application-profile"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "target_dscp", "AF11"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)", ">", + resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "estimate_add")), ), }, // Update with empty strings config or default value { - Config: testConfigVzOOBBrCPReset, + Config: testConfigVzOOBBrCPReset + testConfigDataSourceSystem, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name", "test_name"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "description", ""), - resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "install"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name_alias", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_key", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_tag", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "priority", "unspecified"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "scope", "context"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "target_dscp", "unspecified"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)", ">", + resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "install")), ), }, // Import testing @@ -169,17 +175,18 @@ func TestAccResourceVzOOBBrCP(t *testing.T) { }, // Update with children { - Config: testConfigVzOOBBrCPChildren, + Config: testConfigVzOOBBrCPChildren + testConfigDataSourceSystem, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "description", ""), - resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "install"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name_alias", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_key", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_tag", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "priority", "unspecified"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "scope", "context"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "target_dscp", "unspecified"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)", ">", + resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "install")), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.0.key", "key_0"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.0.value", "value_1"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.1.key", "key_1"), @@ -194,17 +201,18 @@ func TestAccResourceVzOOBBrCP(t *testing.T) { }, // Update with children removed from config { - Config: testConfigVzOOBBrCPChildrenRemoveFromConfig, + Config: testConfigVzOOBBrCPChildrenRemoveFromConfig + testConfigDataSourceSystem, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "description", ""), - resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "install"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name_alias", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_key", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_tag", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "priority", "unspecified"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "scope", "context"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "target_dscp", "unspecified"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)", ">", + resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "install")), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.0.key", "key_0"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.0.value", "value_1"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.1.key", "key_1"), @@ -219,17 +227,18 @@ func TestAccResourceVzOOBBrCP(t *testing.T) { }, // Update with children first child removed { - Config: testConfigVzOOBBrCPChildrenRemoveOne, + Config: testConfigVzOOBBrCPChildrenRemoveOne + testConfigDataSourceSystem, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "description", ""), - resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "install"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name_alias", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_key", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_tag", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "priority", "unspecified"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "scope", "context"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "target_dscp", "unspecified"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)", ">", + resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "install")), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.0.key", "key_1"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.0.value", "test_value"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.#", "1"), @@ -240,17 +249,18 @@ func TestAccResourceVzOOBBrCP(t *testing.T) { }, // Update with all children removed { - Config: testConfigVzOOBBrCPChildrenRemoveAll, + Config: testConfigVzOOBBrCPChildrenRemoveAll + testConfigDataSourceSystem, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "description", ""), - resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "install"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name_alias", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_key", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_tag", ""), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "priority", "unspecified"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "scope", "context"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "target_dscp", "unspecified"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)", ">", + resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "install")), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.#", "0"), resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "tags.#", "0"), ), @@ -265,6 +275,7 @@ func TestAccResourceVzOOBBrCP(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } @@ -289,13 +300,13 @@ resource "aci_out_of_band_contract" "test" { name = "test_name" annotation = "annotation" description = "description_1" - intent = "estimate_add" name_alias = "name_alias_1" owner_key = "owner_key_1" owner_tag = "owner_tag_1" priority = "level1" scope = "application-profile" target_dscp = "AF11" + intent = provider::aci::compare_versions(data.aci_system.version.version,">=","4.2(1i)") ? "estimate_add" : null } ` @@ -304,13 +315,13 @@ resource "aci_out_of_band_contract" "test" { name = "test_name" annotation = "orchestrator:terraform" description = "" - intent = "install" name_alias = "" owner_key = "" owner_tag = "" priority = "unspecified" scope = "context" target_dscp = "unspecified" + intent = provider::aci::compare_versions(data.aci_system.version.version,">=","4.2(1i)") ? "install" : null } ` const testConfigVzOOBBrCPChildren = ` diff --git a/internal/provider/resource_aci_pim_route_map_entry.go b/internal/provider/resource_aci_pim_route_map_entry.go index 8f7a243f4..fb6a96e87 100644 --- a/internal/provider/resource_aci_pim_route_map_entry.go +++ b/internal/provider/resource_aci_pim_route_map_entry.go @@ -379,6 +379,7 @@ func (r *PimRouteMapEntryResource) Create(ctx context.Context, req resource.Crea } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -493,7 +494,7 @@ func (r *PimRouteMapEntryResource) ImportState(ctx context.Context, req resource func getAndSetPimRouteMapEntryAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *PimRouteMapEntryResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "pimRouteMapEntry,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyPimRouteMapEntryResourceModel() + readData := getEmptyPimRouteMapEntryResourceModel() if diags.HasError() { return @@ -504,35 +505,35 @@ func getAndSetPimRouteMapEntryAttributes(ctx context.Context, diags *diag.Diagno attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setPimRouteMapEntryParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setPimRouteMapEntryParentDn(ctx, attributeValue.(string), readData) } if attributeName == "action" { - data.Action = basetypes.NewStringValue(attributeValue.(string)) + readData.Action = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "grp" { - data.Grp = basetypes.NewStringValue(attributeValue.(string)) + readData.Grp = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "order" { - data.Order = basetypes.NewStringValue(attributeValue.(string)) + readData.Order = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "rp" { - data.Rp = basetypes.NewStringValue(attributeValue.(string)) + readData.Rp = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "src" { - data.Src = basetypes.NewStringValue(attributeValue.(string)) + readData.Src = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationPimRouteMapEntryList := make([]TagAnnotationPimRouteMapEntryResourceModel, 0) @@ -570,10 +571,10 @@ func getAndSetPimRouteMapEntryAttributes(ctx context.Context, diags *diag.Diagno } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationPimRouteMapEntryList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagPimRouteMapEntryList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationPimRouteMapEntryList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagPimRouteMapEntryList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -581,8 +582,9 @@ func getAndSetPimRouteMapEntryAttributes(ctx context.Context, diags *diag.Diagno ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getPimRouteMapEntryRn(ctx context.Context, data *PimRouteMapEntryResourceModel) string { @@ -744,7 +746,6 @@ func getPimRouteMapEntryCreateJsonPayload(ctx context.Context, diags *diag.Diagn if !data.Src.IsNull() && !data.Src.IsUnknown() { payloadMap["attributes"].(map[string]string)["src"] = data.Src.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"pimRouteMapEntry": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_pim_route_map_entry_test.go b/internal/provider/resource_aci_pim_route_map_entry_test.go index 929f5568d..867a6bc15 100644 --- a/internal/provider/resource_aci_pim_route_map_entry_test.go +++ b/internal/provider/resource_aci_pim_route_map_entry_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourcePimRouteMapEntryWithPimRouteMapPol(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -47,7 +47,7 @@ func TestAccResourcePimRouteMapEntryWithPimRouteMapPol(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -60,7 +60,7 @@ func TestAccResourcePimRouteMapEntryWithPimRouteMapPol(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -92,7 +92,7 @@ func TestAccResourcePimRouteMapEntryWithPimRouteMapPol(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -232,6 +232,7 @@ func TestAccResourcePimRouteMapEntryWithPimRouteMapPol(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_pim_route_map_policy.go b/internal/provider/resource_aci_pim_route_map_policy.go index eeedc889e..090efc0c6 100644 --- a/internal/provider/resource_aci_pim_route_map_policy.go +++ b/internal/provider/resource_aci_pim_route_map_policy.go @@ -341,6 +341,7 @@ func (r *PimRouteMapPolResource) Create(ctx context.Context, req resource.Create } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -455,7 +456,7 @@ func (r *PimRouteMapPolResource) ImportState(ctx context.Context, req resource.I func getAndSetPimRouteMapPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *PimRouteMapPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "pimRouteMapPol,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyPimRouteMapPolResourceModel() + readData := getEmptyPimRouteMapPolResourceModel() if diags.HasError() { return @@ -466,26 +467,26 @@ func getAndSetPimRouteMapPolAttributes(ctx context.Context, diags *diag.Diagnost attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setPimRouteMapPolParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setPimRouteMapPolParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerKey" { - data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerTag" { - data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationPimRouteMapPolList := make([]TagAnnotationPimRouteMapPolResourceModel, 0) @@ -523,10 +524,10 @@ func getAndSetPimRouteMapPolAttributes(ctx context.Context, diags *diag.Diagnost } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationPimRouteMapPolList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagPimRouteMapPolList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationPimRouteMapPolList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagPimRouteMapPolList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -534,8 +535,9 @@ func getAndSetPimRouteMapPolAttributes(ctx context.Context, diags *diag.Diagnost ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getPimRouteMapPolRn(ctx context.Context, data *PimRouteMapPolResourceModel) string { @@ -688,7 +690,6 @@ func getPimRouteMapPolCreateJsonPayload(ctx context.Context, diags *diag.Diagnos if !data.OwnerTag.IsNull() && !data.OwnerTag.IsUnknown() { payloadMap["attributes"].(map[string]string)["ownerTag"] = data.OwnerTag.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"pimRouteMapPol": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_pim_route_map_policy_test.go b/internal/provider/resource_aci_pim_route_map_policy_test.go index be2935803..335c67556 100644 --- a/internal/provider/resource_aci_pim_route_map_policy_test.go +++ b/internal/provider/resource_aci_pim_route_map_policy_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourcePimRouteMapPolWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -41,7 +41,7 @@ func TestAccResourcePimRouteMapPolWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -54,7 +54,7 @@ func TestAccResourcePimRouteMapPolWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -80,7 +80,7 @@ func TestAccResourcePimRouteMapPolWithFvTenant(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -208,6 +208,7 @@ func TestAccResourcePimRouteMapPolWithFvTenant(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_external_epg.go b/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_external_epg.go index 62686c809..03768ae92 100644 --- a/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_external_epg.go +++ b/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_external_epg.go @@ -297,6 +297,7 @@ func (r *L3extRsLblToInstPResource) Create(ctx context.Context, req resource.Cre } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -411,7 +412,7 @@ func (r *L3extRsLblToInstPResource) ImportState(ctx context.Context, req resourc func getAndSetL3extRsLblToInstPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *L3extRsLblToInstPResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "l3extRsLblToInstP,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyL3extRsLblToInstPResourceModel() + readData := getEmptyL3extRsLblToInstPResourceModel() if diags.HasError() { return @@ -422,14 +423,14 @@ func getAndSetL3extRsLblToInstPAttributes(ctx context.Context, diags *diag.Diagn attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setL3extRsLblToInstPParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setL3extRsLblToInstPParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "tDn" { - data.TDn = basetypes.NewStringValue(attributeValue.(string)) + readData.TDn = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationL3extRsLblToInstPList := make([]TagAnnotationL3extRsLblToInstPResourceModel, 0) @@ -467,10 +468,10 @@ func getAndSetL3extRsLblToInstPAttributes(ctx context.Context, diags *diag.Diagn } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationL3extRsLblToInstPList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagL3extRsLblToInstPList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationL3extRsLblToInstPList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagL3extRsLblToInstPList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -478,8 +479,9 @@ func getAndSetL3extRsLblToInstPAttributes(ctx context.Context, diags *diag.Diagn ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getL3extRsLblToInstPRn(ctx context.Context, data *L3extRsLblToInstPResourceModel) string { @@ -620,7 +622,6 @@ func getL3extRsLblToInstPCreateJsonPayload(ctx context.Context, diags *diag.Diag if !data.TDn.IsNull() && !data.TDn.IsUnknown() { payloadMap["attributes"].(map[string]string)["tDn"] = data.TDn.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"l3extRsLblToInstP": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_external_epg_test.go b/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_external_epg_test.go index 679b80c82..1483ceeae 100644 --- a/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_external_epg_test.go +++ b/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_external_epg_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceL3extRsLblToInstPWithL3extConsLbl(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -33,7 +33,7 @@ func TestAccResourceL3extRsLblToInstPWithL3extConsLbl(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -46,7 +46,7 @@ func TestAccResourceL3extRsLblToInstPWithL3extConsLbl(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -64,7 +64,7 @@ func TestAccResourceL3extRsLblToInstPWithL3extConsLbl(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -176,6 +176,7 @@ func TestAccResourceL3extRsLblToInstPWithL3extConsLbl(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_route_control_profile.go b/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_route_control_profile.go index 2df0022a3..2ffc2687a 100644 --- a/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_route_control_profile.go +++ b/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_route_control_profile.go @@ -314,6 +314,7 @@ func (r *L3extRsLblToProfileResource) Create(ctx context.Context, req resource.C } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -428,7 +429,7 @@ func (r *L3extRsLblToProfileResource) ImportState(ctx context.Context, req resou func getAndSetL3extRsLblToProfileAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *L3extRsLblToProfileResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "l3extRsLblToProfile,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyL3extRsLblToProfileResourceModel() + readData := getEmptyL3extRsLblToProfileResourceModel() if diags.HasError() { return @@ -439,17 +440,17 @@ func getAndSetL3extRsLblToProfileAttributes(ctx context.Context, diags *diag.Dia attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setL3extRsLblToProfileParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setL3extRsLblToProfileParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "direction" { - data.Direction = basetypes.NewStringValue(attributeValue.(string)) + readData.Direction = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "tDn" { - data.TDn = basetypes.NewStringValue(attributeValue.(string)) + readData.TDn = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationL3extRsLblToProfileList := make([]TagAnnotationL3extRsLblToProfileResourceModel, 0) @@ -487,10 +488,10 @@ func getAndSetL3extRsLblToProfileAttributes(ctx context.Context, diags *diag.Dia } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationL3extRsLblToProfileList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagL3extRsLblToProfileList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationL3extRsLblToProfileList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagL3extRsLblToProfileList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -498,8 +499,9 @@ func getAndSetL3extRsLblToProfileAttributes(ctx context.Context, diags *diag.Dia ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getL3extRsLblToProfileRn(ctx context.Context, data *L3extRsLblToProfileResourceModel) string { @@ -643,7 +645,6 @@ func getL3extRsLblToProfileCreateJsonPayload(ctx context.Context, diags *diag.Di if !data.TDn.IsNull() && !data.TDn.IsUnknown() { payloadMap["attributes"].(map[string]string)["tDn"] = data.TDn.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"l3extRsLblToProfile": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_route_control_profile_test.go b/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_route_control_profile_test.go index cb74a8482..6748df5f6 100644 --- a/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_route_control_profile_test.go +++ b/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_route_control_profile_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceL3extRsLblToProfileWithL3extConsLbl(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -35,7 +35,7 @@ func TestAccResourceL3extRsLblToProfileWithL3extConsLbl(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -48,7 +48,7 @@ func TestAccResourceL3extRsLblToProfileWithL3extConsLbl(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -68,7 +68,7 @@ func TestAccResourceL3extRsLblToProfileWithL3extConsLbl(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -185,6 +185,7 @@ func TestAccResourceL3extRsLblToProfileWithL3extConsLbl(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_relation_to_consumed_contract.go b/internal/provider/resource_aci_relation_to_consumed_contract.go index 605d5572c..891e075bc 100644 --- a/internal/provider/resource_aci_relation_to_consumed_contract.go +++ b/internal/provider/resource_aci_relation_to_consumed_contract.go @@ -319,6 +319,7 @@ func (r *FvRsConsResource) Create(ctx context.Context, req resource.CreateReques } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -433,7 +434,7 @@ func (r *FvRsConsResource) ImportState(ctx context.Context, req resource.ImportS func getAndSetFvRsConsAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsConsResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsCons,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvRsConsResourceModel() + readData := getEmptyFvRsConsResourceModel() if diags.HasError() { return @@ -444,17 +445,17 @@ func getAndSetFvRsConsAttributes(ctx context.Context, diags *diag.Diagnostics, c attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvRsConsParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvRsConsParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "prio" { - data.Prio = customTypes.NewFvRsConsPrioStringValue(attributeValue.(string)) + readData.Prio = customTypes.NewFvRsConsPrioStringValue(attributeValue.(string)) } if attributeName == "tnVzBrCPName" { - data.TnVzBrCPName = basetypes.NewStringValue(attributeValue.(string)) + readData.TnVzBrCPName = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvRsConsList := make([]TagAnnotationFvRsConsResourceModel, 0) @@ -492,10 +493,10 @@ func getAndSetFvRsConsAttributes(ctx context.Context, diags *diag.Diagnostics, c } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvRsConsList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvRsConsList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvRsConsList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvRsConsList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -503,8 +504,9 @@ func getAndSetFvRsConsAttributes(ctx context.Context, diags *diag.Diagnostics, c ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvRsConsRn(ctx context.Context, data *FvRsConsResourceModel) string { @@ -648,7 +650,6 @@ func getFvRsConsCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, if !data.TnVzBrCPName.IsNull() && !data.TnVzBrCPName.IsUnknown() { payloadMap["attributes"].(map[string]string)["tnVzBrCPName"] = data.TnVzBrCPName.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvRsCons": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_relation_to_consumed_contract_test.go b/internal/provider/resource_aci_relation_to_consumed_contract_test.go index 8b82f2722..f592ba80c 100644 --- a/internal/provider/resource_aci_relation_to_consumed_contract_test.go +++ b/internal/provider/resource_aci_relation_to_consumed_contract_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFvRsConsWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -35,7 +35,7 @@ func TestAccResourceFvRsConsWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -48,7 +48,7 @@ func TestAccResourceFvRsConsWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -68,7 +68,7 @@ func TestAccResourceFvRsConsWithFvAEPg(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -193,12 +193,13 @@ func TestAccResourceFvRsConsWithFvAEPg(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } func TestAccResourceFvRsConsWithFvESg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -219,7 +220,7 @@ func TestAccResourceFvRsConsWithFvESg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -232,7 +233,7 @@ func TestAccResourceFvRsConsWithFvESg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -252,7 +253,7 @@ func TestAccResourceFvRsConsWithFvESg(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -377,6 +378,7 @@ func TestAccResourceFvRsConsWithFvESg(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_relation_to_consumed_out_of_band_contract.go b/internal/provider/resource_aci_relation_to_consumed_out_of_band_contract.go index 1e38bdf0d..63abf329b 100644 --- a/internal/provider/resource_aci_relation_to_consumed_out_of_band_contract.go +++ b/internal/provider/resource_aci_relation_to_consumed_out_of_band_contract.go @@ -319,6 +319,7 @@ func (r *MgmtRsOoBConsResource) Create(ctx context.Context, req resource.CreateR } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -433,7 +434,7 @@ func (r *MgmtRsOoBConsResource) ImportState(ctx context.Context, req resource.Im func getAndSetMgmtRsOoBConsAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *MgmtRsOoBConsResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "mgmtRsOoBCons,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyMgmtRsOoBConsResourceModel() + readData := getEmptyMgmtRsOoBConsResourceModel() if diags.HasError() { return @@ -444,17 +445,17 @@ func getAndSetMgmtRsOoBConsAttributes(ctx context.Context, diags *diag.Diagnosti attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setMgmtRsOoBConsParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setMgmtRsOoBConsParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "prio" { - data.Prio = customTypes.NewMgmtRsOoBConsPrioStringValue(attributeValue.(string)) + readData.Prio = customTypes.NewMgmtRsOoBConsPrioStringValue(attributeValue.(string)) } if attributeName == "tnVzOOBBrCPName" { - data.TnVzOOBBrCPName = basetypes.NewStringValue(attributeValue.(string)) + readData.TnVzOOBBrCPName = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationMgmtRsOoBConsList := make([]TagAnnotationMgmtRsOoBConsResourceModel, 0) @@ -492,10 +493,10 @@ func getAndSetMgmtRsOoBConsAttributes(ctx context.Context, diags *diag.Diagnosti } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationMgmtRsOoBConsList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagMgmtRsOoBConsList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationMgmtRsOoBConsList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagMgmtRsOoBConsList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -503,8 +504,9 @@ func getAndSetMgmtRsOoBConsAttributes(ctx context.Context, diags *diag.Diagnosti ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getMgmtRsOoBConsRn(ctx context.Context, data *MgmtRsOoBConsResourceModel) string { @@ -648,7 +650,6 @@ func getMgmtRsOoBConsCreateJsonPayload(ctx context.Context, diags *diag.Diagnost if !data.TnVzOOBBrCPName.IsNull() && !data.TnVzOOBBrCPName.IsUnknown() { payloadMap["attributes"].(map[string]string)["tnVzOOBBrCPName"] = data.TnVzOOBBrCPName.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"mgmtRsOoBCons": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_relation_to_consumed_out_of_band_contract_test.go b/internal/provider/resource_aci_relation_to_consumed_out_of_band_contract_test.go index f4b9b1849..73b92f4d3 100644 --- a/internal/provider/resource_aci_relation_to_consumed_out_of_band_contract_test.go +++ b/internal/provider/resource_aci_relation_to_consumed_out_of_band_contract_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceMgmtRsOoBConsWithMgmtInstP(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -35,7 +35,7 @@ func TestAccResourceMgmtRsOoBConsWithMgmtInstP(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -48,7 +48,7 @@ func TestAccResourceMgmtRsOoBConsWithMgmtInstP(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -68,7 +68,7 @@ func TestAccResourceMgmtRsOoBConsWithMgmtInstP(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -193,6 +193,7 @@ func TestAccResourceMgmtRsOoBConsWithMgmtInstP(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_relation_to_contract_master.go b/internal/provider/resource_aci_relation_to_contract_master.go index 60e5eb3da..d8f536bfc 100644 --- a/internal/provider/resource_aci_relation_to_contract_master.go +++ b/internal/provider/resource_aci_relation_to_contract_master.go @@ -297,6 +297,7 @@ func (r *FvRsSecInheritedResource) Create(ctx context.Context, req resource.Crea } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -411,7 +412,7 @@ func (r *FvRsSecInheritedResource) ImportState(ctx context.Context, req resource func getAndSetFvRsSecInheritedAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsSecInheritedResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsSecInherited,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvRsSecInheritedResourceModel() + readData := getEmptyFvRsSecInheritedResourceModel() if diags.HasError() { return @@ -422,14 +423,14 @@ func getAndSetFvRsSecInheritedAttributes(ctx context.Context, diags *diag.Diagno attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvRsSecInheritedParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvRsSecInheritedParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "tDn" { - data.TDn = basetypes.NewStringValue(attributeValue.(string)) + readData.TDn = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvRsSecInheritedList := make([]TagAnnotationFvRsSecInheritedResourceModel, 0) @@ -467,10 +468,10 @@ func getAndSetFvRsSecInheritedAttributes(ctx context.Context, diags *diag.Diagno } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvRsSecInheritedList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvRsSecInheritedList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvRsSecInheritedList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvRsSecInheritedList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -478,8 +479,9 @@ func getAndSetFvRsSecInheritedAttributes(ctx context.Context, diags *diag.Diagno ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvRsSecInheritedRn(ctx context.Context, data *FvRsSecInheritedResourceModel) string { @@ -620,7 +622,6 @@ func getFvRsSecInheritedCreateJsonPayload(ctx context.Context, diags *diag.Diagn if !data.TDn.IsNull() && !data.TDn.IsUnknown() { payloadMap["attributes"].(map[string]string)["tDn"] = data.TDn.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvRsSecInherited": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_relation_to_contract_master_test.go b/internal/provider/resource_aci_relation_to_contract_master_test.go index a45192494..ea69cec0c 100644 --- a/internal/provider/resource_aci_relation_to_contract_master_test.go +++ b/internal/provider/resource_aci_relation_to_contract_master_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFvRsSecInheritedWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.3(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -33,7 +33,7 @@ func TestAccResourceFvRsSecInheritedWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.3(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -46,7 +46,7 @@ func TestAccResourceFvRsSecInheritedWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.3(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -64,7 +64,7 @@ func TestAccResourceFvRsSecInheritedWithFvAEPg(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.3(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -176,12 +176,13 @@ func TestAccResourceFvRsSecInheritedWithFvAEPg(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } func TestAccResourceFvRsSecInheritedWithFvESg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.3(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -200,7 +201,7 @@ func TestAccResourceFvRsSecInheritedWithFvESg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.3(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -213,7 +214,7 @@ func TestAccResourceFvRsSecInheritedWithFvESg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.3(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -231,7 +232,7 @@ func TestAccResourceFvRsSecInheritedWithFvESg(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.3(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -343,6 +344,7 @@ func TestAccResourceFvRsSecInheritedWithFvESg(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_relation_to_domain.go b/internal/provider/resource_aci_relation_to_domain.go index 0aef9ea28..b9bd04bca 100644 --- a/internal/provider/resource_aci_relation_to_domain.go +++ b/internal/provider/resource_aci_relation_to_domain.go @@ -71,7 +71,6 @@ type FvRsDomAttResourceModel struct { SwitchingMode types.String `tfsdk:"switching_mode"` TDn types.String `tfsdk:"target_dn"` Untagged types.String `tfsdk:"untagged"` - VnetOnly types.String `tfsdk:"vnet_only"` TagAnnotation types.Set `tfsdk:"annotations"` TagTag types.Set `tfsdk:"tags"` } @@ -105,7 +104,6 @@ func getEmptyFvRsDomAttResourceModel() *FvRsDomAttResourceModel { SwitchingMode: basetypes.NewStringNull(), TDn: basetypes.NewStringNull(), Untagged: basetypes.NewStringNull(), - VnetOnly: basetypes.NewStringNull(), TagAnnotation: types.SetNull(types.ObjectType{ AttrTypes: map[string]attr.Type{ "key": types.StringType, @@ -470,18 +468,6 @@ func (r *FvRsDomAttResource) Schema(ctx context.Context, req resource.SchemaRequ }, MarkdownDescription: `The untagged status of the Relation To Domain object.`, }, - "vnet_only": schema.StringAttribute{ - Optional: true, - Computed: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(), - }, - Validators: []validator.String{ - stringvalidator.OneOf("no", "yes"), - }, - MarkdownDescription: `The VNET only status of the Relation To Domain object.`, - }, "annotations": schema.SetNestedAttribute{ MarkdownDescription: ``, Optional: true, @@ -606,6 +592,7 @@ func (r *FvRsDomAttResource) Create(ctx context.Context, req resource.CreateRequ } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -720,7 +707,7 @@ func (r *FvRsDomAttResource) ImportState(ctx context.Context, req resource.Impor func getAndSetFvRsDomAttAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsDomAttResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsDomAtt,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvRsDomAttResourceModel() + readData := getEmptyFvRsDomAttResourceModel() if diags.HasError() { return @@ -731,90 +718,87 @@ func getAndSetFvRsDomAttAttributes(ctx context.Context, diags *diag.Diagnostics, attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvRsDomAttParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvRsDomAttParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "bindingType" && attributeValue.(string) == "" { - data.BindingType = basetypes.NewStringValue("none") + readData.BindingType = basetypes.NewStringValue("none") } else if attributeName == "bindingType" { - data.BindingType = basetypes.NewStringValue(attributeValue.(string)) + readData.BindingType = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "classPref" { - data.ClassPref = basetypes.NewStringValue(attributeValue.(string)) + readData.ClassPref = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "customEpgName" { - data.CustomEpgName = basetypes.NewStringValue(attributeValue.(string)) + readData.CustomEpgName = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "delimiter" { - data.Delimiter = basetypes.NewStringValue(attributeValue.(string)) + readData.Delimiter = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "encap" { - data.Encap = basetypes.NewStringValue(attributeValue.(string)) + readData.Encap = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "encapMode" { - data.EncapMode = basetypes.NewStringValue(attributeValue.(string)) + readData.EncapMode = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "epgCos" { - data.EpgCos = basetypes.NewStringValue(attributeValue.(string)) + readData.EpgCos = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "epgCosPref" { - data.EpgCosPref = basetypes.NewStringValue(attributeValue.(string)) + readData.EpgCosPref = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "instrImedcy" { - data.InstrImedcy = basetypes.NewStringValue(attributeValue.(string)) + readData.InstrImedcy = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ipamDhcpOverride" { - data.IpamDhcpOverride = basetypes.NewStringValue(attributeValue.(string)) + readData.IpamDhcpOverride = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ipamEnabled" { - data.IpamEnabled = basetypes.NewStringValue(attributeValue.(string)) + readData.IpamEnabled = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ipamGateway" { - data.IpamGateway = basetypes.NewStringValue(attributeValue.(string)) + readData.IpamGateway = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "lagPolicyName" { - data.LagPolicyName = basetypes.NewStringValue(attributeValue.(string)) + readData.LagPolicyName = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "netflowDir" { - data.NetflowDir = basetypes.NewStringValue(attributeValue.(string)) + readData.NetflowDir = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "netflowPref" { - data.NetflowPref = basetypes.NewStringValue(attributeValue.(string)) + readData.NetflowPref = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "numPorts" { - data.NumPorts = basetypes.NewStringValue(attributeValue.(string)) + readData.NumPorts = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "portAllocation" && attributeValue.(string) == "" { - data.PortAllocation = basetypes.NewStringValue("none") + readData.PortAllocation = basetypes.NewStringValue("none") } else if attributeName == "portAllocation" { - data.PortAllocation = basetypes.NewStringValue(attributeValue.(string)) + readData.PortAllocation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "primaryEncap" { - data.PrimaryEncap = basetypes.NewStringValue(attributeValue.(string)) + readData.PrimaryEncap = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "primaryEncapInner" { - data.PrimaryEncapInner = basetypes.NewStringValue(attributeValue.(string)) + readData.PrimaryEncapInner = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "resImedcy" { - data.ResImedcy = basetypes.NewStringValue(attributeValue.(string)) + readData.ResImedcy = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "secondaryEncapInner" { - data.SecondaryEncapInner = basetypes.NewStringValue(attributeValue.(string)) + readData.SecondaryEncapInner = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "switchingMode" { - data.SwitchingMode = basetypes.NewStringValue(attributeValue.(string)) + readData.SwitchingMode = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "tDn" { - data.TDn = basetypes.NewStringValue(attributeValue.(string)) + readData.TDn = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "untagged" { - data.Untagged = basetypes.NewStringValue(attributeValue.(string)) - } - if attributeName == "vnetOnly" { - data.VnetOnly = basetypes.NewStringValue(attributeValue.(string)) + readData.Untagged = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvRsDomAttList := make([]TagAnnotationFvRsDomAttResourceModel, 0) @@ -852,10 +836,10 @@ func getAndSetFvRsDomAttAttributes(ctx context.Context, diags *diag.Diagnostics, } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvRsDomAttList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvRsDomAttList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvRsDomAttList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvRsDomAttList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -863,8 +847,9 @@ func getAndSetFvRsDomAttAttributes(ctx context.Context, diags *diag.Diagnostics, ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvRsDomAttRn(ctx context.Context, data *FvRsDomAttResourceModel) string { @@ -1074,10 +1059,6 @@ func getFvRsDomAttCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics if !data.Untagged.IsNull() && !data.Untagged.IsUnknown() { payloadMap["attributes"].(map[string]string)["untagged"] = data.Untagged.ValueString() } - if !data.VnetOnly.IsNull() && !data.VnetOnly.IsUnknown() { - payloadMap["attributes"].(map[string]string)["vnetOnly"] = data.VnetOnly.ValueString() - } - payload, err := json.Marshal(map[string]interface{}{"fvRsDomAtt": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_relation_to_domain_test.go b/internal/provider/resource_aci_relation_to_domain_test.go index 4bd9a1986..cac098334 100644 --- a/internal/provider/resource_aci_relation_to_domain_test.go +++ b/internal/provider/resource_aci_relation_to_domain_test.go @@ -14,24 +14,20 @@ import ( func TestAccResourceFvRsDomAttWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigFvRsDomAttMinDependencyWithFvAEPgAllowExisting, + Config: testConfigFvRsDomAttMinDependencyWithFvAEPgAllowExisting + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "target_dn", "uni/vmmp-VMware/dom-domain_1"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "target_dn", "uni/vmmp-VMware/dom-domain_1"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "annotation", "orchestrator:terraform"), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "binding_type", "none"), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "binding_type", "none"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "class_preference", "encap"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "class_preference", "encap"), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "custom_epg_name", ""), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "custom_epg_name", ""), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "delimiter", ""), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "delimiter", ""), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "deployment_immediacy", "lazy"), @@ -50,10 +46,6 @@ func TestAccResourceFvRsDomAttWithFvAEPg(t *testing.T) { resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "lag_policy_name", ""), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "netflow_direction", "both"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "netflow_direction", "both"), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "number_of_ports", "0"), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "number_of_ports", "0"), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "port_allocation", "none"), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "port_allocation", "none"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "primary_encapsulation", "unknown"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "primary_encapsulation", "unknown"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "primary_encapsulation_inner", "unknown"), @@ -66,8 +58,16 @@ func TestAccResourceFvRsDomAttWithFvAEPg(t *testing.T) { resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "switching_mode", "native"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "untagged", "no"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "untagged", "no"), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "vnet_only", "no"), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "vnet_only", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.0(1h)", ">", + resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "binding_type", "none"), + resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "binding_type", "none"), + resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "number_of_ports", "0"), + resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "number_of_ports", "0"), + resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "port_allocation", "none"), + resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "port_allocation", "none")), + composeAggregateTestCheckFuncWithVersion(t, "4.2(3j)", ">", + resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "custom_epg_name", ""), + resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "custom_epg_name", "")), ), }, }, @@ -75,12 +75,12 @@ func TestAccResourceFvRsDomAttWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigFvRsDomAttMinDependencyWithFvAEPgAllowExisting, + Config: testConfigFvRsDomAttMinDependencyWithFvAEPgAllowExisting + testConfigDataSourceSystem, ExpectError: regexp.MustCompile("Object Already Exists"), }, }, @@ -88,24 +88,20 @@ func TestAccResourceFvRsDomAttWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigFvRsDomAttMinDependencyWithFvAEPgAllowExisting, + Config: testConfigFvRsDomAttMinDependencyWithFvAEPgAllowExisting + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "target_dn", "uni/vmmp-VMware/dom-domain_1"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "target_dn", "uni/vmmp-VMware/dom-domain_1"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "annotation", "orchestrator:terraform"), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "binding_type", "none"), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "binding_type", "none"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "class_preference", "encap"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "class_preference", "encap"), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "custom_epg_name", ""), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "custom_epg_name", ""), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "delimiter", ""), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "delimiter", ""), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "deployment_immediacy", "lazy"), @@ -124,10 +120,6 @@ func TestAccResourceFvRsDomAttWithFvAEPg(t *testing.T) { resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "lag_policy_name", ""), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "netflow_direction", "both"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "netflow_direction", "both"), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "number_of_ports", "0"), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "number_of_ports", "0"), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "port_allocation", "none"), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "port_allocation", "none"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "primary_encapsulation", "unknown"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "primary_encapsulation", "unknown"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "primary_encapsulation_inner", "unknown"), @@ -140,27 +132,33 @@ func TestAccResourceFvRsDomAttWithFvAEPg(t *testing.T) { resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "switching_mode", "native"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "untagged", "no"), resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "untagged", "no"), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "vnet_only", "no"), - resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "vnet_only", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.0(1h)", ">", + resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "binding_type", "none"), + resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "binding_type", "none"), + resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "number_of_ports", "0"), + resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "number_of_ports", "0"), + resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "port_allocation", "none"), + resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "port_allocation", "none")), + composeAggregateTestCheckFuncWithVersion(t, "4.2(3j)", ">", + resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test", "custom_epg_name", ""), + resource.TestCheckResourceAttr("aci_relation_to_domain.allow_test_2", "custom_epg_name", "")), ), }, }, }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigFvRsDomAttMinDependencyWithFvAEPg, + Config: testConfigFvRsDomAttMinDependencyWithFvAEPg + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_relation_to_domain.test", "target_dn", "uni/vmmp-VMware/dom-domain_1"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "annotation", "orchestrator:terraform"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "binding_type", "none"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "class_preference", "encap"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "custom_epg_name", ""), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "delimiter", ""), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "deployment_immediacy", "lazy"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "enable_netflow", "disabled"), @@ -170,27 +168,28 @@ func TestAccResourceFvRsDomAttWithFvAEPg(t *testing.T) { resource.TestCheckResourceAttr("aci_relation_to_domain.test", "epg_cos_pref", "disabled"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "lag_policy_name", ""), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "netflow_direction", "both"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "number_of_ports", "0"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "port_allocation", "none"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "primary_encapsulation", "unknown"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "primary_encapsulation_inner", "unknown"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "resolution_immediacy", "lazy"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "secondary_encapsulation_inner", "unknown"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "switching_mode", "native"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "untagged", "no"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "vnet_only", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.0(1h)", ">", + resource.TestCheckResourceAttr("aci_relation_to_domain.test", "binding_type", "none"), + resource.TestCheckResourceAttr("aci_relation_to_domain.test", "number_of_ports", "0"), + resource.TestCheckResourceAttr("aci_relation_to_domain.test", "port_allocation", "none")), + composeAggregateTestCheckFuncWithVersion(t, "4.2(3j)", ">", + resource.TestCheckResourceAttr("aci_relation_to_domain.test", "custom_epg_name", "")), ), }, // Update with all config and verify default APIC values { - Config: testConfigFvRsDomAttAllDependencyWithFvAEPg, + Config: testConfigFvRsDomAttAllDependencyWithFvAEPg + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_relation_to_domain.test", "target_dn", "uni/vmmp-VMware/dom-domain_1"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "annotation", "annotation"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "binding_type", "dynamicBinding"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "class_preference", "encap"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "custom_epg_name", "custom_epg_name_1"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "delimiter", "@"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "deployment_immediacy", "immediate"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "enable_netflow", "disabled"), @@ -200,20 +199,23 @@ func TestAccResourceFvRsDomAttWithFvAEPg(t *testing.T) { resource.TestCheckResourceAttr("aci_relation_to_domain.test", "epg_cos_pref", "disabled"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "lag_policy_name", "lag_policy_name_1"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "netflow_direction", "both"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "number_of_ports", "1"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "port_allocation", "elastic"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "primary_encapsulation", "vlan-200"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "primary_encapsulation_inner", "vlan-300"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "resolution_immediacy", "immediate"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "secondary_encapsulation_inner", "vlan-400"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "switching_mode", "AVE"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "untagged", "no"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "vnet_only", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.0(1h)", ">", + resource.TestCheckResourceAttr("aci_relation_to_domain.test", "binding_type", "dynamicBinding"), + resource.TestCheckResourceAttr("aci_relation_to_domain.test", "number_of_ports", "1"), + resource.TestCheckResourceAttr("aci_relation_to_domain.test", "port_allocation", "elastic")), + composeAggregateTestCheckFuncWithVersion(t, "4.2(3j)", ">", + resource.TestCheckResourceAttr("aci_relation_to_domain.test", "custom_epg_name", "custom_epg_name_1")), ), }, // Update with minimum config and verify config is unchanged { - Config: testConfigFvRsDomAttMinDependencyWithFvAEPg, + Config: testConfigFvRsDomAttMinDependencyWithFvAEPg + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_relation_to_domain.test", "target_dn", "uni/vmmp-VMware/dom-domain_1"), @@ -221,14 +223,12 @@ func TestAccResourceFvRsDomAttWithFvAEPg(t *testing.T) { }, // Update with empty strings config or default value { - Config: testConfigFvRsDomAttResetDependencyWithFvAEPg, + Config: testConfigFvRsDomAttResetDependencyWithFvAEPg + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_relation_to_domain.test", "target_dn", "uni/vmmp-VMware/dom-domain_1"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "annotation", "orchestrator:terraform"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "binding_type", "none"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "class_preference", "encap"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "custom_epg_name", ""), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "delimiter", ""), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "deployment_immediacy", "lazy"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "enable_netflow", "disabled"), @@ -238,15 +238,18 @@ func TestAccResourceFvRsDomAttWithFvAEPg(t *testing.T) { resource.TestCheckResourceAttr("aci_relation_to_domain.test", "epg_cos_pref", "disabled"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "lag_policy_name", ""), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "netflow_direction", "both"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "number_of_ports", "0"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "port_allocation", "none"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "primary_encapsulation", "unknown"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "primary_encapsulation_inner", "unknown"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "resolution_immediacy", "lazy"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "secondary_encapsulation_inner", "unknown"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "switching_mode", "native"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "untagged", "no"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "vnet_only", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.0(1h)", ">", + resource.TestCheckResourceAttr("aci_relation_to_domain.test", "binding_type", "none"), + resource.TestCheckResourceAttr("aci_relation_to_domain.test", "number_of_ports", "0"), + resource.TestCheckResourceAttr("aci_relation_to_domain.test", "port_allocation", "none")), + composeAggregateTestCheckFuncWithVersion(t, "4.2(3j)", ">", + resource.TestCheckResourceAttr("aci_relation_to_domain.test", "custom_epg_name", "")), ), }, // Import testing @@ -257,14 +260,12 @@ func TestAccResourceFvRsDomAttWithFvAEPg(t *testing.T) { }, // Update with children { - Config: testConfigFvRsDomAttChildrenDependencyWithFvAEPg, + Config: testConfigFvRsDomAttChildrenDependencyWithFvAEPg + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_relation_to_domain.test", "target_dn", "uni/vmmp-VMware/dom-domain_1"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "annotation", "orchestrator:terraform"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "binding_type", "none"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "class_preference", "encap"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "custom_epg_name", ""), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "delimiter", ""), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "deployment_immediacy", "lazy"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "enable_netflow", "disabled"), @@ -274,15 +275,18 @@ func TestAccResourceFvRsDomAttWithFvAEPg(t *testing.T) { resource.TestCheckResourceAttr("aci_relation_to_domain.test", "epg_cos_pref", "disabled"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "lag_policy_name", ""), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "netflow_direction", "both"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "number_of_ports", "0"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "port_allocation", "none"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "primary_encapsulation", "unknown"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "primary_encapsulation_inner", "unknown"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "resolution_immediacy", "lazy"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "secondary_encapsulation_inner", "unknown"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "switching_mode", "native"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "untagged", "no"), - resource.TestCheckResourceAttr("aci_relation_to_domain.test", "vnet_only", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.0(1h)", ">", + resource.TestCheckResourceAttr("aci_relation_to_domain.test", "binding_type", "none"), + resource.TestCheckResourceAttr("aci_relation_to_domain.test", "number_of_ports", "0"), + resource.TestCheckResourceAttr("aci_relation_to_domain.test", "port_allocation", "none")), + composeAggregateTestCheckFuncWithVersion(t, "4.2(3j)", ">", + resource.TestCheckResourceAttr("aci_relation_to_domain.test", "custom_epg_name", "")), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "annotations.0.key", "key_0"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "annotations.0.value", "value_1"), resource.TestCheckResourceAttr("aci_relation_to_domain.test", "annotations.1.key", "key_1"), @@ -306,7 +310,7 @@ func TestAccResourceFvRsDomAttWithFvAEPg(t *testing.T) { }, // Update with children removed from config { - Config: testConfigFvRsDomAttChildrenRemoveFromConfigDependencyWithFvAEPg, + Config: testConfigFvRsDomAttChildrenRemoveFromConfigDependencyWithFvAEPg + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_relation_to_domain.test", "annotations.0.key", "key_0"), @@ -323,7 +327,7 @@ func TestAccResourceFvRsDomAttWithFvAEPg(t *testing.T) { }, // Update with children first child removed { - Config: testConfigFvRsDomAttChildrenRemoveOneDependencyWithFvAEPg, + Config: testConfigFvRsDomAttChildrenRemoveOneDependencyWithFvAEPg + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_relation_to_domain.test", "annotations.0.key", "key_1"), @@ -336,7 +340,7 @@ func TestAccResourceFvRsDomAttWithFvAEPg(t *testing.T) { }, // Update with all children removed { - Config: testConfigFvRsDomAttChildrenRemoveAllDependencyWithFvAEPg, + Config: testConfigFvRsDomAttChildrenRemoveAllDependencyWithFvAEPg + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_relation_to_domain.test", "annotations.#", "0"), @@ -344,6 +348,7 @@ func TestAccResourceFvRsDomAttWithFvAEPg(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } @@ -374,9 +379,7 @@ resource "aci_relation_to_domain" "test" { parent_dn = aci_application_epg.test.id target_dn = "uni/vmmp-VMware/dom-domain_1" annotation = "annotation" - binding_type = "dynamicBinding" class_preference = "encap" - custom_epg_name = "custom_epg_name_1" delimiter = "@" deployment_immediacy = "immediate" enable_netflow = "disabled" @@ -386,15 +389,16 @@ resource "aci_relation_to_domain" "test" { epg_cos_pref = "disabled" lag_policy_name = "lag_policy_name_1" netflow_direction = "both" - number_of_ports = "1" - port_allocation = "elastic" primary_encapsulation = "vlan-200" primary_encapsulation_inner = "vlan-300" resolution_immediacy = "immediate" secondary_encapsulation_inner = "vlan-400" switching_mode = "AVE" untagged = "no" - vnet_only = "no" + binding_type = provider::aci::compare_versions(data.aci_system.version.version,">=","4.0(1h)") ? "dynamicBinding" : null + number_of_ports = provider::aci::compare_versions(data.aci_system.version.version,">=","4.0(1h)") ? "1" : null + port_allocation = provider::aci::compare_versions(data.aci_system.version.version,">=","4.0(1h)") ? "elastic" : null + custom_epg_name = provider::aci::compare_versions(data.aci_system.version.version,">=","4.2(3j)") ? "custom_epg_name_1" : null } ` @@ -403,9 +407,7 @@ resource "aci_relation_to_domain" "test" { parent_dn = aci_application_epg.test.id target_dn = "uni/vmmp-VMware/dom-domain_1" annotation = "orchestrator:terraform" - binding_type = "none" class_preference = "encap" - custom_epg_name = "" delimiter = "" deployment_immediacy = "lazy" enable_netflow = "disabled" @@ -415,15 +417,16 @@ resource "aci_relation_to_domain" "test" { epg_cos_pref = "disabled" lag_policy_name = "" netflow_direction = "both" - number_of_ports = "0" - port_allocation = "none" primary_encapsulation = "unknown" primary_encapsulation_inner = "unknown" resolution_immediacy = "lazy" secondary_encapsulation_inner = "unknown" switching_mode = "native" untagged = "no" - vnet_only = "no" + binding_type = provider::aci::compare_versions(data.aci_system.version.version,">=","4.0(1h)") ? "none" : null + number_of_ports = provider::aci::compare_versions(data.aci_system.version.version,">=","4.0(1h)") ? "0" : null + port_allocation = provider::aci::compare_versions(data.aci_system.version.version,">=","4.0(1h)") ? "none" : null + custom_epg_name = provider::aci::compare_versions(data.aci_system.version.version,">=","4.2(3j)") ? "" : null } ` const testConfigFvRsDomAttChildrenDependencyWithFvAEPg = testDependencyConfigFvRsDomAtt + testConfigFvAEPgMinDependencyWithFvAp + ` diff --git a/internal/provider/resource_aci_relation_to_fibre_channel_path.go b/internal/provider/resource_aci_relation_to_fibre_channel_path.go index c0f7580df..4174c272f 100644 --- a/internal/provider/resource_aci_relation_to_fibre_channel_path.go +++ b/internal/provider/resource_aci_relation_to_fibre_channel_path.go @@ -335,6 +335,7 @@ func (r *FvRsFcPathAttResource) Create(ctx context.Context, req resource.CreateR } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -449,7 +450,7 @@ func (r *FvRsFcPathAttResource) ImportState(ctx context.Context, req resource.Im func getAndSetFvRsFcPathAttAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsFcPathAttResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsFcPathAtt,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvRsFcPathAttResourceModel() + readData := getEmptyFvRsFcPathAttResourceModel() if diags.HasError() { return @@ -460,23 +461,23 @@ func getAndSetFvRsFcPathAttAttributes(ctx context.Context, diags *diag.Diagnosti attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvRsFcPathAttParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvRsFcPathAttParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "tDn" { - data.TDn = basetypes.NewStringValue(attributeValue.(string)) + readData.TDn = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "vsan" { - data.Vsan = basetypes.NewStringValue(attributeValue.(string)) + readData.Vsan = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "vsanMode" { - data.VsanMode = basetypes.NewStringValue(attributeValue.(string)) + readData.VsanMode = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvRsFcPathAttList := make([]TagAnnotationFvRsFcPathAttResourceModel, 0) @@ -514,10 +515,10 @@ func getAndSetFvRsFcPathAttAttributes(ctx context.Context, diags *diag.Diagnosti } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvRsFcPathAttList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvRsFcPathAttList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvRsFcPathAttList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvRsFcPathAttList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -525,8 +526,9 @@ func getAndSetFvRsFcPathAttAttributes(ctx context.Context, diags *diag.Diagnosti ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvRsFcPathAttRn(ctx context.Context, data *FvRsFcPathAttResourceModel) string { @@ -676,7 +678,6 @@ func getFvRsFcPathAttCreateJsonPayload(ctx context.Context, diags *diag.Diagnost if !data.VsanMode.IsNull() && !data.VsanMode.IsUnknown() { payloadMap["attributes"].(map[string]string)["vsanMode"] = data.VsanMode.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvRsFcPathAtt": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_relation_to_fibre_channel_path_test.go b/internal/provider/resource_aci_relation_to_fibre_channel_path_test.go index b02bb8ccd..ac672d70f 100644 --- a/internal/provider/resource_aci_relation_to_fibre_channel_path_test.go +++ b/internal/provider/resource_aci_relation_to_fibre_channel_path_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFvRsFcPathAttWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -39,7 +39,7 @@ func TestAccResourceFvRsFcPathAttWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -52,7 +52,7 @@ func TestAccResourceFvRsFcPathAttWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -76,7 +76,7 @@ func TestAccResourceFvRsFcPathAttWithFvAEPg(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "2.0(1m)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -200,6 +200,7 @@ func TestAccResourceFvRsFcPathAttWithFvAEPg(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_relation_to_imported_contract.go b/internal/provider/resource_aci_relation_to_imported_contract.go index 89d313ce1..2319996b2 100644 --- a/internal/provider/resource_aci_relation_to_imported_contract.go +++ b/internal/provider/resource_aci_relation_to_imported_contract.go @@ -319,6 +319,7 @@ func (r *FvRsConsIfResource) Create(ctx context.Context, req resource.CreateRequ } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -433,7 +434,7 @@ func (r *FvRsConsIfResource) ImportState(ctx context.Context, req resource.Impor func getAndSetFvRsConsIfAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsConsIfResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsConsIf,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvRsConsIfResourceModel() + readData := getEmptyFvRsConsIfResourceModel() if diags.HasError() { return @@ -444,17 +445,17 @@ func getAndSetFvRsConsIfAttributes(ctx context.Context, diags *diag.Diagnostics, attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvRsConsIfParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvRsConsIfParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "prio" { - data.Prio = customTypes.NewFvRsConsIfPrioStringValue(attributeValue.(string)) + readData.Prio = customTypes.NewFvRsConsIfPrioStringValue(attributeValue.(string)) } if attributeName == "tnVzCPIfName" { - data.TnVzCPIfName = basetypes.NewStringValue(attributeValue.(string)) + readData.TnVzCPIfName = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvRsConsIfList := make([]TagAnnotationFvRsConsIfResourceModel, 0) @@ -492,10 +493,10 @@ func getAndSetFvRsConsIfAttributes(ctx context.Context, diags *diag.Diagnostics, } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvRsConsIfList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvRsConsIfList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvRsConsIfList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvRsConsIfList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -503,8 +504,9 @@ func getAndSetFvRsConsIfAttributes(ctx context.Context, diags *diag.Diagnostics, ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvRsConsIfRn(ctx context.Context, data *FvRsConsIfResourceModel) string { @@ -648,7 +650,6 @@ func getFvRsConsIfCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics if !data.TnVzCPIfName.IsNull() && !data.TnVzCPIfName.IsUnknown() { payloadMap["attributes"].(map[string]string)["tnVzCPIfName"] = data.TnVzCPIfName.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvRsConsIf": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_relation_to_imported_contract_test.go b/internal/provider/resource_aci_relation_to_imported_contract_test.go index 5792bad89..820dc6034 100644 --- a/internal/provider/resource_aci_relation_to_imported_contract_test.go +++ b/internal/provider/resource_aci_relation_to_imported_contract_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFvRsConsIfWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -35,7 +35,7 @@ func TestAccResourceFvRsConsIfWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -48,7 +48,7 @@ func TestAccResourceFvRsConsIfWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -68,7 +68,7 @@ func TestAccResourceFvRsConsIfWithFvAEPg(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -193,12 +193,13 @@ func TestAccResourceFvRsConsIfWithFvAEPg(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } func TestAccResourceFvRsConsIfWithFvESg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -219,7 +220,7 @@ func TestAccResourceFvRsConsIfWithFvESg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -232,7 +233,7 @@ func TestAccResourceFvRsConsIfWithFvESg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -252,7 +253,7 @@ func TestAccResourceFvRsConsIfWithFvESg(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -377,6 +378,7 @@ func TestAccResourceFvRsConsIfWithFvESg(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_relation_to_intra_epg_contract.go b/internal/provider/resource_aci_relation_to_intra_epg_contract.go index 159fc250f..97d8c6ca2 100644 --- a/internal/provider/resource_aci_relation_to_intra_epg_contract.go +++ b/internal/provider/resource_aci_relation_to_intra_epg_contract.go @@ -297,6 +297,7 @@ func (r *FvRsIntraEpgResource) Create(ctx context.Context, req resource.CreateRe } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -411,7 +412,7 @@ func (r *FvRsIntraEpgResource) ImportState(ctx context.Context, req resource.Imp func getAndSetFvRsIntraEpgAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsIntraEpgResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsIntraEpg,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvRsIntraEpgResourceModel() + readData := getEmptyFvRsIntraEpgResourceModel() if diags.HasError() { return @@ -422,14 +423,14 @@ func getAndSetFvRsIntraEpgAttributes(ctx context.Context, diags *diag.Diagnostic attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvRsIntraEpgParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvRsIntraEpgParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "tnVzBrCPName" { - data.TnVzBrCPName = basetypes.NewStringValue(attributeValue.(string)) + readData.TnVzBrCPName = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvRsIntraEpgList := make([]TagAnnotationFvRsIntraEpgResourceModel, 0) @@ -467,10 +468,10 @@ func getAndSetFvRsIntraEpgAttributes(ctx context.Context, diags *diag.Diagnostic } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvRsIntraEpgList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvRsIntraEpgList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvRsIntraEpgList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvRsIntraEpgList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -478,8 +479,9 @@ func getAndSetFvRsIntraEpgAttributes(ctx context.Context, diags *diag.Diagnostic ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvRsIntraEpgRn(ctx context.Context, data *FvRsIntraEpgResourceModel) string { @@ -620,7 +622,6 @@ func getFvRsIntraEpgCreateJsonPayload(ctx context.Context, diags *diag.Diagnosti if !data.TnVzBrCPName.IsNull() && !data.TnVzBrCPName.IsUnknown() { payloadMap["attributes"].(map[string]string)["tnVzBrCPName"] = data.TnVzBrCPName.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvRsIntraEpg": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_relation_to_intra_epg_contract_test.go b/internal/provider/resource_aci_relation_to_intra_epg_contract_test.go index 0dadc519c..8a6101215 100644 --- a/internal/provider/resource_aci_relation_to_intra_epg_contract_test.go +++ b/internal/provider/resource_aci_relation_to_intra_epg_contract_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFvRsIntraEpgWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -33,7 +33,7 @@ func TestAccResourceFvRsIntraEpgWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -46,7 +46,7 @@ func TestAccResourceFvRsIntraEpgWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -64,7 +64,7 @@ func TestAccResourceFvRsIntraEpgWithFvAEPg(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -176,12 +176,13 @@ func TestAccResourceFvRsIntraEpgWithFvAEPg(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } func TestAccResourceFvRsIntraEpgWithFvESg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -200,7 +201,7 @@ func TestAccResourceFvRsIntraEpgWithFvESg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -213,7 +214,7 @@ func TestAccResourceFvRsIntraEpgWithFvESg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -231,7 +232,7 @@ func TestAccResourceFvRsIntraEpgWithFvESg(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -343,6 +344,7 @@ func TestAccResourceFvRsIntraEpgWithFvESg(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_relation_to_netflow_exporter.go b/internal/provider/resource_aci_relation_to_netflow_exporter.go index 5ba417e0f..8f48ebf8b 100644 --- a/internal/provider/resource_aci_relation_to_netflow_exporter.go +++ b/internal/provider/resource_aci_relation_to_netflow_exporter.go @@ -297,6 +297,7 @@ func (r *NetflowRsMonitorToExporterResource) Create(ctx context.Context, req res } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -411,7 +412,7 @@ func (r *NetflowRsMonitorToExporterResource) ImportState(ctx context.Context, re func getAndSetNetflowRsMonitorToExporterAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *NetflowRsMonitorToExporterResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "netflowRsMonitorToExporter,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyNetflowRsMonitorToExporterResourceModel() + readData := getEmptyNetflowRsMonitorToExporterResourceModel() if diags.HasError() { return @@ -422,14 +423,14 @@ func getAndSetNetflowRsMonitorToExporterAttributes(ctx context.Context, diags *d attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setNetflowRsMonitorToExporterParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setNetflowRsMonitorToExporterParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "tnNetflowExporterPolName" { - data.TnNetflowExporterPolName = basetypes.NewStringValue(attributeValue.(string)) + readData.TnNetflowExporterPolName = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationNetflowRsMonitorToExporterList := make([]TagAnnotationNetflowRsMonitorToExporterResourceModel, 0) @@ -467,10 +468,10 @@ func getAndSetNetflowRsMonitorToExporterAttributes(ctx context.Context, diags *d } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationNetflowRsMonitorToExporterList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagNetflowRsMonitorToExporterList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationNetflowRsMonitorToExporterList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagNetflowRsMonitorToExporterList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -478,8 +479,9 @@ func getAndSetNetflowRsMonitorToExporterAttributes(ctx context.Context, diags *d ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getNetflowRsMonitorToExporterRn(ctx context.Context, data *NetflowRsMonitorToExporterResourceModel) string { @@ -620,7 +622,6 @@ func getNetflowRsMonitorToExporterCreateJsonPayload(ctx context.Context, diags * if !data.TnNetflowExporterPolName.IsNull() && !data.TnNetflowExporterPolName.IsUnknown() { payloadMap["attributes"].(map[string]string)["tnNetflowExporterPolName"] = data.TnNetflowExporterPolName.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"netflowRsMonitorToExporter": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_relation_to_netflow_exporter_test.go b/internal/provider/resource_aci_relation_to_netflow_exporter_test.go index 4ad51c58c..1f8ddd698 100644 --- a/internal/provider/resource_aci_relation_to_netflow_exporter_test.go +++ b/internal/provider/resource_aci_relation_to_netflow_exporter_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceNetflowRsMonitorToExporterWithNetflowMonitorPol(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -33,7 +33,7 @@ func TestAccResourceNetflowRsMonitorToExporterWithNetflowMonitorPol(t *testing.T setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -46,7 +46,7 @@ func TestAccResourceNetflowRsMonitorToExporterWithNetflowMonitorPol(t *testing.T setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -64,7 +64,7 @@ func TestAccResourceNetflowRsMonitorToExporterWithNetflowMonitorPol(t *testing.T }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "2.2(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -176,6 +176,7 @@ func TestAccResourceNetflowRsMonitorToExporterWithNetflowMonitorPol(t *testing.T ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_relation_to_provided_contract.go b/internal/provider/resource_aci_relation_to_provided_contract.go index dd92cdbd0..ed18c4656 100644 --- a/internal/provider/resource_aci_relation_to_provided_contract.go +++ b/internal/provider/resource_aci_relation_to_provided_contract.go @@ -333,6 +333,7 @@ func (r *FvRsProvResource) Create(ctx context.Context, req resource.CreateReques } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -447,7 +448,7 @@ func (r *FvRsProvResource) ImportState(ctx context.Context, req resource.ImportS func getAndSetFvRsProvAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsProvResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsProv,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvRsProvResourceModel() + readData := getEmptyFvRsProvResourceModel() if diags.HasError() { return @@ -458,20 +459,20 @@ func getAndSetFvRsProvAttributes(ctx context.Context, diags *diag.Diagnostics, c attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvRsProvParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvRsProvParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "matchT" { - data.MatchT = basetypes.NewStringValue(attributeValue.(string)) + readData.MatchT = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "prio" { - data.Prio = customTypes.NewFvRsProvPrioStringValue(attributeValue.(string)) + readData.Prio = customTypes.NewFvRsProvPrioStringValue(attributeValue.(string)) } if attributeName == "tnVzBrCPName" { - data.TnVzBrCPName = basetypes.NewStringValue(attributeValue.(string)) + readData.TnVzBrCPName = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvRsProvList := make([]TagAnnotationFvRsProvResourceModel, 0) @@ -509,10 +510,10 @@ func getAndSetFvRsProvAttributes(ctx context.Context, diags *diag.Diagnostics, c } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvRsProvList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvRsProvList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvRsProvList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvRsProvList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -520,8 +521,9 @@ func getAndSetFvRsProvAttributes(ctx context.Context, diags *diag.Diagnostics, c ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvRsProvRn(ctx context.Context, data *FvRsProvResourceModel) string { @@ -668,7 +670,6 @@ func getFvRsProvCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, if !data.TnVzBrCPName.IsNull() && !data.TnVzBrCPName.IsUnknown() { payloadMap["attributes"].(map[string]string)["tnVzBrCPName"] = data.TnVzBrCPName.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvRsProv": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_relation_to_provided_contract_test.go b/internal/provider/resource_aci_relation_to_provided_contract_test.go index 412837693..a03973db5 100644 --- a/internal/provider/resource_aci_relation_to_provided_contract_test.go +++ b/internal/provider/resource_aci_relation_to_provided_contract_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFvRsProvWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -37,7 +37,7 @@ func TestAccResourceFvRsProvWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -50,7 +50,7 @@ func TestAccResourceFvRsProvWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -72,7 +72,7 @@ func TestAccResourceFvRsProvWithFvAEPg(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -201,12 +201,13 @@ func TestAccResourceFvRsProvWithFvAEPg(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } func TestAccResourceFvRsProvWithFvESg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -229,7 +230,7 @@ func TestAccResourceFvRsProvWithFvESg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -242,7 +243,7 @@ func TestAccResourceFvRsProvWithFvESg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -264,7 +265,7 @@ func TestAccResourceFvRsProvWithFvESg(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -393,6 +394,7 @@ func TestAccResourceFvRsProvWithFvESg(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_relation_to_static_leaf.go b/internal/provider/resource_aci_relation_to_static_leaf.go index a46ee4af4..92e0f3248 100644 --- a/internal/provider/resource_aci_relation_to_static_leaf.go +++ b/internal/provider/resource_aci_relation_to_static_leaf.go @@ -348,6 +348,7 @@ func (r *FvRsNodeAttResource) Create(ctx context.Context, req resource.CreateReq } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -462,7 +463,7 @@ func (r *FvRsNodeAttResource) ImportState(ctx context.Context, req resource.Impo func getAndSetFvRsNodeAttAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsNodeAttResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsNodeAtt,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvRsNodeAttResourceModel() + readData := getEmptyFvRsNodeAttResourceModel() if diags.HasError() { return @@ -473,26 +474,26 @@ func getAndSetFvRsNodeAttAttributes(ctx context.Context, diags *diag.Diagnostics attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvRsNodeAttParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvRsNodeAttParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "encap" { - data.Encap = basetypes.NewStringValue(attributeValue.(string)) + readData.Encap = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "instrImedcy" { - data.InstrImedcy = basetypes.NewStringValue(attributeValue.(string)) + readData.InstrImedcy = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "mode" { - data.Mode = basetypes.NewStringValue(attributeValue.(string)) + readData.Mode = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "tDn" { - data.TDn = basetypes.NewStringValue(attributeValue.(string)) + readData.TDn = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvRsNodeAttList := make([]TagAnnotationFvRsNodeAttResourceModel, 0) @@ -530,10 +531,10 @@ func getAndSetFvRsNodeAttAttributes(ctx context.Context, diags *diag.Diagnostics } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvRsNodeAttList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvRsNodeAttList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvRsNodeAttList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvRsNodeAttList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -541,8 +542,9 @@ func getAndSetFvRsNodeAttAttributes(ctx context.Context, diags *diag.Diagnostics ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvRsNodeAttRn(ctx context.Context, data *FvRsNodeAttResourceModel) string { @@ -695,7 +697,6 @@ func getFvRsNodeAttCreateJsonPayload(ctx context.Context, diags *diag.Diagnostic if !data.TDn.IsNull() && !data.TDn.IsUnknown() { payloadMap["attributes"].(map[string]string)["tDn"] = data.TDn.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvRsNodeAtt": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_relation_to_static_leaf_test.go b/internal/provider/resource_aci_relation_to_static_leaf_test.go index a9596ee52..2da93f4eb 100644 --- a/internal/provider/resource_aci_relation_to_static_leaf_test.go +++ b/internal/provider/resource_aci_relation_to_static_leaf_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFvRsNodeAttWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -41,7 +41,7 @@ func TestAccResourceFvRsNodeAttWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -54,7 +54,7 @@ func TestAccResourceFvRsNodeAttWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -80,7 +80,7 @@ func TestAccResourceFvRsNodeAttWithFvAEPg(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -209,6 +209,7 @@ func TestAccResourceFvRsNodeAttWithFvAEPg(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_relation_to_static_path.go b/internal/provider/resource_aci_relation_to_static_path.go index 0e99bd3e7..e2ab3a139 100644 --- a/internal/provider/resource_aci_relation_to_static_path.go +++ b/internal/provider/resource_aci_relation_to_static_path.go @@ -359,6 +359,7 @@ func (r *FvRsPathAttResource) Create(ctx context.Context, req resource.CreateReq } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -473,7 +474,7 @@ func (r *FvRsPathAttResource) ImportState(ctx context.Context, req resource.Impo func getAndSetFvRsPathAttAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsPathAttResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsPathAtt,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvRsPathAttResourceModel() + readData := getEmptyFvRsPathAttResourceModel() if diags.HasError() { return @@ -484,29 +485,29 @@ func getAndSetFvRsPathAttAttributes(ctx context.Context, diags *diag.Diagnostics attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvRsPathAttParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvRsPathAttParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "encap" { - data.Encap = basetypes.NewStringValue(attributeValue.(string)) + readData.Encap = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "instrImedcy" { - data.InstrImedcy = basetypes.NewStringValue(attributeValue.(string)) + readData.InstrImedcy = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "mode" { - data.Mode = basetypes.NewStringValue(attributeValue.(string)) + readData.Mode = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "primaryEncap" { - data.PrimaryEncap = basetypes.NewStringValue(attributeValue.(string)) + readData.PrimaryEncap = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "tDn" { - data.TDn = basetypes.NewStringValue(attributeValue.(string)) + readData.TDn = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvRsPathAttList := make([]TagAnnotationFvRsPathAttResourceModel, 0) @@ -544,10 +545,10 @@ func getAndSetFvRsPathAttAttributes(ctx context.Context, diags *diag.Diagnostics } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvRsPathAttList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvRsPathAttList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvRsPathAttList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvRsPathAttList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -555,8 +556,9 @@ func getAndSetFvRsPathAttAttributes(ctx context.Context, diags *diag.Diagnostics ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvRsPathAttRn(ctx context.Context, data *FvRsPathAttResourceModel) string { @@ -712,7 +714,6 @@ func getFvRsPathAttCreateJsonPayload(ctx context.Context, diags *diag.Diagnostic if !data.TDn.IsNull() && !data.TDn.IsUnknown() { payloadMap["attributes"].(map[string]string)["tDn"] = data.TDn.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvRsPathAtt": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_relation_to_static_path_test.go b/internal/provider/resource_aci_relation_to_static_path_test.go index 00e014ab9..459ce89ee 100644 --- a/internal/provider/resource_aci_relation_to_static_path_test.go +++ b/internal/provider/resource_aci_relation_to_static_path_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFvRsPathAttWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -43,7 +43,7 @@ func TestAccResourceFvRsPathAttWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -56,7 +56,7 @@ func TestAccResourceFvRsPathAttWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -84,7 +84,7 @@ func TestAccResourceFvRsPathAttWithFvAEPg(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -217,6 +217,7 @@ func TestAccResourceFvRsPathAttWithFvAEPg(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_relation_to_taboo_contract.go b/internal/provider/resource_aci_relation_to_taboo_contract.go index e1faf9691..b786c81f3 100644 --- a/internal/provider/resource_aci_relation_to_taboo_contract.go +++ b/internal/provider/resource_aci_relation_to_taboo_contract.go @@ -297,6 +297,7 @@ func (r *FvRsProtByResource) Create(ctx context.Context, req resource.CreateRequ } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -411,7 +412,7 @@ func (r *FvRsProtByResource) ImportState(ctx context.Context, req resource.Impor func getAndSetFvRsProtByAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsProtByResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsProtBy,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvRsProtByResourceModel() + readData := getEmptyFvRsProtByResourceModel() if diags.HasError() { return @@ -422,14 +423,14 @@ func getAndSetFvRsProtByAttributes(ctx context.Context, diags *diag.Diagnostics, attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvRsProtByParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvRsProtByParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "tnVzTabooName" { - data.TnVzTabooName = basetypes.NewStringValue(attributeValue.(string)) + readData.TnVzTabooName = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvRsProtByList := make([]TagAnnotationFvRsProtByResourceModel, 0) @@ -467,10 +468,10 @@ func getAndSetFvRsProtByAttributes(ctx context.Context, diags *diag.Diagnostics, } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvRsProtByList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvRsProtByList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvRsProtByList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvRsProtByList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -478,8 +479,9 @@ func getAndSetFvRsProtByAttributes(ctx context.Context, diags *diag.Diagnostics, ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvRsProtByRn(ctx context.Context, data *FvRsProtByResourceModel) string { @@ -620,7 +622,6 @@ func getFvRsProtByCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics if !data.TnVzTabooName.IsNull() && !data.TnVzTabooName.IsUnknown() { payloadMap["attributes"].(map[string]string)["tnVzTabooName"] = data.TnVzTabooName.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvRsProtBy": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_relation_to_taboo_contract_test.go b/internal/provider/resource_aci_relation_to_taboo_contract_test.go index 12f1629b2..93b3b24a7 100644 --- a/internal/provider/resource_aci_relation_to_taboo_contract_test.go +++ b/internal/provider/resource_aci_relation_to_taboo_contract_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFvRsProtByWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -33,7 +33,7 @@ func TestAccResourceFvRsProtByWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -46,7 +46,7 @@ func TestAccResourceFvRsProtByWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -64,7 +64,7 @@ func TestAccResourceFvRsProtByWithFvAEPg(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -176,6 +176,7 @@ func TestAccResourceFvRsProtByWithFvAEPg(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_relation_to_vrf_fallback_route_group.go b/internal/provider/resource_aci_relation_to_vrf_fallback_route_group.go index 4a76b2499..6b14b3ebd 100644 --- a/internal/provider/resource_aci_relation_to_vrf_fallback_route_group.go +++ b/internal/provider/resource_aci_relation_to_vrf_fallback_route_group.go @@ -297,6 +297,7 @@ func (r *L3extRsOutToFBRGroupResource) Create(ctx context.Context, req resource. } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -411,7 +412,7 @@ func (r *L3extRsOutToFBRGroupResource) ImportState(ctx context.Context, req reso func getAndSetL3extRsOutToFBRGroupAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *L3extRsOutToFBRGroupResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "l3extRsOutToFBRGroup,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyL3extRsOutToFBRGroupResourceModel() + readData := getEmptyL3extRsOutToFBRGroupResourceModel() if diags.HasError() { return @@ -422,14 +423,14 @@ func getAndSetL3extRsOutToFBRGroupAttributes(ctx context.Context, diags *diag.Di attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setL3extRsOutToFBRGroupParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setL3extRsOutToFBRGroupParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "tDn" { - data.TDn = basetypes.NewStringValue(attributeValue.(string)) + readData.TDn = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationL3extRsOutToFBRGroupList := make([]TagAnnotationL3extRsOutToFBRGroupResourceModel, 0) @@ -467,10 +468,10 @@ func getAndSetL3extRsOutToFBRGroupAttributes(ctx context.Context, diags *diag.Di } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationL3extRsOutToFBRGroupList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagL3extRsOutToFBRGroupList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationL3extRsOutToFBRGroupList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagL3extRsOutToFBRGroupList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -478,8 +479,9 @@ func getAndSetL3extRsOutToFBRGroupAttributes(ctx context.Context, diags *diag.Di ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getL3extRsOutToFBRGroupRn(ctx context.Context, data *L3extRsOutToFBRGroupResourceModel) string { @@ -620,7 +622,6 @@ func getL3extRsOutToFBRGroupCreateJsonPayload(ctx context.Context, diags *diag.D if !data.TDn.IsNull() && !data.TDn.IsUnknown() { payloadMap["attributes"].(map[string]string)["tDn"] = data.TDn.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"l3extRsOutToFBRGroup": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_relation_to_vrf_fallback_route_group_test.go b/internal/provider/resource_aci_relation_to_vrf_fallback_route_group_test.go index e9b0ad523..c00f3c123 100644 --- a/internal/provider/resource_aci_relation_to_vrf_fallback_route_group_test.go +++ b/internal/provider/resource_aci_relation_to_vrf_fallback_route_group_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceL3extRsOutToFBRGroupWithL3extOut(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -33,7 +33,7 @@ func TestAccResourceL3extRsOutToFBRGroupWithL3extOut(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -46,7 +46,7 @@ func TestAccResourceL3extRsOutToFBRGroupWithL3extOut(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -64,7 +64,7 @@ func TestAccResourceL3extRsOutToFBRGroupWithL3extOut(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "apic", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -176,6 +176,7 @@ func TestAccResourceL3extRsOutToFBRGroupWithL3extOut(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_rest_managed_test.go b/internal/provider/resource_aci_rest_managed_test.go index 80dc01e33..514fee9fc 100644 --- a/internal/provider/resource_aci_rest_managed_test.go +++ b/internal/provider/resource_aci_rest_managed_test.go @@ -13,7 +13,7 @@ func TestAccAciRestManaged_tenant(t *testing.T) { name := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(7g)") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -52,7 +52,7 @@ func TestAccAciRestManaged_tenant(t *testing.T) { func TestAccAciRestManaged_connPref(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(7g)") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -79,7 +79,7 @@ func TestAccAciRestManaged_connPref(t *testing.T) { func TestAccAciRestManaged_escapeHtml(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(7g)") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -98,7 +98,7 @@ func TestAccAciRestManaged_escapeHtml(t *testing.T) { func TestAccAciRestManaged_noContent(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(7g)") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -116,7 +116,7 @@ func TestAccAciRestManaged_tenantVrf(t *testing.T) { name := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(7g)") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -139,7 +139,7 @@ func TestAccAciRestManaged_import(t *testing.T) { name := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(7g)") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -319,7 +319,7 @@ func TestAccAciRestManaged_importWithIpv6(t *testing.T) { name := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(7g)") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -407,7 +407,7 @@ func TestAccAciRestManaged_importWithBracket(t *testing.T) { name := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(7g)") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -484,7 +484,7 @@ func TestAccAciRestManaged_tagTag(t *testing.T) { name := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(7g)") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -507,7 +507,7 @@ func TestAccAciRestManaged_tenantChildren(t *testing.T) { name := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(7g)") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -548,7 +548,7 @@ func TestAccAciRestManaged_globalAllowExistingOnCreate(t *testing.T) { name := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(7g)") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -564,7 +564,7 @@ func TestAccAciRestManaged_globalAllowExistingOnCreate(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(7g)") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -576,7 +576,7 @@ func TestAccAciRestManaged_globalAllowExistingOnCreate(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(7g)") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -595,7 +595,7 @@ func TestAccAciRestManaged_globalAnnotation(t *testing.T) { name := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(7g)") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -613,7 +613,7 @@ func TestAccAciRestManaged_globalAnnotation(t *testing.T) { setEnvVariable(t, "ACI_ANNOTATION", "orchestrator:from_env") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(7g)") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -678,7 +678,7 @@ func TestAccAciRestManaged_globalAnnotation(t *testing.T) { }) setEnvVariable(t, "ACI_ANNOTATION", "") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(7g)") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -698,7 +698,7 @@ func TestAccAciRestManaged_globalAnnotation(t *testing.T) { func TestAccAciRestManaged_undeletableClass(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(7g)") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -732,7 +732,7 @@ func TestAccAciRestManaged_explicitNull(t *testing.T) { name := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(7g)") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/resource_aci_route_control_profile.go b/internal/provider/resource_aci_route_control_profile.go index 3c0fc69ba..e34abb2dc 100644 --- a/internal/provider/resource_aci_route_control_profile.go +++ b/internal/provider/resource_aci_route_control_profile.go @@ -372,6 +372,7 @@ func (r *RtctrlProfileResource) Create(ctx context.Context, req resource.CreateR } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -486,7 +487,7 @@ func (r *RtctrlProfileResource) ImportState(ctx context.Context, req resource.Im func getAndSetRtctrlProfileAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *RtctrlProfileResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "rtctrlProfile,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyRtctrlProfileResourceModel() + readData := getEmptyRtctrlProfileResourceModel() if diags.HasError() { return @@ -497,32 +498,32 @@ func getAndSetRtctrlProfileAttributes(ctx context.Context, diags *diag.Diagnosti attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setRtctrlProfileParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setRtctrlProfileParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "autoContinue" { - data.AutoContinue = basetypes.NewStringValue(attributeValue.(string)) + readData.AutoContinue = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerKey" { - data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerTag" { - data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "type" { - data.Type = basetypes.NewStringValue(attributeValue.(string)) + readData.Type = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationRtctrlProfileList := make([]TagAnnotationRtctrlProfileResourceModel, 0) @@ -560,10 +561,10 @@ func getAndSetRtctrlProfileAttributes(ctx context.Context, diags *diag.Diagnosti } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationRtctrlProfileList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagRtctrlProfileList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationRtctrlProfileList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagRtctrlProfileList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -571,8 +572,9 @@ func getAndSetRtctrlProfileAttributes(ctx context.Context, diags *diag.Diagnosti ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getRtctrlProfileRn(ctx context.Context, data *RtctrlProfileResourceModel) string { @@ -731,7 +733,6 @@ func getRtctrlProfileCreateJsonPayload(ctx context.Context, diags *diag.Diagnost if !data.Type.IsNull() && !data.Type.IsUnknown() { payloadMap["attributes"].(map[string]string)["type"] = data.Type.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"rtctrlProfile": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_route_control_profile_test.go b/internal/provider/resource_aci_route_control_profile_test.go index 8801e0db9..00f1ec6ce 100644 --- a/internal/provider/resource_aci_route_control_profile_test.go +++ b/internal/provider/resource_aci_route_control_profile_test.go @@ -14,12 +14,12 @@ import ( func TestAccResourceRtctrlProfileWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigRtctrlProfileMinDependencyWithFvTenantAllowExisting, + Config: testConfigRtctrlProfileMinDependencyWithFvTenantAllowExisting + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.allow_test", "name", "test_name"), @@ -36,8 +36,9 @@ func TestAccResourceRtctrlProfileWithFvTenant(t *testing.T) { resource.TestCheckResourceAttr("aci_route_control_profile.allow_test_2", "owner_tag", ""), resource.TestCheckResourceAttr("aci_route_control_profile.allow_test", "route_control_profile_type", "combinable"), resource.TestCheckResourceAttr("aci_route_control_profile.allow_test_2", "route_control_profile_type", "combinable"), - resource.TestCheckResourceAttr("aci_route_control_profile.allow_test", "route_map_continue", "no"), - resource.TestCheckResourceAttr("aci_route_control_profile.allow_test_2", "route_map_continue", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(6d)-4.2(7w),5.1(3e)", ">", + resource.TestCheckResourceAttr("aci_route_control_profile.allow_test", "route_map_continue", "no"), + resource.TestCheckResourceAttr("aci_route_control_profile.allow_test_2", "route_map_continue", "no")), ), }, }, @@ -45,12 +46,12 @@ func TestAccResourceRtctrlProfileWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigRtctrlProfileMinDependencyWithFvTenantAllowExisting, + Config: testConfigRtctrlProfileMinDependencyWithFvTenantAllowExisting + testConfigDataSourceSystem, ExpectError: regexp.MustCompile("Object Already Exists"), }, }, @@ -58,12 +59,12 @@ func TestAccResourceRtctrlProfileWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigRtctrlProfileMinDependencyWithFvTenantAllowExisting, + Config: testConfigRtctrlProfileMinDependencyWithFvTenantAllowExisting + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.allow_test", "name", "test_name"), @@ -80,20 +81,21 @@ func TestAccResourceRtctrlProfileWithFvTenant(t *testing.T) { resource.TestCheckResourceAttr("aci_route_control_profile.allow_test_2", "owner_tag", ""), resource.TestCheckResourceAttr("aci_route_control_profile.allow_test", "route_control_profile_type", "combinable"), resource.TestCheckResourceAttr("aci_route_control_profile.allow_test_2", "route_control_profile_type", "combinable"), - resource.TestCheckResourceAttr("aci_route_control_profile.allow_test", "route_map_continue", "no"), - resource.TestCheckResourceAttr("aci_route_control_profile.allow_test_2", "route_map_continue", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(6d)-4.2(7w),5.1(3e)", ">", + resource.TestCheckResourceAttr("aci_route_control_profile.allow_test", "route_map_continue", "no"), + resource.TestCheckResourceAttr("aci_route_control_profile.allow_test_2", "route_map_continue", "no")), ), }, }, }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigRtctrlProfileMinDependencyWithFvTenant, + Config: testConfigRtctrlProfileMinDependencyWithFvTenant + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.test", "name", "test_name"), @@ -103,12 +105,13 @@ func TestAccResourceRtctrlProfileWithFvTenant(t *testing.T) { resource.TestCheckResourceAttr("aci_route_control_profile.test", "owner_key", ""), resource.TestCheckResourceAttr("aci_route_control_profile.test", "owner_tag", ""), resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_control_profile_type", "combinable"), - resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_map_continue", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(6d)-4.2(7w),5.1(3e)", ">", + resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_map_continue", "no")), ), }, // Update with all config and verify default APIC values { - Config: testConfigRtctrlProfileAllDependencyWithFvTenant, + Config: testConfigRtctrlProfileAllDependencyWithFvTenant + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.test", "name", "test_name"), @@ -118,12 +121,13 @@ func TestAccResourceRtctrlProfileWithFvTenant(t *testing.T) { resource.TestCheckResourceAttr("aci_route_control_profile.test", "owner_key", "owner_key_1"), resource.TestCheckResourceAttr("aci_route_control_profile.test", "owner_tag", "owner_tag_1"), resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_control_profile_type", "combinable"), - resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_map_continue", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(6d)-4.2(7w),5.1(3e)", ">", + resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_map_continue", "no")), ), }, // Update with minimum config and verify config is unchanged { - Config: testConfigRtctrlProfileMinDependencyWithFvTenant, + Config: testConfigRtctrlProfileMinDependencyWithFvTenant + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.test", "name", "test_name"), @@ -131,7 +135,7 @@ func TestAccResourceRtctrlProfileWithFvTenant(t *testing.T) { }, // Update with empty strings config or default value { - Config: testConfigRtctrlProfileResetDependencyWithFvTenant, + Config: testConfigRtctrlProfileResetDependencyWithFvTenant + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.test", "name", "test_name"), @@ -141,7 +145,8 @@ func TestAccResourceRtctrlProfileWithFvTenant(t *testing.T) { resource.TestCheckResourceAttr("aci_route_control_profile.test", "owner_key", ""), resource.TestCheckResourceAttr("aci_route_control_profile.test", "owner_tag", ""), resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_control_profile_type", "combinable"), - resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_map_continue", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(6d)-4.2(7w),5.1(3e)", ">", + resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_map_continue", "no")), ), }, // Import testing @@ -152,7 +157,7 @@ func TestAccResourceRtctrlProfileWithFvTenant(t *testing.T) { }, // Update with children { - Config: testConfigRtctrlProfileChildrenDependencyWithFvTenant, + Config: testConfigRtctrlProfileChildrenDependencyWithFvTenant + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.test", "name", "test_name"), @@ -162,7 +167,8 @@ func TestAccResourceRtctrlProfileWithFvTenant(t *testing.T) { resource.TestCheckResourceAttr("aci_route_control_profile.test", "owner_key", ""), resource.TestCheckResourceAttr("aci_route_control_profile.test", "owner_tag", ""), resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_control_profile_type", "combinable"), - resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_map_continue", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(6d)-4.2(7w),5.1(3e)", ">", + resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_map_continue", "no")), resource.TestCheckResourceAttr("aci_route_control_profile.test", "annotations.0.key", "key_0"), resource.TestCheckResourceAttr("aci_route_control_profile.test", "annotations.0.value", "value_1"), resource.TestCheckResourceAttr("aci_route_control_profile.test", "annotations.1.key", "key_1"), @@ -186,7 +192,7 @@ func TestAccResourceRtctrlProfileWithFvTenant(t *testing.T) { }, // Update with children removed from config { - Config: testConfigRtctrlProfileChildrenRemoveFromConfigDependencyWithFvTenant, + Config: testConfigRtctrlProfileChildrenRemoveFromConfigDependencyWithFvTenant + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.test", "annotations.0.key", "key_0"), @@ -203,7 +209,7 @@ func TestAccResourceRtctrlProfileWithFvTenant(t *testing.T) { }, // Update with children first child removed { - Config: testConfigRtctrlProfileChildrenRemoveOneDependencyWithFvTenant, + Config: testConfigRtctrlProfileChildrenRemoveOneDependencyWithFvTenant + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.test", "annotations.0.key", "key_1"), @@ -216,7 +222,7 @@ func TestAccResourceRtctrlProfileWithFvTenant(t *testing.T) { }, // Update with all children removed { - Config: testConfigRtctrlProfileChildrenRemoveAllDependencyWithFvTenant, + Config: testConfigRtctrlProfileChildrenRemoveAllDependencyWithFvTenant + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.test", "annotations.#", "0"), @@ -224,17 +230,18 @@ func TestAccResourceRtctrlProfileWithFvTenant(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } func TestAccResourceRtctrlProfileWithL3extOut(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigRtctrlProfileMinDependencyWithL3extOutAllowExisting, + Config: testConfigRtctrlProfileMinDependencyWithL3extOutAllowExisting + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.allow_test", "name", "test_name"), @@ -251,8 +258,9 @@ func TestAccResourceRtctrlProfileWithL3extOut(t *testing.T) { resource.TestCheckResourceAttr("aci_route_control_profile.allow_test_2", "owner_tag", ""), resource.TestCheckResourceAttr("aci_route_control_profile.allow_test", "route_control_profile_type", "combinable"), resource.TestCheckResourceAttr("aci_route_control_profile.allow_test_2", "route_control_profile_type", "combinable"), - resource.TestCheckResourceAttr("aci_route_control_profile.allow_test", "route_map_continue", "no"), - resource.TestCheckResourceAttr("aci_route_control_profile.allow_test_2", "route_map_continue", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(6d)-4.2(7w),5.1(3e)", ">", + resource.TestCheckResourceAttr("aci_route_control_profile.allow_test", "route_map_continue", "no"), + resource.TestCheckResourceAttr("aci_route_control_profile.allow_test_2", "route_map_continue", "no")), ), }, }, @@ -260,12 +268,12 @@ func TestAccResourceRtctrlProfileWithL3extOut(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigRtctrlProfileMinDependencyWithL3extOutAllowExisting, + Config: testConfigRtctrlProfileMinDependencyWithL3extOutAllowExisting + testConfigDataSourceSystem, ExpectError: regexp.MustCompile("Object Already Exists"), }, }, @@ -273,12 +281,12 @@ func TestAccResourceRtctrlProfileWithL3extOut(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigRtctrlProfileMinDependencyWithL3extOutAllowExisting, + Config: testConfigRtctrlProfileMinDependencyWithL3extOutAllowExisting + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.allow_test", "name", "test_name"), @@ -295,20 +303,21 @@ func TestAccResourceRtctrlProfileWithL3extOut(t *testing.T) { resource.TestCheckResourceAttr("aci_route_control_profile.allow_test_2", "owner_tag", ""), resource.TestCheckResourceAttr("aci_route_control_profile.allow_test", "route_control_profile_type", "combinable"), resource.TestCheckResourceAttr("aci_route_control_profile.allow_test_2", "route_control_profile_type", "combinable"), - resource.TestCheckResourceAttr("aci_route_control_profile.allow_test", "route_map_continue", "no"), - resource.TestCheckResourceAttr("aci_route_control_profile.allow_test_2", "route_map_continue", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(6d)-4.2(7w),5.1(3e)", ">", + resource.TestCheckResourceAttr("aci_route_control_profile.allow_test", "route_map_continue", "no"), + resource.TestCheckResourceAttr("aci_route_control_profile.allow_test_2", "route_map_continue", "no")), ), }, }, }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "1.0(1e)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values { - Config: testConfigRtctrlProfileMinDependencyWithL3extOut, + Config: testConfigRtctrlProfileMinDependencyWithL3extOut + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.test", "name", "test_name"), @@ -318,12 +327,13 @@ func TestAccResourceRtctrlProfileWithL3extOut(t *testing.T) { resource.TestCheckResourceAttr("aci_route_control_profile.test", "owner_key", ""), resource.TestCheckResourceAttr("aci_route_control_profile.test", "owner_tag", ""), resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_control_profile_type", "combinable"), - resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_map_continue", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(6d)-4.2(7w),5.1(3e)", ">", + resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_map_continue", "no")), ), }, // Update with all config and verify default APIC values { - Config: testConfigRtctrlProfileAllDependencyWithL3extOut, + Config: testConfigRtctrlProfileAllDependencyWithL3extOut + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.test", "name", "test_name"), @@ -333,12 +343,13 @@ func TestAccResourceRtctrlProfileWithL3extOut(t *testing.T) { resource.TestCheckResourceAttr("aci_route_control_profile.test", "owner_key", "owner_key_1"), resource.TestCheckResourceAttr("aci_route_control_profile.test", "owner_tag", "owner_tag_1"), resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_control_profile_type", "combinable"), - resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_map_continue", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(6d)-4.2(7w),5.1(3e)", ">", + resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_map_continue", "no")), ), }, // Update with minimum config and verify config is unchanged { - Config: testConfigRtctrlProfileMinDependencyWithL3extOut, + Config: testConfigRtctrlProfileMinDependencyWithL3extOut + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.test", "name", "test_name"), @@ -346,7 +357,7 @@ func TestAccResourceRtctrlProfileWithL3extOut(t *testing.T) { }, // Update with empty strings config or default value { - Config: testConfigRtctrlProfileResetDependencyWithL3extOut, + Config: testConfigRtctrlProfileResetDependencyWithL3extOut + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.test", "name", "test_name"), @@ -356,7 +367,8 @@ func TestAccResourceRtctrlProfileWithL3extOut(t *testing.T) { resource.TestCheckResourceAttr("aci_route_control_profile.test", "owner_key", ""), resource.TestCheckResourceAttr("aci_route_control_profile.test", "owner_tag", ""), resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_control_profile_type", "combinable"), - resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_map_continue", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(6d)-4.2(7w),5.1(3e)", ">", + resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_map_continue", "no")), ), }, // Import testing @@ -367,7 +379,7 @@ func TestAccResourceRtctrlProfileWithL3extOut(t *testing.T) { }, // Update with children { - Config: testConfigRtctrlProfileChildrenDependencyWithL3extOut, + Config: testConfigRtctrlProfileChildrenDependencyWithL3extOut + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.test", "name", "test_name"), @@ -377,7 +389,8 @@ func TestAccResourceRtctrlProfileWithL3extOut(t *testing.T) { resource.TestCheckResourceAttr("aci_route_control_profile.test", "owner_key", ""), resource.TestCheckResourceAttr("aci_route_control_profile.test", "owner_tag", ""), resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_control_profile_type", "combinable"), - resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_map_continue", "no"), + composeAggregateTestCheckFuncWithVersion(t, "4.2(6d)-4.2(7w),5.1(3e)", ">", + resource.TestCheckResourceAttr("aci_route_control_profile.test", "route_map_continue", "no")), resource.TestCheckResourceAttr("aci_route_control_profile.test", "annotations.0.key", "key_0"), resource.TestCheckResourceAttr("aci_route_control_profile.test", "annotations.0.value", "value_1"), resource.TestCheckResourceAttr("aci_route_control_profile.test", "annotations.1.key", "key_1"), @@ -401,7 +414,7 @@ func TestAccResourceRtctrlProfileWithL3extOut(t *testing.T) { }, // Update with children removed from config { - Config: testConfigRtctrlProfileChildrenRemoveFromConfigDependencyWithL3extOut, + Config: testConfigRtctrlProfileChildrenRemoveFromConfigDependencyWithL3extOut + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.test", "annotations.0.key", "key_0"), @@ -418,7 +431,7 @@ func TestAccResourceRtctrlProfileWithL3extOut(t *testing.T) { }, // Update with children first child removed { - Config: testConfigRtctrlProfileChildrenRemoveOneDependencyWithL3extOut, + Config: testConfigRtctrlProfileChildrenRemoveOneDependencyWithL3extOut + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.test", "annotations.0.key", "key_1"), @@ -431,7 +444,7 @@ func TestAccResourceRtctrlProfileWithL3extOut(t *testing.T) { }, // Update with all children removed { - Config: testConfigRtctrlProfileChildrenRemoveAllDependencyWithL3extOut, + Config: testConfigRtctrlProfileChildrenRemoveAllDependencyWithL3extOut + testConfigDataSourceSystem, ExpectNonEmptyPlan: false, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("aci_route_control_profile.test", "annotations.#", "0"), @@ -439,6 +452,7 @@ func TestAccResourceRtctrlProfileWithL3extOut(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } @@ -471,7 +485,7 @@ resource "aci_route_control_profile" "test" { owner_key = "owner_key_1" owner_tag = "owner_tag_1" route_control_profile_type = "combinable" - route_map_continue = "no" + route_map_continue = provider::aci::compare_versions(data.aci_system.version.version,">=","4.2(6d)-4.2(7w),5.1(3e)") ? "no" : null } ` @@ -485,7 +499,7 @@ resource "aci_route_control_profile" "test" { owner_key = "" owner_tag = "" route_control_profile_type = "combinable" - route_map_continue = "no" + route_map_continue = provider::aci::compare_versions(data.aci_system.version.version,">=","4.2(6d)-4.2(7w),5.1(3e)") ? "no" : null } ` const testConfigRtctrlProfileChildrenDependencyWithFvTenant = testConfigFvTenantMin + ` @@ -579,7 +593,7 @@ resource "aci_route_control_profile" "test" { owner_key = "owner_key_1" owner_tag = "owner_tag_1" route_control_profile_type = "combinable" - route_map_continue = "no" + route_map_continue = provider::aci::compare_versions(data.aci_system.version.version,">=","4.2(6d)-4.2(7w),5.1(3e)") ? "no" : null } ` @@ -593,7 +607,7 @@ resource "aci_route_control_profile" "test" { owner_key = "" owner_tag = "" route_control_profile_type = "combinable" - route_map_continue = "no" + route_map_continue = provider::aci::compare_versions(data.aci_system.version.version,">=","4.2(6d)-4.2(7w),5.1(3e)") ? "no" : null } ` const testConfigRtctrlProfileChildrenDependencyWithL3extOut = testConfigL3extOutMin + ` diff --git a/internal/provider/resource_aci_tag.go b/internal/provider/resource_aci_tag.go index 2b554bd86..d7fac2e88 100644 --- a/internal/provider/resource_aci_tag.go +++ b/internal/provider/resource_aci_tag.go @@ -181,6 +181,7 @@ func (r *TagTagResource) Create(ctx context.Context, req resource.CreateRequest, } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -287,7 +288,7 @@ func (r *TagTagResource) ImportState(ctx context.Context, req resource.ImportSta func getAndSetTagTagAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *TagTagResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "GET", nil) - *data = *getEmptyTagTagResourceModel() + readData := getEmptyTagTagResourceModel() if diags.HasError() { return @@ -298,14 +299,14 @@ func getAndSetTagTagAttributes(ctx context.Context, diags *diag.Diagnostics, cli attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setTagTagParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setTagTagParentDn(ctx, attributeValue.(string), readData) } if attributeName == "key" { - data.Key = basetypes.NewStringValue(attributeValue.(string)) + readData.Key = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "value" { - data.Value = basetypes.NewStringValue(attributeValue.(string)) + readData.Value = basetypes.NewStringValue(attributeValue.(string)) } } } else { @@ -315,8 +316,9 @@ func getAndSetTagTagAttributes(ctx context.Context, diags *diag.Diagnostics, cli ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getTagTagRn(ctx context.Context, data *TagTagResourceModel) string { @@ -363,7 +365,6 @@ func getTagTagCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, cr if !data.Value.IsNull() && !data.Value.IsUnknown() { payloadMap["attributes"].(map[string]string)["value"] = data.Value.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"tagTag": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_tag_test.go b/internal/provider/resource_aci_tag_test.go index 61ee020fe..da7089115 100644 --- a/internal/provider/resource_aci_tag_test.go +++ b/internal/provider/resource_aci_tag_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceTagTagWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -33,7 +33,7 @@ func TestAccResourceTagTagWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -46,7 +46,7 @@ func TestAccResourceTagTagWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -64,7 +64,7 @@ func TestAccResourceTagTagWithFvTenant(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -110,12 +110,13 @@ func TestAccResourceTagTagWithFvTenant(t *testing.T) { ImportStateVerify: true, }, }, + CheckDestroy: testCheckResourceDestroy, }) } func TestAccResourceTagTagWithFvAEPg(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -134,7 +135,7 @@ func TestAccResourceTagTagWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -147,7 +148,7 @@ func TestAccResourceTagTagWithFvAEPg(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -165,7 +166,7 @@ func TestAccResourceTagTagWithFvAEPg(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.2(1l)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -211,6 +212,7 @@ func TestAccResourceTagTagWithFvAEPg(t *testing.T) { ImportStateVerify: true, }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_trust_control_policy.go b/internal/provider/resource_aci_trust_control_policy.go index 95de08d92..d346d8f86 100644 --- a/internal/provider/resource_aci_trust_control_policy.go +++ b/internal/provider/resource_aci_trust_control_policy.go @@ -427,6 +427,7 @@ func (r *FhsTrustCtrlPolResource) Create(ctx context.Context, req resource.Creat } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -541,7 +542,7 @@ func (r *FhsTrustCtrlPolResource) ImportState(ctx context.Context, req resource. func getAndSetFhsTrustCtrlPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FhsTrustCtrlPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fhsTrustCtrlPol,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFhsTrustCtrlPolResourceModel() + readData := getEmptyFhsTrustCtrlPolResourceModel() if diags.HasError() { return @@ -552,44 +553,44 @@ func getAndSetFhsTrustCtrlPolAttributes(ctx context.Context, diags *diag.Diagnos attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFhsTrustCtrlPolParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFhsTrustCtrlPolParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "hasDhcpv4Server" { - data.HasDhcpv4Server = basetypes.NewStringValue(attributeValue.(string)) + readData.HasDhcpv4Server = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "hasDhcpv6Server" { - data.HasDhcpv6Server = basetypes.NewStringValue(attributeValue.(string)) + readData.HasDhcpv6Server = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "hasIpv6Router" { - data.HasIpv6Router = basetypes.NewStringValue(attributeValue.(string)) + readData.HasIpv6Router = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerKey" { - data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "ownerTag" { - data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "trustArp" { - data.TrustArp = basetypes.NewStringValue(attributeValue.(string)) + readData.TrustArp = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "trustNd" { - data.TrustNd = basetypes.NewStringValue(attributeValue.(string)) + readData.TrustNd = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "trustRa" { - data.TrustRa = basetypes.NewStringValue(attributeValue.(string)) + readData.TrustRa = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFhsTrustCtrlPolList := make([]TagAnnotationFhsTrustCtrlPolResourceModel, 0) @@ -627,10 +628,10 @@ func getAndSetFhsTrustCtrlPolAttributes(ctx context.Context, diags *diag.Diagnos } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFhsTrustCtrlPolList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFhsTrustCtrlPolList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFhsTrustCtrlPolList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFhsTrustCtrlPolList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -638,8 +639,9 @@ func getAndSetFhsTrustCtrlPolAttributes(ctx context.Context, diags *diag.Diagnos ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFhsTrustCtrlPolRn(ctx context.Context, data *FhsTrustCtrlPolResourceModel) string { @@ -810,7 +812,6 @@ func getFhsTrustCtrlPolCreateJsonPayload(ctx context.Context, diags *diag.Diagno if !data.TrustRa.IsNull() && !data.TrustRa.IsUnknown() { payloadMap["attributes"].(map[string]string)["trustRa"] = data.TrustRa.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fhsTrustCtrlPol": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_trust_control_policy_test.go b/internal/provider/resource_aci_trust_control_policy_test.go index f36bc1a29..82a14fe11 100644 --- a/internal/provider/resource_aci_trust_control_policy_test.go +++ b/internal/provider/resource_aci_trust_control_policy_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFhsTrustCtrlPolWithFvTenant(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -53,7 +53,7 @@ func TestAccResourceFhsTrustCtrlPolWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -66,7 +66,7 @@ func TestAccResourceFhsTrustCtrlPolWithFvTenant(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -104,7 +104,7 @@ func TestAccResourceFhsTrustCtrlPolWithFvTenant(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "3.0(1k)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -256,6 +256,7 @@ func TestAccResourceFhsTrustCtrlPolWithFvTenant(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_vrf_fallback_route.go b/internal/provider/resource_aci_vrf_fallback_route.go index 7c0136f42..95aeaf60c 100644 --- a/internal/provider/resource_aci_vrf_fallback_route.go +++ b/internal/provider/resource_aci_vrf_fallback_route.go @@ -330,6 +330,7 @@ func (r *FvFBRouteResource) Create(ctx context.Context, req resource.CreateReque } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -444,7 +445,7 @@ func (r *FvFBRouteResource) ImportState(ctx context.Context, req resource.Import func getAndSetFvFBRouteAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvFBRouteResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvFBRoute,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvFBRouteResourceModel() + readData := getEmptyFvFBRouteResourceModel() if diags.HasError() { return @@ -455,23 +456,23 @@ func getAndSetFvFBRouteAttributes(ctx context.Context, diags *diag.Diagnostics, attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvFBRouteParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvFBRouteParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "fbrPrefix" { - data.FbrPrefix = basetypes.NewStringValue(attributeValue.(string)) + readData.FbrPrefix = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvFBRouteList := make([]TagAnnotationFvFBRouteResourceModel, 0) @@ -509,10 +510,10 @@ func getAndSetFvFBRouteAttributes(ctx context.Context, diags *diag.Diagnostics, } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvFBRouteList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvFBRouteList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvFBRouteList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvFBRouteList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -520,8 +521,9 @@ func getAndSetFvFBRouteAttributes(ctx context.Context, diags *diag.Diagnostics, ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvFBRouteRn(ctx context.Context, data *FvFBRouteResourceModel) string { @@ -671,7 +673,6 @@ func getFvFBRouteCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, if !data.NameAlias.IsNull() && !data.NameAlias.IsUnknown() { payloadMap["attributes"].(map[string]string)["nameAlias"] = data.NameAlias.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvFBRoute": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_vrf_fallback_route_group.go b/internal/provider/resource_aci_vrf_fallback_route_group.go index 61b23eb91..a441674fa 100644 --- a/internal/provider/resource_aci_vrf_fallback_route_group.go +++ b/internal/provider/resource_aci_vrf_fallback_route_group.go @@ -502,6 +502,7 @@ func (r *FvFBRGroupResource) Create(ctx context.Context, req resource.CreateRequ } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -622,7 +623,7 @@ func (r *FvFBRGroupResource) ImportState(ctx context.Context, req resource.Impor func getAndSetFvFBRGroupAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvFBRGroupResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvFBRGroup,fvFBRMember,fvFBRoute,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvFBRGroupResourceModel() + readData := getEmptyFvFBRGroupResourceModel() if diags.HasError() { return @@ -633,20 +634,20 @@ func getAndSetFvFBRGroupAttributes(ctx context.Context, diags *diag.Diagnostics, attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvFBRGroupParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvFBRGroupParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } } FvFBRMemberFvFBRGroupList := make([]FvFBRMemberFvFBRGroupResourceModel, 0) @@ -728,19 +729,19 @@ func getAndSetFvFBRGroupAttributes(ctx context.Context, diags *diag.Diagnostics, } } } - fvFBRMemberSet, _ := types.SetValueFrom(ctx, data.FvFBRMember.ElementType(ctx), FvFBRMemberFvFBRGroupList) - data.FvFBRMember = fvFBRMemberSet + fvFBRMemberSet, _ := types.SetValueFrom(ctx, readData.FvFBRMember.ElementType(ctx), FvFBRMemberFvFBRGroupList) + readData.FvFBRMember = fvFBRMemberSet if len(FvFBRouteFvFBRGroupList) == 1 { fvFBRouteObject, _ := types.ObjectValueFrom(ctx, FvFBRouteFvFBRGroupType, FvFBRouteFvFBRGroupList[0]) - data.FvFBRoute = fvFBRouteObject + readData.FvFBRoute = fvFBRouteObject } else { fvFBRouteObject, _ := types.ObjectValueFrom(ctx, FvFBRouteFvFBRGroupType, getEmptyFvFBRouteFvFBRGroupResourceModel()) - data.FvFBRoute = fvFBRouteObject + readData.FvFBRoute = fvFBRouteObject } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvFBRGroupList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvFBRGroupList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvFBRGroupList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvFBRGroupList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -748,8 +749,9 @@ func getAndSetFvFBRGroupAttributes(ctx context.Context, diags *diag.Diagnostics, ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvFBRGroupRn(ctx context.Context, data *FvFBRGroupResourceModel) string { @@ -993,7 +995,6 @@ func getFvFBRGroupCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics if !data.NameAlias.IsNull() && !data.NameAlias.IsUnknown() { payloadMap["attributes"].(map[string]string)["nameAlias"] = data.NameAlias.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvFBRGroup": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_vrf_fallback_route_group_member.go b/internal/provider/resource_aci_vrf_fallback_route_group_member.go index fa6e2291a..d70c6bc3c 100644 --- a/internal/provider/resource_aci_vrf_fallback_route_group_member.go +++ b/internal/provider/resource_aci_vrf_fallback_route_group_member.go @@ -330,6 +330,7 @@ func (r *FvFBRMemberResource) Create(ctx context.Context, req resource.CreateReq } DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { return } @@ -444,7 +445,7 @@ func (r *FvFBRMemberResource) ImportState(ctx context.Context, req resource.Impo func getAndSetFvFBRMemberAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvFBRMemberResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "fvFBRMember,tagAnnotation,tagTag"), "GET", nil) - *data = *getEmptyFvFBRMemberResourceModel() + readData := getEmptyFvFBRMemberResourceModel() if diags.HasError() { return @@ -455,23 +456,23 @@ func getAndSetFvFBRMemberAttributes(ctx context.Context, diags *diag.Diagnostics attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) for attributeName, attributeValue := range attributes { if attributeName == "dn" { - data.Id = basetypes.NewStringValue(attributeValue.(string)) - setFvFBRMemberParentDn(ctx, attributeValue.(string), data) + readData.Id = basetypes.NewStringValue(attributeValue.(string)) + setFvFBRMemberParentDn(ctx, attributeValue.(string), readData) } if attributeName == "annotation" { - data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + readData.Annotation = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "descr" { - data.Descr = basetypes.NewStringValue(attributeValue.(string)) + readData.Descr = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "name" { - data.Name = basetypes.NewStringValue(attributeValue.(string)) + readData.Name = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "nameAlias" { - data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + readData.NameAlias = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "rnhAddr" { - data.RnhAddr = basetypes.NewStringValue(attributeValue.(string)) + readData.RnhAddr = basetypes.NewStringValue(attributeValue.(string)) } } TagAnnotationFvFBRMemberList := make([]TagAnnotationFvFBRMemberResourceModel, 0) @@ -509,10 +510,10 @@ func getAndSetFvFBRMemberAttributes(ctx context.Context, diags *diag.Diagnostics } } } - tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationFvFBRMemberList) - data.TagAnnotation = tagAnnotationSet - tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagFvFBRMemberList) - data.TagTag = tagTagSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvFBRMemberList) + readData.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvFBRMemberList) + readData.TagTag = tagTagSet } else { diags.AddError( "too many results in response", @@ -520,8 +521,9 @@ func getAndSetFvFBRMemberAttributes(ctx context.Context, diags *diag.Diagnostics ) } } else { - data.Id = basetypes.NewStringNull() + readData.Id = basetypes.NewStringNull() } + *data = *readData } func getFvFBRMemberRn(ctx context.Context, data *FvFBRMemberResourceModel) string { @@ -671,7 +673,6 @@ func getFvFBRMemberCreateJsonPayload(ctx context.Context, diags *diag.Diagnostic if !data.RnhAddr.IsNull() && !data.RnhAddr.IsUnknown() { payloadMap["attributes"].(map[string]string)["rnhAddr"] = data.RnhAddr.ValueString() } - payload, err := json.Marshal(map[string]interface{}{"fvFBRMember": payloadMap}) if err != nil { diags.AddError( diff --git a/internal/provider/resource_aci_vrf_fallback_route_group_member_test.go b/internal/provider/resource_aci_vrf_fallback_route_group_member_test.go index 0aaa31895..c7b0ea3dd 100644 --- a/internal/provider/resource_aci_vrf_fallback_route_group_member_test.go +++ b/internal/provider/resource_aci_vrf_fallback_route_group_member_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFvFBRMemberWithFvFBRGroup(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -39,7 +39,7 @@ func TestAccResourceFvFBRMemberWithFvFBRGroup(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -52,7 +52,7 @@ func TestAccResourceFvFBRMemberWithFvFBRGroup(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -76,7 +76,7 @@ func TestAccResourceFvFBRMemberWithFvFBRGroup(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -200,6 +200,7 @@ func TestAccResourceFvFBRMemberWithFvFBRGroup(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_vrf_fallback_route_group_test.go b/internal/provider/resource_aci_vrf_fallback_route_group_test.go index 882c47906..7d5a2333d 100644 --- a/internal/provider/resource_aci_vrf_fallback_route_group_test.go +++ b/internal/provider/resource_aci_vrf_fallback_route_group_test.go @@ -17,7 +17,7 @@ import ( func TestAccResourceFvFBRGroupWithFvCtx(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -40,7 +40,7 @@ func TestAccResourceFvFBRGroupWithFvCtx(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -53,7 +53,7 @@ func TestAccResourceFvFBRGroupWithFvCtx(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -75,7 +75,7 @@ func TestAccResourceFvFBRGroupWithFvCtx(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -261,6 +261,7 @@ func TestAccResourceFvFBRGroupWithFvCtx(t *testing.T) { }, }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/resource_aci_vrf_fallback_route_test.go b/internal/provider/resource_aci_vrf_fallback_route_test.go index e9002a29e..c45240878 100644 --- a/internal/provider/resource_aci_vrf_fallback_route_test.go +++ b/internal/provider/resource_aci_vrf_fallback_route_test.go @@ -14,7 +14,7 @@ import ( func TestAccResourceFvFBRouteWithFvFBRGroup(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -39,7 +39,7 @@ func TestAccResourceFvFBRouteWithFvFBRGroup(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -52,7 +52,7 @@ func TestAccResourceFvFBRouteWithFvFBRGroup(t *testing.T) { setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -76,7 +76,7 @@ func TestAccResourceFvFBRouteWithFvFBRGroup(t *testing.T) { }) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t, "both", "5.2(4d)-") }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create with minimum config and verify default APIC values @@ -200,6 +200,7 @@ func TestAccResourceFvFBRouteWithFvFBRGroup(t *testing.T) { ), }, }, + CheckDestroy: testCheckResourceDestroy, }) } diff --git a/internal/provider/test_constants.go b/internal/provider/test_constants.go index 5383a2867..8aae53f30 100644 --- a/internal/provider/test_constants.go +++ b/internal/provider/test_constants.go @@ -4,7 +4,6 @@ const testConfigFvTenantMin = ` resource "aci_tenant" "test" { name = "test_tenant" } - ` const testConfigL3extOutMin = testConfigFvTenantMin + ` @@ -95,3 +94,55 @@ resource "aci_l3out_loopback_interface_profile" "test" { addr = "1.2.3.5" } ` + +const testConfigFvTenantMinDependencyWithPkiTP = testConfigFvTenantMin + ` +resource "aci_certificate_authority" "test" { + parent_dn = aci_tenant.test.id + certificate_chain = <