From 373ba7d3a38e92872882d3586de8cdd2bcb1d33a Mon Sep 17 00:00:00 2001 From: Rutvik Shiyani <88027613+RutvikS-crest@users.noreply.github.com> Date: Fri, 31 Dec 2021 15:47:22 +0530 Subject: [PATCH] S2 dev (#67) Added Test files for following resources along with minor fixes for following resource. aci_vrf aci_contract aci_contract_subject aci_filter aci_epg_to_static_path aci_any aci_epg_to_contract aci_epg_to_domain aci_endpoint_security_group_selector aci_endpoint_security_group aci_imported_contract aci_l3_outside aci_external_network_instance_profile aci_logical_node_profile aci_logical_interface_profile aci_l3_ext_subnet aci_l3out_ospf_interface_profile aci_hsrp_interface_policy aci_bgp_route_control_profile aci_l3out_hsrp_interface_group aci_l3out_floating_svi aci_l3out_hsrp_secondary_vip aci_l3out_bfd_interface_profile aci_l3out_hsrp_interface_profile aci_l3out_route_tag_policy aci_taboo_contract aci_aaa_domain --- aci/data_source_aci_fvrsprovcons.go | 20 +- aci/provider.go | 6 +- aci/resource_aci_aaadomain_test.go | 141 -- aci/resource_aci_bfdifp.go | 2 + aci/resource_aci_bfdifp_test.go | 143 -- aci/resource_aci_fvaepg.go | 4 +- aci/resource_aci_fvaepg_test.go | 196 --- aci/resource_aci_fvap.go | 2 +- aci/resource_aci_fvap_test.go | 155 -- aci/resource_aci_fvbd.go | 10 +- aci/resource_aci_fvbd_test.go | 235 --- aci/resource_aci_fvctx.go | 25 +- aci/resource_aci_fvctx_test.go | 172 --- aci/resource_aci_fvepselector.go | 1 + aci/resource_aci_fvepselector_test.go | 120 -- aci/resource_aci_fvesg.go | 1 + aci/resource_aci_fvesg_test.go | 112 -- aci/resource_aci_fvrsdomatt_test.go | 136 -- aci/resource_aci_fvrspathatt.go | 2 +- aci/resource_aci_fvrspathatt_test.go | 161 -- aci/resource_aci_fvrsprovcons.go | 22 +- aci/resource_aci_fvrsprovcons_test.go | 157 -- aci/resource_aci_fvsubnet.go | 5 + aci/resource_aci_fvsubnet_test.go | 162 -- aci/resource_aci_fvtenant.go | 2 +- aci/resource_aci_fvtenant_test.go | 140 -- aci/resource_aci_hsrpgroupp.go | 2 +- aci/resource_aci_hsrpgroupp_test.go | 176 --- aci/resource_aci_hsrpifp.go | 4 +- aci/resource_aci_hsrpifp_test.go | 141 -- aci/resource_aci_hsrpifpol.go | 34 +- aci/resource_aci_hsrpifpol_test.go | 157 -- aci/resource_aci_hsrpsecvip_test.go | 147 -- aci/resource_aci_l3extinstp.go | 8 +- aci/resource_aci_l3extinstp_test.go | 182 --- aci/resource_aci_l3extlifp.go | 10 +- aci/resource_aci_l3extlifp_test.go | 153 -- aci/resource_aci_l3extlnodep_test.go | 154 -- aci/resource_aci_l3extout.go | 10 +- aci/resource_aci_l3extout_test.go | 153 -- aci/resource_aci_l3extroutetagpol_test.go | 146 -- aci/resource_aci_l3extrsnodel3outatt.go | 2 + aci/resource_aci_l3extsubnet.go | 8 + aci/resource_aci_l3extsubnet_test.go | 149 -- aci/resource_aci_l3extvirtuallifp.go | 2 +- aci/resource_aci_l3extvirtuallifp_test.go | 192 --- aci/resource_aci_ospfifp.go | 4 +- aci/resource_aci_ospfifp_test.go | 148 -- aci/resource_aci_rtctrlprofile.go | 1 + aci/resource_aci_rtctrlprofile_test.go | 160 -- aci/resource_aci_vzany_test.go | 152 -- aci/resource_aci_vzbrcp.go | 22 +- aci/resource_aci_vzcpif.go | 2 + aci/resource_aci_vzcpif_test.go | 144 -- aci/resource_aci_vzfilter_test.go | 143 -- aci/resource_aci_vzsubj_test.go | 168 -- aci/resource_aci_vztaboo_test.go | 147 -- aci/utils.go | 2 +- go.mod | 2 +- go.sum | 4 +- testacc/data_source_aci_aaadomain_test.go | 137 ++ testacc/data_source_aci_bfdifp_test.go | 238 +++ testacc/data_source_aci_fvaepg_test.go | 8 +- testacc/data_source_aci_fvany_test.go | 159 ++ testacc/data_source_aci_fvap_test.go | 14 +- testacc/data_source_aci_fvbd_test.go | 8 +- ..._test.go => data_source_aci_fvctx_test.go} | 8 +- testacc/data_source_aci_fvepselector_test.go | 229 +++ testacc/data_source_aci_fvesg_test.go | 198 +++ testacc/data_source_aci_fvrsdomatt_test.go | 287 ++++ testacc/data_source_aci_fvrspathatt_test.go | 220 +++ testacc/data_source_aci_fvrsprovcons_test.go | 308 ++++ testacc/data_source_aci_fvsubnet_test.go | 8 +- ...st.go => data_source_aci_fvtenant_test.go} | 8 +- testacc/data_source_aci_hsrpgroupp_test.go | 282 ++++ testacc/data_source_aci_hsrpifp_test.go | 254 +++ testacc/data_source_aci_hsrpifpol_test.go | 181 +++ testacc/data_source_aci_hsrpsecvip_test.go | 299 ++++ testacc/data_source_aci_l3extOut_test.go | 194 +++ testacc/data_source_aci_l3extinstp_test.go | 197 +++ testacc/data_source_aci_l3extlifp_test.go | 266 ++++ testacc/data_source_aci_l3extlnodep_test.go | 185 +++ .../data_source_aci_l3extloopbackifp_test.go | 234 +++ .../data_source_aci_l3extroutetagpol_test.go | 193 +++ testacc/data_source_aci_l3extsubnet_test.go | 231 +++ .../data_source_aci_l3extvirtuallifp_test.go | 403 +++++ testacc/data_source_aci_ospfifp_test.go | 295 ++++ testacc/data_source_aci_rtctrlprofile_test.go | 201 +++ testacc/data_source_aci_vzFilter_test.go | 32 +- testacc/data_source_aci_vzbrcp_test.go | 172 +++ testacc/data_source_aci_vzcpif_test.go | 159 ++ testacc/data_source_aci_vzsubj_test.go | 213 +++ testacc/data_source_aci_vztaboo_test.go | 185 +++ testacc/provider_test.go | 52 +- testacc/resource_aci_aaadomain_test.go | 276 ++++ testacc/resource_aci_bfdifp_test.go | 467 ++++++ testacc/resource_aci_fvaepg_test.go | 32 +- testacc/resource_aci_fvany_test.go | 513 +++++++ testacc/resource_aci_fvap_test.go | 61 +- testacc/resource_aci_fvbd_test.go | 34 +- testacc/resource_aci_fvctx_test.go | 34 +- testacc/resource_aci_fvepselector_test.go | 443 ++++++ testacc/resource_aci_fvesg_test.go | 508 ++++++ testacc/resource_aci_fvrsdomatt_test.go | 842 ++++++++++ testacc/resource_aci_fvrspathatt_test.go | 639 ++++++++ testacc/resource_aci_fvrsproscons_test.go | 900 +++++++++++ testacc/resource_aci_fvsubnet_test.go | 59 +- testacc/resource_aci_fvtenant_test.go | 33 +- testacc/resource_aci_hsrpgroupp_test.go | 979 ++++++++++++ testacc/resource_aci_hsrpifp_test.go | 531 +++++++ testacc/resource_aci_hsrpifpol_test.go | 519 +++++++ testacc/resource_aci_hsrpsecvip_test.go | 625 ++++++++ testacc/resource_aci_l3extOut_test.go | 777 ++++++++++ testacc/resource_aci_l3extinstp_test.go | 702 +++++++++ testacc/resource_aci_l3extlifp_test.go | 606 ++++++++ testacc/resource_aci_l3extlnodep_test.go | 577 +++++++ testacc/resource_aci_l3extloopbackifp_test.go | 422 +++++ testacc/resource_aci_l3extroutetagpol_test.go | 392 +++++ testacc/resource_aci_l3extsubnet_test.go | 740 +++++++++ testacc/resource_aci_l3extvirtuallifp_test.go | 869 +++++++++++ testacc/resource_aci_ospfifp_test.go | 500 ++++++ testacc/resource_aci_rtctrlprofile_test.go | 448 ++++++ testacc/resource_aci_vzbrcp_test.go | 1360 +++++++++++++++++ testacc/resource_aci_vzcpif_test.go | 359 +++++ testacc/resource_aci_vzfilter_test.go | 102 +- testacc/resource_aci_vzsubj_test.go | 834 ++++++++++ testacc/resource_aci_vztaboo_test.go | 401 +++++ testacc/sweeper_test.go | 37 + testacc/utils.go | 2 +- .../client/aaaLdapProvider_service.go | 5 +- .../aci-go-client/client/aaaUserEp_service.go | 46 +- .../aci-go-client/client/bfdIfP_service.go | 3 +- .../aci-go-client/client/bgpPeerP_service.go | 5 +- .../aci-go-client/client/bgpProtP_service.go | 3 +- .../client/cloudRouterP_service.go | 7 +- .../aci-go-client/client/dhcpLbl_service.go | 3 +- .../client/dhcpRelayP_service.go | 3 +- .../client/fileRemotePath_service.go | 5 +- .../client/fvEPgSelector_service.go | 3 +- .../aci-go-client/client/fvESg_service.go | 17 +- .../client/hsrpGroupP_service.go | 3 +- .../aci-go-client/client/hsrpIfP_service.go | 3 +- .../client/infraAccNodePGrp_service.go | 37 +- .../client/infraBrkoutPortGrp_service.go | 3 +- .../client/infraFexBndlGrp_service.go | 5 +- .../client/infraGeneric_service.go | 3 +- .../client/infraSpAccPortGrp_service.go | 11 +- .../client/infraSpineAccNodePGrp_service.go | 13 +- .../client/infraSpineP_service.go | 3 +- .../client/infraSpineS_service.go | 3 +- .../client/ipNexthopP_service.go | 5 +- .../aci-go-client/client/ipRouteP_service.go | 3 +- .../aci-go-client/client/l2extDomP_service.go | 11 +- .../client/l2extInstP_service.go | 17 +- .../aci-go-client/client/l2extOut_service.go | 5 +- .../client/l3extVirtualLIfP_service.go | 3 +- .../client/maintMaintGrp_service.go | 3 +- .../client/maintMaintP_service.go | 3 +- .../client/mgmtInBZone_service.go | 7 +- .../aci-go-client/client/mgmtInB_service.go | 19 +- .../client/mgmtOoBZone_service.go | 7 +- .../aci-go-client/client/mgmtOoB_service.go | 7 +- .../aci-go-client/client/ospfIfP_service.go | 3 +- .../client/rtctrlCtxP_service.go | 3 +- .../client/rtctrlScope_service.go | 3 +- .../aci-go-client/client/tacacsSrc_service.go | 3 +- .../aci-go-client/client/vmmCtrlrP_service.go | 17 +- .../client/vmmVSwitchPolicyCont_service.go | 17 +- .../client/vnsAbsConnection_service.go | 5 +- .../client/vnsAbsFuncConn_service.go | 9 +- .../client/vnsAbsNode_service.go | 11 +- .../client/vnsLDevCtx_service.go | 5 +- .../aci-go-client/client/vnsLIfCtx_service.go | 17 +- .../client/vnsRedirectDest_service.go | 3 +- .../client/vnsSvcRedirectPol_service.go | 3 +- .../aci-go-client/client/vzCPIf_service.go | 3 +- vendor/modules.txt | 2 +- website/docs/d/epg_to_contract.html.markdown | 3 +- .../docs/d/epg_to_static_path.html.markdown | 1 + ...nal_network_instance_profile.html.markdown | 1 + .../d/l3out_hsrp_secondary_vip.html.markdown | 1 - website/docs/r/contract.html.markdown | 2 +- website/docs/r/epg_to_contract.html.markdown | 3 +- website/docs/r/epg_to_domain.html.markdown | 8 +- .../docs/r/epg_to_static_path.html.markdown | 1 + ...nal_network_instance_profile.html.markdown | 3 +- website/docs/r/l3_ext_subnet.html.markdown | 2 - .../docs/r/l3out_floating_svi.html.markdown | 2 +- .../l3out_hsrp_interface_group.html.markdown | 4 +- .../r/l3out_hsrp_secondary_vip.html.markdown | 1 - website/docs/r/vrf.html.markdown | 6 + 191 files changed, 22836 insertions(+), 5322 deletions(-) delete mode 100644 aci/resource_aci_aaadomain_test.go delete mode 100644 aci/resource_aci_bfdifp_test.go delete mode 100644 aci/resource_aci_fvaepg_test.go delete mode 100644 aci/resource_aci_fvap_test.go delete mode 100644 aci/resource_aci_fvbd_test.go delete mode 100644 aci/resource_aci_fvctx_test.go delete mode 100644 aci/resource_aci_fvepselector_test.go delete mode 100644 aci/resource_aci_fvesg_test.go delete mode 100644 aci/resource_aci_fvrsdomatt_test.go delete mode 100644 aci/resource_aci_fvrspathatt_test.go delete mode 100644 aci/resource_aci_fvrsprovcons_test.go delete mode 100644 aci/resource_aci_fvsubnet_test.go delete mode 100644 aci/resource_aci_fvtenant_test.go delete mode 100644 aci/resource_aci_hsrpgroupp_test.go delete mode 100644 aci/resource_aci_hsrpifp_test.go delete mode 100644 aci/resource_aci_hsrpifpol_test.go delete mode 100644 aci/resource_aci_hsrpsecvip_test.go delete mode 100644 aci/resource_aci_l3extinstp_test.go delete mode 100644 aci/resource_aci_l3extlifp_test.go delete mode 100644 aci/resource_aci_l3extlnodep_test.go delete mode 100644 aci/resource_aci_l3extout_test.go delete mode 100644 aci/resource_aci_l3extroutetagpol_test.go delete mode 100644 aci/resource_aci_l3extsubnet_test.go delete mode 100644 aci/resource_aci_l3extvirtuallifp_test.go delete mode 100644 aci/resource_aci_ospfifp_test.go delete mode 100644 aci/resource_aci_rtctrlprofile_test.go delete mode 100644 aci/resource_aci_vzany_test.go delete mode 100644 aci/resource_aci_vzcpif_test.go delete mode 100644 aci/resource_aci_vzfilter_test.go delete mode 100644 aci/resource_aci_vzsubj_test.go delete mode 100644 aci/resource_aci_vztaboo_test.go create mode 100644 testacc/data_source_aci_aaadomain_test.go create mode 100644 testacc/data_source_aci_bfdifp_test.go create mode 100644 testacc/data_source_aci_fvany_test.go rename testacc/{data_sorce_aci_fvctx_test.go => data_source_aci_fvctx_test.go} (96%) create mode 100644 testacc/data_source_aci_fvepselector_test.go create mode 100644 testacc/data_source_aci_fvesg_test.go create mode 100644 testacc/data_source_aci_fvrsdomatt_test.go create mode 100644 testacc/data_source_aci_fvrspathatt_test.go create mode 100644 testacc/data_source_aci_fvrsprovcons_test.go rename testacc/{data_resource_aci_fvtenant_test.go => data_source_aci_fvtenant_test.go} (95%) create mode 100644 testacc/data_source_aci_hsrpgroupp_test.go create mode 100644 testacc/data_source_aci_hsrpifp_test.go create mode 100644 testacc/data_source_aci_hsrpifpol_test.go create mode 100644 testacc/data_source_aci_hsrpsecvip_test.go create mode 100644 testacc/data_source_aci_l3extOut_test.go create mode 100644 testacc/data_source_aci_l3extinstp_test.go create mode 100644 testacc/data_source_aci_l3extlifp_test.go create mode 100644 testacc/data_source_aci_l3extlnodep_test.go create mode 100644 testacc/data_source_aci_l3extloopbackifp_test.go create mode 100644 testacc/data_source_aci_l3extroutetagpol_test.go create mode 100644 testacc/data_source_aci_l3extsubnet_test.go create mode 100644 testacc/data_source_aci_l3extvirtuallifp_test.go create mode 100644 testacc/data_source_aci_ospfifp_test.go create mode 100644 testacc/data_source_aci_rtctrlprofile_test.go create mode 100644 testacc/data_source_aci_vzbrcp_test.go create mode 100644 testacc/data_source_aci_vzcpif_test.go create mode 100644 testacc/data_source_aci_vzsubj_test.go create mode 100644 testacc/data_source_aci_vztaboo_test.go create mode 100644 testacc/resource_aci_aaadomain_test.go create mode 100644 testacc/resource_aci_bfdifp_test.go create mode 100644 testacc/resource_aci_fvany_test.go create mode 100644 testacc/resource_aci_fvepselector_test.go create mode 100644 testacc/resource_aci_fvesg_test.go create mode 100644 testacc/resource_aci_fvrsdomatt_test.go create mode 100644 testacc/resource_aci_fvrspathatt_test.go create mode 100644 testacc/resource_aci_fvrsproscons_test.go create mode 100644 testacc/resource_aci_hsrpgroupp_test.go create mode 100644 testacc/resource_aci_hsrpifp_test.go create mode 100644 testacc/resource_aci_hsrpifpol_test.go create mode 100644 testacc/resource_aci_hsrpsecvip_test.go create mode 100644 testacc/resource_aci_l3extOut_test.go create mode 100644 testacc/resource_aci_l3extinstp_test.go create mode 100644 testacc/resource_aci_l3extlifp_test.go create mode 100644 testacc/resource_aci_l3extlnodep_test.go create mode 100644 testacc/resource_aci_l3extloopbackifp_test.go create mode 100644 testacc/resource_aci_l3extroutetagpol_test.go create mode 100644 testacc/resource_aci_l3extsubnet_test.go create mode 100644 testacc/resource_aci_l3extvirtuallifp_test.go create mode 100644 testacc/resource_aci_ospfifp_test.go create mode 100644 testacc/resource_aci_rtctrlprofile_test.go create mode 100644 testacc/resource_aci_vzbrcp_test.go create mode 100644 testacc/resource_aci_vzcpif_test.go create mode 100644 testacc/resource_aci_vzsubj_test.go create mode 100644 testacc/resource_aci_vztaboo_test.go create mode 100644 testacc/sweeper_test.go diff --git a/aci/data_source_aci_fvrsprovcons.go b/aci/data_source_aci_fvrsprovcons.go index 39033446a..e394f8e31 100644 --- a/aci/data_source_aci_fvrsprovcons.go +++ b/aci/data_source_aci_fvrsprovcons.go @@ -17,14 +17,14 @@ func dataSourceAciContractProvider() *schema.Resource { SchemaVersion: 1, - Schema: AppendBaseAttrSchema(map[string]*schema.Schema{ + Schema: map[string]*schema.Schema{ "application_epg_dn": &schema.Schema{ Type: schema.TypeString, Required: true, ForceNew: true, }, - "contract_name": &schema.Schema{ + "contract_dn": &schema.Schema{ Type: schema.TypeString, Required: true, ForceNew: true, @@ -47,14 +47,22 @@ func dataSourceAciContractProvider() *schema.Resource { Optional: true, Computed: true, }, - }), + "annotation": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + DefaultFunc: func() (interface{}, error) { + return "orchestrator:terraform", nil + }, + }, + }, } } func dataSourceAciContractProviderRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { aciClient := m.(*client.Client) contractType := d.Get("contract_type").(string) - tnVzBrCPName := d.Get("contract_name").(string) + tnVzBrCPName := GetMOName(d.Get("contract_dn").(string)) ApplicationEPGDn := d.Get("application_epg_dn").(string) if contractType == "provider" { @@ -102,7 +110,7 @@ func setContractConsumerDataAttributes(fvRsCons *models.ContractConsumer, d *sch return d, err } - d.Set("contract_name", fvRsConsMap["tnVzBrCPName"]) + // d.Set("contract_name", fvRsConsMap["tnVzBrCPName"]) d.Set("annotation", fvRsConsMap["annotation"]) d.Set("prio", fvRsConsMap["prio"]) @@ -117,7 +125,7 @@ func setContractProviderDataAttributes(fvRsProv *models.ContractProvider, d *sch if err != nil { return d, err } - d.Set("contract_name", fvRsProvMap["tnVzBrCPName"]) + // d.Set("contract_name", fvRsProvMap["tnVzBrCPName"]) d.Set("annotation", fvRsProvMap["annotation"]) d.Set("match_t", fvRsProvMap["matchT"]) diff --git a/aci/provider.go b/aci/provider.go index d34daf763..e99298485 100644 --- a/aci/provider.go +++ b/aci/provider.go @@ -497,10 +497,10 @@ func configureClient(d *schema.ResourceData) (interface{}, error) { return nil, err } - return config.getClient(), nil + return config.GetClient(), nil } -func (c Config) Valid() error { +func (c *Config) Valid() error { if c.Username == "" { return fmt.Errorf("Username must be provided for the ACI provider") @@ -522,7 +522,7 @@ func (c Config) Valid() error { return nil } -func (c Config) getClient() interface{} { +func (c *Config) GetClient() interface{} { if c.Password != "" { return client.GetClient(c.URL, c.Username, client.Password(c.Password), client.Insecure(c.IsInsecure), client.ProxyUrl(c.ProxyUrl), client.ProxyCreds(c.ProxyCreds), client.ValidateRelationDn(c.ValidateRelationDn)) diff --git a/aci/resource_aci_aaadomain_test.go b/aci/resource_aci_aaadomain_test.go deleted file mode 100644 index 9ef4a7793..000000000 --- a/aci/resource_aci_aaadomain_test.go +++ /dev/null @@ -1,141 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciSecurityDomain_Basic(t *testing.T) { - var security_domain models.SecurityDomain - description := "aaa domain created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciSecurityDomainDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciSecurityDomainConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciSecurityDomainExists("aci_aaa_domain.foosecurity_domain", &security_domain), - testAccCheckAciSecurityDomainAttributes(description, &security_domain), - ), - }, - }, - }) -} - -func TestAccAciSecurityDomain_update(t *testing.T) { - var security_domain models.SecurityDomain - description := "aaa domain created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciSecurityDomainDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciSecurityDomainConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciSecurityDomainExists("aci_aaa_domain.foosecurity_domain", &security_domain), - testAccCheckAciSecurityDomainAttributes(description, &security_domain), - ), - }, - { - Config: testAccCheckAciSecurityDomainConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciSecurityDomainExists("aci_aaa_domain.foosecurity_domain", &security_domain), - testAccCheckAciSecurityDomainAttributes(description, &security_domain), - ), - }, - }, - }) -} - -func testAccCheckAciSecurityDomainConfig_basic(description string) string { - return fmt.Sprintf(` - - resource "aci_aaa_domain" "foosecurity_domain" { - description = "%s" - name = "aaa_domain_1" - annotation = "example" - name_alias = "example" - } - `, description) -} - -func testAccCheckAciSecurityDomainExists(name string, security_domain *models.SecurityDomain) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("aaa domain %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No aaa domain dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - security_domainFound := models.SecurityDomainFromContainer(cont) - if security_domainFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("aaa domain %s not found", rs.Primary.ID) - } - *security_domain = *security_domainFound - return nil - } -} - -func testAccCheckAciSecurityDomainDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_aaa_domain" { - cont, err := client.Get(rs.Primary.ID) - security_domain := models.SecurityDomainFromContainer(cont) - if err == nil { - return fmt.Errorf("aaa domain %s Still exists", security_domain.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciSecurityDomainAttributes(description string, security_domain *models.SecurityDomain) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != security_domain.Description { - return fmt.Errorf("Bad aaa domain Description %s", security_domain.Description) - } - - if "aaa_domain_1" != security_domain.Name { - return fmt.Errorf("Bad aaa domain name %s", security_domain.Name) - } - - if "example" != security_domain.Annotation { - return fmt.Errorf("Bad aaa domain annotation %s", security_domain.Annotation) - } - - if "example" != security_domain.NameAlias { - return fmt.Errorf("Bad aaa domain name_alias %s", security_domain.NameAlias) - } - - return nil - } -} diff --git a/aci/resource_aci_bfdifp.go b/aci/resource_aci_bfdifp.go index 9fa7c15d4..f462b0841 100644 --- a/aci/resource_aci_bfdifp.go +++ b/aci/resource_aci_bfdifp.go @@ -62,6 +62,7 @@ func resourceAciBFDInterfaceProfile() *schema.Resource { "relation_bfd_rs_if_pol": &schema.Schema{ Type: schema.TypeString, + Optional: true, }, }), @@ -120,6 +121,7 @@ func resourceAciBFDInterfaceProfileImport(d *schema.ResourceData, m interface{}) return nil, err } + d.Set("logical_interface_profile_dn", GetParentDn(dn, "/bfdIfP")) log.Printf("[DEBUG] %s: Import finished successfully", d.Id()) return []*schema.ResourceData{schemaFilled}, nil diff --git a/aci/resource_aci_bfdifp_test.go b/aci/resource_aci_bfdifp_test.go deleted file mode 100644 index 4429ad2ad..000000000 --- a/aci/resource_aci_bfdifp_test.go +++ /dev/null @@ -1,143 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciBFDInterfaceProfile_Basic(t *testing.T) { - var interface_profile models.BFDInterfaceProfile - description := "interface_profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciBFDInterfaceProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciBFDInterfaceProfileConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciBFDInterfaceProfileExists("aci_l3out_bfd_interface_profile.test", &interface_profile), - testAccCheckAciBFDInterfaceProfileAttributes(description, &interface_profile), - ), - }, - }, - }) -} - -func TestAccAciBFDInterfaceProfile_update(t *testing.T) { - var interface_profile models.BFDInterfaceProfile - description := "interface_profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciBFDInterfaceProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciBFDInterfaceProfileConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciBFDInterfaceProfileExists("aci_l3out_bfd_interface_profile.test", &interface_profile), - testAccCheckAciBFDInterfaceProfileAttributes(description, &interface_profile), - ), - }, - { - Config: testAccCheckAciBFDInterfaceProfileConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciBFDInterfaceProfileExists("aci_l3out_bfd_interface_profile.test", &interface_profile), - testAccCheckAciBFDInterfaceProfileAttributes(description, &interface_profile), - ), - }, - }, - }) -} - -func testAccCheckAciBFDInterfaceProfileConfig_basic(description string) string { - return fmt.Sprintf(` - - resource "aci_l3out_bfd_interface_profile" "test" { - logical_interface_profile_dn = aci_logical_interface_profile.example.id - annotation = "example" - description = "%s" - key = "example" - key_id = "25" - interface_profile_type = "sha1" - } - `, description) -} - -func testAccCheckAciBFDInterfaceProfileExists(name string, interface_profile *models.BFDInterfaceProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Interface Profile %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Interface Profile dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - interface_profileFound := models.BFDInterfaceProfileFromContainer(cont) - if interface_profileFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Interface Profile %s not found", rs.Primary.ID) - } - *interface_profile = *interface_profileFound - return nil - } -} - -func testAccCheckAciBFDInterfaceProfileDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_l3out_bfd_interface_profile" { - cont, err := client.Get(rs.Primary.ID) - interface_profile := models.BFDInterfaceProfileFromContainer(cont) - if err == nil { - return fmt.Errorf("Interface Profile %s Still exists", interface_profile.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciBFDInterfaceProfileAttributes(description string, interface_profile *models.BFDInterfaceProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != interface_profile.Description { - return fmt.Errorf("Bad interface_profile Description %s", interface_profile.Description) - } - - if "example" != interface_profile.Annotation { - return fmt.Errorf("Bad interface_profile annotation %s", interface_profile.Annotation) - } - - if "25" != interface_profile.KeyId { - return fmt.Errorf("Bad interface_profile key_id %s", interface_profile.KeyId) - } - - if "sha1" != interface_profile.InterfaceProfileType { - return fmt.Errorf("Bad interface_profile interface_profile_type %s", interface_profile.InterfaceProfileType) - } - - return nil - } -} diff --git a/aci/resource_aci_fvaepg.go b/aci/resource_aci_fvaepg.go index ee9de39d2..b89df02aa 100644 --- a/aci/resource_aci_fvaepg.go +++ b/aci/resource_aci_fvaepg.go @@ -141,12 +141,12 @@ func resourceAciApplicationEPG() *schema.Resource { "relation_fv_rs_bd": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, "relation_fv_rs_cust_qos_pol": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, "relation_fv_rs_fc_path_att": &schema.Schema{ diff --git a/aci/resource_aci_fvaepg_test.go b/aci/resource_aci_fvaepg_test.go deleted file mode 100644 index 4d633d56c..000000000 --- a/aci/resource_aci_fvaepg_test.go +++ /dev/null @@ -1,196 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciApplicationEPG_Basic(t *testing.T) { - var application_epg models.ApplicationEPG - description := "application_epg created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciApplicationEPGDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciApplicationEPGConfig_basic(description, "unspecified"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciApplicationEPGExists("aci_application_epg.fooapplication_epg", &application_epg), - testAccCheckAciApplicationEPGAttributes(description, "unspecified", &application_epg), - ), - }, - }, - }) -} - -func TestAccAciApplicationEPG_update(t *testing.T) { - var application_epg models.ApplicationEPG - description := "application_epg created while acceptance testing" - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciApplicationEPGDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciApplicationEPGConfig_basic(description, "unspecified"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciApplicationEPGExists("aci_application_epg.fooapplication_epg", &application_epg), - testAccCheckAciApplicationEPGAttributes(description, "unspecified", &application_epg), - ), - }, - { - Config: testAccCheckAciApplicationEPGConfig_basic(description, "level3"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciApplicationEPGExists("aci_application_epg.fooapplication_epg", &application_epg), - testAccCheckAciApplicationEPGAttributes(description, "level3", &application_epg), - ), - }, - }, - }) -} - -func testAccCheckAciApplicationEPGConfig_basic(description, prio string) string { - return fmt.Sprintf(` - resource "aci_tenant" "tenant_for_epg" { - name = "tenant_for_epg" - description = "This tenant is created by terraform ACI provider" - } - - resource "aci_application_profile" "app_profile_for_epg" { - tenant_dn = aci_tenant.tenant_for_epg.id - name = "ap_for_epg" - description = "This app profile is created by terraform ACI providers" - } - - resource "aci_application_epg" "fooapplication_epg" { - application_profile_dn = aci_application_profile.app_profile_for_epg.id - name = "demo_epg" - description = "%s" - annotation = "tag_epg" - exception_tag = "0" - flood_on_encap = "disabled" - fwd_ctrl = "none" - has_mcast_source = "no" - is_attr_based_epg = "no" - match_t = "AtleastOne" - name_alias = "alias_epg" - pc_enf_pref = "unenforced" - pref_gr_memb = "exclude" - prio = "%s" - shutdown = "no" - } - `, description, prio) -} - -func testAccCheckAciApplicationEPGExists(name string, application_epg *models.ApplicationEPG) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Application EPG %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Application EPG dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - application_epgFound := models.ApplicationEPGFromContainer(cont) - if application_epgFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Application EPG %s not found", rs.Primary.ID) - } - *application_epg = *application_epgFound - return nil - } -} - -func testAccCheckAciApplicationEPGDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_application_epg" { - cont, err := client.Get(rs.Primary.ID) - application_epg := models.ApplicationEPGFromContainer(cont) - if err == nil { - return fmt.Errorf("Application EPG %s Still exists", application_epg.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciApplicationEPGAttributes(description, prio string, application_epg *models.ApplicationEPG) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != application_epg.Description { - return fmt.Errorf("Bad application_epg Description %s", application_epg.Description) - } - - if "demo_epg" != application_epg.Name { - return fmt.Errorf("Bad application_epg name %s", application_epg.Name) - } - - if "tag_epg" != application_epg.Annotation { - return fmt.Errorf("Bad application_epg annotation %s", application_epg.Annotation) - } - - if "0" != application_epg.ExceptionTag { - return fmt.Errorf("Bad application_epg exception_tag %s", application_epg.ExceptionTag) - } - - if "disabled" != application_epg.FloodOnEncap { - return fmt.Errorf("Bad application_epg flood_on_encap %s", application_epg.FloodOnEncap) - } - - if "no" != application_epg.HasMcastSource { - return fmt.Errorf("Bad application_epg has_mcast_source %s", application_epg.HasMcastSource) - } - - if "no" != application_epg.IsAttrBasedEPg { - return fmt.Errorf("Bad application_epg is_attr_based_epg %s", application_epg.IsAttrBasedEPg) - } - - if "AtleastOne" != application_epg.MatchT { - return fmt.Errorf("Bad application_epg match_t %s", application_epg.MatchT) - } - - if "alias_epg" != application_epg.NameAlias { - return fmt.Errorf("Bad application_epg name_alias %s", application_epg.NameAlias) - } - - if "unenforced" != application_epg.PcEnfPref { - return fmt.Errorf("Bad application_epg pc_enf_pref %s", application_epg.PcEnfPref) - } - - if "exclude" != application_epg.PrefGrMemb { - return fmt.Errorf("Bad application_epg pref_gr_memb %s", application_epg.PrefGrMemb) - } - - if prio != application_epg.Prio { - return fmt.Errorf("Bad application_epg prio %s", application_epg.Prio) - } - - if "no" != application_epg.Shutdown { - return fmt.Errorf("Bad application_epg shutdown %s", application_epg.Shutdown) - } - return nil - } -} diff --git a/aci/resource_aci_fvap.go b/aci/resource_aci_fvap.go index 56febe1ad..b728d675b 100644 --- a/aci/resource_aci_fvap.go +++ b/aci/resource_aci_fvap.go @@ -61,7 +61,7 @@ func resourceAciApplicationProfile() *schema.Resource { "relation_fv_rs_ap_mon_pol": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, }), diff --git a/aci/resource_aci_fvap_test.go b/aci/resource_aci_fvap_test.go deleted file mode 100644 index d9b548ff1..000000000 --- a/aci/resource_aci_fvap_test.go +++ /dev/null @@ -1,155 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciApplicationProfile_Basic(t *testing.T) { - var application_profile models.ApplicationProfile - description := "application_profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciApplicationProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciApplicationProfileConfig_basic(description, "unspecified"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciApplicationProfileExists("aci_application_profile.fooapplication_profile", &application_profile), - testAccCheckAciApplicationProfileAttributes(description, "unspecified", &application_profile), - ), - }, - { - ResourceName: "aci_application_profile", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAciApplicationProfile_update(t *testing.T) { - var application_profile models.ApplicationProfile - description := "application_profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciApplicationProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciApplicationProfileConfig_basic(description, "unspecified"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciApplicationProfileExists("aci_application_profile.fooapplication_profile", &application_profile), - testAccCheckAciApplicationProfileAttributes(description, "unspecified", &application_profile), - ), - }, - { - Config: testAccCheckAciApplicationProfileConfig_basic(description, "level2"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciApplicationProfileExists("aci_application_profile.fooapplication_profile", &application_profile), - testAccCheckAciApplicationProfileAttributes(description, "level2", &application_profile), - ), - }, - }, - }) -} - -func testAccCheckAciApplicationProfileConfig_basic(description, prio string) string { - return fmt.Sprintf(` - resource "aci_tenant" "tenant_for_ap" { - name = "tenant_for_ap" - description = "This tenant is created by terraform ACI provider" - } - resource "aci_application_profile" "fooapplication_profile" { - tenant_dn = aci_tenant.tenant_for_ap.id - description = "%s" - name = "demo_ap" - annotation = "tag_ap" - name_alias = "alias_ap" - prio = "%s" - } - `, description, prio) -} - -func testAccCheckAciApplicationProfileExists(name string, application_profile *models.ApplicationProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Application Profile %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Application Profile dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - application_profileFound := models.ApplicationProfileFromContainer(cont) - if application_profileFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Application Profile %s not found", rs.Primary.ID) - } - *application_profile = *application_profileFound - return nil - } -} - -func testAccCheckAciApplicationProfileDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_application_profile" { - cont, err := client.Get(rs.Primary.ID) - application_profile := models.ApplicationProfileFromContainer(cont) - if err == nil { - return fmt.Errorf("Application Profile %s Still exists", application_profile.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciApplicationProfileAttributes(description, prio string, application_profile *models.ApplicationProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != application_profile.Description { - return fmt.Errorf("Bad application_profile Description %s", application_profile.Description) - } - - if "demo_ap" != application_profile.Name { - return fmt.Errorf("Bad application_profile name %s", application_profile.Name) - } - - if "tag_ap" != application_profile.Annotation { - return fmt.Errorf("Bad application_profile annotation %s", application_profile.Annotation) - } - - if "alias_ap" != application_profile.NameAlias { - return fmt.Errorf("Bad application_profile name_alias %s", application_profile.NameAlias) - } - - if prio != application_profile.Prio { - return fmt.Errorf("Bad application_profile prio %s", application_profile.Prio) - } - - return nil - } -} diff --git a/aci/resource_aci_fvbd.go b/aci/resource_aci_fvbd.go index 8e61f60e3..26d5455a5 100644 --- a/aci/resource_aci_fvbd.go +++ b/aci/resource_aci_fvbd.go @@ -235,7 +235,7 @@ func resourceAciBridgeDomain() *schema.Resource { }, "relation_fv_rs_mldsn": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, "relation_fv_rs_abd_pol_mon_pol": &schema.Schema{ @@ -245,7 +245,7 @@ func resourceAciBridgeDomain() *schema.Resource { }, "relation_fv_rs_bd_to_nd_p": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, "relation_fv_rs_bd_flood_to": &schema.Schema{ @@ -266,7 +266,7 @@ func resourceAciBridgeDomain() *schema.Resource { }, "relation_fv_rs_ctx": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, "relation_fv_rs_bd_to_netflow_monitor_pol": &schema.Schema{ @@ -287,12 +287,12 @@ func resourceAciBridgeDomain() *schema.Resource { }, "relation_fv_rs_igmpsn": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, "relation_fv_rs_bd_to_ep_ret": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, "relation_fv_rs_bd_to_out": &schema.Schema{ diff --git a/aci/resource_aci_fvbd_test.go b/aci/resource_aci_fvbd_test.go deleted file mode 100644 index e17089a3f..000000000 --- a/aci/resource_aci_fvbd_test.go +++ /dev/null @@ -1,235 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciBridgeDomain_Basic(t *testing.T) { - var bridge_domain models.BridgeDomain - description := "bridge_domain created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciBridgeDomainDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciBridgeDomainConfig_basic(description, "yes"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciBridgeDomainExists("aci_bridge_domain.foobridge_domain", &bridge_domain), - testAccCheckAciBridgeDomainAttributes(description, "yes", &bridge_domain), - ), - }, - }, - }) -} - -func TestAccAciBridgeDomain_update(t *testing.T) { - var bridge_domain models.BridgeDomain - description := "bridge_domain created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciBridgeDomainDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciBridgeDomainConfig_basic(description, "yes"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciBridgeDomainExists("aci_bridge_domain.foobridge_domain", &bridge_domain), - testAccCheckAciBridgeDomainAttributes(description, "yes", &bridge_domain), - ), - }, - { - Config: testAccCheckAciBridgeDomainConfig_basic(description, "no"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciBridgeDomainExists("aci_bridge_domain.foobridge_domain", &bridge_domain), - testAccCheckAciBridgeDomainAttributes(description, "no", &bridge_domain), - ), - }, - }, - }) -} - -func testAccCheckAciBridgeDomainConfig_basic(description, ipv6_mcast_allow string) string { - return fmt.Sprintf(` - resource "aci_tenant" "tenant_for_bd" { - name = "tenant_for_bd" - description = "This tenant is created by terraform ACI provider" - } - resource "aci_bridge_domain" "foobridge_domain" { - tenant_dn = aci_tenant.tenant_for_bd.id - description = "%s" - name = "demo_bd" - optimize_wan_bandwidth = "no" - annotation = "tag_bd" - arp_flood = "no" - ep_clear = "no" - ep_move_detect_mode = "garp" - host_based_routing = "no" - intersite_bum_traffic_allow = "yes" - intersite_l2_stretch = "yes" - ip_learning = "yes" - ipv6_mcast_allow = "%s" - limit_ip_learn_to_subnets = "yes" - mac = "00:22:BD:F8:19:FF" - mcast_allow = "yes" - multi_dst_pkt_act = "bd-flood" - name_alias = "alias_bd" - bridge_domain_type = "regular" - unicast_route = "no" - unk_mac_ucast_act = "flood" - unk_mcast_act = "flood" - vmac = "not-applicable" - } - `, description, ipv6_mcast_allow) -} - -func testAccCheckAciBridgeDomainExists(name string, bridge_domain *models.BridgeDomain) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Bridge Domain %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Bridge Domain dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - bridge_domainFound := models.BridgeDomainFromContainer(cont) - if bridge_domainFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Bridge Domain %s not found", rs.Primary.ID) - } - *bridge_domain = *bridge_domainFound - return nil - } -} - -func testAccCheckAciBridgeDomainDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_bridge_domain" { - cont, err := client.Get(rs.Primary.ID) - bridge_domain := models.BridgeDomainFromContainer(cont) - if err == nil { - return fmt.Errorf("Bridge Domain %s Still exists", bridge_domain.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciBridgeDomainAttributes(description, ipv6_mcast_allow string, bridge_domain *models.BridgeDomain) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != bridge_domain.Description { - return fmt.Errorf("Bad bridge_domain Description %s", bridge_domain.Description) - } - - if "demo_bd" != bridge_domain.Name { - return fmt.Errorf("Bad bridge_domain name %s", bridge_domain.Name) - } - - if "no" != bridge_domain.OptimizeWanBandwidth { - return fmt.Errorf("Bad bridge_domain optimize_wan_bandwidth %s", bridge_domain.OptimizeWanBandwidth) - } - - if "tag_bd" != bridge_domain.Annotation { - return fmt.Errorf("Bad bridge_domain annotation %s", bridge_domain.Annotation) - } - - if "no" != bridge_domain.ArpFlood { - return fmt.Errorf("Bad bridge_domain arp_flood %s", bridge_domain.ArpFlood) - } - - if "no" != bridge_domain.EpClear { - return fmt.Errorf("Bad bridge_domain ep_clear %s", bridge_domain.EpClear) - } - - if "garp" != bridge_domain.EpMoveDetectMode { - return fmt.Errorf("Bad bridge_domain ep_move_detect_mode %s", bridge_domain.EpMoveDetectMode) - } - - if "no" != bridge_domain.HostBasedRouting { - return fmt.Errorf("Bad bridge_domain host_based_routing %s", bridge_domain.HostBasedRouting) - } - - if "yes" != bridge_domain.IntersiteBumTrafficAllow { - return fmt.Errorf("Bad bridge_domain intersite_bum_traffic_allow %s", bridge_domain.IntersiteBumTrafficAllow) - } - - if "yes" != bridge_domain.IntersiteL2Stretch { - return fmt.Errorf("Bad bridge_domain intersite_l2_stretch %s", bridge_domain.IntersiteL2Stretch) - } - - if "yes" != bridge_domain.IpLearning { - return fmt.Errorf("Bad bridge_domain ip_learning %s", bridge_domain.IpLearning) - } - - if ipv6_mcast_allow != bridge_domain.Ipv6McastAllow { - return fmt.Errorf("Bad bridge_domain ipv6_mcast_allow %s", bridge_domain.Ipv6McastAllow) - } - - if "yes" != bridge_domain.LimitIpLearnToSubnets { - return fmt.Errorf("Bad bridge_domain limit_ip_learn_to_subnets %s", bridge_domain.LimitIpLearnToSubnets) - } - - if "00:22:BD:F8:19:FF" != bridge_domain.Mac { - return fmt.Errorf("Bad bridge_domain mac %s", bridge_domain.Mac) - } - - if "yes" != bridge_domain.McastAllow { - return fmt.Errorf("Bad bridge_domain mcast_allow %s", bridge_domain.McastAllow) - } - - if "bd-flood" != bridge_domain.MultiDstPktAct { - return fmt.Errorf("Bad bridge_domain multi_dst_pkt_act %s", bridge_domain.MultiDstPktAct) - } - - if "alias_bd" != bridge_domain.NameAlias { - return fmt.Errorf("Bad bridge_domain name_alias %s", bridge_domain.NameAlias) - } - - if "regular" != bridge_domain.BridgeDomain_type { - return fmt.Errorf("Bad bridge_domain bridge_domain_type %s", bridge_domain.BridgeDomain_type) - } - - if "no" != bridge_domain.UnicastRoute { - return fmt.Errorf("Bad bridge_domain unicast_route %s", bridge_domain.UnicastRoute) - } - - if "flood" != bridge_domain.UnkMacUcastAct { - return fmt.Errorf("Bad bridge_domain unk_mac_ucast_act %s", bridge_domain.UnkMacUcastAct) - } - - if "flood" != bridge_domain.UnkMcastAct { - return fmt.Errorf("Bad bridge_domain unk_mcast_act %s", bridge_domain.UnkMcastAct) - } - - if "not-applicable" != bridge_domain.Vmac { - return fmt.Errorf("Bad bridge_domain vmac %s", bridge_domain.Vmac) - } - - return nil - } -} diff --git a/aci/resource_aci_fvctx.go b/aci/resource_aci_fvctx.go index a4532888c..0349614db 100644 --- a/aci/resource_aci_fvctx.go +++ b/aci/resource_aci_fvctx.go @@ -92,12 +92,12 @@ func resourceAciVRF() *schema.Resource { "relation_fv_rs_ospf_ctx_pol": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, "relation_fv_rs_vrf_validation_pol": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, "relation_fv_rs_ctx_mcast_to": &schema.Schema{ @@ -116,8 +116,9 @@ func resourceAciVRF() *schema.Resource { Required: true, }, "af": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"ipv4-ucast", "ipv6-ucast"}, false), }, }, }, @@ -132,20 +133,21 @@ func resourceAciVRF() *schema.Resource { Required: true, }, "af": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"ipv4-ucast", "ipv6-ucast"}, false), }, }, }, }, "relation_fv_rs_ctx_to_ep_ret": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, "relation_fv_rs_bgp_ctx_pol": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, "relation_fv_rs_ctx_mon_pol": &schema.Schema{ @@ -155,7 +157,7 @@ func resourceAciVRF() *schema.Resource { }, "relation_fv_rs_ctx_to_ext_route_tag_pol": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, "relation_fv_rs_ctx_to_bgp_ctx_af_pol": &schema.Schema{ @@ -168,8 +170,9 @@ func resourceAciVRF() *schema.Resource { Required: true, }, "af": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"ipv4-ucast", "ipv6-ucast"}, false), }, }, }, diff --git a/aci/resource_aci_fvctx_test.go b/aci/resource_aci_fvctx_test.go deleted file mode 100644 index d0b1054d3..000000000 --- a/aci/resource_aci_fvctx_test.go +++ /dev/null @@ -1,172 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciVRF_Basic(t *testing.T) { - var vrf models.VRF - description := "vrf created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciVRFDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciVRFConfig_basic(description, "enabled"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciVRFExists("aci_vrf.foovrf", &vrf), - testAccCheckAciVRFAttributes(description, "enabled", &vrf), - ), - }, - }, - }) -} - -func TestAccAciVRF_update(t *testing.T) { - var vrf models.VRF - description := "vrf created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciVRFDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciVRFConfig_basic(description, "enabled"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciVRFExists("aci_vrf.foovrf", &vrf), - testAccCheckAciVRFAttributes(description, "enabled", &vrf), - ), - }, - { - Config: testAccCheckAciVRFConfig_basic(description, "disabled"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciVRFExists("aci_vrf.foovrf", &vrf), - testAccCheckAciVRFAttributes(description, "disabled", &vrf), - ), - }, - }, - }) -} - -func testAccCheckAciVRFConfig_basic(description, ip_data_plane_learning string) string { - return fmt.Sprintf(` - - resource "aci_tenant" "tenant_for_vrf" { - name = "tenant_for_vrf" - description = "This tenant is created by terraform ACI provider" - } - - resource "aci_vrf" "foovrf" { - tenant_dn = aci_tenant.tenant_for_vrf.id - description = "%s" - name = "demo_vrf" - annotation = "tag_vrf" - bd_enforced_enable = "no" - ip_data_plane_learning = "%s" - knw_mcast_act = "permit" - name_alias = "alias_vrf" - pc_enf_dir = "egress" - pc_enf_pref = "unenforced" - } - `, description, ip_data_plane_learning) -} - -func testAccCheckAciVRFExists(name string, vrf *models.VRF) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("VRF %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No VRF dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - vrfFound := models.VRFFromContainer(cont) - if vrfFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("VRF %s not found", rs.Primary.ID) - } - *vrf = *vrfFound - return nil - } -} - -func testAccCheckAciVRFDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_vrf" { - cont, err := client.Get(rs.Primary.ID) - vrf := models.VRFFromContainer(cont) - if err == nil { - return fmt.Errorf("VRF %s Still exists", vrf.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciVRFAttributes(description, ip_data_plane_learning string, vrf *models.VRF) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != vrf.Description { - return fmt.Errorf("Bad vrf Description %s", vrf.Description) - } - - if "demo_vrf" != vrf.Name { - return fmt.Errorf("Bad vrf name %s", vrf.Name) - } - - if "tag_vrf" != vrf.Annotation { - return fmt.Errorf("Bad vrf annotation %s", vrf.Annotation) - } - - if "no" != vrf.BdEnforcedEnable { - return fmt.Errorf("Bad vrf bd_enforced_enable %s", vrf.BdEnforcedEnable) - } - - if ip_data_plane_learning != vrf.IpDataPlaneLearning { - return fmt.Errorf("Bad vrf ip_data_plane_learning %s", vrf.IpDataPlaneLearning) - } - - if "permit" != vrf.KnwMcastAct { - return fmt.Errorf("Bad vrf knw_mcast_act %s", vrf.KnwMcastAct) - } - - if "alias_vrf" != vrf.NameAlias { - return fmt.Errorf("Bad vrf name_alias %s", vrf.NameAlias) - } - - if "egress" != vrf.PcEnfDir { - return fmt.Errorf("Bad vrf pc_enf_dir %s", vrf.PcEnfDir) - } - - if "unenforced" != vrf.PcEnfPref { - return fmt.Errorf("Bad vrf pc_enf_pref %s", vrf.PcEnfPref) - } - - return nil - } -} diff --git a/aci/resource_aci_fvepselector.go b/aci/resource_aci_fvepselector.go index 4f7ed8c74..b4372d7a3 100644 --- a/aci/resource_aci_fvepselector.go +++ b/aci/resource_aci_fvepselector.go @@ -78,6 +78,7 @@ func resourceAciEndpointSecurityGroupSelectorImport(d *schema.ResourceData, m in if err != nil { return nil, err } + d.Set("endpoint_security_group_dn", GetParentDn(dn, fmt.Sprintf("/epselector-[%s]", fvEPSelector.MatchExpression))) schemaFilled, err := setEndpointSecurityGroupSelectorAttributes(fvEPSelector, d) if err != nil { return nil, err diff --git a/aci/resource_aci_fvepselector_test.go b/aci/resource_aci_fvepselector_test.go deleted file mode 100644 index b620a6605..000000000 --- a/aci/resource_aci_fvepselector_test.go +++ /dev/null @@ -1,120 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciEndpointSecurityGroupSelector_Basic(t *testing.T) { - var endpoint_security_group_selector models.EndpointSecurityGroupSelector - fv_tenant_name := acctest.RandString(5) - fv_ap_name := acctest.RandString(5) - fv_e_sg_name := acctest.RandString(5) - fv_ep_selector_name := acctest.RandString(5) - description := "endpoint_security_group_selector created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciEndpointSecurityGroupSelectorDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciEndpointSecurityGroupSelectorConfig_basic(fv_tenant_name, fv_ap_name, fv_e_sg_name, fv_ep_selector_name), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciEndpointSecurityGroupSelectorExists("aci_endpoint_security_group_selector.fooendpoint_security_group_selector", &endpoint_security_group_selector), - testAccCheckAciEndpointSecurityGroupSelectorAttributes(fv_tenant_name, fv_ap_name, fv_e_sg_name, fv_ep_selector_name, description, &endpoint_security_group_selector), - ), - }, - }, - }) -} - -func testAccCheckAciEndpointSecurityGroupSelectorConfig_basic(fv_tenant_name, fv_ap_name, fv_e_sg_name, fv_ep_selector_name string) string { - return fmt.Sprintf(` - - resource "aci_tenant" "footenant" { - name = "%s" - description = "tenant created while acceptance testing" - - } - - resource "aci_application_profile" "fooapplication_profile" { - name = "%s" - description = "application_profile created while acceptance testing" - tenant_dn = aci_tenant.footenant.id - } - - resource "aci_endpoint_security_group" "fooendpoint_security_group" { - name = "%s" - description = "endpoint_security_group created while acceptance testing" - application_profile_dn = aci_application_profile.fooapplication_profile.id - } - - resource "aci_endpoint_security_group_selector" "fooendpoint_security_group_selector" { - name = "%s" - description = "endpoint_security_group_selector created while acceptance testing" - endpoint_security_group_dn = aci_endpoint_security_group.fooendpoint_security_group.id - match_expression = "ip=='10.10.10.0/24'" - } - - `, fv_tenant_name, fv_ap_name, fv_e_sg_name, fv_ep_selector_name) -} - -func testAccCheckAciEndpointSecurityGroupSelectorExists(name string, endpoint_security_group_selector *models.EndpointSecurityGroupSelector) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Endpoint Security Group Selector %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Endpoint Security Group Selector dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - endpoint_security_group_selectorFound := models.EndpointSecurityGroupSelectorFromContainer(cont) - if endpoint_security_group_selectorFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Endpoint Security Group Selector %s not found", rs.Primary.ID) - } - *endpoint_security_group_selector = *endpoint_security_group_selectorFound - return nil - } -} - -func testAccCheckAciEndpointSecurityGroupSelectorDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - for _, rs := range s.RootModule().Resources { - if rs.Type == "aci_endpoint_security_group_selector" { - cont, err := client.Get(rs.Primary.ID) - endpoint_security_group_selector := models.EndpointSecurityGroupSelectorFromContainer(cont) - if err == nil { - return fmt.Errorf("Endpoint Security Group Selector %s Still exists", endpoint_security_group_selector.DistinguishedName) - } - } else { - continue - } - } - return nil -} - -func testAccCheckAciEndpointSecurityGroupSelectorAttributes(fv_tenant_name, fv_ap_name, fv_e_sg_name, fv_ep_selector_name, description string, endpoint_security_group_selector *models.EndpointSecurityGroupSelector) resource.TestCheckFunc { - return func(s *terraform.State) error { - if description != endpoint_security_group_selector.Description { - return fmt.Errorf("Bad endpoint_security_group_selector Description %s", endpoint_security_group_selector.Description) - } - return nil - } -} diff --git a/aci/resource_aci_fvesg.go b/aci/resource_aci_fvesg.go index b55f9e116..b16d748b2 100644 --- a/aci/resource_aci_fvesg.go +++ b/aci/resource_aci_fvesg.go @@ -224,6 +224,7 @@ func resourceAciEndpointSecurityGroupImport(d *schema.ResourceData, m interface{ if err != nil { return nil, err } + d.Set("application_profile_dn", GetParentDn(dn, fmt.Sprintf("/esg-%s", fvESg.Name))) schemaFilled, err := setEndpointSecurityGroupAttributes(fvESg, d) if err != nil { return nil, err diff --git a/aci/resource_aci_fvesg_test.go b/aci/resource_aci_fvesg_test.go deleted file mode 100644 index ca3973c08..000000000 --- a/aci/resource_aci_fvesg_test.go +++ /dev/null @@ -1,112 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciEndpointSecurityGroup_Basic(t *testing.T) { - var endpoint_security_group models.EndpointSecurityGroup - fv_tenant_name := acctest.RandString(5) - fv_ap_name := acctest.RandString(5) - fv_e_sg_name := acctest.RandString(5) - description := "endpoint_security_group created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciEndpointSecurityGroupDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciEndpointSecurityGroupConfig_basic(fv_tenant_name, fv_ap_name, fv_e_sg_name), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciEndpointSecurityGroupExists("aci_endpoint_security_group.fooendpoint_security_group", &endpoint_security_group), - testAccCheckAciEndpointSecurityGroupAttributes(fv_tenant_name, fv_ap_name, fv_e_sg_name, description, &endpoint_security_group), - ), - }, - }, - }) -} - -func testAccCheckAciEndpointSecurityGroupConfig_basic(fv_tenant_name, fv_ap_name, fv_e_sg_name string) string { - return fmt.Sprintf(` - - resource "aci_tenant" "footenant" { - name = "%s" - description = "tenant created while acceptance testing" - - } - - resource "aci_application_profile" "fooapplication_profile" { - name = "%s" - description = "application_profile created while acceptance testing" - tenant_dn = aci_tenant.footenant.id - } - - resource "aci_endpoint_security_group" "fooendpoint_security_group" { - name = "%s" - description = "endpoint_security_group created while acceptance testing" - application_profile_dn = aci_application_profile.fooapplication_profile.id - } - - `, fv_tenant_name, fv_ap_name, fv_e_sg_name) -} - -func testAccCheckAciEndpointSecurityGroupExists(name string, endpoint_security_group *models.EndpointSecurityGroup) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Endpoint Security Group %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Endpoint Security Group dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - endpoint_security_groupFound := models.EndpointSecurityGroupFromContainer(cont) - if endpoint_security_groupFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Endpoint Security Group %s not found", rs.Primary.ID) - } - *endpoint_security_group = *endpoint_security_groupFound - return nil - } -} - -func testAccCheckAciEndpointSecurityGroupDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - for _, rs := range s.RootModule().Resources { - if rs.Type == "aci_endpoint_security_group" { - cont, err := client.Get(rs.Primary.ID) - endpoint_security_group := models.EndpointSecurityGroupFromContainer(cont) - if err == nil { - return fmt.Errorf("Endpoint Security Group %s Still exists", endpoint_security_group.DistinguishedName) - } - } else { - continue - } - } - return nil -} - -func testAccCheckAciEndpointSecurityGroupAttributes(fv_tenant_name, fv_ap_name, fv_e_sg_name, description string, endpoint_security_group *models.EndpointSecurityGroup) resource.TestCheckFunc { - return func(s *terraform.State) error { - if description != endpoint_security_group.Description { - return fmt.Errorf("Bad endpoint_security_group Description %s", endpoint_security_group.Description) - } - return nil - } -} diff --git a/aci/resource_aci_fvrsdomatt_test.go b/aci/resource_aci_fvrsdomatt_test.go deleted file mode 100644 index f754c0f53..000000000 --- a/aci/resource_aci_fvrsdomatt_test.go +++ /dev/null @@ -1,136 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciFVDomain_Basic(t *testing.T) { - var fvdomain models.FVDomain - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciFVDomainDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciFVDomainConfig_basic(), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciFVDomainExists("aci_epg_to_domain.check", &fvdomain), - testAccCheckAciFVDomainAttributes(&fvdomain), - ), - }, - }, - }) -} - -func TestAccAciFVDomain_update(t *testing.T) { - var domain models.FVDomain - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciFVDomainDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciFVDomainConfig_basic(), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciFVDomainExists("aci_epg_to_domain.check", &domain), - testAccCheckAciFVDomainAttributes(&domain), - ), - }, - { - Config: testAccCheckAciFVDomainConfig_basic(), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciFVDomainExists("aci_epg_to_domain.check", &domain), - testAccCheckAciFVDomainAttributes(&domain), - ), - }, - }, - }) -} - -func testAccCheckAciFVDomainConfig_basic() string { - return fmt.Sprintf(` - - resource "aci_epg_to_domain" "check" { - application_epg_dn = aci_application_epg.fooapplication_epg.id - tdn = aci_fc_domain.foofc_domain.id - vmm_allow_promiscuous = "accept" - vmm_forged_transmits = "reject" - vmm_mac_changes = "accept" - epg_cos = "Cos0" - } - - `) -} - -func testAccCheckAciFVDomainExists(name string, domain *models.FVDomain) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Domain %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Domain dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - domainFound := models.FVDomainFromContainer(cont) - if domainFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Domain %s not found", rs.Primary.ID) - } - *domain = *domainFound - return nil - } -} - -func testAccCheckAciFVDomainDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_epg_to_domain" { - cont, err := client.Get(rs.Primary.ID) - domain := models.FVDomainFromContainer(cont) - if err == nil { - return fmt.Errorf("Domain %s Still exists", domain.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciFVDomainAttributes(domain *models.FVDomain) resource.TestCheckFunc { - return func(s *terraform.State) error { - if "none" != domain.BindingType { - return fmt.Errorf("Bad domain binding_type %s", domain.BindingType) - } - - if "encap" != domain.ClassPref { - return fmt.Errorf("Bad domain class_pref %s", domain.ClassPref) - } - - if "Cos0" != domain.EpgCos { - return fmt.Errorf("Bad domain epg_cos %s", domain.EpgCos) - } - return nil - } -} diff --git a/aci/resource_aci_fvrspathatt.go b/aci/resource_aci_fvrspathatt.go index 834b5699a..242d408be 100644 --- a/aci/resource_aci_fvrspathatt.go +++ b/aci/resource_aci_fvrspathatt.go @@ -98,7 +98,7 @@ func setStaticPathAttributes(fvRsPathAtt *models.StaticPath, d *schema.ResourceD d.Set("application_epg_dn", GetParentDn(fvRsPathAtt.DistinguishedName, fmt.Sprintf("/rspathAtt-[%s]", fvRsPathAttMap["tDn"]))) d.Set("tdn", fvRsPathAttMap["tDn"]) - + d.Set("description", fvRsPathAtt.Description) d.Set("annotation", fvRsPathAttMap["annotation"]) d.Set("encap", fvRsPathAttMap["encap"]) d.Set("instr_imedcy", fvRsPathAttMap["instrImedcy"]) diff --git a/aci/resource_aci_fvrspathatt_test.go b/aci/resource_aci_fvrspathatt_test.go deleted file mode 100644 index ecb671cd3..000000000 --- a/aci/resource_aci_fvrspathatt_test.go +++ /dev/null @@ -1,161 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciStaticPath_Basic(t *testing.T) { - var static_path models.StaticPath - description := "static_path created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciStaticPathDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciStaticPathConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciStaticPathExists("aci_epg_to_static_path.foostatic_path", &static_path), - testAccCheckAciStaticPathAttributes(description, &static_path), - ), - }, - }, - }) -} - -func TestAccAciStaticPath_update(t *testing.T) { - var static_path models.StaticPath - description := "static_path created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciStaticPathDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciStaticPathConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciStaticPathExists("aci_epg_to_static_path.foostatic_path", &static_path), - testAccCheckAciStaticPathAttributes(description, &static_path), - ), - }, - { - Config: testAccCheckAciStaticPathConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciStaticPathExists("aci_epg_to_static_path.foostatic_path", &static_path), - testAccCheckAciStaticPathAttributes(description, &static_path), - ), - }, - }, - }) -} - -func testAccCheckAciStaticPathConfig_basic(description string) string { - return fmt.Sprintf(` - - - - resource "aci_epg_to_static_path" "foostatic_path" { - application_epg_dn = "uni/tn-demo_dev_tenant/ap-demo_ap/epg-demo_epg" - #application_epg_dn = aci_application_epg.example.id - description = "%s" - - tdn = "topology/pod-1/paths-101/pathep-[eth1/1]" - annotation = "example" - instr_imedcy = "immediate" - mode = "regular" - encap = "vlan-1000" - primary_encap = "unknown" - } - `, description) -} - -func testAccCheckAciStaticPathExists(name string, static_path *models.StaticPath) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Static Path %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Static Path dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - static_pathFound := models.StaticPathFromContainer(cont) - if static_pathFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Static Path %s not found", rs.Primary.ID) - } - *static_path = *static_pathFound - return nil - } -} - -func testAccCheckAciStaticPathDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_epg_to_static_path" { - cont, err := client.Get(rs.Primary.ID) - static_path := models.StaticPathFromContainer(cont) - if err == nil { - return fmt.Errorf("Static Path %s Still exists", static_path.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciStaticPathAttributes(description string, static_path *models.StaticPath) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != static_path.Description { - return fmt.Errorf("Bad static_path Description %s", static_path.Description) - } - - if "topology/pod-1/paths-101/pathep-[eth1/1]" != static_path.TDn { - return fmt.Errorf("Bad static_path t_dn %s", static_path.TDn) - } - - if "example" != static_path.Annotation { - return fmt.Errorf("Bad static_path annotation %s", static_path.Annotation) - } - - if "vlan-1000" != static_path.Encap { - return fmt.Errorf("Bad static_path encap %s", static_path.Encap) - } - - if "immediate" != static_path.InstrImedcy { - return fmt.Errorf("Bad static_path instr_imedcy %s", static_path.InstrImedcy) - } - - if "regular" != static_path.Mode { - return fmt.Errorf("Bad static_path mode %s", static_path.Mode) - } - - if "unknown" != static_path.PrimaryEncap { - return fmt.Errorf("Bad static_path primary_encap %s", static_path.PrimaryEncap) - } - - return nil - } -} diff --git a/aci/resource_aci_fvrsprovcons.go b/aci/resource_aci_fvrsprovcons.go index 1d7eef44e..5498882a3 100644 --- a/aci/resource_aci_fvrsprovcons.go +++ b/aci/resource_aci_fvrsprovcons.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log" + "strings" "github.com/ciscoecosystem/aci-go-client/client" "github.com/ciscoecosystem/aci-go-client/models" @@ -25,7 +26,7 @@ func resourceAciContractProvider() *schema.Resource { SchemaVersion: 1, - Schema: AppendBaseAttrSchema(map[string]*schema.Schema{ + Schema: map[string]*schema.Schema{ "application_epg_dn": &schema.Schema{ Type: schema.TypeString, Required: true, @@ -70,7 +71,15 @@ func resourceAciContractProvider() *schema.Resource { "level1", }, false), }, - }), + "annotation": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + DefaultFunc: func() (interface{}, error) { + return "orchestrator:terraform", nil + }, + }, + }, } } @@ -155,7 +164,12 @@ func resourceAciContractProviderImport(d *schema.ResourceData, m interface{}) ([ aciClient := m.(*client.Client) dn := d.Id() - contractType := d.Get("contract_type").(string) + contractType := "" + if strings.Contains(dn, "/rsprov") { + contractType = "provider" + } else if strings.Contains(dn, "/rscons") { + contractType = "consumer" + } var schemaFilled *schema.ResourceData if contractType == "provider" { @@ -172,6 +186,7 @@ func resourceAciContractProviderImport(d *schema.ResourceData, m interface{}) ([ if err != nil { return nil, err } + d.Set("contract_type", contractType) } else if contractType == "consumer" { fvRsCons, err := getRemoteContractConsumer(aciClient, dn) @@ -187,6 +202,7 @@ func resourceAciContractProviderImport(d *schema.ResourceData, m interface{}) ([ if err != nil { return nil, err } + d.Set("contract_type", contractType) } else { return nil, fmt.Errorf("Contract Type: Value must be from [provider, consumer]") diff --git a/aci/resource_aci_fvrsprovcons_test.go b/aci/resource_aci_fvrsprovcons_test.go deleted file mode 100644 index 097533d0e..000000000 --- a/aci/resource_aci_fvrsprovcons_test.go +++ /dev/null @@ -1,157 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciContractProvider_Basic(t *testing.T) { - var contract_provider models.ContractProvider - description := "contract_provider created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciContractProviderDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciContractProviderConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciContractProviderExists("aci_contract_provider.foocontract_provider", &contract_provider), - testAccCheckAciContractProviderAttributes(description, &contract_provider), - ), - }, - { - ResourceName: "aci_contract_provider", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAciContractProvider_update(t *testing.T) { - var contract_provider models.ContractProvider - description := "contract_provider created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciContractProviderDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciContractProviderConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciContractProviderExists("aci_contract_provider.foocontract_provider", &contract_provider), - testAccCheckAciContractProviderAttributes(description, &contract_provider), - ), - }, - { - Config: testAccCheckAciContractProviderConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciContractProviderExists("aci_contract_provider.foocontract_provider", &contract_provider), - testAccCheckAciContractProviderAttributes(description, &contract_provider), - ), - }, - }, - }) -} - -func testAccCheckAciContractProviderConfig_basic(description string) string { - return fmt.Sprintf(` - - resource "aci_contract_provider" "foocontract_provider" { - application_epg_dn = aci_application_epg.example.id - description = "%s" - tnVzBrCPName = "example" - annotation = "example" - match_t = "All" - prio = "unspecified" - tn_vz_br_cp_name = "example" - } - `, description) -} - -func testAccCheckAciContractProviderExists(name string, contract_provider *models.ContractProvider) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Contract Provider %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Contract Provider dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - contract_providerFound := models.ContractProviderFromContainer(cont) - if contract_providerFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Contract Provider %s not found", rs.Primary.ID) - } - *contract_provider = *contract_providerFound - return nil - } -} - -func testAccCheckAciContractProviderDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_contract_provider" { - cont, err := client.Get(rs.Primary.ID) - contract_provider := models.ContractProviderFromContainer(cont) - if err == nil { - return fmt.Errorf("Contract Provider %s Still exists", contract_provider.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciContractProviderAttributes(description string, contract_provider *models.ContractProvider) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != contract_provider.Description { - return fmt.Errorf("Bad contract_provider Description %s", contract_provider.Description) - } - - if "example" != contract_provider.TnVzBrCPName { - return fmt.Errorf("Bad contract_provider tn_vz_br_cp_name %s", contract_provider.TnVzBrCPName) - } - - if "example" != contract_provider.Annotation { - return fmt.Errorf("Bad contract_provider annotation %s", contract_provider.Annotation) - } - - if "All" != contract_provider.MatchT { - return fmt.Errorf("Bad contract_provider match_t %s", contract_provider.MatchT) - } - - if "unspecified" != contract_provider.Prio { - return fmt.Errorf("Bad contract_provider prio %s", contract_provider.Prio) - } - - if "example" != contract_provider.TnVzBrCPName { - return fmt.Errorf("Bad contract_provider tn_vz_br_cp_name %s", contract_provider.TnVzBrCPName) - } - - return nil - } -} diff --git a/aci/resource_aci_fvsubnet.go b/aci/resource_aci_fvsubnet.go index 9284bac00..21749d834 100644 --- a/aci/resource_aci_fvsubnet.go +++ b/aci/resource_aci_fvsubnet.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "reflect" + "regexp" "sort" "strings" @@ -253,6 +254,10 @@ func checkForConflictingVRF(client *client.Client, tenantDN, bdName, vrfDn, ip s } func checkForConflictingIP(client *client.Client, parentDN string, ip string) error { + bdRegex := `^uni\/tn-[a-zA-Z0-9_.-]+\/BD-[a-zA-Z0-9_.-]+$` + if match, _ := regexp.MatchString(bdRegex, parentDN); !match { + return fmt.Errorf("%s is not valid bridge_domain_dn", parentDN) + } tokens := strings.Split(parentDN, "/") bdName := (strings.Split(tokens[2], "-"))[1] tenantDn := fmt.Sprintf("%s/%s", tokens[0], tokens[1]) diff --git a/aci/resource_aci_fvsubnet_test.go b/aci/resource_aci_fvsubnet_test.go deleted file mode 100644 index ada9920a1..000000000 --- a/aci/resource_aci_fvsubnet_test.go +++ /dev/null @@ -1,162 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciSubnet_Basic(t *testing.T) { - var subnet models.Subnet - description := "subnet created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciSubnetDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciSubnetConfig_basic(description, "unspecified"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciSubnetExists("aci_subnet.foosubnet", &subnet), - testAccCheckAciSubnetAttributes(description, "unspecified", &subnet), - ), - }, - }, - }) -} - -func TestAccAciSubnet_update(t *testing.T) { - var subnet models.Subnet - description := "subnet created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciSubnetDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciSubnetConfig_basic(description, "unspecified"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciSubnetExists("aci_subnet.foosubnet", &subnet), - testAccCheckAciSubnetAttributes(description, "unspecified", &subnet), - ), - }, - { - Config: testAccCheckAciSubnetConfig_basic(description, "nd"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciSubnetExists("aci_subnet.foosubnet", &subnet), - testAccCheckAciSubnetAttributes(description, "nd", &subnet), - ), - }, - }, - }) -} - -func testAccCheckAciSubnetConfig_basic(description, Ctrl string) string { - return fmt.Sprintf(` - resource "aci_tenant" "tenant_for_subnet" { - name = "tenant_for_subnet" - description = "This tenant is created by terraform ACI provider" - } - resource "aci_bridge_domain" "bd_for_subnet" { - tenant_dn = aci_tenant.tenant_for_subnet.id - name = "bd_for_subnet" - } - - resource "aci_subnet" "foosubnet" { - parent_dn = aci_bridge_domain.bd_for_subnet.id - description = "%s" - ip = "10.0.3.28/27" - annotation = "tag_subnet" - ctrl = ["nd"] - name_alias = "alias_subnet" - preferred = "no" - scope = ["private"] - virtual = "yes" - } - `, description) -} - -func testAccCheckAciSubnetExists(name string, subnet *models.Subnet) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Subnet %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Subnet dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - subnetFound := models.SubnetFromContainer(cont) - if subnetFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Subnet %s not found", rs.Primary.ID) - } - *subnet = *subnetFound - return nil - } -} - -func testAccCheckAciSubnetDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_subnet" { - cont, err := client.Get(rs.Primary.ID) - subnet := models.SubnetFromContainer(cont) - if err == nil { - return fmt.Errorf("Subnet %s Still exists", subnet.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciSubnetAttributes(description, Ctrl string, subnet *models.Subnet) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != subnet.Description { - return fmt.Errorf("Bad subnet Description %s", subnet.Description) - } - - if "10.0.3.28/27" != subnet.Ip { - return fmt.Errorf("Bad subnet ip %s", subnet.Ip) - } - - if "tag_subnet" != subnet.Annotation { - return fmt.Errorf("Bad subnet annotation %s", subnet.Annotation) - } - - if "alias_subnet" != subnet.NameAlias { - return fmt.Errorf("Bad subnet name_alias %s", subnet.NameAlias) - } - - if "no" != subnet.Preferred { - return fmt.Errorf("Bad subnet preferred %s", subnet.Preferred) - } - - if "yes" != subnet.Virtual { - return fmt.Errorf("Bad subnet virtual %s", subnet.Virtual) - } - - return nil - } -} diff --git a/aci/resource_aci_fvtenant.go b/aci/resource_aci_fvtenant.go index e046b3f6a..7ce50703d 100644 --- a/aci/resource_aci_fvtenant.go +++ b/aci/resource_aci_fvtenant.go @@ -46,7 +46,7 @@ func resourceAciTenant() *schema.Resource { }, "relation_fv_rs_tenant_mon_pol": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, }), diff --git a/aci/resource_aci_fvtenant_test.go b/aci/resource_aci_fvtenant_test.go deleted file mode 100644 index 5cb4b9592..000000000 --- a/aci/resource_aci_fvtenant_test.go +++ /dev/null @@ -1,140 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciTenant_Basic(t *testing.T) { - var tenant models.Tenant - description := "tenant created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciTenantDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciTenantConfig_basic(description, "tag_tenant"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciTenantExists("aci_tenant.footenant", &tenant), - testAccCheckAciTenantAttributes(description, "tag_tenant", &tenant), - ), - }, - }, - }) -} - -func TestAccAciTenant_update(t *testing.T) { - var tenant models.Tenant - description := "tenant created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciTenantDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciTenantConfig_basic(description, "tag_tenant"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciTenantExists("aci_tenant.footenant", &tenant), - testAccCheckAciTenantAttributes(description, "tag_tenant", &tenant), - ), - }, - { - Config: testAccCheckAciTenantConfig_basic(description, "tag_change"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciTenantExists("aci_tenant.footenant", &tenant), - testAccCheckAciTenantAttributes(description, "tag_change", &tenant), - ), - }, - }, - }) -} - -func testAccCheckAciTenantConfig_basic(description, annotation string) string { - return fmt.Sprintf(` - resource "aci_tenant" "footenant" { - description = "%s" - name = "demo_tenant" - annotation = "%s" - name_alias = "alias_tenant" - } - `, description, annotation) -} - -func testAccCheckAciTenantExists(name string, tenant *models.Tenant) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Tenant %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Tenant dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - tenantFound := models.TenantFromContainer(cont) - if tenantFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Tenant %s not found", rs.Primary.ID) - } - *tenant = *tenantFound - return nil - } -} - -func testAccCheckAciTenantDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_tenant" { - cont, err := client.Get(rs.Primary.ID) - tenant := models.TenantFromContainer(cont) - if err == nil { - return fmt.Errorf("Tenant %s Still exists", tenant.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciTenantAttributes(description, annotation string, tenant *models.Tenant) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != tenant.Description { - return fmt.Errorf("Bad tenant Description %s", tenant.Description) - } - - if "demo_tenant" != tenant.Name { - return fmt.Errorf("Bad tenant name %s", tenant.Name) - } - - if annotation != tenant.Annotation { - return fmt.Errorf("Bad tenant annotation %s", tenant.Annotation) - } - - if "alias_tenant" != tenant.NameAlias { - return fmt.Errorf("Bad tenant name_alias %s", tenant.NameAlias) - } - - return nil - } -} diff --git a/aci/resource_aci_hsrpgroupp.go b/aci/resource_aci_hsrpgroupp.go index b994a02b4..00e4fb54c 100644 --- a/aci/resource_aci_hsrpgroupp.go +++ b/aci/resource_aci_hsrpgroupp.go @@ -178,7 +178,7 @@ func resourceAciHSRPGroupProfileImport(d *schema.ResourceData, m interface{}) ([ if err != nil { return nil, err } - + d.Set("l3out_hsrp_interface_profile_dn", GetParentDn(dn, fmt.Sprintf("/hsrpGroupP-%s", hsrpGroupP.Name))) log.Printf("[DEBUG] %s: Import finished successfully", d.Id()) return []*schema.ResourceData{schemaFilled}, nil diff --git a/aci/resource_aci_hsrpgroupp_test.go b/aci/resource_aci_hsrpgroupp_test.go deleted file mode 100644 index 56dc434ad..000000000 --- a/aci/resource_aci_hsrpgroupp_test.go +++ /dev/null @@ -1,176 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciHSRPGroupProfile_Basic(t *testing.T) { - var hsrp_group_profile models.HSRPGroupProfile - description := "hsrp_group_profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciHSRPGroupProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciHSRPGroupProfileConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciHSRPGroupProfileExists("aci_l3out_hsrp_interface_group.test", &hsrp_group_profile), - testAccCheckAciHSRPGroupProfileAttributes(description, &hsrp_group_profile), - ), - }, - }, - }) -} - -func TestAccAciHSRPGroupProfile_update(t *testing.T) { - var hsrp_group_profile models.HSRPGroupProfile - description := "hsrp_group_profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciHSRPGroupProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciHSRPGroupProfileConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciHSRPGroupProfileExists("aci_l3out_hsrp_interface_group.test", &hsrp_group_profile), - testAccCheckAciHSRPGroupProfileAttributes(description, &hsrp_group_profile), - ), - }, - { - Config: testAccCheckAciHSRPGroupProfileConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciHSRPGroupProfileExists("aci_l3out_hsrp_interface_group.test", &hsrp_group_profile), - testAccCheckAciHSRPGroupProfileAttributes(description, &hsrp_group_profile), - ), - }, - }, - }) -} - -func testAccCheckAciHSRPGroupProfileConfig_basic(description string) string { - return fmt.Sprintf(` - resource "aci_l3out_hsrp_interface_group" "test" { - l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.example.id - name = "one" - annotation = "example" - description = "%s" - config_issues = "Secondary-vip-conflicts-if-ip" - group_af = "ipv4" - group_id = "20" - group_name = "test" - ip = "10.22.30.40" - ip_obtain_mode = "admin" - mac = "02:10:45:00:00:56" - name_alias = "example" - } - `, description) -} - -func testAccCheckAciHSRPGroupProfileExists(name string, hsrp_group_profile *models.HSRPGroupProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("HSRP Group Profile %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No HSRP Group Profile dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - hsrp_group_profileFound := models.HSRPGroupProfileFromContainer(cont) - if hsrp_group_profileFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("HSRP Group Profile %s not found", rs.Primary.ID) - } - *hsrp_group_profile = *hsrp_group_profileFound - return nil - } -} - -func testAccCheckAciHSRPGroupProfileDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_l3out_hsrp_interface_group" { - cont, err := client.Get(rs.Primary.ID) - hsrp_group_profile := models.HSRPGroupProfileFromContainer(cont) - if err == nil { - return fmt.Errorf("HSRP Group Profile %s Still exists", hsrp_group_profile.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciHSRPGroupProfileAttributes(description string, hsrp_group_profile *models.HSRPGroupProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != hsrp_group_profile.Description { - return fmt.Errorf("Bad hsrp_group_profile Description %s", hsrp_group_profile.Description) - } - - if "one" != hsrp_group_profile.Name { - return fmt.Errorf("Bad hsrp_group_profile name %s", hsrp_group_profile.Name) - } - - if "example" != hsrp_group_profile.Annotation { - return fmt.Errorf("Bad hsrp_group_profile annotation %s", hsrp_group_profile.Annotation) - } - - if "Secondary-vip-conflicts-if-ip" != hsrp_group_profile.ConfigIssues { - return fmt.Errorf("Bad hsrp_group_profile config_issues %s", hsrp_group_profile.ConfigIssues) - } - - if "ipv4" != hsrp_group_profile.GroupAf { - return fmt.Errorf("Bad hsrp_group_profile group_af %s", hsrp_group_profile.GroupAf) - } - - if "20" != hsrp_group_profile.GroupId { - return fmt.Errorf("Bad hsrp_group_profile group_id %s", hsrp_group_profile.GroupId) - } - - if "test" != hsrp_group_profile.GroupName { - return fmt.Errorf("Bad hsrp_group_profile group_name %s", hsrp_group_profile.GroupName) - } - - if "10.22.30.40" != hsrp_group_profile.Ip { - return fmt.Errorf("Bad hsrp_group_profile ip %s", hsrp_group_profile.Ip) - } - - if "admin" != hsrp_group_profile.IpObtainMode { - return fmt.Errorf("Bad hsrp_group_profile ip_obtain_mode %s", hsrp_group_profile.IpObtainMode) - } - - if "02:10:45:00:00:56" != hsrp_group_profile.Mac { - return fmt.Errorf("Bad hsrp_group_profile mac %s", hsrp_group_profile.Mac) - } - - if "example" != hsrp_group_profile.NameAlias { - return fmt.Errorf("Bad hsrp_group_profile name_alias %s", hsrp_group_profile.NameAlias) - } - - return nil - } -} diff --git a/aci/resource_aci_hsrpifp.go b/aci/resource_aci_hsrpifp.go index f0fe62d77..359061a93 100644 --- a/aci/resource_aci_hsrpifp.go +++ b/aci/resource_aci_hsrpifp.go @@ -49,8 +49,8 @@ func resourceAciL3outHSRPInterfaceProfile() *schema.Resource { }, "relation_hsrp_rs_if_pol": &schema.Schema{ - Type: schema.TypeString, - Computed: true, + Type: schema.TypeString, + Optional: true, }, }), diff --git a/aci/resource_aci_hsrpifp_test.go b/aci/resource_aci_hsrpifp_test.go deleted file mode 100644 index 82dce1400..000000000 --- a/aci/resource_aci_hsrpifp_test.go +++ /dev/null @@ -1,141 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciL3outHSRPInterfaceProfile_Basic(t *testing.T) { - var l3out_hsrp_interface_profile models.L3outHSRPInterfaceProfile - description := "interface_profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciL3outHSRPInterfaceProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciL3outHSRPInterfaceProfileConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciL3outHSRPInterfaceProfileExists("aci_l3out_hsrp_interface_profile.fool3out_hsrp_interface_profile", &l3out_hsrp_interface_profile), - testAccCheckAciL3outHSRPInterfaceProfileAttributes(description, &l3out_hsrp_interface_profile), - ), - }, - }, - }) -} - -func TestAccAciL3outHSRPInterfaceProfile_update(t *testing.T) { - var l3out_hsrp_interface_profile models.L3outHSRPInterfaceProfile - description := "interface_profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciL3outHSRPInterfaceProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciL3outHSRPInterfaceProfileConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciL3outHSRPInterfaceProfileExists("aci_l3out_hsrp_interface_profile.fool3out_hsrp_interface_profile", &l3out_hsrp_interface_profile), - testAccCheckAciL3outHSRPInterfaceProfileAttributes(description, &l3out_hsrp_interface_profile), - ), - }, - { - Config: testAccCheckAciL3outHSRPInterfaceProfileConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciL3outHSRPInterfaceProfileExists("aci_l3out_hsrp_interface_profile.fool3out_hsrp_interface_profile", &l3out_hsrp_interface_profile), - testAccCheckAciL3outHSRPInterfaceProfileAttributes(description, &l3out_hsrp_interface_profile), - ), - }, - }, - }) -} - -func testAccCheckAciL3outHSRPInterfaceProfileConfig_basic(description string) string { - return fmt.Sprintf(` - resource "aci_l3out_hsrp_interface_profile" "fool3out_hsrp_interface_profile" { - logical_interface_profile_dn = aci_logical_interface_profile.example.id - description = "%s" - annotation = "example" - name_alias = "example" - version = "v1" - } - `, description) -} - -func testAccCheckAciL3outHSRPInterfaceProfileExists(name string, l3out_hsrp_interface_profile *models.L3outHSRPInterfaceProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("L3out HSRP Interface Profile %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No L3out HSRP Interface Profile dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - l3out_hsrp_interface_profileFound := models.L3outHSRPInterfaceProfileFromContainer(cont) - if l3out_hsrp_interface_profileFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("L3out HSRP Interface Profile %s not found", rs.Primary.ID) - } - *l3out_hsrp_interface_profile = *l3out_hsrp_interface_profileFound - return nil - } -} - -func testAccCheckAciL3outHSRPInterfaceProfileDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_interface_profile" { - cont, err := client.Get(rs.Primary.ID) - l3out_hsrp_interface_profile := models.L3outHSRPInterfaceProfileFromContainer(cont) - if err == nil { - return fmt.Errorf("L3out HSRP Interface Profile %s Still exists", l3out_hsrp_interface_profile.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciL3outHSRPInterfaceProfileAttributes(description string, l3out_hsrp_interface_profile *models.L3outHSRPInterfaceProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != l3out_hsrp_interface_profile.Description { - return fmt.Errorf("Bad l3out_hsrp_interface_profile Description %s", l3out_hsrp_interface_profile.Description) - } - - if "example" != l3out_hsrp_interface_profile.Annotation { - return fmt.Errorf("Bad l3out_hsrp_interface_profile annotation %s", l3out_hsrp_interface_profile.Annotation) - } - - if "example" != l3out_hsrp_interface_profile.NameAlias { - return fmt.Errorf("Bad l3out_hsrp_interface_profile name_alias %s", l3out_hsrp_interface_profile.NameAlias) - } - - if "v1" != l3out_hsrp_interface_profile.Version { - return fmt.Errorf("Bad l3out_hsrp_interface_profile version %s", l3out_hsrp_interface_profile.Version) - } - - return nil - } -} diff --git a/aci/resource_aci_hsrpifpol.go b/aci/resource_aci_hsrpifpol.go index 7284c6915..17f64bb2c 100644 --- a/aci/resource_aci_hsrpifpol.go +++ b/aci/resource_aci_hsrpifpol.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log" + "reflect" "sort" "strings" @@ -43,6 +44,7 @@ func resourceAciHSRPInterfacePolicy() *schema.Resource { "ctrl": &schema.Schema{ Type: schema.TypeList, Optional: true, + Computed: true, Elem: &schema.Schema{ Type: schema.TypeString, ValidateFunc: validation.StringInSlice([]string{ @@ -106,11 +108,22 @@ func setHSRPInterfacePolicyAttributes(hsrpIfPol *models.HSRPInterfacePolicy, d * d.Set("annotation", hsrpIfPolMap["annotation"]) ctrlGet := make([]string, 0, 1) for _, val := range strings.Split(hsrpIfPolMap["ctrl"], ",") { - ctrlGet = append(ctrlGet, strings.Trim(val, " ")) + if val != "" { + ctrlGet = append(ctrlGet, strings.Trim(val, " ")) + } } sort.Strings(ctrlGet) - if len(ctrlGet) == 1 && ctrlGet[0] == "" { - d.Set("ctrl", make([]string, 0, 1)) + if ctrlInp, ok := d.GetOk("ctrl"); ok { + ctrlAct := make([]string, 0, 1) + for _, val := range ctrlInp.([]interface{}) { + ctrlAct = append(ctrlAct, val.(string)) + } + sort.Strings(ctrlAct) + if reflect.DeepEqual(ctrlAct, ctrlGet) { + d.Set("ctrl", d.Get("ctrl").([]interface{})) + } else { + d.Set("ctrl", ctrlGet) + } } else { d.Set("ctrl", ctrlGet) } @@ -128,7 +141,6 @@ func resourceAciHSRPInterfacePolicyImport(d *schema.ResourceData, m interface{}) dn := d.Id() hsrpIfPol, err := getRemoteHSRPInterfacePolicy(aciClient, dn) - if err != nil { return nil, err } @@ -137,7 +149,7 @@ func resourceAciHSRPInterfacePolicyImport(d *schema.ResourceData, m interface{}) if err != nil { return nil, err } - + d.Set("tenant_dn", GetParentDn(dn, fmt.Sprintf("/hsrpIfPol-%s", hsrpIfPol.Name))) log.Printf("[DEBUG] %s: Import finished successfully", d.Id()) return []*schema.ResourceData{schemaFilled}, nil @@ -163,8 +175,14 @@ func resourceAciHSRPInterfacePolicyCreate(ctx context.Context, d *schema.Resourc for _, val := range ctrl.([]interface{}) { ctrlList = append(ctrlList, val.(string)) } + err := checkDuplicate(ctrlList) + if err != nil { + return diag.FromErr(err) + } ctrl := strings.Join(ctrlList, ",") hsrpIfPolAttr.Ctrl = ctrl + } else { + hsrpIfPolAttr.Ctrl = "" } if Delay, ok := d.GetOk("delay"); ok { hsrpIfPolAttr.Delay = Delay.(string) @@ -209,8 +227,14 @@ func resourceAciHSRPInterfacePolicyUpdate(ctx context.Context, d *schema.Resourc for _, val := range ctrl.([]interface{}) { ctrlList = append(ctrlList, val.(string)) } + err := checkDuplicate(ctrlList) + if err != nil { + return diag.FromErr(err) + } ctrl := strings.Join(ctrlList, ",") hsrpIfPolAttr.Ctrl = ctrl + } else { + hsrpIfPolAttr.Ctrl = "" } if Delay, ok := d.GetOk("delay"); ok { hsrpIfPolAttr.Delay = Delay.(string) diff --git a/aci/resource_aci_hsrpifpol_test.go b/aci/resource_aci_hsrpifpol_test.go deleted file mode 100644 index 8b6fd3f88..000000000 --- a/aci/resource_aci_hsrpifpol_test.go +++ /dev/null @@ -1,157 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciHSRPInterfacePolicy_Basic(t *testing.T) { - var hsrp_interface_policy models.HSRPInterfacePolicy - description := "hsrp_interface_policy created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciHSRPInterfacePolicyDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciHSRPInterfacePolicyConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciHSRPInterfacePolicyExists("aci_hsrp_interface_policy.test", &hsrp_interface_policy), - testAccCheckAciHSRPInterfacePolicyAttributes(description, &hsrp_interface_policy), - ), - }, - }, - }) -} - -func TestAccAciHSRPInterfacePolicy_update(t *testing.T) { - var hsrp_interface_policy models.HSRPInterfacePolicy - description := "hsrp_interface_policy created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciHSRPInterfacePolicyDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciHSRPInterfacePolicyConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciHSRPInterfacePolicyExists("aci_hsrp_interface_policy.test", &hsrp_interface_policy), - testAccCheckAciHSRPInterfacePolicyAttributes(description, &hsrp_interface_policy), - ), - }, - { - Config: testAccCheckAciHSRPInterfacePolicyConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciHSRPInterfacePolicyExists("aci_hsrp_interface_policy.test", &hsrp_interface_policy), - testAccCheckAciHSRPInterfacePolicyAttributes(description, &hsrp_interface_policy), - ), - }, - }, - }) -} - -func testAccCheckAciHSRPInterfacePolicyConfig_basic(description string) string { - return fmt.Sprintf(` - resource "aci_hsrp_interface_policy" "test" { - tenant_dn = aci_tenant.example.id - #tenant_dn = "uni/tn-aaaaa" - name = "one" - annotation = "example" - description = "%s" - ctrl = "bia" - delay = "10" - name_alias = "example" - reload_delay = "10" - } - `, description) -} - -func testAccCheckAciHSRPInterfacePolicyExists(name string, hsrp_interface_policy *models.HSRPInterfacePolicy) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("HSRP Interface Policy %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No HSRP Interface Policy dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - hsrp_interface_policyFound := models.HSRPInterfacePolicyFromContainer(cont) - if hsrp_interface_policyFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("HSRP Interface Policy %s not found", rs.Primary.ID) - } - *hsrp_interface_policy = *hsrp_interface_policyFound - return nil - } -} - -func testAccCheckAciHSRPInterfacePolicyDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_hsrp_interface_policy" { - cont, err := client.Get(rs.Primary.ID) - hsrp_interface_policy := models.HSRPInterfacePolicyFromContainer(cont) - if err == nil { - return fmt.Errorf("HSRP Interface Policy %s Still exists", hsrp_interface_policy.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciHSRPInterfacePolicyAttributes(description string, hsrp_interface_policy *models.HSRPInterfacePolicy) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != hsrp_interface_policy.Description { - return fmt.Errorf("Bad hsrp_interface_policy Description %s", hsrp_interface_policy.Description) - } - - if "one" != hsrp_interface_policy.Name { - return fmt.Errorf("Bad hsrp_interface_policy name %s", hsrp_interface_policy.Name) - } - - if "example" != hsrp_interface_policy.Annotation { - return fmt.Errorf("Bad hsrp_interface_policy annotation %s", hsrp_interface_policy.Annotation) - } - - if "bia" != hsrp_interface_policy.Ctrl { - return fmt.Errorf("Bad hsrp_interface_policy ctrl %s", hsrp_interface_policy.Ctrl) - } - - if "10" != hsrp_interface_policy.Delay { - return fmt.Errorf("Bad hsrp_interface_policy delay %s", hsrp_interface_policy.Delay) - } - - if "example" != hsrp_interface_policy.NameAlias { - return fmt.Errorf("Bad hsrp_interface_policy name_alias %s", hsrp_interface_policy.NameAlias) - } - - if "10" != hsrp_interface_policy.ReloadDelay { - return fmt.Errorf("Bad hsrp_interface_policy reload_delay %s", hsrp_interface_policy.ReloadDelay) - } - - return nil - } -} diff --git a/aci/resource_aci_hsrpsecvip_test.go b/aci/resource_aci_hsrpsecvip_test.go deleted file mode 100644 index 856daf71d..000000000 --- a/aci/resource_aci_hsrpsecvip_test.go +++ /dev/null @@ -1,147 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciL3outHSRPSecondaryVIP_Basic(t *testing.T) { - var l3out_hsrp_secondary_vip models.L3outHSRPSecondaryVIP - description := "secondary_virtual_ip_policy created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciL3outHSRPSecondaryVIPDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciL3outHSRPSecondaryVIPConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciL3outHSRPSecondaryVIPExists("aci_l3out_hsrp_secondary_vip.fool3out_hsrp_secondary_vip", &l3out_hsrp_secondary_vip), - testAccCheckAciL3outHSRPSecondaryVIPAttributes(description, &l3out_hsrp_secondary_vip), - ), - }, - }, - }) -} - -func TestAccAciL3outHSRPSecondaryVIP_update(t *testing.T) { - var l3out_hsrp_secondary_vip models.L3outHSRPSecondaryVIP - description := "secondary_virtual_ip_policy created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciL3outHSRPSecondaryVIPDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciL3outHSRPSecondaryVIPConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciL3outHSRPSecondaryVIPExists("aci_l3out_hsrp_secondary_vip.fool3out_hsrp_secondary_vip", &l3out_hsrp_secondary_vip), - testAccCheckAciL3outHSRPSecondaryVIPAttributes(description, &l3out_hsrp_secondary_vip), - ), - }, - { - Config: testAccCheckAciL3outHSRPSecondaryVIPConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciL3outHSRPSecondaryVIPExists("aci_l3out_hsrp_secondary_vip.fool3out_hsrp_secondary_vip", &l3out_hsrp_secondary_vip), - testAccCheckAciL3outHSRPSecondaryVIPAttributes(description, &l3out_hsrp_secondary_vip), - ), - }, - }, - }) -} - -func testAccCheckAciL3outHSRPSecondaryVIPConfig_basic(description string) string { - return fmt.Sprintf(` - - resource "aci_l3out_hsrp_secondary_vip" "fool3out_hsrp_secondary_vip" { - l3out_hsrp_interface_group_dn = "uni/tn-check_tenantnk/out-crest_test_rutvik_l3out/lnodep-crest_test_rutvik_node/lifp-demo_int_prof/hsrpIfP/hsrpGroupP-hsrp_group_profile" - description = "%s" - ip = "10.0.0.3" - annotation = "example" - config_issues = "GroupMac-Conflicts-Other-Group" - name_alias = "example" - } - `, description) -} - -func testAccCheckAciL3outHSRPSecondaryVIPExists(name string, l3out_hsrp_secondary_vip *models.L3outHSRPSecondaryVIP) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("L3out HSRP Secondary VIP %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No L3out HSRP Secondary VIP dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - l3out_hsrp_secondary_vipFound := models.L3outHSRPSecondaryVIPFromContainer(cont) - if l3out_hsrp_secondary_vipFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("L3out HSRP Secondary VIP %s not found", rs.Primary.ID) - } - *l3out_hsrp_secondary_vip = *l3out_hsrp_secondary_vipFound - return nil - } -} - -func testAccCheckAciL3outHSRPSecondaryVIPDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_secondary_virtual_ip_policy" { - cont, err := client.Get(rs.Primary.ID) - l3out_hsrp_secondary_vip := models.L3outHSRPSecondaryVIPFromContainer(cont) - if err == nil { - return fmt.Errorf("L3out HSRP Secondary VIP %s Still exists", l3out_hsrp_secondary_vip.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciL3outHSRPSecondaryVIPAttributes(description string, l3out_hsrp_secondary_vip *models.L3outHSRPSecondaryVIP) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != l3out_hsrp_secondary_vip.Description { - return fmt.Errorf("Bad l3out_hsrp_secondary_vip Description %s", l3out_hsrp_secondary_vip.Description) - } - - if "10.0.0.3" != l3out_hsrp_secondary_vip.Ip { - return fmt.Errorf("Bad l3out_hsrp_secondary_vip ip %s", l3out_hsrp_secondary_vip.Ip) - } - - if "example" != l3out_hsrp_secondary_vip.Annotation { - return fmt.Errorf("Bad l3out_hsrp_secondary_vip annotation %s", l3out_hsrp_secondary_vip.Annotation) - } - - if "GroupMac-Conflicts-Other-Group" != l3out_hsrp_secondary_vip.ConfigIssues { - return fmt.Errorf("Bad l3out_hsrp_secondary_vip config_issues %s", l3out_hsrp_secondary_vip.ConfigIssues) - } - - if "example" != l3out_hsrp_secondary_vip.NameAlias { - return fmt.Errorf("Bad l3out_hsrp_secondary_vip name_alias %s", l3out_hsrp_secondary_vip.NameAlias) - } - - return nil - } -} diff --git a/aci/resource_aci_l3extinstp.go b/aci/resource_aci_l3extinstp.go index 0e9cf2533..06b65c0b7 100644 --- a/aci/resource_aci_l3extinstp.go +++ b/aci/resource_aci_l3extinstp.go @@ -39,9 +39,9 @@ func resourceAciExternalNetworkInstanceProfile() *schema.Resource { }, "exception_tag": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - Computed: true, + Type: schema.TypeString, + Optional: true, + Computed: true, }, "flood_on_encap": &schema.Schema{ @@ -158,7 +158,7 @@ func resourceAciExternalNetworkInstanceProfile() *schema.Resource { }, "relation_fv_rs_cust_qos_pol": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, "relation_l3ext_rs_inst_p_to_profile": &schema.Schema{ diff --git a/aci/resource_aci_l3extinstp_test.go b/aci/resource_aci_l3extinstp_test.go deleted file mode 100644 index 11b55fa7b..000000000 --- a/aci/resource_aci_l3extinstp_test.go +++ /dev/null @@ -1,182 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciExternalNetworkInstanceProfile_Basic(t *testing.T) { - var external_network_instance_profile models.ExternalNetworkInstanceProfile - description := "external_network_instance_profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciExternalNetworkInstanceProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciExternalNetworkInstanceProfileConfig_basic(description, "AtleastOne"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciExternalNetworkInstanceProfileExists("aci_external_network_instance_profile.fooexternal_network_instance_profile", &external_network_instance_profile), - testAccCheckAciExternalNetworkInstanceProfileAttributes(description, "AtleastOne", &external_network_instance_profile), - ), - }, - }, - }) -} - -func TestAccAciExternalNetworkInstanceProfile_update(t *testing.T) { - var external_network_instance_profile models.ExternalNetworkInstanceProfile - description := "external_network_instance_profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciExternalNetworkInstanceProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciExternalNetworkInstanceProfileConfig_basic(description, "AtleastOne"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciExternalNetworkInstanceProfileExists("aci_external_network_instance_profile.fooexternal_network_instance_profile", &external_network_instance_profile), - testAccCheckAciExternalNetworkInstanceProfileAttributes(description, "AtleastOne", &external_network_instance_profile), - ), - }, - { - Config: testAccCheckAciExternalNetworkInstanceProfileConfig_basic(description, "All"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciExternalNetworkInstanceProfileExists("aci_external_network_instance_profile.fooexternal_network_instance_profile", &external_network_instance_profile), - testAccCheckAciExternalNetworkInstanceProfileAttributes(description, "All", &external_network_instance_profile), - ), - }, - }, - }) -} - -func testAccCheckAciExternalNetworkInstanceProfileConfig_basic(description, match_t string) string { - return fmt.Sprintf(` - - resource "aci_tenant" "example" { - name = "test_acc_tenant" - } - - resource "aci_l3_outside" "example" { - tenant_dn = aci_tenant.example.id - name = "demo_l3out" - target_dscp = "CS0" - } - - resource "aci_external_network_instance_profile" "fooexternal_network_instance_profile" { - l3_outside_dn = aci_l3_outside.example.id - description = "%s" - name = "demo_inst_prof" - annotation = "tag_network_profile" - exception_tag = "2" - flood_on_encap = "disabled" - match_t = "%s" - name_alias = "alias_profile" - pref_gr_memb = "exclude" - prio = "level1" - target_dscp = "unspecified" - } - `, description, match_t) -} - -func testAccCheckAciExternalNetworkInstanceProfileExists(name string, external_network_instance_profile *models.ExternalNetworkInstanceProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("External Network Instance Profile %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No External Network Instance Profile dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - external_network_instance_profileFound := models.ExternalNetworkInstanceProfileFromContainer(cont) - if external_network_instance_profileFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("External Network Instance Profile %s not found", rs.Primary.ID) - } - *external_network_instance_profile = *external_network_instance_profileFound - return nil - } -} - -func testAccCheckAciExternalNetworkInstanceProfileDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_external_network_instance_profile" { - cont, err := client.Get(rs.Primary.ID) - external_network_instance_profile := models.ExternalNetworkInstanceProfileFromContainer(cont) - if err == nil { - return fmt.Errorf("External Network Instance Profile %s Still exists", external_network_instance_profile.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciExternalNetworkInstanceProfileAttributes(description, match_t string, external_network_instance_profile *models.ExternalNetworkInstanceProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != external_network_instance_profile.Description { - return fmt.Errorf("Bad external_network_instance_profile Description %s", external_network_instance_profile.Description) - } - - if "demo_inst_prof" != external_network_instance_profile.Name { - return fmt.Errorf("Bad external_network_instance_profile name %s", external_network_instance_profile.Name) - } - - if "tag_network_profile" != external_network_instance_profile.Annotation { - return fmt.Errorf("Bad external_network_instance_profile annotation %s", external_network_instance_profile.Annotation) - } - - if "2" != external_network_instance_profile.ExceptionTag { - return fmt.Errorf("Bad external_network_instance_profile exception_tag %s", external_network_instance_profile.ExceptionTag) - } - - if "disabled" != external_network_instance_profile.FloodOnEncap { - return fmt.Errorf("Bad external_network_instance_profile flood_on_encap %s", external_network_instance_profile.FloodOnEncap) - } - - if match_t != external_network_instance_profile.MatchT { - return fmt.Errorf("Bad external_network_instance_profile match_t %s", external_network_instance_profile.MatchT) - } - - if "alias_profile" != external_network_instance_profile.NameAlias { - return fmt.Errorf("Bad external_network_instance_profile name_alias %s", external_network_instance_profile.NameAlias) - } - - if "exclude" != external_network_instance_profile.PrefGrMemb { - return fmt.Errorf("Bad external_network_instance_profile pref_gr_memb %s", external_network_instance_profile.PrefGrMemb) - } - - if "level1" != external_network_instance_profile.Prio { - return fmt.Errorf("Bad external_network_instance_profile prio %s", external_network_instance_profile.Prio) - } - - if "unspecified" != external_network_instance_profile.TargetDscp { - return fmt.Errorf("Bad external_network_instance_profile target_dscp %s", external_network_instance_profile.TargetDscp) - } - - return nil - } -} diff --git a/aci/resource_aci_l3extlifp.go b/aci/resource_aci_l3extlifp.go index 763d41fb8..8829377e2 100644 --- a/aci/resource_aci_l3extlifp.go +++ b/aci/resource_aci_l3extlifp.go @@ -74,27 +74,27 @@ func resourceAciLogicalInterfaceProfile() *schema.Resource { "relation_l3ext_rs_egress_qos_dpp_pol": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, "relation_l3ext_rs_ingress_qos_dpp_pol": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, "relation_l3ext_rs_l_if_p_cust_qos_pol": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, "relation_l3ext_rs_arp_if_pol": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, "relation_l3ext_rs_nd_if_pol": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, }), diff --git a/aci/resource_aci_l3extlifp_test.go b/aci/resource_aci_l3extlifp_test.go deleted file mode 100644 index 1d433ef96..000000000 --- a/aci/resource_aci_l3extlifp_test.go +++ /dev/null @@ -1,153 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciLogicalInterfaceProfile_Basic(t *testing.T) { - var logical_interface_profile models.LogicalInterfaceProfile - description := "logical_interface_profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciLogicalInterfaceProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciLogicalInterfaceProfileConfig_basic(description, "black"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciLogicalInterfaceProfileExists("aci_logical_interface_profile.foological_interface_profile", &logical_interface_profile), - testAccCheckAciLogicalInterfaceProfileAttributes(description, "black", &logical_interface_profile), - ), - }, - }, - }) -} - -func TestAccAciLogicalInterfaceProfile_update(t *testing.T) { - var logical_interface_profile models.LogicalInterfaceProfile - description := "logical_interface_profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciLogicalInterfaceProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciLogicalInterfaceProfileConfig_basic(description, "black"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciLogicalInterfaceProfileExists("aci_logical_interface_profile.foological_interface_profile", &logical_interface_profile), - testAccCheckAciLogicalInterfaceProfileAttributes(description, "black", &logical_interface_profile), - ), - }, - { - Config: testAccCheckAciLogicalInterfaceProfileConfig_basic(description, "white"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciLogicalInterfaceProfileExists("aci_logical_interface_profile.foological_interface_profile", &logical_interface_profile), - testAccCheckAciLogicalInterfaceProfileAttributes(description, "white", &logical_interface_profile), - ), - }, - }, - }) -} - -func testAccCheckAciLogicalInterfaceProfileConfig_basic(description, tag string) string { - return fmt.Sprintf(` - - resource "aci_logical_interface_profile" "foological_interface_profile" { - # logical_node_profile_dn = aci_logical_node_profile.example.id - logical_node_profile_dn = "uni/tn-check_tenantnk/out-demo_l3out/lnodep-demo_node_one" - description = "%s" - name = "demo_int_prof" - annotation = "tag_prof" - name_alias = "alias_prof" - prio = "unspecified" - tag = "%s" - } - `, description, tag) -} - -func testAccCheckAciLogicalInterfaceProfileExists(name string, logical_interface_profile *models.LogicalInterfaceProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Logical Interface Profile %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Logical Interface Profile dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - logical_interface_profileFound := models.LogicalInterfaceProfileFromContainer(cont) - if logical_interface_profileFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Logical Interface Profile %s not found", rs.Primary.ID) - } - *logical_interface_profile = *logical_interface_profileFound - return nil - } -} - -func testAccCheckAciLogicalInterfaceProfileDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_logical_interface_profile" { - cont, err := client.Get(rs.Primary.ID) - logical_interface_profile := models.LogicalInterfaceProfileFromContainer(cont) - if err == nil { - return fmt.Errorf("Logical Interface Profile %s Still exists", logical_interface_profile.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciLogicalInterfaceProfileAttributes(description, tag string, logical_interface_profile *models.LogicalInterfaceProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != logical_interface_profile.Description { - return fmt.Errorf("Bad logical_interface_profile Description %s", logical_interface_profile.Description) - } - - if "demo_int_prof" != logical_interface_profile.Name { - return fmt.Errorf("Bad logical_interface_profile name %s", logical_interface_profile.Name) - } - - if "tag_prof" != logical_interface_profile.Annotation { - return fmt.Errorf("Bad logical_interface_profile annotation %s", logical_interface_profile.Annotation) - } - - if "alias_prof" != logical_interface_profile.NameAlias { - return fmt.Errorf("Bad logical_interface_profile name_alias %s", logical_interface_profile.NameAlias) - } - - if "unspecified" != logical_interface_profile.Prio { - return fmt.Errorf("Bad logical_interface_profile prio %s", logical_interface_profile.Prio) - } - - if tag != logical_interface_profile.Tag { - return fmt.Errorf("Bad logical_interface_profile tag %s", logical_interface_profile.Tag) - } - - return nil - } -} diff --git a/aci/resource_aci_l3extlnodep_test.go b/aci/resource_aci_l3extlnodep_test.go deleted file mode 100644 index 88eb5fff0..000000000 --- a/aci/resource_aci_l3extlnodep_test.go +++ /dev/null @@ -1,154 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciLogicalNodeProfile_Basic(t *testing.T) { - var logical_node_profile models.LogicalNodeProfile - description := "logical_node_profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciLogicalNodeProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciLogicalNodeProfileConfig_basic(description, "black"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciLogicalNodeProfileExists("aci_logical_node_profile.foological_node_profile", &logical_node_profile), - testAccCheckAciLogicalNodeProfileAttributes(description, "black", &logical_node_profile), - ), - }, - }, - }) -} - -func TestAccAciLogicalNodeProfile_update(t *testing.T) { - var logical_node_profile models.LogicalNodeProfile - description := "logical_node_profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciLogicalNodeProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciLogicalNodeProfileConfig_basic(description, "black"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciLogicalNodeProfileExists("aci_logical_node_profile.foological_node_profile", &logical_node_profile), - testAccCheckAciLogicalNodeProfileAttributes(description, "black", &logical_node_profile), - ), - }, - { - Config: testAccCheckAciLogicalNodeProfileConfig_basic(description, "white"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciLogicalNodeProfileExists("aci_logical_node_profile.foological_node_profile", &logical_node_profile), - testAccCheckAciLogicalNodeProfileAttributes(description, "white", &logical_node_profile), - ), - }, - }, - }) -} - -func testAccCheckAciLogicalNodeProfileConfig_basic(description, tag string) string { - return fmt.Sprintf(` - - resource "aci_logical_node_profile" "foological_node_profile" { - # l3_outside_dn = aci_l3_outside.example.id - l3_outside_dn = "uni/tn-check_tenantnk/out-demo_l3out" - description = "%s" - name = "demo_node" - annotation = "tag_node" - config_issues = "none" - name_alias = "alias_node" - tag = "%s" - target_dscp = "unspecified" - } - `, description, tag) -} - -func testAccCheckAciLogicalNodeProfileExists(name string, logical_node_profile *models.LogicalNodeProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Logical Node Profile %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Logical Node Profile dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - logical_node_profileFound := models.LogicalNodeProfileFromContainer(cont) - if logical_node_profileFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Logical Node Profile %s not found", rs.Primary.ID) - } - *logical_node_profile = *logical_node_profileFound - return nil - } -} - -func testAccCheckAciLogicalNodeProfileDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_logical_node_profile" { - cont, err := client.Get(rs.Primary.ID) - logical_node_profile := models.LogicalNodeProfileFromContainer(cont) - if err == nil { - return fmt.Errorf("Logical Node Profile %s Still exists", logical_node_profile.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciLogicalNodeProfileAttributes(description, tag string, logical_node_profile *models.LogicalNodeProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != logical_node_profile.Description { - return fmt.Errorf("Bad logical_node_profile Description %s", logical_node_profile.Description) - } - - if "demo_node" != logical_node_profile.Name { - return fmt.Errorf("Bad logical_node_profile name %s", logical_node_profile.Name) - } - - if "tag_node" != logical_node_profile.Annotation { - return fmt.Errorf("Bad logical_node_profile annotation %s", logical_node_profile.Annotation) - } - - if "alias_node" != logical_node_profile.NameAlias { - return fmt.Errorf("Bad logical_node_profile name_alias %s", logical_node_profile.NameAlias) - } - - if tag != logical_node_profile.Tag { - return fmt.Errorf("Bad logical_node_profile tag %s", logical_node_profile.Tag) - } - - if "unspecified" != logical_node_profile.TargetDscp { - return fmt.Errorf("Bad logical_node_profile target_dscp %s", logical_node_profile.TargetDscp) - } - - return nil - } -} diff --git a/aci/resource_aci_l3extout.go b/aci/resource_aci_l3extout.go index 753503813..27604161f 100644 --- a/aci/resource_aci_l3extout.go +++ b/aci/resource_aci_l3extout.go @@ -109,7 +109,7 @@ func resourceAciL3Outside() *schema.Resource { }, "relation_l3ext_rs_ectx": &schema.Schema{ Type: schema.TypeString, - Computed: true, + Optional: true, }, "relation_l3ext_rs_out_to_bd_public_subnet_holder": &schema.Schema{ @@ -236,6 +236,10 @@ func resourceAciL3OutsideCreate(ctx context.Context, d *schema.ResourceData, m i for _, val := range EnforceRtctrl.([]interface{}) { enforceRtctrlList = append(enforceRtctrlList, val.(string)) } + err := checkDuplicate(enforceRtctrlList) + if err != nil { + return diag.FromErr(err) + } EnforceRtctrl := strings.Join(enforceRtctrlList, ",") l3extOutAttr.EnforceRtctrl = EnforceRtctrl } @@ -361,6 +365,10 @@ func resourceAciL3OutsideUpdate(ctx context.Context, d *schema.ResourceData, m i for _, val := range EnforceRtctrl.([]interface{}) { enforceRtctrlList = append(enforceRtctrlList, val.(string)) } + err := checkDuplicate(enforceRtctrlList) + if err != nil { + return diag.FromErr(err) + } EnforceRtctrl := strings.Join(enforceRtctrlList, ",") l3extOutAttr.EnforceRtctrl = EnforceRtctrl } diff --git a/aci/resource_aci_l3extout_test.go b/aci/resource_aci_l3extout_test.go deleted file mode 100644 index 260ff2353..000000000 --- a/aci/resource_aci_l3extout_test.go +++ /dev/null @@ -1,153 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciL3Outside_Basic(t *testing.T) { - var l3_outside models.L3Outside - description := "l3_outside created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciL3OutsideDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciL3OutsideConfig_basic(description, "export"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciL3OutsideExists("aci_l3_outside.fool3_outside", &l3_outside), - testAccCheckAciL3OutsideAttributes(description, "export", &l3_outside), - ), - }, - }, - }) -} - -func TestAccAciL3Outside_update(t *testing.T) { - var l3_outside models.L3Outside - description := "l3_outside created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciL3OutsideDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciL3OutsideConfig_basic(description, "export"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciL3OutsideExists("aci_l3_outside.fool3_outside", &l3_outside), - testAccCheckAciL3OutsideAttributes(description, "export", &l3_outside), - ), - }, - { - Config: testAccCheckAciL3OutsideConfig_basic(description, "export"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciL3OutsideExists("aci_l3_outside.fool3_outside", &l3_outside), - testAccCheckAciL3OutsideAttributes(description, "export", &l3_outside), - ), - }, - }, - }) -} - -func testAccCheckAciL3OutsideConfig_basic(description, enforce_rtctrl string) string { - return fmt.Sprintf(` - - resource "aci_l3_outside" "fool3_outside" { - tenant_dn = aci_tenant.example.id - description = "%s" - name = "demo_l3out" - annotation = "tag_l3out" - enforce_rtctrl = "%s" - name_alias = "alias_out" - target_dscp = "unspecified" - } - - `, description, enforce_rtctrl) -} - -func testAccCheckAciL3OutsideExists(name string, l3_outside *models.L3Outside) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("L3 Outside %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No L3 Outside dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - l3_outsideFound := models.L3OutsideFromContainer(cont) - if l3_outsideFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("L3 Outside %s not found", rs.Primary.ID) - } - *l3_outside = *l3_outsideFound - return nil - } -} - -func testAccCheckAciL3OutsideDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_l3_outside" { - cont, err := client.Get(rs.Primary.ID) - l3_outside := models.L3OutsideFromContainer(cont) - if err == nil { - return fmt.Errorf("L3 Outside %s Still exists", l3_outside.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciL3OutsideAttributes(description, enforce_rtctrl string, l3_outside *models.L3Outside) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != l3_outside.Description { - return fmt.Errorf("Bad l3_outside Description %s", l3_outside.Description) - } - - if "demo_l3out" != l3_outside.Name { - return fmt.Errorf("Bad l3_outside name %s", l3_outside.Name) - } - - if "tag_l3out" != l3_outside.Annotation { - return fmt.Errorf("Bad l3_outside annotation %s", l3_outside.Annotation) - } - - if enforce_rtctrl != l3_outside.EnforceRtctrl { - return fmt.Errorf("Bad l3_outside enforce_rtctrl %s", l3_outside.EnforceRtctrl) - } - - if "alias_out" != l3_outside.NameAlias { - return fmt.Errorf("Bad l3_outside name_alias %s", l3_outside.NameAlias) - } - - if "unspecified" != l3_outside.TargetDscp { - return fmt.Errorf("Bad l3_outside target_dscp %s", l3_outside.TargetDscp) - } - - return nil - } -} diff --git a/aci/resource_aci_l3extroutetagpol_test.go b/aci/resource_aci_l3extroutetagpol_test.go deleted file mode 100644 index 273bd3566..000000000 --- a/aci/resource_aci_l3extroutetagpol_test.go +++ /dev/null @@ -1,146 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciL3outRouteTagPolicy_Basic(t *testing.T) { - var l3out_route_tag_policy models.L3outRouteTagPolicy - description := "route_tag_policy created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciL3outRouteTagPolicyDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciL3outRouteTagPolicyConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciL3outRouteTagPolicyExists("aci_l3out_route_tag_policy.fool3out_route_tag_policy", &l3out_route_tag_policy), - testAccCheckAciL3outRouteTagPolicyAttributes(description, &l3out_route_tag_policy), - ), - }, - }, - }) -} - -func TestAccAciL3outRouteTagPolicy_update(t *testing.T) { - var l3out_route_tag_policy models.L3outRouteTagPolicy - description := "route_tag_policy created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciL3outRouteTagPolicyDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciL3outRouteTagPolicyConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciL3outRouteTagPolicyExists("aci_l3out_route_tag_policy.fool3out_route_tag_policy", &l3out_route_tag_policy), - testAccCheckAciL3outRouteTagPolicyAttributes(description, &l3out_route_tag_policy), - ), - }, - { - Config: testAccCheckAciL3outRouteTagPolicyConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciL3outRouteTagPolicyExists("aci_l3out_route_tag_policy.fool3out_route_tag_policy", &l3out_route_tag_policy), - testAccCheckAciL3outRouteTagPolicyAttributes(description, &l3out_route_tag_policy), - ), - }, - }, - }) -} - -func testAccCheckAciL3outRouteTagPolicyConfig_basic(description string) string { - return fmt.Sprintf(` - resource "aci_l3out_route_tag_policy" "fool3out_route_tag_policy" { - tenant_dn = aci_tenant.example.id - description = "%s" - name = "example" - annotation = "example" - name_alias = "example" - tag = "1" - } - `, description) -} - -func testAccCheckAciL3outRouteTagPolicyExists(name string, l3out_route_tag_policy *models.L3outRouteTagPolicy) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("L3out Route Tag Policy %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No L3out Route Tag Policy dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - l3out_route_tag_policyFound := models.L3outRouteTagPolicyFromContainer(cont) - if l3out_route_tag_policyFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("L3out Route Tag Policy %s not found", rs.Primary.ID) - } - *l3out_route_tag_policy = *l3out_route_tag_policyFound - return nil - } -} - -func testAccCheckAciL3outRouteTagPolicyDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_route_tag_policy" { - cont, err := client.Get(rs.Primary.ID) - l3out_route_tag_policy := models.L3outRouteTagPolicyFromContainer(cont) - if err == nil { - return fmt.Errorf("L3out Route Tag Policy %s Still exists", l3out_route_tag_policy.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciL3outRouteTagPolicyAttributes(description string, l3out_route_tag_policy *models.L3outRouteTagPolicy) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != l3out_route_tag_policy.Description { - return fmt.Errorf("Bad l3out_route_tag_policy Description %s", l3out_route_tag_policy.Description) - } - - if "example" != l3out_route_tag_policy.Name { - return fmt.Errorf("Bad l3out_route_tag_policy name %s", l3out_route_tag_policy.Name) - } - - if "example" != l3out_route_tag_policy.Annotation { - return fmt.Errorf("Bad l3out_route_tag_policy annotation %s", l3out_route_tag_policy.Annotation) - } - - if "example" != l3out_route_tag_policy.NameAlias { - return fmt.Errorf("Bad l3out_route_tag_policy name_alias %s", l3out_route_tag_policy.NameAlias) - } - - if "1" != l3out_route_tag_policy.Tag { - return fmt.Errorf("Bad l3out_route_tag_policy tag %s", l3out_route_tag_policy.Tag) - } - - return nil - } -} diff --git a/aci/resource_aci_l3extrsnodel3outatt.go b/aci/resource_aci_l3extrsnodel3outatt.go index 9e9217277..52ad223b6 100644 --- a/aci/resource_aci_l3extrsnodel3outatt.go +++ b/aci/resource_aci_l3extrsnodel3outatt.go @@ -29,11 +29,13 @@ func resourceAciFabricNode() *schema.Resource { "logical_node_profile_dn": &schema.Schema{ Type: schema.TypeString, Required: true, + ForceNew: true, }, "tdn": &schema.Schema{ Type: schema.TypeString, Required: true, + ForceNew: true, }, "config_issues": &schema.Schema{ diff --git a/aci/resource_aci_l3extsubnet.go b/aci/resource_aci_l3extsubnet.go index 097c1c235..d076e67bc 100644 --- a/aci/resource_aci_l3extsubnet.go +++ b/aci/resource_aci_l3extsubnet.go @@ -229,6 +229,10 @@ func resourceAciL3ExtSubnetCreate(ctx context.Context, d *schema.ResourceData, m for _, val := range Scope.([]interface{}) { scpList = append(scpList, val.(string)) } + err := checkDuplicate(scpList) + if err != nil { + return diag.FromErr(err) + } scp := strings.Join(scpList, ",") l3extSubnetAttr.Scope = scp } @@ -325,6 +329,10 @@ func resourceAciL3ExtSubnetUpdate(ctx context.Context, d *schema.ResourceData, m for _, val := range Scope.([]interface{}) { scpList = append(scpList, val.(string)) } + err := checkDuplicate(scpList) + if err != nil { + return diag.FromErr(err) + } scp := strings.Join(scpList, ",") l3extSubnetAttr.Scope = scp } diff --git a/aci/resource_aci_l3extsubnet_test.go b/aci/resource_aci_l3extsubnet_test.go deleted file mode 100644 index dea08ea73..000000000 --- a/aci/resource_aci_l3extsubnet_test.go +++ /dev/null @@ -1,149 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciL3ExtSubnet_Basic(t *testing.T) { - var subnet models.L3ExtSubnet - description := "L3 subnet created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciL3ExtSubnetDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciL3ExtSubnetConfig_basic(description, "import-rtctrl"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciL3ExtSubnetExists("aci_l3_ext_subnet.foosubnet", &subnet), - testAccCheckAciL3ExtSubnetAttributes(description, "import-rtctrl", &subnet), - ), - }, - }, - }) -} - -func TestAccAciL3ExtSubnet_update(t *testing.T) { - var subnet models.L3ExtSubnet - description := "subnet created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciL3ExtSubnetDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciL3ExtSubnetConfig_basic(description, "import-rtctrl"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciL3ExtSubnetExists("aci_l3_ext_subnet.foosubnet", &subnet), - testAccCheckAciL3ExtSubnetAttributes(description, "import-rtctrl", &subnet), - ), - }, - { - Config: testAccCheckAciL3ExtSubnetConfig_basic(description, "export-rtctrl"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciL3ExtSubnetExists("aci_l3_ext_subnet.foosubnet", &subnet), - testAccCheckAciL3ExtSubnetAttributes(description, "export-rtctrl", &subnet), - ), - }, - }, - }) -} - -func testAccCheckAciL3ExtSubnetConfig_basic(description, aggregate string) string { - return fmt.Sprintf(` - - resource "aci_l3_ext_subnet" "foosubnet" { - # external_network_instance_profile_dn = aci_external_network_instance_profile.example.id - external_network_instance_profile_dn = "uni/tn-check_tenantnk/out-demo_l3out/instP-demo_inst_prof" - description = "%s" - ip = "0.0.0.0/0" - aggregate = "%s" - annotation = "tag_ext_subnet" - name_alias = "alias_ext_subnet" - scope = ["import-security"] - } - `, description, aggregate) -} - -func testAccCheckAciL3ExtSubnetExists(name string, subnet *models.L3ExtSubnet) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("L3 Ext Subnet %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No L3 Ext Subnet dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - subnetFound := models.L3ExtSubnetFromContainer(cont) - if subnetFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("L3 Ext Subnet %s not found", rs.Primary.ID) - } - *subnet = *subnetFound - return nil - } -} - -func testAccCheckAciL3ExtSubnetDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_l3_ext_subnet" { - cont, err := client.Get(rs.Primary.ID) - subnet := models.SubnetFromContainer(cont) - if err == nil { - return fmt.Errorf("Subnet %s Still exists", subnet.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciL3ExtSubnetAttributes(description, aggregate string, subnet *models.L3ExtSubnet) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != subnet.Description { - return fmt.Errorf("Bad subnet Description %s", subnet.Description) - } - - if "0.0.0.0/0" != subnet.Ip { - return fmt.Errorf("Bad subnet ip %s", subnet.Ip) - } - - if aggregate != subnet.Aggregate { - return fmt.Errorf("Bad subnet aggregate %s", subnet.Aggregate) - } - - if "tag_ext_subnet" != subnet.Annotation { - return fmt.Errorf("Bad subnet annotation %s", subnet.Annotation) - } - - if "alias_ext_subnet" != subnet.NameAlias { - return fmt.Errorf("Bad subnet name_alias %s", subnet.NameAlias) - } - - return nil - } -} diff --git a/aci/resource_aci_l3extvirtuallifp.go b/aci/resource_aci_l3extvirtuallifp.go index 3054e2d24..0efc606f6 100644 --- a/aci/resource_aci_l3extvirtuallifp.go +++ b/aci/resource_aci_l3extvirtuallifp.go @@ -223,7 +223,7 @@ func resourceAciVirtualLogicalInterfaceProfileImport(d *schema.ResourceData, m i if err != nil { return nil, err } - + d.Set("logical_interface_profile_dn", GetParentDn(dn, fmt.Sprintf("/vlifp-[%s]-[%s]", l3extVirtualLIfP.NodeDn, l3extVirtualLIfP.Encap))) log.Printf("[DEBUG] %s: Import finished successfully", d.Id()) return []*schema.ResourceData{schemaFilled}, nil diff --git a/aci/resource_aci_l3extvirtuallifp_test.go b/aci/resource_aci_l3extvirtuallifp_test.go deleted file mode 100644 index 3df65abb5..000000000 --- a/aci/resource_aci_l3extvirtuallifp_test.go +++ /dev/null @@ -1,192 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciVirtualLogicalInterfaceProfile_Basic(t *testing.T) { - var logical_interface_profile models.VirtualLogicalInterfaceProfile - description := "logical_interface_profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciVirtualLogicalInterfaceProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciVirtualLogicalInterfaceProfileConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciVirtualLogicalInterfaceProfileExists("aci_l3out_floating_svi.test", &logical_interface_profile), - testAccCheckAciVirtualLogicalInterfaceProfileAttributes(description, &logical_interface_profile), - ), - }, - }, - }) -} - -func TestAccAciVirtualLogicalInterfaceProfile_update(t *testing.T) { - var logical_interface_profile models.VirtualLogicalInterfaceProfile - description := "logical_interface_profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciVirtualLogicalInterfaceProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciVirtualLogicalInterfaceProfileConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciVirtualLogicalInterfaceProfileExists("aci_l3out_floating_svi.test", &logical_interface_profile), - testAccCheckAciVirtualLogicalInterfaceProfileAttributes(description, &logical_interface_profile), - ), - }, - { - Config: testAccCheckAciVirtualLogicalInterfaceProfileConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciVirtualLogicalInterfaceProfileExists("aci_l3out_floating_svi.test", &logical_interface_profile), - testAccCheckAciVirtualLogicalInterfaceProfileAttributes(description, &logical_interface_profile), - ), - }, - }, - }) -} - -func testAccCheckAciVirtualLogicalInterfaceProfileConfig_basic(description string) string { - return fmt.Sprintf(` - - resource "aci_l3out_floating_svi" "test" { - logical_interface_profile_dn = "uni/tn-aaaaa/out-demo_l3out/lnodep-demo_node/lifp-demo_int_prof" - node_dn = "topology/pod-1/node-201" - encap = "vlan-20" - addr = "10.20.30.40/16" - annotation = "example" - description = "%s" - autostate = "enabled" - encap_scope = "ctx" - if_inst_t = "ext-svi" - ipv6_dad = "disabled" - ll_addr = "::" - mac = "12:23:34:45:56:67" - mode = "untagged" - mtu = "580" - target_dscp = "CS1" - } - `, description) -} - -func testAccCheckAciVirtualLogicalInterfaceProfileExists(name string, logical_interface_profile *models.VirtualLogicalInterfaceProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Logical Interface Profile %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Logical Interface Profile dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - logical_interface_profileFound := models.VirtualLogicalInterfaceProfileFromContainer(cont) - if logical_interface_profileFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Logical Interface Profile %s not found", rs.Primary.ID) - } - *logical_interface_profile = *logical_interface_profileFound - return nil - } -} - -func testAccCheckAciVirtualLogicalInterfaceProfileDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_l3out_floating_svi" { - cont, err := client.Get(rs.Primary.ID) - logical_interface_profile := models.LogicalInterfaceProfileFromContainer(cont) - if err == nil { - return fmt.Errorf("Logical Interface Profile %s Still exists", logical_interface_profile.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciVirtualLogicalInterfaceProfileAttributes(description string, logical_interface_profile *models.VirtualLogicalInterfaceProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != logical_interface_profile.Description { - return fmt.Errorf("Bad logical_interface_profile Description %s", logical_interface_profile.Description) - } - - if "topology/pod-1/node-201" != logical_interface_profile.NodeDn { - return fmt.Errorf("Bad logical_interface_profile node_dn %s", logical_interface_profile.NodeDn) - } - - if "vlan-20" != logical_interface_profile.Encap { - return fmt.Errorf("Bad logical_interface_profile encap %s", logical_interface_profile.Encap) - } - - if "10.20.30.40/16" != logical_interface_profile.Addr { - return fmt.Errorf("Bad logical_interface_profile addr %s", logical_interface_profile.Addr) - } - - if "example" != logical_interface_profile.Annotation { - return fmt.Errorf("Bad logical_interface_profile annotation %s", logical_interface_profile.Annotation) - } - - if "enabled" != logical_interface_profile.Autostate { - return fmt.Errorf("Bad logical_interface_profile autostate %s", logical_interface_profile.Autostate) - } - - if "ctx" != logical_interface_profile.EncapScope { - return fmt.Errorf("Bad logical_interface_profile encap_scope %s", logical_interface_profile.EncapScope) - } - - if "ext-svi" != logical_interface_profile.IfInstT { - return fmt.Errorf("Bad logical_interface_profile if_inst_t %s", logical_interface_profile.IfInstT) - } - - if "disabled" != logical_interface_profile.Ipv6Dad { - return fmt.Errorf("Bad logical_interface_profile ipv6_dad %s", logical_interface_profile.Ipv6Dad) - } - - if "::" != logical_interface_profile.LlAddr { - return fmt.Errorf("Bad logical_interface_profile ll_addr %s", logical_interface_profile.LlAddr) - } - - if "12:23:34:45:56:67" != logical_interface_profile.Mac { - return fmt.Errorf("Bad logical_interface_profile mac %s", logical_interface_profile.Mac) - } - - if "untagged" != logical_interface_profile.Mode { - return fmt.Errorf("Bad logical_interface_profile mode %s", logical_interface_profile.Mode) - } - - if "580" != logical_interface_profile.Mtu { - return fmt.Errorf("Bad logical_interface_profile mtu %s", logical_interface_profile.Mtu) - } - - if "CS1" != logical_interface_profile.TargetDscp { - return fmt.Errorf("Bad logical_interface_profile target_dscp %s", logical_interface_profile.TargetDscp) - } - - return nil - } -} diff --git a/aci/resource_aci_ospfifp.go b/aci/resource_aci_ospfifp.go index ccb0fd4d0..7dc438169 100644 --- a/aci/resource_aci_ospfifp.go +++ b/aci/resource_aci_ospfifp.go @@ -20,7 +20,7 @@ func resourceAciOSPFInterfaceProfile() *schema.Resource { DeleteContext: resourceAciOSPFInterfaceProfileDelete, Importer: &schema.ResourceImporter{ - State: resourceAciInterfaceProfileImport, + State: resourceAciOSPFInterfaceProfileImport, }, SchemaVersion: 1, @@ -120,7 +120,7 @@ func resourceAciOSPFInterfaceProfileImport(d *schema.ResourceData, m interface{} if err != nil { return nil, err } - + d.Set("logical_interface_profile_dn", GetParentDn(dn, "/ospfIfP")) log.Printf("[DEBUG] %s: Import finished successfully", d.Id()) return []*schema.ResourceData{schemaFilled}, nil diff --git a/aci/resource_aci_ospfifp_test.go b/aci/resource_aci_ospfifp_test.go deleted file mode 100644 index 0f1b19b9e..000000000 --- a/aci/resource_aci_ospfifp_test.go +++ /dev/null @@ -1,148 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciOSPFInterfaceProfile_Basic(t *testing.T) { - var L3outOSPF models.OSPFInterfaceProfile - description := "L3out OSPF Interface Profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciOSPFInterfaceProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciOSPFInterfaceProfileConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciOSPFInterfaceProfileExists("aci_l3out_ospf_interface_profile.test", &L3outOSPF), - testAccCheckAciOSPFInterfaceProfileAttributes(description, &L3outOSPF), - ), - }, - }, - }) -} - -func TestAccAciOSPFInterfaceProfile_update(t *testing.T) { - var L3outOSPF models.OSPFInterfaceProfile - description := "L3out OSPF Interface Profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciOSPFInterfaceProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciOSPFInterfaceProfileConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciOSPFInterfaceProfileExists("aci_l3out_ospf_interface_profile.test", &L3outOSPF), - testAccCheckAciOSPFInterfaceProfileAttributes(description, &L3outOSPF), - ), - }, - { - Config: testAccCheckAciOSPFInterfaceProfileConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciOSPFInterfaceProfileExists("aci_l3out_ospf_interface_profile.test", &L3outOSPF), - testAccCheckAciOSPFInterfaceProfileAttributes(description, &L3outOSPF), - ), - }, - }, - }) -} - -func testAccCheckAciOSPFInterfaceProfileConfig_basic(description string) string { - return fmt.Sprintf(` - - resource "aci_l3out_ospf_interface_profile" "test" { - logical_interface_profile_dn = aci_logical_interface_profile.example.id - description = "%s" - annotation = "example" - auth_key = "example" - auth_key_id = "255" - auth_type = "simple" - name_alias = "example" - } - `, description) -} - -func testAccCheckAciOSPFInterfaceProfileExists(name string, interface_profile *models.OSPFInterfaceProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("L3out OSPF Interface Profile %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No L3out OSPF Interface Profile dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - interface_profileFound := models.OSPFInterfaceProfileFromContainer(cont) - if interface_profileFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("L3out OSPF Interface Profile %s not found", rs.Primary.ID) - } - *interface_profile = *interface_profileFound - return nil - } -} - -func testAccCheckAciOSPFInterfaceProfileDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_l3out_ospf_interface_profile" { - cont, err := client.Get(rs.Primary.ID) - interface_profile := models.OSPFInterfaceProfileFromContainer(cont) - if err == nil { - return fmt.Errorf("L3out OSPF Interface Profile %s Still exists", interface_profile.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciOSPFInterfaceProfileAttributes(description string, interface_profile *models.OSPFInterfaceProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != interface_profile.Description { - return fmt.Errorf("Bad L3out OSPF Interface Profile Description %s", interface_profile.Description) - } - - if "example" != interface_profile.Annotation { - return fmt.Errorf("Bad L3out OSPF Interface Profile annotation %s", interface_profile.Annotation) - } - - if "255" != interface_profile.AuthKeyId { - return fmt.Errorf("Bad L3out OSPF Interface Profile auth_key_id %s", interface_profile.AuthKeyId) - } - - if "simple" != interface_profile.AuthType { - return fmt.Errorf("Bad L3out OSPF Interface Profile auth_type %s", interface_profile.AuthType) - } - - if "example" != interface_profile.NameAlias { - return fmt.Errorf("Bad L3out OSPF Interface Profile name_alias %s", interface_profile.NameAlias) - } - - return nil - } -} diff --git a/aci/resource_aci_rtctrlprofile.go b/aci/resource_aci_rtctrlprofile.go index 22605f227..f0c20cd3b 100644 --- a/aci/resource_aci_rtctrlprofile.go +++ b/aci/resource_aci_rtctrlprofile.go @@ -108,6 +108,7 @@ func resourceAciRouteControlProfileImport(d *schema.ResourceData, m interface{}) if err != nil { return nil, err } + d.Set("parent_dn", GetParentDn(dn, fmt.Sprintf("/prof-%s", rtctrlProfile.Name))) log.Printf("[DEBUG] %s: Import finished successfully", d.Id()) return []*schema.ResourceData{schemaFilled}, nil diff --git a/aci/resource_aci_rtctrlprofile_test.go b/aci/resource_aci_rtctrlprofile_test.go deleted file mode 100644 index f040b12a6..000000000 --- a/aci/resource_aci_rtctrlprofile_test.go +++ /dev/null @@ -1,160 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciRouteControlProfile_Basic(t *testing.T) { - var route_control_profile models.RouteControlProfile - description := "route_control_profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciRouteControlProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciRouteControlProfileConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciRouteControlProfileExists("aci_bgp_route_control_profile.test", &route_control_profile), - testAccCheckAciRouteControlProfileAttributes(description, &route_control_profile), - ), - }, - }, - }) -} - -func TestAccAciRouteControlProfile_update(t *testing.T) { - var route_control_profile models.RouteControlProfile - description := "route_control_profile created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciRouteControlProfileDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciRouteControlProfileConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciRouteControlProfileExists("aci_bgp_route_control_profile.test", &route_control_profile), - testAccCheckAciRouteControlProfileAttributes(description, &route_control_profile), - ), - }, - { - Config: testAccCheckAciRouteControlProfileConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciRouteControlProfileExists("aci_bgp_route_control_profile.test", &route_control_profile), - testAccCheckAciRouteControlProfileAttributes(description, &route_control_profile), - ), - }, - }, - }) -} - -func testAccCheckAciRouteControlProfileConfig_basic(description string) string { - return fmt.Sprintf(` - - resource "aci_tenant" "foo_tenant" { - name = "tenant_1" - description = "This tenant is created by terraform ACI provider" - } - - resource "aci_l3_outside" "fool3_outside" { - tenant_dn = aci_tenant.foo_tenant.id - name = "l3_outside_1" - annotation = "l3_outside_tag" - name_alias = "alias_out" - target_dscp = "unspecified" - } - - resource "aci_bgp_route_control_profile" "test" { - parent_dn = aci_l3_outside.fool3_outside.id - name = "one" - annotation = "example" - description = "%s" - name_alias = "example" - route_control_profile_type = "global" - } - `, description) -} - -func testAccCheckAciRouteControlProfileExists(name string, route_control_profile *models.RouteControlProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Route Control Profile %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Route Control Profile dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - route_control_profileFound := models.RouteControlProfileFromContainer(cont) - if route_control_profileFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Route Control Profile %s not found", rs.Primary.ID) - } - *route_control_profile = *route_control_profileFound - return nil - } -} - -func testAccCheckAciRouteControlProfileDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_bgp_route_control_profile" { - cont, err := client.Get(rs.Primary.ID) - route_control_profile := models.RouteControlProfileFromContainer(cont) - if err == nil { - return fmt.Errorf("Route Control Profile %s Still exists", route_control_profile.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciRouteControlProfileAttributes(description string, route_control_profile *models.RouteControlProfile) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != route_control_profile.Description { - return fmt.Errorf("Bad route_control_profile Description %s", route_control_profile.Description) - } - - if "one" != route_control_profile.Name { - return fmt.Errorf("Bad route_control_profile name %s", route_control_profile.Name) - } - - if "example" != route_control_profile.Annotation { - return fmt.Errorf("Bad route_control_profile annotation %s", route_control_profile.Annotation) - } - - if "example" != route_control_profile.NameAlias { - return fmt.Errorf("Bad route_control_profile name_alias %s", route_control_profile.NameAlias) - } - - if "global" != route_control_profile.RouteControlProfileType { - return fmt.Errorf("Bad route_control_profile route_control_profile_type %s", route_control_profile.RouteControlProfileType) - } - - return nil - } -} diff --git a/aci/resource_aci_vzany_test.go b/aci/resource_aci_vzany_test.go deleted file mode 100644 index cc03a6d60..000000000 --- a/aci/resource_aci_vzany_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciAny_Basic(t *testing.T) { - var any models.Any - description := "any created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciAnyDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciAnyConfig_basic(description, "AtleastOne"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciAnyExists("aci_any.fooany", &any), - testAccCheckAciAnyAttributes(description, "AtleastOne", &any), - ), - }, - }, - }) -} - -func TestAccAciAny_update(t *testing.T) { - var any models.Any - description := "any created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciAnyDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciAnyConfig_basic(description, "AtleastOne"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciAnyExists("aci_any.fooany", &any), - testAccCheckAciAnyAttributes(description, "AtleastOne", &any), - ), - }, - { - Config: testAccCheckAciAnyConfig_basic(description, "AtmostOne"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciAnyExists("aci_any.fooany", &any), - testAccCheckAciAnyAttributes(description, "AtmostOne", &any), - ), - }, - }, - }) -} - -func testAccCheckAciAnyConfig_basic(description, match_t string) string { - return fmt.Sprintf(` - - resource "aci_vrf" "example" { - tenant_dn = aci_tenant.example.id - name = "demo_vrf" - } - resource "aci_any" "fooany" { - vrf_dn = aci_vrf.example.id - description = "%s" - annotation = "tag_any" - match_t = "%s" - name_alias = "alias_any" - pref_gr_memb = "disabled" - } - - `, description, match_t) -} - -func testAccCheckAciAnyExists(name string, any *models.Any) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Any %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Any dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - anyFound := models.AnyFromContainer(cont) - if anyFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Any %s not found", rs.Primary.ID) - } - *any = *anyFound - return nil - } -} - -func testAccCheckAciAnyDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_any" { - cont, err := client.Get(rs.Primary.ID) - any := models.AnyFromContainer(cont) - if err == nil { - return fmt.Errorf("Any %s Still exists", any.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciAnyAttributes(description, match_t string, any *models.Any) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != any.Description { - return fmt.Errorf("Bad any Description %s", any.Description) - } - - if "tag_any" != any.Annotation { - return fmt.Errorf("Bad any annotation %s", any.Annotation) - } - - if match_t != any.MatchT { - return fmt.Errorf("Bad any match_t %s", any.MatchT) - } - - if "alias_any" != any.NameAlias { - return fmt.Errorf("Bad any name_alias %s", any.NameAlias) - } - - if "disabled" != any.PrefGrMemb { - return fmt.Errorf("Bad any pref_gr_memb %s", any.PrefGrMemb) - } - - return nil - } -} diff --git a/aci/resource_aci_vzbrcp.go b/aci/resource_aci_vzbrcp.go index 890f50e7a..38bc7a664 100644 --- a/aci/resource_aci_vzbrcp.go +++ b/aci/resource_aci_vzbrcp.go @@ -428,13 +428,13 @@ func resourceAciContract() *schema.Resource { "filter_ids": &schema.Schema{ Type: schema.TypeList, - Optional: true, + Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, "filter_entry_ids": &schema.Schema{ Type: schema.TypeList, - Optional: true, + Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, }), @@ -574,10 +574,12 @@ func setFilterEntryAttributesFromContract(vzentry *models.FilterEntry, d *schema eMap["match_dscp"] = vzEntryMap["matchDscp"] eMap["entry_name_alias"] = vzEntryMap["nameAlias"] eMap["prot"] = vzEntryMap["prot"] - eMap["s_from_port"] = vzEntryMap["sFromPort"] - eMap["s_to_port"] = vzEntryMap["sToPort"] eMap["stateful"] = vzEntryMap["stateful"] - eMap["tcp_rules"] = vzEntryMap["tcpRules"] + if vzEntryMap["tcpRules"] == "" { + eMap["tcp_rules"] = "unspecified" + } else { + eMap["tcp_rules"] = vzEntryMap["tcpRules"] + } if v, found := constantPortMapping[vzEntryMap["dFromPort"]]; found { eMap["d_from_port"] = v } else { @@ -588,6 +590,16 @@ func setFilterEntryAttributesFromContract(vzentry *models.FilterEntry, d *schema } else { eMap["d_to_port"] = vzEntryMap["dToPort"] } + if v, found := constantPortMapping[vzEntryMap["sFromPort"]]; found { + eMap["s_from_port"] = v + } else { + eMap["s_from_port"] = vzEntryMap["sFromPort"] + } + if v, found := constantPortMapping[vzEntryMap["sToPort"]]; found { + eMap["s_to_port"] = v + } else { + eMap["s_to_port"] = vzEntryMap["sToPort"] + } return eMap, nil } diff --git a/aci/resource_aci_vzcpif.go b/aci/resource_aci_vzcpif.go index 12d89384e..8b133719b 100644 --- a/aci/resource_aci_vzcpif.go +++ b/aci/resource_aci_vzcpif.go @@ -28,11 +28,13 @@ func resourceAciImportedContract() *schema.Resource { "tenant_dn": &schema.Schema{ Type: schema.TypeString, Required: true, + ForceNew: true, }, "name": &schema.Schema{ Type: schema.TypeString, Required: true, + ForceNew: true, }, "name_alias": &schema.Schema{ diff --git a/aci/resource_aci_vzcpif_test.go b/aci/resource_aci_vzcpif_test.go deleted file mode 100644 index 9a4cd9dc4..000000000 --- a/aci/resource_aci_vzcpif_test.go +++ /dev/null @@ -1,144 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciImportedContract_Basic(t *testing.T) { - var imported_contract models.ImportedContract - description := "imported_contract created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciImportedContractDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciImportedContractConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciImportedContractExists("aci_imported_contract.fooimported_contract", &imported_contract), - testAccCheckAciImportedContractAttributes(description, &imported_contract), - ), - }, - }, - }) -} - -func TestAccAciImportedContract_update(t *testing.T) { - var imported_contract models.ImportedContract - description := "imported_contract created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciImportedContractDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciImportedContractConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciImportedContractExists("aci_imported_contract.fooimported_contract", &imported_contract), - testAccCheckAciImportedContractAttributes(description, &imported_contract), - ), - }, - { - Config: testAccCheckAciImportedContractConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciImportedContractExists("aci_imported_contract.fooimported_contract", &imported_contract), - testAccCheckAciImportedContractAttributes(description, &imported_contract), - ), - }, - }, - }) -} - -func testAccCheckAciImportedContractConfig_basic(description string) string { - return fmt.Sprintf(` - - - - resource "aci_imported_contract" "fooimported_contract" { - tenant_dn = aci_tenant.example.id - description = "%s" - name = "example" - annotation = "example" - name_alias = "example" - } - `, description) -} - -func testAccCheckAciImportedContractExists(name string, imported_contract *models.ImportedContract) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Imported Contract %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Imported Contract dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - imported_contractFound := models.ImportedContractFromContainer(cont) - if imported_contractFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Imported Contract %s not found", rs.Primary.ID) - } - *imported_contract = *imported_contractFound - return nil - } -} - -func testAccCheckAciImportedContractDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_imported_contract" { - cont, err := client.Get(rs.Primary.ID) - imported_contract := models.ImportedContractFromContainer(cont) - if err == nil { - return fmt.Errorf("Imported Contract %s Still exists", imported_contract.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciImportedContractAttributes(description string, imported_contract *models.ImportedContract) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != imported_contract.Description { - return fmt.Errorf("Bad imported_contract Description %s", imported_contract.Description) - } - - if "example" != imported_contract.Name { - return fmt.Errorf("Bad imported_contract name %s", imported_contract.Name) - } - - if "example" != imported_contract.Annotation { - return fmt.Errorf("Bad imported_contract annotation %s", imported_contract.Annotation) - } - - if "example" != imported_contract.NameAlias { - return fmt.Errorf("Bad imported_contract name_alias %s", imported_contract.NameAlias) - } - - return nil - } -} diff --git a/aci/resource_aci_vzfilter_test.go b/aci/resource_aci_vzfilter_test.go deleted file mode 100644 index 5b140ff3f..000000000 --- a/aci/resource_aci_vzfilter_test.go +++ /dev/null @@ -1,143 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciFilter_Basic(t *testing.T) { - var filter models.Filter - description := "filter created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciFilterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciFilterConfig_basic(description, "alias_filter"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciFilterExists("aci_filter.foofilter", &filter), - testAccCheckAciFilterAttributes(description, "alias_filter", &filter), - ), - }, - }, - }) -} - -func TestAccAciFilter_update(t *testing.T) { - var filter models.Filter - description := "filter created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciFilterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciFilterConfig_basic(description, "alias_filter"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciFilterExists("aci_filter.foofilter", &filter), - testAccCheckAciFilterAttributes(description, "alias_filter", &filter), - ), - }, - { - Config: testAccCheckAciFilterConfig_basic(description, "update_filter"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciFilterExists("aci_filter.foofilter", &filter), - testAccCheckAciFilterAttributes(description, "update_filter", &filter), - ), - }, - }, - }) -} - -func testAccCheckAciFilterConfig_basic(description, name_alias string) string { - return fmt.Sprintf(` - - resource "aci_filter" "foofilter" { - tenant_dn = aci_tenant.example.id - description = "%s" - name = "demo_filter" - annotation = "tag_filter" - name_alias = "%s" - } - - `, description, name_alias) -} - -func testAccCheckAciFilterExists(name string, filter *models.Filter) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Filter %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Filter dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - filterFound := models.FilterFromContainer(cont) - if filterFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Filter %s not found", rs.Primary.ID) - } - *filter = *filterFound - return nil - } -} - -func testAccCheckAciFilterDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_filter" { - cont, err := client.Get(rs.Primary.ID) - filter := models.FilterFromContainer(cont) - if err == nil { - return fmt.Errorf("Filter %s Still exists", filter.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciFilterAttributes(description, name_alias string, filter *models.Filter) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != filter.Description { - return fmt.Errorf("Bad filter Description %s", filter.Description) - } - - if "demo_filter" != filter.Name { - return fmt.Errorf("Bad filter name %s", filter.Name) - } - - if "tag_filter" != filter.Annotation { - return fmt.Errorf("Bad filter annotation %s", filter.Annotation) - } - - if name_alias != filter.NameAlias { - return fmt.Errorf("Bad filter name_alias %s", filter.NameAlias) - } - - return nil - } -} diff --git a/aci/resource_aci_vzsubj_test.go b/aci/resource_aci_vzsubj_test.go deleted file mode 100644 index 0124fd152..000000000 --- a/aci/resource_aci_vzsubj_test.go +++ /dev/null @@ -1,168 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciContractSubject_Basic(t *testing.T) { - var contract_subject models.ContractSubject - description := "contract_subject created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciContractSubjectDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciContractSubjectConfig_basic(description, "AtleastOne"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciContractSubjectExists("aci_contract_subject.foocontract_subject", &contract_subject), - testAccCheckAciContractSubjectAttributes(description, "AtleastOne", &contract_subject), - ), - }, - }, - }) -} - -func TestAccAciContractSubject_update(t *testing.T) { - var contract_subject models.ContractSubject - description := "contract_subject created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciContractSubjectDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciContractSubjectConfig_basic(description, "AtleastOne"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciContractSubjectExists("aci_contract_subject.foocontract_subject", &contract_subject), - testAccCheckAciContractSubjectAttributes(description, "AtleastOne", &contract_subject), - ), - }, - { - Config: testAccCheckAciContractSubjectConfig_basic(description, "All"), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciContractSubjectExists("aci_contract_subject.foocontract_subject", &contract_subject), - testAccCheckAciContractSubjectAttributes(description, "All", &contract_subject), - ), - }, - }, - }) -} - -func testAccCheckAciContractSubjectConfig_basic(description, cons_match_t string) string { - return fmt.Sprintf(` - - resource "aci_contract_subject" "foocontract_subject" { - contract_dn = "uni/tn-test_rutvik_tenant/brc-demo_contract" - description = "%s" - name = "demo_subject" - annotation = "tag_subject" - cons_match_t = "%s" - name_alias = "alias_subject" - prio = "level1" - prov_match_t = "AtleastOne" - rev_flt_ports = "yes" - target_dscp = "CS0" - } - - `, description, cons_match_t) -} - -func testAccCheckAciContractSubjectExists(name string, contract_subject *models.ContractSubject) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Contract Subject %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Contract Subject dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - contract_subjectFound := models.ContractSubjectFromContainer(cont) - if contract_subjectFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Contract Subject %s not found", rs.Primary.ID) - } - *contract_subject = *contract_subjectFound - return nil - } -} - -func testAccCheckAciContractSubjectDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_contract_subject" { - cont, err := client.Get(rs.Primary.ID) - contract_subject := models.ContractSubjectFromContainer(cont) - if err == nil { - return fmt.Errorf("Contract Subject %s Still exists", contract_subject.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciContractSubjectAttributes(description, cons_match_t string, contract_subject *models.ContractSubject) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != contract_subject.Description { - return fmt.Errorf("Bad contract_subject Description %s", contract_subject.Description) - } - - if "demo_subject" != contract_subject.Name { - return fmt.Errorf("Bad contract_subject name %s", contract_subject.Name) - } - - if "tag_subject" != contract_subject.Annotation { - return fmt.Errorf("Bad contract_subject annotation %s", contract_subject.Annotation) - } - - if cons_match_t != contract_subject.ConsMatchT { - return fmt.Errorf("Bad contract_subject cons_match_t %s", contract_subject.ConsMatchT) - } - - if "alias_subject" != contract_subject.NameAlias { - return fmt.Errorf("Bad contract_subject name_alias %s", contract_subject.NameAlias) - } - - if "level1" != contract_subject.Prio { - return fmt.Errorf("Bad contract_subject prio %s", contract_subject.Prio) - } - - if "AtleastOne" != contract_subject.ProvMatchT { - return fmt.Errorf("Bad contract_subject prov_match_t %s", contract_subject.ProvMatchT) - } - - if "yes" != contract_subject.RevFltPorts { - return fmt.Errorf("Bad contract_subject rev_flt_ports %s", contract_subject.RevFltPorts) - } - - if "CS0" != contract_subject.TargetDscp { - return fmt.Errorf("Bad contract_subject target_dscp %s", contract_subject.TargetDscp) - } - - return nil - } -} diff --git a/aci/resource_aci_vztaboo_test.go b/aci/resource_aci_vztaboo_test.go deleted file mode 100644 index 78722f47e..000000000 --- a/aci/resource_aci_vztaboo_test.go +++ /dev/null @@ -1,147 +0,0 @@ -package aci - -import ( - "fmt" - "testing" - - "github.com/ciscoecosystem/aci-go-client/client" - "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccAciTabooContract_Basic(t *testing.T) { - var taboo_contract models.TabooContract - description := "taboo_contract created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciTabooContractDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciTabooContractConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciTabooContractExists("aci_taboo_contract.footaboo_contract", &taboo_contract), - testAccCheckAciTabooContractAttributes(description, &taboo_contract), - ), - }, - }, - }) -} - -func TestAccAciTabooContract_update(t *testing.T) { - var taboo_contract models.TabooContract - description := "taboo_contract created while acceptance testing" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciTabooContractDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAciTabooContractConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciTabooContractExists("aci_taboo_contract.footaboo_contract", &taboo_contract), - testAccCheckAciTabooContractAttributes(description, &taboo_contract), - ), - }, - { - Config: testAccCheckAciTabooContractConfig_basic(description), - Check: resource.ComposeTestCheckFunc( - testAccCheckAciTabooContractExists("aci_taboo_contract.footaboo_contract", &taboo_contract), - testAccCheckAciTabooContractAttributes(description, &taboo_contract), - ), - }, - }, - }) -} - -func testAccCheckAciTabooContractConfig_basic(description string) string { - return fmt.Sprintf(` - resource "aci_tenant" "example"{ - description = "Tenant created while acceptance testing" - name = "demo_tenant" - } - - resource "aci_taboo_contract" "footaboo_contract" { - tenant_dn = aci_tenant.example.id - description = "%s" - - name = "example" - annotation = "example" - name_alias = "example" - } - `, description) -} - -func testAccCheckAciTabooContractExists(name string, taboo_contract *models.TabooContract) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - - if !ok { - return fmt.Errorf("Taboo Contract %s not found", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Taboo Contract dn was set") - } - - client := testAccProvider.Meta().(*client.Client) - - cont, err := client.Get(rs.Primary.ID) - if err != nil { - return err - } - - taboo_contractFound := models.TabooContractFromContainer(cont) - if taboo_contractFound.DistinguishedName != rs.Primary.ID { - return fmt.Errorf("Taboo Contract %s not found", rs.Primary.ID) - } - *taboo_contract = *taboo_contractFound - return nil - } -} - -func testAccCheckAciTabooContractDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - for _, rs := range s.RootModule().Resources { - - if rs.Type == "aci_taboo_contract" { - cont, err := client.Get(rs.Primary.ID) - taboo_contract := models.TabooContractFromContainer(cont) - if err == nil { - return fmt.Errorf("Taboo Contract %s Still exists", taboo_contract.DistinguishedName) - } - - } else { - continue - } - } - - return nil -} - -func testAccCheckAciTabooContractAttributes(description string, taboo_contract *models.TabooContract) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if description != taboo_contract.Description { - return fmt.Errorf("Bad taboo_contract Description %s", taboo_contract.Description) - } - - if "example" != taboo_contract.Name { - return fmt.Errorf("Bad taboo_contract name %s", taboo_contract.Name) - } - - if "example" != taboo_contract.Annotation { - return fmt.Errorf("Bad taboo_contract annotation %s", taboo_contract.Annotation) - } - - if "example" != taboo_contract.NameAlias { - return fmt.Errorf("Bad taboo_contract name_alias %s", taboo_contract.NameAlias) - } - - return nil - } -} diff --git a/aci/utils.go b/aci/utils.go index d53feaf0f..22b75d7c3 100644 --- a/aci/utils.go +++ b/aci/utils.go @@ -310,7 +310,7 @@ func checkDuplicate(arr []string) error { for i := 0; i < len(arr)-1; i++ { for j := i + 1; j < len(arr); j++ { if arr[i] == arr[j] { - return fmt.Errorf("duplication in list") + return fmt.Errorf("duplication is not supported in list") } } } diff --git a/go.mod b/go.mod index 73cfe1fde..05529dd10 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/terraform-providers/terraform-provider-aci go 1.12 require ( - github.com/ciscoecosystem/aci-go-client v1.20.1 + github.com/ciscoecosystem/aci-go-client v1.20.2 github.com/ghodss/yaml v1.0.0 github.com/hashicorp/terraform-json v0.13.0 // indirect github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.3 diff --git a/go.sum b/go.sum index 204304b31..33cb3df28 100644 --- a/go.sum +++ b/go.sum @@ -67,8 +67,8 @@ github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXH github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= -github.com/ciscoecosystem/aci-go-client v1.20.1 h1:S+69z28Nd8DGSKRGTD0OPUdF7PpdLwosZgzovdbGopo= -github.com/ciscoecosystem/aci-go-client v1.20.1/go.mod h1:pGK3tDhR/D4+P5f6utT1V7TQQxDw2fL7j79QXeVk6po= +github.com/ciscoecosystem/aci-go-client v1.20.2 h1:UQNPU+/ga7XrXfO7SgEG760A4WJFzpYpORb+L1Wq1nA= +github.com/ciscoecosystem/aci-go-client v1.20.2/go.mod h1:pGK3tDhR/D4+P5f6utT1V7TQQxDw2fL7j79QXeVk6po= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= diff --git a/testacc/data_source_aci_aaadomain_test.go b/testacc/data_source_aci_aaadomain_test.go new file mode 100644 index 000000000..9eff3d3b4 --- /dev/null +++ b/testacc/data_source_aci_aaadomain_test.go @@ -0,0 +1,137 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciAAADomainDataSource_Basic(t *testing.T) { + resourceName := "aci_aaa_domain.test" + dataSourceName := "data.aci_aaa_domain.test" + rName := makeTestVariable(acctest.RandString(5)) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciAAADomainDestroy, + Steps: []resource.TestStep{ + + { + Config: CreateAAADomainDSWithoutRequired(rName, "name"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccAAADomainDSConfig(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), + ), + }, + { + Config: CreateAccAAADomainDSConfigWithRandomAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccAAADomainDSConfigWithUpdatedResource(rName, "description", randomValue), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + ), + }, + { + Config: CreateAccAAADomainDSConfigWithInvalidName(rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + }, + }) +} + +func CreateAAADomainDSWithoutRequired(rName, attrName string) string { + fmt.Println("=== STEP Basic: testing aaa_domain data source without ", attrName) + rBlock := ` + resource "aci_aaa_domain" "test" { + + name = "%s" + } + ` + + switch attrName { + case "name": + rBlock += ` + data "aci_aaa_domain" "test" { + + # name = "%s" + description = "created while acceptance testing" + } + ` + } + return fmt.Sprintf(rBlock, rName) +} + +func CreateAccAAADomainDSConfigWithInvalidName(rName string) string { + fmt.Println("=== STEP testing aaa_domain data source with invalid name") + resource := fmt.Sprintf(` + + resource "aci_aaa_domain" "test" { + name = "%s" + } + + data "aci_aaa_domain" "test" { + name = "${aci_aaa_domain.test.name}xyz" + } + `, rName) + return resource +} + +func CreateAccAAADomainDSConfigWithUpdatedResource(rName, key, value string) string { + fmt.Println("=== STEP testing aaa_domain data source with updated resource") + resource := fmt.Sprintf(` + + resource "aci_aaa_domain" "test" { + name = "%s" + %s = "%s" + } + + data "aci_aaa_domain" "test" { + name = aci_aaa_domain.test.name + } + `, rName, key, value) + return resource +} + +func CreateAccAAADomainDSConfigWithRandomAttr(rName, key, value string) string { + fmt.Println("=== STEP testing aaa_domain data source with random attribute") + resource := fmt.Sprintf(` + + resource "aci_aaa_domain" "test" { + name = "%s" + } + + data "aci_aaa_domain" "test" { + name = aci_aaa_domain.test.name + %s = "%s" + } + `, rName, key, value) + return resource +} + +func CreateAccAAADomainDSConfig(rName string) string { + fmt.Println("=== STEP testing aaa_domain data source with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_aaa_domain" "test" { + name = "%s" + } + + data "aci_aaa_domain" "test" { + name = aci_aaa_domain.test.name + } + `, rName) + return resource +} diff --git a/testacc/data_source_aci_bfdifp_test.go b/testacc/data_source_aci_bfdifp_test.go new file mode 100644 index 000000000..604ceed94 --- /dev/null +++ b/testacc/data_source_aci_bfdifp_test.go @@ -0,0 +1,238 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciL3outBfdInterfaceProfileDataSource_Basic(t *testing.T) { + resourceName := "aci_l3out_bfd_interface_profile.test" + dataSourceName := "data.aci_l3out_bfd_interface_profile.test" + randomParameter := acctest.RandStringFromCharSet(10, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(10) + rName := makeTestVariable(acctest.RandString(5)) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outBfdInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateL3outBfdInterfaceProfileDataSourceWithoutRequired(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, { + Config: CreateAccL3outBfdInterfaceProfileConfigDataSource(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "logical_interface_profile_dn", resourceName, "logical_interface_profile_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "key_id", resourceName, "key_id"), + resource.TestCheckResourceAttrPair(dataSourceName, "interface_profile_type", resourceName, "interface_profile_type"), + ), + }, + { + Config: CreateAccL3outBfdInterfaceProfileDataSourceUpdateRandomAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + + { + Config: CreateAccL3outBfdInterfaceProfileDataSourceWithInvalidParentDn(rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + { + Config: CreateAccL3outBfdInterfaceProfileDataSourceUpdate(rName, "annotation", "orchestrator:terraform-testacc"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + ), + }, + }, + }) +} + +func CreateL3outBfdInterfaceProfileDataSourceWithoutRequired(rName string) string { + fmt.Println("=== STEP Basic: Testing l3out_bfd_interface_profile data soruce creation without required attribute") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_bfd_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + data "aci_l3out_bfd_interface_profile" "test" { + depends_on = [aci_l3out_bfd_interface_profile.test] + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccL3outBfdInterfaceProfileConfigDataSource(rName string) string { + fmt.Println("=== STEP Testing l3out_bfd_interface_profile data source creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_bfd_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + data "aci_l3out_bfd_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + depends_on = [ + aci_l3out_bfd_interface_profile.test + ] + } + `, rName, rName, rName, rName) + return resource +} +func CreateAccL3outBfdInterfaceProfileDataSourceWithInvalidParentDn(rName string) string { + fmt.Println("=== STEP testing l3out_bfd_interface_profile creation with Invalid Parent Dn") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_bfd_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + data "aci_l3out_bfd_interface_profile" "test" { + logical_interface_profile_dn = "${aci_logical_interface_profile.test.id}xyz" + depends_on = [ + aci_l3out_bfd_interface_profile.test + ] + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccL3outBfdInterfaceProfileDataSourceUpdateRandomAttr(rName, key, value string) string { + fmt.Println("=== STEP Testing l3out_bfd_interface_profile data source update with random attribute") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_bfd_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + data "aci_l3out_bfd_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + %s = "%s" + depends_on = [ + aci_l3out_bfd_interface_profile.test + ] + } + `, rName, rName, rName, rName, key, value) + return resource +} + +func CreateAccL3outBfdInterfaceProfileDataSourceUpdate(rName, key, value string) string { + fmt.Printf("=== STEP Testing l3out_bfd_interface_profile data source update with %s = %s\n", key, value) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_bfd_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + %s = "%s" + } + + data "aci_l3out_bfd_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + depends_on = [ + aci_l3out_bfd_interface_profile.test + ] + } + `, rName, rName, rName, rName, key, value) + return resource +} diff --git a/testacc/data_source_aci_fvaepg_test.go b/testacc/data_source_aci_fvaepg_test.go index a55d6541a..7f95036fd 100644 --- a/testacc/data_source_aci_fvaepg_test.go +++ b/testacc/data_source_aci_fvaepg_test.go @@ -1,4 +1,4 @@ -package acctest +package testacc import ( "fmt" @@ -16,9 +16,9 @@ func TestAccAciApplicationEPGDataSource_Basic(t *testing.T) { randomParameter := acctest.RandStringFromCharSet(10, "abcdefghijklmnopqrstuvwxyz") randomValue := acctest.RandString(10) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciApplicationEPGDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciApplicationEPGDestroy, Steps: []resource.TestStep{ { Config: CreateAccApplicationEPGDSWithoutApplicationProfile(rName), diff --git a/testacc/data_source_aci_fvany_test.go b/testacc/data_source_aci_fvany_test.go new file mode 100644 index 000000000..12b521386 --- /dev/null +++ b/testacc/data_source_aci_fvany_test.go @@ -0,0 +1,159 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciAnyDataSource_Basic(t *testing.T) { + resourceName := "aci_any.test" + dataSourceName := "data.aci_any.test" + rName := makeTestVariable(acctest.RandString(5)) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciAnyDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccAnyDSWithoutVRFdn(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccAnyDataSource(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "match_t", resourceName, "match_t"), + resource.TestCheckResourceAttrPair(dataSourceName, "pref_gr_memb", resourceName, "pref_gr_memb"), + resource.TestCheckResourceAttrPair(dataSourceName, "vrf_dn", resourceName, "vrf_dn"), + ), + }, + { + Config: CreateAccAnyDataSourceUpdateRandomAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccAnyDSWithInvalidVRFdn(rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + { + Config: CreateAccAnyDataSourceUpdate(rName, "description", "test_annotation_1"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + ), + }, + }, + }) +} + +func CreateAccAnyDataSource(rName string) string { + fmt.Println("=== STEP Basic: testing any data source reading with required arguments") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_vrf" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_any" "test" { + vrf_dn = aci_vrf.test.id + } + data "aci_any" "test" { + vrf_dn = aci_vrf.test.id + depends_on = [aci_any.test] + } + `, rName, rName) + return resource +} + +func CreateAccAnyDataSourceUpdateRandomAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP testing any data source update for attribute: %s = %s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_vrf" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_any" "test" { + vrf_dn = aci_vrf.test.id + } + data "aci_any" "test" { + vrf_dn = aci_vrf.test.id + %s = "%s" + depends_on = [aci_any.test] + } + `, rName, rName, attribute, value) + return resource +} + +func CreateAccAnyDataSourceUpdate(rName, attribute, value string) string { + fmt.Printf("=== STEP testing any data source update for attribute: %s = %s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_vrf" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_any" "test" { + vrf_dn = aci_vrf.test.id + %s = "%s" + } + data "aci_any" "test" { + vrf_dn = aci_vrf.test.id + depends_on = [aci_any.test] + } + `, rName, rName, attribute, value) + return resource +} + +func CreateAccAnyDSWithInvalidVRFdn(rName string) string { + fmt.Println("=== STEP Basic: testing any data source reading with invalid vrf_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_vrf" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_any" "test" { + vrf_dn = aci_vrf.test.id + } + data "aci_any" "test" { + vrf_dn = "${aci_vrf.test.id}xyz" + depends_on = [aci_any.test] + } + `, rName, rName) + return resource +} + +func CreateAccAnyDSWithoutVRFdn(rName string) string { + fmt.Println("=== STEP Basic: testing any data source reading without giving vrf_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = %s + } + resource "aci_vrf" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_any" "test" { + vrf_dn = aci_vrf.test.id + } + data "aci_any" "test" { + } + `, rName, rName) + return resource +} diff --git a/testacc/data_source_aci_fvap_test.go b/testacc/data_source_aci_fvap_test.go index a998ade3f..d2cc7687a 100644 --- a/testacc/data_source_aci_fvap_test.go +++ b/testacc/data_source_aci_fvap_test.go @@ -1,4 +1,4 @@ -package acctest +package testacc import ( "fmt" @@ -16,20 +16,20 @@ func TestAccAciApplicationProfileDataSource_Basic(t *testing.T) { randomValue := acctest.RandString(5) rName := makeTestVariable(acctest.RandString(5)) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciApplicationProfileDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciApplicationProfileDestroy, Steps: []resource.TestStep{ { - Config: CreateAccApplicationProfileDSWithoutTenant(rName), // creating data source for application profile without required arguement tenant_dn + Config: CreateAccApplicationProfileDSWithoutTenant(rName), // creating data source for application profile without required argument tenant_dn ExpectError: regexp.MustCompile(`Missing required argument`), // test step expect error which should be match with defined regex }, { - Config: CreateAccApplicationProfileDSWithoutName(rName), // creating data source for application profile without required arguement name + Config: CreateAccApplicationProfileDSWithoutName(rName), // creating data source for application profile without required argument name ExpectError: regexp.MustCompile(`Missing required argument`), }, { - Config: CreateAccApplicationProfileConfigDataSource(rName), // creating data source with required arguements from the resource + Config: CreateAccApplicationProfileConfigDataSource(rName), // creating data source with required arguments from the resource Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), // comparing value of parameter description in data source and resoruce resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), // comparing value of parameter description in data source and resoruce diff --git a/testacc/data_source_aci_fvbd_test.go b/testacc/data_source_aci_fvbd_test.go index 6635c2422..1666dcc47 100644 --- a/testacc/data_source_aci_fvbd_test.go +++ b/testacc/data_source_aci_fvbd_test.go @@ -1,4 +1,4 @@ -package acctest +package testacc import ( "fmt" @@ -16,9 +16,9 @@ func TestAccAciBridgeDomainDataSource_Basic(t *testing.T) { randomParameter := acctest.RandStringFromCharSet(10, "abcdefghijklmnopqrstuvwxyz") randomValue := acctest.RandString(10) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciBridgeDomainDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciBridgeDomainDestroy, Steps: []resource.TestStep{ { Config: CreateAccBridgeDomainDSWithoutTenant(rName), diff --git a/testacc/data_sorce_aci_fvctx_test.go b/testacc/data_source_aci_fvctx_test.go similarity index 96% rename from testacc/data_sorce_aci_fvctx_test.go rename to testacc/data_source_aci_fvctx_test.go index cf3ccdd4c..d93e50a2b 100644 --- a/testacc/data_sorce_aci_fvctx_test.go +++ b/testacc/data_source_aci_fvctx_test.go @@ -1,4 +1,4 @@ -package acctest +package testacc import ( "fmt" @@ -16,9 +16,9 @@ func TestAccAciVRFDataSource_Basic(t *testing.T) { randomValue := acctest.RandString(5) rName := makeTestVariable(acctest.RandString(5)) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciVRFDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciVRFDestroy, Steps: []resource.TestStep{ { Config: CreateAccVRFDSWithoutTenant(rName), diff --git a/testacc/data_source_aci_fvepselector_test.go b/testacc/data_source_aci_fvepselector_test.go new file mode 100644 index 000000000..b01355267 --- /dev/null +++ b/testacc/data_source_aci_fvepselector_test.go @@ -0,0 +1,229 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciEndpointSecurityGroupSelectorDataSource_Basic(t *testing.T) { + resourceName := "aci_endpoint_security_group_selector.test" + dataSourceName := "data.aci_endpoint_security_group_selector.test" + rName := makeTestVariable(acctest.RandString(5)) + ip, _ := acctest.RandIpAddress("10.30.0.0/17") + ip = fmt.Sprintf("%s/17", ip) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciEndpointSecurityGroupSelectorDestroy, + Steps: []resource.TestStep{ + { + Config: CreateEndpointSecurityGroupSelectorDSWithoutRequired(rName, ip, "endpoint_security_group_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateEndpointSecurityGroupSelectorDSWithoutRequired(rName, ip, "matchExpression"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccEndpointSecurityGroupSelectorDSConfig(rName, ip), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "endpoint_security_group_dn", resourceName, "endpoint_security_group_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "match_expression", resourceName, "match_expression"), + ), + }, + { + Config: CreateAccEndpointSecurityGroupSelectorDataSourceUpdateRandomAttr(rName, ip, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccEndpointSecurityGroupDSWithInvalidEndpointSecurityGroup(rName, ip), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + { + Config: CreateAccEndpointSecurityGroupDSWithUpdatedResource(rName, ip, "description", randomValue), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + ), + }, + }, + }) +} + +func CreateAccEndpointSecurityGroupDSWithUpdatedResource(rName, ip, key, value string) string { + fmt.Println("=== STEP testing endpoint_security_group_selector data source creation with updated resource") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + resource "aci_endpoint_security_group_selector" "test" { + endpoint_security_group_dn = aci_endpoint_security_group.test.id + match_expression = "ip=='%s'" + %s = "%s" + } + + data "aci_endpoint_security_group_selector" "test" { + endpoint_security_group_dn = aci_endpoint_security_group_selector.test.endpoint_security_group_dn + match_expression = aci_endpoint_security_group_selector.test.match_expression + } + `, rName, rName, rName, ip, key, value) + return resource +} + +func CreateAccEndpointSecurityGroupDSWithInvalidEndpointSecurityGroup(rName, ip string) string { + fmt.Println("=== STEP testing endpoint_security_group_selector data source creation with invalid endpoint_security_group_dn") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + resource "aci_endpoint_security_group_selector" "test" { + endpoint_security_group_dn = aci_endpoint_security_group.test.id + match_expression = "ip=='%s'" + } + + data "aci_endpoint_security_group_selector" "test" { + endpoint_security_group_dn = "${aci_endpoint_security_group_selector.test.endpoint_security_group_dn}xyz" + match_expression = aci_endpoint_security_group_selector.test.match_expression + } + `, rName, rName, rName, ip) + return resource +} + +func CreateAccEndpointSecurityGroupSelectorDataSourceUpdateRandomAttr(rName, ip, key, value string) string { + fmt.Println("=== STEP testing endpoint_security_group_selector data source creation with random parameter") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + resource "aci_endpoint_security_group_selector" "test" { + endpoint_security_group_dn = aci_endpoint_security_group.test.id + match_expression = "ip=='%s'" + } + + data "aci_endpoint_security_group_selector" "test" { + endpoint_security_group_dn = aci_endpoint_security_group_selector.test.endpoint_security_group_dn + match_expression = aci_endpoint_security_group_selector.test.match_expression + %s = "%s" + } + `, rName, rName, rName, ip, key, value) + return resource +} + +func CreateAccEndpointSecurityGroupSelectorDSConfig(rName, ip string) string { + fmt.Println("=== STEP testing endpoint_security_group_selector data source creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + resource "aci_endpoint_security_group_selector" "test" { + endpoint_security_group_dn = aci_endpoint_security_group.test.id + match_expression = "ip=='%s'" + } + + data "aci_endpoint_security_group_selector" "test" { + endpoint_security_group_dn = aci_endpoint_security_group_selector.test.endpoint_security_group_dn + match_expression = aci_endpoint_security_group_selector.test.match_expression + } + `, rName, rName, rName, ip) + return resource +} + +func CreateEndpointSecurityGroupSelectorDSWithoutRequired(rName, ip, attrName string) string { + fmt.Println("=== STEP Basic: testing endpoint_security_group_selector data source creation without ", attrName) + rBlock := ` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + resource "aci_endpoint_security_group_selector" "test" { + endpoint_security_group_dn = aci_endpoint_security_group.test.id + match_expression = "ip=='%s'" + } + + ` + switch attrName { + case "endpoint_security_group_dn": + rBlock += ` + data "aci_endpoint_security_group_selector" "test" { + # endpoint_security_group_dn = aci_endpoint_security_group_selector.test.endpoint_security_group_dn + match_expression = aci_endpoint_security_group_selector.test.match_expression + } + ` + case "matchExpression": + rBlock += ` + data "aci_endpoint_security_group_selector" "test" { + endpoint_security_group_dn = aci_endpoint_security_group_selector.test.endpoint_security_group_dn + # match_expression = aci_endpoint_security_group_selector.test.match_expression + } + ` + } + return fmt.Sprintf(rBlock, rName, rName, rName, ip) +} diff --git a/testacc/data_source_aci_fvesg_test.go b/testacc/data_source_aci_fvesg_test.go new file mode 100644 index 000000000..8eb3f2060 --- /dev/null +++ b/testacc/data_source_aci_fvesg_test.go @@ -0,0 +1,198 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciEndpointSecurityGroupDataSource_Basic(t *testing.T) { + resourceName := "aci_endpoint_security_group.test" + dataSourceName := "data.aci_endpoint_security_group.test" + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciEndpointSecurityGroupDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccEndpointSecurityGroupDSWithoutAP(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccEndpointSecurityGroupDSWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccEndpointSecurityGroupConfigDataSource(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "application_profile_dn", resourceName, "application_profile_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "flood_on_encap", resourceName, "flood_on_encap"), + resource.TestCheckResourceAttrPair(dataSourceName, "match_t", resourceName, "match_t"), + resource.TestCheckResourceAttrPair(dataSourceName, "pc_enf_pref", resourceName, "pc_enf_pref"), + resource.TestCheckResourceAttrPair(dataSourceName, "pref_gr_memb", resourceName, "pref_gr_memb"), + resource.TestCheckResourceAttrPair(dataSourceName, "prio", resourceName, "prio"), + ), + }, + { + Config: CreateAccEndpointSecurityGroupDataSourceUpdateRandomAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccEndpointSecurityGroupDSWithInvalidName(rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + { + Config: CreateAccEndpointSecurityGroupDataSourceUpdate(rName, "description", randomValue), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + ), + }, + }, + }) +} + +func CreateAccEndpointSecurityGroupDataSourceUpdate(rName, key, value string) string { + fmt.Printf("=== STEP Basic: testing endpoint_security_group data source update for attribute: %s = %s \n", key, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + %s = "%s" + } + + data "aci_endpoint_security_group" "test" { + name = aci_endpoint_security_group.test.name + application_profile_dn = aci_endpoint_security_group.test.application_profile_dn + } + `, rName, rName, rName, key, value) + return resource +} + +func CreateAccEndpointSecurityGroupDSWithInvalidName(rName string) string { + fmt.Println("=== STEP Basic: testing endpoint_security_group reading with invalid name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + data "aci_endpoint_security_group" "test" { + name = "${aci_endpoint_security_group.test.name}xyz" + application_profile_dn = aci_endpoint_security_group.test.application_profile_dn + } + `, rName, rName, rName) + return resource +} + +func CreateAccEndpointSecurityGroupDataSourceUpdateRandomAttr(rName, key, val string) string { + fmt.Printf("=== STEP Basic: testing endpoint_security_group data source update for attribute: %s = %s \n", key, val) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + data "aci_endpoint_security_group" "test" { + name = aci_endpoint_security_group.test.name + application_profile_dn = aci_endpoint_security_group.test.application_profile_dn + %s = "%s" + } + `, rName, rName, rName, key, val) + return resource +} + +func CreateAccEndpointSecurityGroupConfigDataSource(rName string) string { + fmt.Println("=== STEP testing endpoint_security_group data source creation with required arguments only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + data "aci_endpoint_security_group" "test" { + name = aci_endpoint_security_group.test.name + application_profile_dn = aci_endpoint_security_group.test.application_profile_dn + } + `, rName, rName, rName) + return resource +} + +func CreateAccEndpointSecurityGroupDSWithoutAP(rName string) string { + fmt.Println("=== STEP Basic: testing endpoint_security_group data source creation without creating application_profile_dn") + resource := fmt.Sprintf(` + data "aci_endpoint_security_group" "test" { + name = "%s" + } + `, rName) + return resource +} + +func CreateAccEndpointSecurityGroupDSWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing endpoint_security_group creation without name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + data "aci_endpoint_security_group" "test" { + application_profile_dn = aci_endpoint_security_group.test.application_profile_dn + } + `, rName, rName, rName) + return resource +} diff --git a/testacc/data_source_aci_fvrsdomatt_test.go b/testacc/data_source_aci_fvrsdomatt_test.go new file mode 100644 index 000000000..10579c46c --- /dev/null +++ b/testacc/data_source_aci_fvrsdomatt_test.go @@ -0,0 +1,287 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciFVDomainDataSource_Basic(t *testing.T) { + resourceName := "aci_epg_to_domain.test" + dataSourceName := "data.aci_epg_to_domain.test" + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciFVDomainDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccFVDomainDSWithoutTdn(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccFVDomainDSWithoutApplicationEPG(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccFVDomainDSConfig(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(resourceName, "application_epg_dn", dataSourceName, "application_epg_dn"), + resource.TestCheckResourceAttrPair(resourceName, "tdn", dataSourceName, "tdn"), + resource.TestCheckResourceAttrPair(resourceName, "annotation", dataSourceName, "annotation"), + resource.TestCheckResourceAttrPair(resourceName, "binding_type", dataSourceName, "binding_type"), + resource.TestCheckResourceAttrPair(resourceName, "allow_micro_seg", dataSourceName, "allow_micro_seg"), + resource.TestCheckResourceAttrPair(resourceName, "delimiter", dataSourceName, "delimiter"), + resource.TestCheckResourceAttrPair(resourceName, "encap", dataSourceName, "encap"), + resource.TestCheckResourceAttrPair(resourceName, "encap_mode", dataSourceName, "encap_mode"), + resource.TestCheckResourceAttrPair(resourceName, "epg_cos", dataSourceName, "epg_cos"), + resource.TestCheckResourceAttrPair(resourceName, "epg_cos_pref", dataSourceName, "epg_cos_pref"), + resource.TestCheckResourceAttrPair(resourceName, "instr_imedcy", dataSourceName, "instr_imedcy"), + resource.TestCheckResourceAttrPair(resourceName, "lag_policy_name", dataSourceName, "lag_policy_name"), + resource.TestCheckResourceAttrPair(resourceName, "netflow_dir", dataSourceName, "netflow_dir"), + resource.TestCheckResourceAttrPair(resourceName, "netflow_pref", dataSourceName, "netflow_pref"), + resource.TestCheckResourceAttrPair(resourceName, "num_ports", dataSourceName, "num_ports"), + resource.TestCheckResourceAttrPair(resourceName, "port_allocation", dataSourceName, "port_allocation"), + resource.TestCheckResourceAttrPair(resourceName, "primary_encap", dataSourceName, "primary_encap"), + resource.TestCheckResourceAttrPair(resourceName, "primary_encap_inner", dataSourceName, "primary_encap_inner"), + resource.TestCheckResourceAttrPair(resourceName, "res_imedcy", dataSourceName, "res_imedcy"), + resource.TestCheckResourceAttrPair(resourceName, "secondary_encap_inner", dataSourceName, "secondary_encap_inner"), + resource.TestCheckResourceAttrPair(resourceName, "switching_mode", dataSourceName, "switching_mode"), + ), + }, + { + Config: CreateAccFVDomainDSConfigUpdatedAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccFVDomainDSConfigWithInvalidEPgDn(rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + { + Config: CreateAccFVDomainDSConfigWithUpdatedResource(rName, "annotation", randomValue), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(resourceName, "annotation", dataSourceName, "annotation"), + ), + }, + }, + }) +} + +func CreateAccFVDomainDSWithoutTdn(rName string) string { + fmt.Println("=== STEP testing epg_to_domain Data Source without tdn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_fc_domain" "test" { + name = "%s" + } + + resource "aci_epg_to_domain" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = aci_fc_domain.test.id + } + + data "aci_epg_to_domain" "test" { + application_epg_dn = aci_epg_to_domain.test.application_epg_dn + } + `, rName, rName, rName, rName) + return resource + +} + +func CreateAccFVDomainDSWithoutApplicationEPG(rName string) string { + fmt.Println("=== STEP testing aci_epg_to_domain Data Source without application_epg_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_fc_domain" "test" { + name = "%s" + } + + resource "aci_epg_to_domain" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = aci_fc_domain.test.id + } + + data "aci_epg_to_domain" "test" { + tdn = aci_epg_to_domain.test.tdn + } + `, rName, rName, rName, rName) + return resource + +} + +func CreateAccFVDomainDSConfigWithInvalidEPgDn(rName string) string { + fmt.Println("=== STEP testing epg_to_domain Data Source with invalid application_epg_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_vmm_domain" "test" { + name = "%s" + provider_profile_dn = "uni/vmmp-VMware" + enable_ave = "yes" + } + + resource "aci_epg_to_domain" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = aci_vmm_domain.test.id + } + + data "aci_epg_to_domain" "test" { + application_epg_dn = "${aci_epg_to_domain.test.application_epg_dn}xyz" + tdn = aci_epg_to_domain.test.tdn + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccFVDomainDSConfigWithUpdatedResource(rName, key, value string) string { + fmt.Println("=== STEP testing epg_to_domain Data Source with updated resource") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_vmm_domain" "test" { + name = "%s" + provider_profile_dn = "uni/vmmp-VMware" + enable_ave = "yes" + } + + resource "aci_epg_to_domain" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = aci_vmm_domain.test.id + %s = "%s" + } + + data "aci_epg_to_domain" "test" { + application_epg_dn = aci_epg_to_domain.test.application_epg_dn + tdn = aci_epg_to_domain.test.tdn + } + `, rName, rName, rName, rName, key, value) + return resource +} + +func CreateAccFVDomainDSConfigUpdatedAttr(rName, key, value string) string { + fmt.Println("=== STEP testing epg_to_domain Data Source with random attribute") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_vmm_domain" "test" { + name = "%s" + provider_profile_dn = "uni/vmmp-VMware" + enable_ave = "yes" + } + + resource "aci_epg_to_domain" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = aci_vmm_domain.test.id + } + + data "aci_epg_to_domain" "test" { + application_epg_dn = aci_epg_to_domain.test.application_epg_dn + tdn = aci_epg_to_domain.test.tdn + %s = "%s" + } + `, rName, rName, rName, rName, key, value) + return resource +} + +func CreateAccFVDomainDSConfig(rName string) string { + fmt.Println("=== STEP testing epg_to_domain Data Source required parameters only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_vmm_domain" "test" { + name = "%s" + provider_profile_dn = "uni/vmmp-VMware" + enable_ave = "yes" + } + + resource "aci_epg_to_domain" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = aci_vmm_domain.test.id + } + + data "aci_epg_to_domain" "test" { + application_epg_dn = aci_epg_to_domain.test.application_epg_dn + tdn = aci_epg_to_domain.test.tdn + } + `, rName, rName, rName, rName) + return resource +} diff --git a/testacc/data_source_aci_fvrspathatt_test.go b/testacc/data_source_aci_fvrspathatt_test.go new file mode 100644 index 000000000..9c611270a --- /dev/null +++ b/testacc/data_source_aci_fvrspathatt_test.go @@ -0,0 +1,220 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciStaticPathDataSource_Basic(t *testing.T) { + resourceName := "aci_epg_to_static_path.test" + dataSourceName := "data.aci_epg_to_static_path.test" + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciStaticPathDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccStaticPathDSWithoutEpg(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccStaticPathDSWithoutTdn(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccStaticPathConfigDataSource(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "application_epg_dn", resourceName, "application_epg_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "tdn", resourceName, "tdn"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "encap", resourceName, "encap"), + resource.TestCheckResourceAttrPair(dataSourceName, "instr_imedcy", resourceName, "instr_imedcy"), + resource.TestCheckResourceAttrPair(dataSourceName, "mode", resourceName, "mode"), + resource.TestCheckResourceAttrPair(dataSourceName, "primary_encap", resourceName, "primary_encap"), + ), + }, + { + Config: CreateAccStaticPathDataSourceUpdateRandomAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccStaticPathDSWithInvalidEpg(rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + { + Config: CreateAccStaticPathDataSourceUpdate(rName, "description", randomValue), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + ), + }, + }, + }) +} + +func CreateAccStaticPathDataSourceUpdateRandomAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP Basic: testing epg_to_static_path data source update for attribute: %s = %s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_application_epg" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + resource "aci_epg_to_static_path" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = "%s" + encap = "vlan-201" + } + + data "aci_epg_to_static_path" "test" { + application_epg_dn = aci_epg_to_static_path.test.application_epg_dn + tdn = aci_epg_to_static_path.test.tdn + %s = "%s" + } + `, rName, rName, rName, tdn1, attribute, value) + return resource +} + +func CreateAccStaticPathDataSourceUpdate(rName, attribute, value string) string { + fmt.Printf("=== STEP Basic: testing epg_to_static_path data source update for attribute: %s = %s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_application_epg" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + resource "aci_epg_to_static_path" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = "%s" + encap = "vlan-201" + %s = "%s" + } + + data "aci_epg_to_static_path" "test" { + application_epg_dn = aci_epg_to_static_path.test.application_epg_dn + tdn = aci_epg_to_static_path.test.tdn + } + `, rName, rName, rName, tdn1, attribute, value) + return resource +} + +func CreateAccStaticPathConfigDataSource(rName string) string { + fmt.Println("=== STEP Basic: testing epg_to_static_path creation for data source test") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_application_epg" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + resource "aci_epg_to_static_path" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = "%s" + encap = "vlan-201" + } + + data "aci_epg_to_static_path" "test" { + application_epg_dn = aci_epg_to_static_path.test.application_epg_dn + tdn = aci_epg_to_static_path.test.tdn + } + `, rName, rName, rName, tdn1) + return resource +} + +func CreateAccStaticPathDSWithInvalidEpg(rName string) string { + fmt.Println("=== STEP Basic: testing epg_to_static_path reading with invalid application_epg_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_application_epg" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + resource "aci_epg_to_static_path" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = "%s" + encap = "vlan-201" + } + + data "aci_epg_to_static_path" "test" { + application_epg_dn = "${aci_epg_to_static_path.test.application_epg_dn}xyz" + tdn = aci_epg_to_static_path.test.tdn + } + `, rName, rName, rName, tdn1) + return resource +} + +func CreateAccStaticPathDSWithoutEpg() string { + fmt.Println("=== STEP Basic: testing epg_to_static_path reading without giving application_epg_dn") + resource := fmt.Sprintf(` + data "aci_epg_to_static_path" "test" { + tdn = "%s" + } + `, tdn1) + return resource +} + +func CreateAccStaticPathDSWithoutTdn(rName string) string { + fmt.Println("=== STEP Basic: testing epg_to_static_path reading without giving tdn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_application_epg" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + data "aci_epg_to_static_path" "test" { + application_epg_dn = aci_application_epg.test.id + } + `, rName, rName, rName) + return resource +} diff --git a/testacc/data_source_aci_fvrsprovcons_test.go b/testacc/data_source_aci_fvrsprovcons_test.go new file mode 100644 index 000000000..f2b5ccb92 --- /dev/null +++ b/testacc/data_source_aci_fvrsprovcons_test.go @@ -0,0 +1,308 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciEPGToContractDataSource_Basic(t *testing.T) { + resourceName := "aci_epg_to_contract.test" + dataSourceName := "data.aci_epg_to_contract.test" + rName := makeTestVariable(acctest.RandString(5)) + randomParameter := acctest.RandStringFromCharSet(10, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(10) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciEPGToContractDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccEPGToContractDSWithoutApplicationEPG(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccEPGToContractDSWithoutContract(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccEPGToContractDSWithoutContractType(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccEPGToContractConfigDataSource(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "contract_dn", resourceName, "contract_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "application_epg_dn", resourceName, "application_epg_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "contract_type", resourceName, "contract_type"), + resource.TestCheckResourceAttrPair(dataSourceName, "match_t", resourceName, "match_t"), + resource.TestCheckResourceAttrPair(dataSourceName, "prio", resourceName, "prio"), + ), + }, + { + Config: CreateAccEPGToContractUpdatedConfigDataSourceRandomAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccEPGToContractUpdatedConfigDataSource(rName, "annotation", randomValue), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + ), + }, + }, + }) +} + +func CreateAccEPGToContractUpdatedConfigDataSourceRandomAttr(rName, attribute, value string) string { + fmt.Println("=== STEP Basic: Testing EPG to Contract data source with Random Attribute") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_epg.test.id + contract_type = "provider" + } + + data "aci_epg_to_contract" "test" { + contract_dn = aci_epg_to_contract.test.contract_dn + application_epg_dn = aci_epg_to_contract.test.application_epg_dn + contract_type = aci_epg_to_contract.test.contract_type + %s = "%s" + } + `, rName, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccEPGToContractUpdatedConfigDataSource(rName, attribute, value string) string { + fmt.Println("=== STEP Basic: Testing EPG to Contract data source with updated resource") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_epg.test.id + contract_type = "provider" + %s = "%s" + } + + data "aci_epg_to_contract" "test" { + contract_dn = aci_epg_to_contract.test.contract_dn + application_epg_dn = aci_epg_to_contract.test.application_epg_dn + contract_type = aci_epg_to_contract.test.contract_type + } + `, rName, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccEPGToContractConfigDataSource(rName string) string { + fmt.Println("=== STEP Basic: Testing EPG to Contract data source") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_epg.test.id + contract_type = "provider" + } + + data "aci_epg_to_contract" "test" { + contract_dn = aci_epg_to_contract.test.contract_dn + application_epg_dn = aci_epg_to_contract.test.application_epg_dn + contract_type = aci_epg_to_contract.test.contract_type + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccEPGToContractDSWithoutApplicationEPG(rName string) string { + fmt.Println("=== STEP Basic: Testing EPG to Contract data source without Application EPG") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_epg.test.id + contract_type = "provider" + } + + data "aci_epg_to_contract" "test" { + contract_dn = aci_epg_to_contract.test.contract_dn + contract_type = aci_epg_to_contract.test.contract_type + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccEPGToContractDSWithInvalidApplicationEPG(rName string) string { + fmt.Println("=== STEP Basic: Testing EPG to Contract data source with Invalid Application EPG") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_epg.test.id + contract_type = "provider" + } + + data "aci_epg_to_contract" "test" { + contract_dn = aci_epg_to_contract.test.contract_dn + contract_type = aci_epg_to_contract.test.contract_type + application_epg_dn = "${aci_epg_to_contract.test.application_epg_dn}abc" + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccEPGToContractDSWithoutContract(rName string) string { + fmt.Println("=== STEP Basic: Testing EPG to Contract data source without Contract") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_epg.test.id + contract_type = "provider" + } + + data "aci_epg_to_contract" "test" { + application_epg_dn = aci_epg_to_contract.test.application_epg_dn + contract_type = aci_epg_to_contract.test.contract_type + } + `, rName, rName, rName, rName) + return resource +} +func CreateAccEPGToContractDSWithoutContractType(rName string) string { + fmt.Println("=== STEP Basic: Testing EPG to Contract data source without Contract Type") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_epg.test.id + contract_type = "provider" + } + + data "aci_epg_to_contract" "test" { + contract_dn = aci_epg_to_contract.test.contract_dn + application_epg_dn = aci_epg_to_contract.test.application_epg_dn + } + `, rName, rName, rName, rName) + return resource +} diff --git a/testacc/data_source_aci_fvsubnet_test.go b/testacc/data_source_aci_fvsubnet_test.go index b3323fb57..105f22edb 100644 --- a/testacc/data_source_aci_fvsubnet_test.go +++ b/testacc/data_source_aci_fvsubnet_test.go @@ -1,4 +1,4 @@ -package acctest +package testacc import ( "fmt" @@ -18,9 +18,9 @@ func TestAccAciSubnetDataSource_Basic(t *testing.T) { randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") // creating random string of 5 characters (to give as random parameter) randomValue := acctest.RandString(5) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciSubnetDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciSubnetDestroy, Steps: []resource.TestStep{ { Config: CreateAccSubnetDSWithoutParentDn(rName, ip), diff --git a/testacc/data_resource_aci_fvtenant_test.go b/testacc/data_source_aci_fvtenant_test.go similarity index 95% rename from testacc/data_resource_aci_fvtenant_test.go rename to testacc/data_source_aci_fvtenant_test.go index afaebe7e4..7ef4f0832 100644 --- a/testacc/data_resource_aci_fvtenant_test.go +++ b/testacc/data_source_aci_fvtenant_test.go @@ -1,4 +1,4 @@ -package acctest +package testacc import ( "fmt" @@ -16,9 +16,9 @@ func TestAccAciTenantDataSource_Basic(t *testing.T) { randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") randomValue := acctest.RandString(5) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciTenantDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciTenantDestroy, Steps: []resource.TestStep{ { Config: CreateAccTenantDSWithoutName(rName), diff --git a/testacc/data_source_aci_hsrpgroupp_test.go b/testacc/data_source_aci_hsrpgroupp_test.go new file mode 100644 index 000000000..d82d2b059 --- /dev/null +++ b/testacc/data_source_aci_hsrpgroupp_test.go @@ -0,0 +1,282 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciL3outHsrpInterfaceGroupDataSource_Basic(t *testing.T) { + resourceName := "aci_l3out_hsrp_interface_group.test" + dataSourceName := "data.aci_l3out_hsrp_interface_group.test" + rName := makeTestVariable(acctest.RandString(5)) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outHsrpInterfaceGroupDestroy, + Steps: []resource.TestStep{ + { + Config: CreateL3outHsrpInterfaceGroupDSWithoutRequired(rName, rName, rName, rName, rName, "l3out_hsrp_interface_profile_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateL3outHsrpInterfaceGroupDSWithoutRequired(rName, rName, rName, rName, rName, "name"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupDSConfig(rName, rName, rName, rName, rName), + Check: resource.ComposeTestCheckFunc( + resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "l3out_hsrp_interface_profile_dn", resourceName, "l3out_hsrp_interface_profile_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "config_issues", resourceName, "config_issues"), + resource.TestCheckResourceAttrPair(dataSourceName, "group_af", resourceName, "group_af"), + resource.TestCheckResourceAttrPair(dataSourceName, "group_id", resourceName, "group_id"), + resource.TestCheckResourceAttrPair(dataSourceName, "group_name", resourceName, "group_name"), + resource.TestCheckResourceAttrPair(dataSourceName, "ip", resourceName, "ip"), + resource.TestCheckResourceAttrPair(dataSourceName, "ip_obtain_mode", resourceName, "ip_obtain_mode"), + resource.TestCheckResourceAttrPair(dataSourceName, "mac", resourceName, "mac"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + ), + ), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupDSConfigRandomAttr(rName, rName, rName, rName, rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named(.)+ is not expected here.`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupDSConfigUpdatedResource(rName, rName, rName, rName, rName, "description", randomValue), + Check: resource.ComposeTestCheckFunc( + resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + ), + ), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupDSConfigInvalidName(rName, rName, rName, rName, rName), + ExpectError: regexp.MustCompile(`Object may not exists`), + }, + }, + }) +} + +func CreateAccL3outHsrpInterfaceGroupDSConfigInvalidName(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName string) string { + fmt.Println("=== STEP testing l3out_hsrp_interface_group Data Source creation with invalid name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip = "10.20.30.40" + } + + data "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_group.test.l3out_hsrp_interface_profile_dn + name = "${aci_l3out_hsrp_interface_group.test.name}xyz" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName) + return resource +} + +func CreateAccL3outHsrpInterfaceGroupDSConfigUpdatedResource(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName, key, value string) string { + fmt.Println("=== STEP testing l3out_hsrp_interface_group Data Source with updated resource") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip = "10.20.30.40" + %s = "%s" + } + + data "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_group.test.l3out_hsrp_interface_profile_dn + name = aci_l3out_hsrp_interface_group.test.name + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName, key, value) + return resource +} + +func CreateAccL3outHsrpInterfaceGroupDSConfigRandomAttr(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName, key, value string) string { + fmt.Println("=== STEP testing l3out_hsrp_interface_group Data Source with random attribute") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip = "10.20.30.40" + } + + data "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_group.test.l3out_hsrp_interface_profile_dn + name = aci_l3out_hsrp_interface_group.test.name + %s = "%s" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName, key, value) + return resource +} + +func CreateAccL3outHsrpInterfaceGroupDSConfig(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName string) string { + fmt.Println("=== STEP testing l3out_hsrp_interface_group Data Source with required arguments") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip = "10.20.30.40" + } + + data "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_group.test.l3out_hsrp_interface_profile_dn + name = aci_l3out_hsrp_interface_group.test.name + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName) + return resource +} + +func CreateL3outHsrpInterfaceGroupDSWithoutRequired(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName, attrName string) string { + fmt.Println("=== STEP Basic: testing l3out_hsrp_interface_group Data Source creation without ", attrName) + rBlock := ` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip = "10.20.30.40" + } + + ` + switch attrName { + case "l3out_hsrp_interface_profile_dn": + rBlock += ` + data "aci_l3out_hsrp_interface_group" "test" { + # l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_group.test.l3out_hsrp_interface_profile_dn + name = aci_l3out_hsrp_interface_group.test.name + } + ` + case "name": + rBlock += ` + data "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_group.test.l3out_hsrp_interface_profile_dn + # name = aci_l3out_hsrp_interface_group.test.name + } + ` + } + return fmt.Sprintf(rBlock, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName) +} diff --git a/testacc/data_source_aci_hsrpifp_test.go b/testacc/data_source_aci_hsrpifp_test.go new file mode 100644 index 000000000..e27e7d133 --- /dev/null +++ b/testacc/data_source_aci_hsrpifp_test.go @@ -0,0 +1,254 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciL3outHSRPInterfaceProfileDataSource_Basic(t *testing.T) { + resourceName := "aci_l3out_hsrp_interface_profile.test" + dataSourceName := "data.aci_l3out_hsrp_interface_profile.test" + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outHSRPInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateL3outHSRPInterfaceProfileDSWithoutRequired(rName, rName, rName, rName, "logical_interface_profile_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outHSRPInterfaceProfileConfigDataSource(rName, rName, rName, rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "logical_interface_profile_dn", resourceName, "logical_interface_profile_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "version", resourceName, "version"), + ), + }, + { + Config: CreateAccL3outHSRPInterfaceProfileDataSourceUpdate(rName, rName, rName, rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + + { + Config: CreateAccL3outHSRPInterfaceProfileDSWithInvalidParentDn(rName, rName, rName, rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + { + Config: CreateAccL3outHSRPInterfaceProfileDataSourceUpdateResource(rName, rName, rName, rName, "annotation", "orchestrator:terraform-testacc"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + ), + }, + }, + }) +} + +func CreateL3outHSRPInterfaceProfileDSWithoutRequired(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, attrName string) string { + fmt.Println("=== STEP testing l3out_hsrp_interface_profile Data Source without ", attrName) + rBlock := ` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + ` + switch attrName { + case "logical_interface_profile_dn": + rBlock += ` + data "aci_l3out_hsrp_interface_profile" "test" { + # logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + ` + + } + return fmt.Sprintf(rBlock, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName) +} + +func CreateAccL3outHSRPInterfaceProfileConfigDataSource(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName string) string { + fmt.Println("=== STEP testing l3out_hsrp_interface_profile Data Source with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + data "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + depends_on = [ + aci_l3out_hsrp_interface_profile.test + ] + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName) + return resource +} + +func CreateAccL3outHSRPInterfaceProfileDSWithInvalidParentDn(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName string) string { + fmt.Println("=== STEP testing l3out_hsrp_interface_profile Data Source Invalid logical_interface_profile_dn") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + data "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = "${aci_logical_interface_profile.test.id}xyz" + depends_on = [ + aci_l3out_hsrp_interface_profile.test + ] + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName) + return resource +} + +func CreateAccL3outHSRPInterfaceProfileDataSourceUpdateResource(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, key, value string) string { + fmt.Println("=== STEP testing l3out_hsrp_interface_profile Data Source with updated resource") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + %s = "%s" + } + + data "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + depends_on = [ + aci_l3out_hsrp_interface_profile.test + ] + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, key, value) + return resource +} + +func CreateAccL3outHSRPInterfaceProfileDataSourceUpdate(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, key, value string) string { + fmt.Println("=== STEP testing l3out_hsrp_interface_profile Data Source with random attributes") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + data "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + %s = "%s" + depends_on = [ + aci_l3out_hsrp_interface_profile.test + ] + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, key, value) + return resource +} diff --git a/testacc/data_source_aci_hsrpifpol_test.go b/testacc/data_source_aci_hsrpifpol_test.go new file mode 100644 index 000000000..8f3268606 --- /dev/null +++ b/testacc/data_source_aci_hsrpifpol_test.go @@ -0,0 +1,181 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciHsrpInterfacePolicyDataSource_Basic(t *testing.T) { + resourceName := "aci_hsrp_interface_policy.test" + dataSourceName := "data.aci_hsrp_interface_policy.test" + rName := acctest.RandString(5) + randomParameter := acctest.RandStringFromCharSet(10, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(10) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciHsrpInterfacePolicyDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccHsrpInterfacePolicyDSWithoutTenant(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccHsrpInterfacePolicyDSWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccHsrpInterfacePolicyConfigDataSource(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), + resource.TestCheckResourceAttrPair(dataSourceName, "tenant_dn", resourceName, "tenant_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "ctrl", resourceName, "ctrl"), + resource.TestCheckResourceAttrPair(dataSourceName, "reload_delay", resourceName, "reload_delay"), + resource.TestCheckResourceAttrPair(dataSourceName, "delay", resourceName, "delay"), + ), + }, + { + Config: CreateAccHsrpInterfacePolicyUpdatedConfigDataSourceRandomAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccHsrpInterfacePolicyUpdatedConfigDataSource(rName, "description", randomValue), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + ), + }, + { + Config: CreateAccHsrpInterfacePolicyDSWithInvalidName(rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + }, + }) +} + +func CreateAccHsrpInterfacePolicyUpdatedConfigDataSourceRandomAttr(rName, attribute, value string) string { + fmt.Println("=== STEP Basic: Testing Hrsp Interface Policy data source with random attribute") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_hsrp_interface_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + data "aci_hsrp_interface_policy" "test" { + tenant_dn = aci_hsrp_interface_policy.test.tenant_dn + name = aci_hsrp_interface_policy.test.name + %s = "%s" + } + `, rName, rName, attribute, value) + return resource +} + +func CreateAccHsrpInterfacePolicyUpdatedConfigDataSource(rName, attribute, value string) string { + fmt.Println("=== STEP Basic: Testing Hsrp Interface Policy data source with updated resource") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_hsrp_interface_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + %s = "%s" + + } + + data "aci_hsrp_interface_policy" "test" { + tenant_dn = aci_hsrp_interface_policy.test.tenant_dn + name = aci_hsrp_interface_policy.test.name + } + `, rName, rName, attribute, value) + return resource +} + +func CreateAccHsrpInterfacePolicyConfigDataSource(rName string) string { + fmt.Println("=== STEP Basic: Testing Hsrp Interface Policy data source") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_hsrp_interface_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + data "aci_hsrp_interface_policy" "test" { + tenant_dn = aci_hsrp_interface_policy.test.tenant_dn + name = aci_hsrp_interface_policy.test.name + } + `, rName, rName) + return resource +} + +func CreateAccHsrpInterfacePolicyDSWithInvalidName(rName string) string { + fmt.Println("=== STEP Basic: testing Hsrp Interface Policy reading with invalid name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_hsrp_interface_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + data "aci_hsrp_interface_policy" "test" { + tenant_dn = "${aci_hsrp_interface_policy.test.tenant_dn}abc" + name = aci_hsrp_interface_policy.test.name + } + `, rName, rName) + return resource +} + +func CreateAccHsrpInterfacePolicyDSWithoutTenant(rName string) string { + fmt.Println("=== STEP Basic: testing Hsrp Interface Policy reading without giving tenant_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_hsrp_interface_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + data "aci_hsrp_interface_policy" "test" { + name = aci_hsrp_interface_policy.test.name + } + `, rName, rName) + return resource +} + +func CreateAccHsrpInterfacePolicyDSWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing Hsrp Interface Policy reading without giving name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_hsrp_interface_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + data "aci_hsrp_interface_policy" "test" { + tenant_dn = aci_hsrp_interface_policy.test.tenant_dn + } + `, rName, rName) + return resource +} diff --git a/testacc/data_source_aci_hsrpsecvip_test.go b/testacc/data_source_aci_hsrpsecvip_test.go new file mode 100644 index 000000000..0b805c03e --- /dev/null +++ b/testacc/data_source_aci_hsrpsecvip_test.go @@ -0,0 +1,299 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciL3outHSRPSecondaryVIPDataSource_Basic(t *testing.T) { + resourceName := "aci_l3out_hsrp_secondary_vip.test" + dataSourceName := "data.aci_l3out_hsrp_secondary_vip.test" + randomParameter := acctest.RandStringFromCharSet(10, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(10) + rName := makeTestVariable(acctest.RandString(5)) + ip, _ := acctest.RandIpAddress("10.5.0.0/16") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outHSRPSecondaryVIPDestroy, + Steps: []resource.TestStep{ + { + Config: CreateL3outHSRPSecondaryVIPDSWithoutRequired(rName, rName, rName, rName, rName, ip, "l3out_hsrp_interface_group_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateL3outHSRPSecondaryVIPDSWithoutRequired(rName, rName, rName, rName, rName, ip, "ip"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPConfigDataSource(rName, rName, rName, rName, rName, ip), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "l3out_hsrp_interface_group_dn", resourceName, "l3out_hsrp_interface_group_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "ip", resourceName, "ip"), + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "config_issues", resourceName, "config_issues"), + ), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPDataSourceUpdate(rName, rName, rName, rName, rName, ip, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + + { + Config: CreateAccL3outHSRPSecondaryVIPDSWithInvalidParentDn(rName, rName, rName, rName, rName, ip), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPDataSourceUpdateResource(rName, rName, rName, rName, rName, ip, "annotation", "orchestrator:terraform-testacc"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + ), + }, + }, + }) +} + +func CreateL3outHSRPSecondaryVIPDSWithoutRequired(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip, attrName string) string { + fmt.Println("=== STEP testing l3out_hsrp_secondary_vip Data Source without ", attrName) + rBlock := ` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip_obtain_mode = "learn" + } + + resource "aci_l3out_hsrp_secondary_vip" "test" { + l3out_hsrp_interface_group_dn = aci_l3out_hsrp_interface_group.test.id + ip = "%s" + } + + ` + switch attrName { + case "l3out_hsrp_interface_group_dn": + rBlock += ` + data "aci_l3out_hsrp_secondary_vip" "test" { + # l3out_hsrp_interface_group_dn = aci_l3out_hsrp_secondary_vip.test.l3out_hsrp_interface_group_dn + ip = aci_l3out_hsrp_interface_group.test.ip + } + ` + case "ip": + rBlock += ` + data "aci_l3out_hsrp_secondary_vip" "test" { + l3out_hsrp_interface_group_dn = aci_l3out_hsrp_secondary_vip.test.l3out_hsrp_interface_group_dn + # ip = aci_l3out_hsrp_interface_group.test.ip + } + ` + } + return fmt.Sprintf(rBlock, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip) +} + +func CreateAccL3outHSRPSecondaryVIPConfigDataSource(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip string) string { + fmt.Println("=== STEP testing l3out_hsrp_secondary_vip Data Source with required arguments only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip_obtain_mode = "learn" + } + + resource "aci_l3out_hsrp_secondary_vip" "test" { + l3out_hsrp_interface_group_dn = aci_l3out_hsrp_interface_group.test.id + ip = "%s" + } + + data "aci_l3out_hsrp_secondary_vip" "test" { + l3out_hsrp_interface_group_dn = aci_l3out_hsrp_secondary_vip.test.l3out_hsrp_interface_group_dn + ip = aci_l3out_hsrp_secondary_vip.test.ip + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip) + return resource +} +func CreateAccL3outHSRPSecondaryVIPDSWithInvalidParentDn(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip string) string { + fmt.Println("=== STEP testing l3out_hsrp_secondary_vip Data Source with Invalid l3out_hsrp_interface_group_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip_obtain_mode = "learn" + } + + resource "aci_l3out_hsrp_secondary_vip" "test" { + l3out_hsrp_interface_group_dn = aci_l3out_hsrp_interface_group.test.id + ip = "%s" + } + + data "aci_l3out_hsrp_secondary_vip" "test" { + l3out_hsrp_interface_group_dn = "${aci_l3out_hsrp_secondary_vip.test.l3out_hsrp_interface_group_dn}invalid" + ip = aci_l3out_hsrp_secondary_vip.test.ip + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip) + return resource +} + +func CreateAccL3outHSRPSecondaryVIPDataSourceUpdateResource(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip, key, value string) string { + fmt.Println("=== STEP testing l3out_hsrp_secondary_vip Data Source with updated resource") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip_obtain_mode = "learn" + } + + resource "aci_l3out_hsrp_secondary_vip" "test" { + l3out_hsrp_interface_group_dn = aci_l3out_hsrp_interface_group.test.id + ip = "%s" + %s = "%s" + } + + data "aci_l3out_hsrp_secondary_vip" "test" { + l3out_hsrp_interface_group_dn = aci_l3out_hsrp_secondary_vip.test.l3out_hsrp_interface_group_dn + ip = aci_l3out_hsrp_secondary_vip.test.ip + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip, key, value) + return resource +} + +func CreateAccL3outHSRPSecondaryVIPDataSourceUpdate(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip, key, value string) string { + fmt.Println("=== STEP testing l3out_hsrp_secondary_vip Data Source invalid attribute") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip_obtain_mode = "learn" + } + + resource "aci_l3out_hsrp_secondary_vip" "test" { + l3out_hsrp_interface_group_dn = aci_l3out_hsrp_interface_group.test.id + ip = "%s" + } + + data "aci_l3out_hsrp_secondary_vip" "test" { + l3out_hsrp_interface_group_dn = aci_l3out_hsrp_secondary_vip.test.l3out_hsrp_interface_group_dn + ip = aci_l3out_hsrp_secondary_vip.test.ip + %s = "%s" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip, key, value) + return resource +} diff --git a/testacc/data_source_aci_l3extOut_test.go b/testacc/data_source_aci_l3extOut_test.go new file mode 100644 index 000000000..850bf1998 --- /dev/null +++ b/testacc/data_source_aci_l3extOut_test.go @@ -0,0 +1,194 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciL3OutsideDataSource_Basic(t *testing.T) { + resourceName := "aci_l3_outside.test" + dataSourceName := "data.aci_l3_outside.test" + rName := makeTestVariable(acctest.RandString(5)) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3OutsideDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3OutsideDSConfigWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3OutsideDSConfigWithoutTenantdn(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3OutsideDataSource(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "target_dscp", resourceName, "target_dscp"), + resource.TestCheckResourceAttrPair(dataSourceName, "enforce_rtctrl", resourceName, "enforce_rtctrl"), + ), + }, + { + Config: CreateAccL3OutsideDataSourceUpdateRandomAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccL3OutsideDSWithInvalidTenantdn(rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + { + Config: CreateAccL3OutsideDSWithInvalidName(rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + { + Config: CreateAccL3OutsideDataSourceUpdate(rName, "description", "test_annotation_1"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + ), + }, + }, + }) +} + +func CreateAccL3OutsideDataSource(rName string) string { + fmt.Println("=== STEP Basic: testing l3outside data source reading with required arguments only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + data "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = aci_tenant.test.name + depends_on = [aci_l3_outside.test] + } + `, rName, rName) + return resource +} + +func CreateAccL3OutsideDataSourceUpdateRandomAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP testing l3outside data source update for attribute: %s = %s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + data "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = aci_l3_outside.test.name + %s = "%s" + depends_on = [aci_l3_outside.test] + } + `, rName, rName, attribute, value) + return resource +} + +func CreateAccL3OutsideDataSourceUpdate(rName, attribute, value string) string { + fmt.Printf("=== STEP testing l3outside data source update for attribute: %s = %s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + %s = "%s" + } + data "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = aci_l3_outside.test.name + depends_on = [aci_l3_outside.test] + } + `, rName, rName, attribute, value) + return resource +} + +func CreateAccL3OutsideDSWithInvalidTenantdn(rName string) string { + fmt.Println("=== STEP Basic: testing l3outside data source reading with invalid tenant dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + data "aci_l3_outside" "test" { + tenant_dn = "${aci_tenant.test.id}xyz" + name = aci_l3_outside.test.name + depends_on = [aci_l3_outside.test] + } + `, rName, rName) + return resource +} + +func CreateAccL3OutsideDSWithInvalidName(rName string) string { + fmt.Println("=== STEP Basic: testing l3outside data source reading with invalid name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + data "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "${aci_l3_outside.test.name}xyz" + depends_on = [aci_l3_outside.test] + } + `, rName, rName) + return resource +} + +func CreateAccL3OutsideDSConfigWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing l3outside data source reading without giving name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + data "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + depends_on = [aci_l3_outside.test] + } + `, rName, rName) + return resource +} + +func CreateAccL3OutsideDSConfigWithoutTenantdn(rName string) string { + fmt.Println("=== STEP Basic: testing l3outside data source reading without giving tenant dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + data "aci_l3_outside" "test" { + name = aci_l3_outside.test.name + depends_on = [aci_l3_outside.test] + } + `, rName, rName) + return resource +} diff --git a/testacc/data_source_aci_l3extinstp_test.go b/testacc/data_source_aci_l3extinstp_test.go new file mode 100644 index 000000000..8237e9c40 --- /dev/null +++ b/testacc/data_source_aci_l3extinstp_test.go @@ -0,0 +1,197 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciExternalNetworkInstanceProfileDataSource_Basic(t *testing.T) { + resourceName := "aci_external_network_instance_profile.test" + dataSourceName := "data.aci_external_network_instance_profile.test" + rName := makeTestVariable(acctest.RandString(5)) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciExternalNetworkInstanceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccExternalNetworkInstanceProfileDSWithoutL3Out(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccExternalNetworkInstanceProfileDSWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccExternalNetworkInstanceProfileConfigDS(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "exception_tag", resourceName, "exception_tag"), + resource.TestCheckResourceAttrPair(dataSourceName, "flood_on_encap", resourceName, "flood_on_encap"), + resource.TestCheckResourceAttrPair(dataSourceName, "match_t", resourceName, "match_t"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "pref_gr_memb", resourceName, "pref_gr_memb"), + resource.TestCheckResourceAttrPair(dataSourceName, "prio", resourceName, "prio"), + resource.TestCheckResourceAttrPair(dataSourceName, "target_dscp", resourceName, "target_dscp"), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileDataSourceUpdateRandomAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccExternalNetworkInstanceProfileDataSourceUpdate(rName, "description", randomValue), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileDSWithInvalidL3OutDn(rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + }, + }) +} + +func CreateAccExternalNetworkInstanceProfileDataSourceUpdate(rName, key, value string) string { + fmt.Printf("=== STEP Basic: testing external_network_instance_profile data source update for %s = %s\n", key, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_l3_outside" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_external_network_instance_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + %s = "%s" + } + + data "aci_external_network_instance_profile" "test" { + l3_outside_dn = aci_external_network_instance_profile.test.l3_outside_dn + name = aci_external_network_instance_profile.test.name + } + `, rName, rName, rName, key, value) + return resource +} + +func CreateAccExternalNetworkInstanceProfileDSWithInvalidL3OutDn(rName string) string { + fmt.Println("=== STEP testing external_network_instance_profile data source creation with invalid l3_outside_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_l3_outside" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_external_network_instance_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + + data "aci_external_network_instance_profile" "test" { + l3_outside_dn = "${aci_external_network_instance_profile.test.l3_outside_dn}xyz" + name = aci_external_network_instance_profile.test.name + } + `, rName, rName, rName) + return resource +} + +func CreateAccExternalNetworkInstanceProfileDataSourceUpdateRandomAttr(rName, key, value string) string { + fmt.Printf("=== STEP Basic: testing external_network_instance_profile data source creation with %s = %s in data source\n", key, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_l3_outside" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_external_network_instance_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + + data "aci_external_network_instance_profile" "test" { + l3_outside_dn = aci_external_network_instance_profile.test.l3_outside_dn + name = aci_external_network_instance_profile.test.name + %s = "%s" + } + `, rName, rName, rName, key, value) + return resource +} + +func CreateAccExternalNetworkInstanceProfileConfigDS(rName string) string { + fmt.Println("=== STEP Basic: testing external_network_instance_profile data source creation with required arguments only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_l3_outside" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_external_network_instance_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + + data "aci_external_network_instance_profile" "test" { + l3_outside_dn = aci_external_network_instance_profile.test.l3_outside_dn + name = aci_external_network_instance_profile.test.name + } + `, rName, rName, rName) + return resource +} + +func CreateAccExternalNetworkInstanceProfileDSWithoutL3Out(rName string) string { + fmt.Println("=== STEP Basic: testing external_network_instance_profile data source creation without creating l3_outside") + resource := fmt.Sprintf(` + data "aci_external_network_instance_profile" "test" { + name = "%s" + } + `, rName) + return resource +} + +func CreateAccExternalNetworkInstanceProfileDSWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing external_network_instance_profile data source creation without name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_l3_outside" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_external_network_instance_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + + data "aci_external_network_instance_profile" "test" { + l3_outside_dn = aci_external_network_instance_profile.test.l3_outside_dn + } + `, rName, rName, rName) + return resource +} diff --git a/testacc/data_source_aci_l3extlifp_test.go b/testacc/data_source_aci_l3extlifp_test.go new file mode 100644 index 000000000..384409cea --- /dev/null +++ b/testacc/data_source_aci_l3extlifp_test.go @@ -0,0 +1,266 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciLogicalInterfaceProfileDataSource_Basic(t *testing.T) { + resourceName := "aci_logical_interface_profile.test" + dataSourceName := "data.aci_logical_interface_profile.test" + rName := makeTestVariable(acctest.RandString(5)) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciLogicalInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccLogicalInterfaceProfileDSWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccLogicalInterfaceProfileDSWithoutLogicalNodeProfileDn(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccAciLogicalInterfaceProfileDataSource(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "prio", resourceName, "prio"), + resource.TestCheckResourceAttrPair(dataSourceName, "tag", resourceName, "tag"), + resource.TestCheckResourceAttrPair(dataSourceName, "logical_node_profile_dn", resourceName, "logical_node_profile_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), + ), + }, + { + Config: CreateAccAciLogicalInterfaceProfileDataSourceUpdateRandomAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccLogicalInterfaceProfileDSWithInvalidNodeProfileDn(rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + { + Config: CreateAccLogicalInterfaceProfileDSWithInvalidName(rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + { + Config: CreateAccLogicalInterfaceProfileDataSourceUpdate(rName, "description", "test_annotation_1"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + ), + }, + }, + }) +} + +func CreateAccAciLogicalInterfaceProfileDataSource(rName string) string { + fmt.Println("=== STEP Basic: testing LogicalInterfaceProfile data source reading with required arguments only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + description = "from terraform" + name = "%s" + } + + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + data "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = aci_logical_node_profile.test.name + depends_on = [aci_logical_interface_profile.test] + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccAciLogicalInterfaceProfileDataSourceUpdateRandomAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP testing LogicalInterfaceProfile data source update for attribute: %s = %s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + description = "from terraform" + name = "%s" + } + + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + data "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = aci_logical_node_profile.test.name + depends_on = [aci_logical_interface_profile.test] + %s = "%s" + } + `, rName, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccLogicalInterfaceProfileDataSourceUpdate(rName, attribute, value string) string { + fmt.Printf("=== STEP testing LogicalInterfaceProfile data source update for attribute: %s = %s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + description = "from terraform" + name = "%s" + } + + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + %s = "%s" + } + data "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = aci_logical_node_profile.test.name + depends_on = [aci_logical_interface_profile.test] + } + `, rName, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccLogicalInterfaceProfileDSWithInvalidNodeProfileDn(rName string) string { + fmt.Println("=== STEP Basic: testing LogicalInterfaceProfile data source reading with invalid Logical Node Profile dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + description = "from terraform" + name = "%s" + } + + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + data "aci_logical_interface_profile" "test" { + logical_node_profile_dn = "${aci_logical_node_profile.test.id}xyz" + name = aci_logical_node_profile.test.name + depends_on = [aci_logical_interface_profile.test] + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccLogicalInterfaceProfileDSWithInvalidName(rName string) string { + fmt.Println("=== STEP Basic: testing LogicalInterfaceProfile data source reading with invalid name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + description = "from terraform" + name = "%s" + } + + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + data "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "{aci_logical_node_profile.test.name}xyz" + depends_on = [aci_logical_interface_profile.test] + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccLogicalInterfaceProfileDSWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing LogicalInterfaceProfile data source reading without giving name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + description = "from terraform" + name = "%s" + } + + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + data "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + depends_on = [aci_logical_interface_profile.test] + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccLogicalInterfaceProfileDSWithoutLogicalNodeProfileDn(rName string) string { + fmt.Println("=== STEP Basic: testing LogicalInterfaceProfile data source reading without giving Logical Node Profile dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + description = "from terraform" + name = "%s" + } + + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + data "aci_logical_interface_profile" "test" { + name = aci_logical_node_profile.test.name + depends_on = [aci_logical_interface_profile.test] + } + `, rName, rName, rName, rName) + return resource +} diff --git a/testacc/data_source_aci_l3extlnodep_test.go b/testacc/data_source_aci_l3extlnodep_test.go new file mode 100644 index 000000000..de063ddc7 --- /dev/null +++ b/testacc/data_source_aci_l3extlnodep_test.go @@ -0,0 +1,185 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciLogicalNodeProfileDataSource_Basic(t *testing.T) { + resourceName := "aci_logical_node_profile.test" + dataSourceName := "data.aci_logical_node_profile.test" + rName := makeTestVariable(acctest.RandString(5)) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciLogicalNodeProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccLogicalNodeProfileDSWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccLogicalNodeProfileDSWithoutParentDn(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccLogicalNodeProfileDataSource(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "tag", resourceName, "tag"), + resource.TestCheckResourceAttrPair(dataSourceName, "target_dscp", resourceName, "target_dscp"), + resource.TestCheckResourceAttrPair(dataSourceName, "l3_outside_dn", resourceName, "l3_outside_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), + resource.TestCheckResourceAttrPair(dataSourceName, "config_issues", resourceName, "config_issues"), + ), + }, + { + Config: CreateAccLogicalNodeProfileDataSourceUpdateRandomAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccLogicalNodeProfileDSWithInvalidName(rName), + ExpectError: regexp.MustCompile(`Object may not exists`), + }, + { + Config: CreateAccLogicalNodeProfileDataSourceUpdate(rName, "description", "test_annotation_1"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + ), + }, + }, + }) +} + +func CreateAccLogicalNodeProfileDSWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing LogicalNodeProfile data source creation without giving Name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + data "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + } + `, rName, rName, rName) + return resource +} + +func CreateAccLogicalNodeProfileDataSourceUpdate(rName, attribute, value string) string { + fmt.Printf("=== STEP testing any data source update for attribute: %s = %s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + %s = "%s" + } + data "aci_logical_node_profile" "test" { + l3_outside_dn = aci_logical_node_profile.test.l3_outside_dn + name = aci_logical_node_profile.test.name + } + `, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccLogicalNodeProfileDataSource(rName string) string { + fmt.Println("=== STEP Basic: testing any data source reading with required arguments only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + data "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + depends_on = [aci_logical_node_profile.test] + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccLogicalNodeProfileDataSourceUpdateRandomAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP testing any data source update for attribute: %s = %s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + data "aci_logical_node_profile" "test" { + l3_outside_dn = aci_logical_node_profile.test.l3_outside_dn + name = aci_logical_node_profile.test.name + %s = "%s" + } + `, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccLogicalNodeProfileDSWithInvalidName(rName string) string { + fmt.Println("=== STEP Basic: testing LogicalNodeProfile data source reading with invalid name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + data "aci_logical_node_profile" "test" { + l3_outside_dn = aci_logical_node_profile.test.l3_outside_dn + name = "${aci_logical_node_profile.test.name}xyz" + } + `, rName, rName, rName) + return resource +} + +func CreateAccLogicalNodeProfileDSWithoutParentDn(rName string) string { + fmt.Println("=== STEP Basic: testing LogicalNodeProfile creation without giving parent dn") + resource := fmt.Sprintf(` + + data "aci_logical_node_profile" "test" { + name = "%s" + } + `, rName) + return resource +} diff --git a/testacc/data_source_aci_l3extloopbackifp_test.go b/testacc/data_source_aci_l3extloopbackifp_test.go new file mode 100644 index 000000000..16a75b437 --- /dev/null +++ b/testacc/data_source_aci_l3extloopbackifp_test.go @@ -0,0 +1,234 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAcil3extLoopBackIfPDataSource_Basic(t *testing.T) { + resourceName := "aci_l3out_loopback_interface_profile.test" + dataSourceName := "data.aci_l3out_loopback_interface_profile.test" + rName := makeTestVariable(acctest.RandString(5)) + addr, _ := acctest.RandIpAddress("5.5.0.0/16") + addrother, _ := acctest.RandIpAddress("6.6.0.0/16") + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciLoopBackInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateLoopBackInterfaceProfileDSWithoutRequired(rName, fabricNodeDn4, addr, addr, "fabric_node_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateLoopBackInterfaceProfileDSWithoutRequired(rName, fabricNodeDn4, addr, addr, "addr"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccLoopBackInterfaceProfileDSConfig(rName, fabricNodeDn4, addr, addr), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(resourceName, "fabric_node_dn", dataSourceName, "fabric_node_dn"), + resource.TestCheckResourceAttrPair(resourceName, "addr", dataSourceName, "addr"), + resource.TestCheckResourceAttrPair(resourceName, "description", dataSourceName, "description"), + resource.TestCheckResourceAttrPair(resourceName, "annotation", dataSourceName, "annotation"), + resource.TestCheckResourceAttrPair(resourceName, "name_alias", dataSourceName, "name_alias"), + ), + }, + { + Config: CreateAccLoopBackInterfaceProfileDSConfigRandomAttr(rName, fabricNodeDn4, addr, addr, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, { + Config: CreateAccLoopBackInterfaceProfileDSConfigWithInvalidIP(rName, fabricNodeDn4, addr, addr, addrother), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + { + Config: CreateAccLoopBackInterfaceProfileDSConfigUpdatedResource(rName, fabricNodeDn4, addr, addr, "description", randomValue), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(resourceName, "description", dataSourceName, "description"), + ), + }, + }, + }) +} + +func CreateAccLoopBackInterfaceProfileDSConfigUpdatedResource(rName, tdn, parent_addr, addr, key, value string) string { + fmt.Println("=== STEP testing LoopBackInterfaceProfile Data Source with updated resource") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name ="%s" + } + resource "aci_logical_node_to_fabric_node" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + tdn = "%s" + rtr_id = "%s" + } + resource "aci_l3out_loopback_interface_profile" "test" { + fabric_node_dn = aci_logical_node_to_fabric_node.test.id + addr = "%s" + } + data "aci_l3out_loopback_interface_profile" "test" { + fabric_node_dn = aci_l3out_loopback_interface_profile.test.fabric_node_dn + addr = aci_l3out_loopback_interface_profile.test.addr + %s = "%s" + } + `, rName, rName, rName, tdn, addr, addr, key, value) + return resource +} + +func CreateAccLoopBackInterfaceProfileDSConfigWithInvalidIP(rName, tdn, parent_addr, addr, addrother string) string { + fmt.Println("=== STEP testing LoopBackInterfaceProfile Data Source with invalid ip") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name ="%s" + } + resource "aci_logical_node_to_fabric_node" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + tdn = "%s" + rtr_id = "%s" + } + resource "aci_l3out_loopback_interface_profile" "test" { + fabric_node_dn = aci_logical_node_to_fabric_node.test.id + addr = "%s" + } + data "aci_l3out_loopback_interface_profile" "test" { + fabric_node_dn = aci_l3out_loopback_interface_profile.test.fabric_node_dn + addr = "%s" + } + `, rName, rName, rName, tdn, parent_addr, addr, addrother) + return resource +} + +func CreateAccLoopBackInterfaceProfileDSConfigRandomAttr(rName, tdn, parent_addr, addr, key, value string) string { + fmt.Println("=== STEP testing LoopBackInterfaceProfile Data Source with random attribute") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name ="%s" + } + resource "aci_logical_node_to_fabric_node" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + tdn = "%s" + rtr_id = "%s" + } + resource "aci_l3out_loopback_interface_profile" "test" { + fabric_node_dn = aci_logical_node_to_fabric_node.test.id + addr = "%s" + } + data "aci_l3out_loopback_interface_profile" "test" { + fabric_node_dn = aci_l3out_loopback_interface_profile.test.fabric_node_dn + addr = aci_l3out_loopback_interface_profile.test.addr + %s = "%s" + } + `, rName, rName, rName, tdn, addr, addr, key, value) + return resource +} + +func CreateAccLoopBackInterfaceProfileDSConfig(rName, tdn, parent_addr, addr string) string { + fmt.Println("=== STEP testing LoopBackInterfaceProfile Data Source with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name ="%s" + } + resource "aci_logical_node_to_fabric_node" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + tdn = "%s" + rtr_id = "%s" + } + resource "aci_l3out_loopback_interface_profile" "test" { + fabric_node_dn = aci_logical_node_to_fabric_node.test.id + addr = "%s" + } + data "aci_l3out_loopback_interface_profile" "test" { + fabric_node_dn = aci_l3out_loopback_interface_profile.test.fabric_node_dn + addr = aci_l3out_loopback_interface_profile.test.addr + } + `, rName, rName, rName, tdn, addr, addr) + return resource +} + +func CreateLoopBackInterfaceProfileDSWithoutRequired(rName, tdn, parent_addr, addr, attrName string) string { + fmt.Println("=== STEP testing LoopBackInterfaceProfile Data Source without ", attrName) + rBlock := ` + + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name ="%s" + } + resource "aci_logical_node_to_fabric_node" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + tdn = "%s" + rtr_id ="%s" + } + + resource "aci_l3out_loopback_interface_profile" "test" { + fabric_node_dn = aci_logical_node_to_fabric_node.test.id + addr = "%s" + } + + ` + switch attrName { + case "fabric_node_dn": + rBlock += ` + data "aci_l3out_loopback_interface_profile" "test" { + #fabric_node_dn = aci_l3out_loopback_interface_profile.test.fabric_node_dn + addr = aci_l3out_loopback_interface_profile.test.addr + } + ` + case "addr": + rBlock += ` + data "aci_l3out_loopback_interface_profile" "test" { + fabric_node_dn = aci_l3out_loopback_interface_profile.test.fabric_node_dn + # addr = aci_l3out_loopback_interface_profile.test.addr + } ` + } + + return fmt.Sprintf(rBlock, rName, rName, rName, tdn, parent_addr, addr) +} diff --git a/testacc/data_source_aci_l3extroutetagpol_test.go b/testacc/data_source_aci_l3extroutetagpol_test.go new file mode 100644 index 000000000..17c8db4f8 --- /dev/null +++ b/testacc/data_source_aci_l3extroutetagpol_test.go @@ -0,0 +1,193 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciL3outRouteTagPolicyDataSource_Basic(t *testing.T) { + resourceName := "aci_l3out_route_tag_policy.test" + dataSourceName := "data.aci_l3out_route_tag_policy.test" + randomParameter := acctest.RandStringFromCharSet(10, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(10) + rName := makeTestVariable(acctest.RandString(5)) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outRouteTagPolicyDestroy, + Steps: []resource.TestStep{ + { + Config: CreateL3outRouteTagPolicyDSWithoutRequired(rName, rName, "tenant_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateL3outRouteTagPolicyDSWithoutRequired(rName, rName, "name"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outRouteTagPolicyConfigDataSource(rName, rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "tenant_dn", resourceName, "tenant_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "tag", resourceName, "tag"), + resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), + ), + }, + { + Config: CreateAccL3outRouteTagPolicyDataSourceUpdate(rName, rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + + { + Config: CreateAccL3outRouteTagPolicyDSWithInvalidParentDn(rName, rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + { + Config: CreateAccL3outRouteTagPolicyDataSourceUpdatedResource(rName, "annotation", "orchestrator:terraform-testacc"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + ), + }, + }, + }) +} + +func CreateAccL3outRouteTagPolicyDataSourceUpdatedResource(rName, key, value string) string { + fmt.Println("=== STEP testing l3out_hsrp_interface_group Data Source with updated resource") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + + } + resource "aci_l3out_route_tag_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + %s = "%s" + } + + data "aci_l3out_route_tag_policy" "test" { + tenant_dn = aci_tenant.test.id + name = aci_l3out_route_tag_policy.test.name + depends_on = [ + aci_l3out_route_tag_policy.test + ] + } + + `, rName, rName, key, value) + return resource +} + +func CreateL3outRouteTagPolicyDSWithoutRequired(fvTenantName, rName, attrName string) string { + fmt.Println("=== STEP Basic: testing l3out_route_tag_policy Data Source without", attrName) + rBlock := ` + + resource "aci_tenant" "test" { + name = "%s" + + } + resource "aci_l3out_route_tag_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + ` + switch attrName { + case "tenant_dn": + rBlock += ` + data "aci_l3out_route_tag_policy" "test" { + # tenant_dn = aci_l3out_route_tag_policy.test.tenant_dn + name = aci_l3out_route_tag_policy.test.name + } + ` + case "name": + rBlock += ` + data "aci_l3out_route_tag_policy" "test" { + tenant_dn = aci_l3out_route_tag_policy.test.tenant_dn + # name = "aci_l3out_route_tag_policy.test.name" + } ` + } + + return fmt.Sprintf(rBlock, fvTenantName, rName) +} + +func CreateAccL3outRouteTagPolicyConfigDataSource(fvTenantName, rName string) string { + fmt.Println("=== STEP testing l3out_route_tag_policy Data Source with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3out_route_tag_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + data "aci_l3out_route_tag_policy" "test" { + tenant_dn = aci_tenant.test.id + name = aci_l3out_route_tag_policy.test.name + depends_on = [ + aci_l3out_route_tag_policy.test + ] + } + `, fvTenantName, rName) + return resource +} +func CreateAccL3outRouteTagPolicyDSWithInvalidParentDn(fvTenantName, rName string) string { + fmt.Println("=== STEP testing l3out_route_tag_policy creation with Invalid Parent Dn") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3out_route_tag_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + data "aci_l3out_route_tag_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "${aci_l3out_route_tag_policy.test.name}_invalid" + depends_on = [ + aci_l3out_route_tag_policy.test + ] + } + `, fvTenantName, rName) + return resource +} + +func CreateAccL3outRouteTagPolicyDataSourceUpdate(fvTenantName, rName, key, value string) string { + fmt.Println("=== STEP testing l3out_route_tag_policy Data Source with random parameter") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3out_route_tag_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + data "aci_l3out_route_tag_policy" "test" { + tenant_dn = aci_tenant.test.id + name = aci_l3out_route_tag_policy.test.name + %s = "%s" + depends_on = [ + aci_l3out_route_tag_policy.test + ] + } + `, fvTenantName, rName, key, value) + return resource +} diff --git a/testacc/data_source_aci_l3extsubnet_test.go b/testacc/data_source_aci_l3extsubnet_test.go new file mode 100644 index 000000000..2dfdd6a8c --- /dev/null +++ b/testacc/data_source_aci_l3extsubnet_test.go @@ -0,0 +1,231 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciL3ExtSubnetDataSource_Basic(t *testing.T) { + resourceName := "aci_l3_ext_subnet.test" + dataSourceName := "data.aci_l3_ext_subnet.test" + rName := makeTestVariable(acctest.RandString(5)) + ip, _ := acctest.RandIpAddress("10.0.5.0/20") + ip = fmt.Sprintf("%s/20", ip) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3ExtSubnetDestroy, + Steps: []resource.TestStep{ + { + Config: CreateL3ExtSubnetDSWithoutRequired(rName, rName, rName, ip, "external_network_instance_profile_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateL3ExtSubnetDSWithoutRequired(rName, rName, rName, ip, "ip"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3ExtSubnetDSConfig(rName, rName, rName, ip), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "external_network_instance_profile_dn", resourceName, "external_network_instance_profile_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "ip", resourceName, "ip"), + resource.TestCheckResourceAttrPair(dataSourceName, "aggregate", resourceName, "aggregate"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "scope.#", resourceName, "scope.#"), + resource.TestCheckResourceAttrPair(dataSourceName, "scope.0", resourceName, "scope.0"), + ), + }, + { + Config: CreateAccL3ExtSubnetDSUpdateRandomAttr(rName, rName, rName, ip, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccL3ExtSubnetDSWithInvalidParentDn(rName, rName, rName, ip, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`Object may not exists`), + }, + { + Config: CreateAccL3ExtSubnetDSUpdate(rName, rName, rName, ip, "description", randomValue), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + ), + }, + }, + }) +} + +func CreateL3ExtSubnetDSWithoutRequired(fvTenantName, l3extOutName, l3extInstPName, ip, attrName string) string { + fmt.Println("=== STEP Basic: testing l3_ext_subnet data source creation without ", attrName) + rBlock := ` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_external_network_instance_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_l3_ext_subnet" "test" { + external_network_instance_profile_dn = aci_external_network_instance_profile.test.id + ip = "%s" + } + + ` + switch attrName { + case "external_network_instance_profile_dn": + rBlock += ` + data "aci_l3_ext_subnet" "test" { + # external_network_instance_profile_dn = aci_l3_ext_subnet.test.external_network_instance_profile_dn + ip = aci_l3_ext_subnet.test.ip + } + ` + case "ip": + rBlock += ` + data "aci_l3_ext_subnet" "test" { + external_network_instance_profile_dn = aci_l3_ext_subnet.test.external_network_instance_profile_dn + # ip = aci_l3_ext_subnet.test.ip + } + ` + } + return fmt.Sprintf(rBlock, fvTenantName, l3extOutName, l3extInstPName, ip) +} + +func CreateAccL3ExtSubnetDSConfig(fvTenantName, l3extOutName, l3extInstPName, ip string) string { + fmt.Println("=== STEP testing l3_ext_subnet data source creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_external_network_instance_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_l3_ext_subnet" "test" { + external_network_instance_profile_dn = aci_external_network_instance_profile.test.id + ip = "%s" + } + + data "aci_l3_ext_subnet" "test" { + external_network_instance_profile_dn = aci_l3_ext_subnet.test.external_network_instance_profile_dn + ip = aci_l3_ext_subnet.test.ip + } + `, fvTenantName, l3extOutName, l3extInstPName, ip) + return resource +} + +func CreateAccL3ExtSubnetDSUpdateRandomAttr(fvTenantName, l3extOutName, l3extInstPName, ip, attribute, value string) string { + fmt.Println("=== STEP testing l3_ext_subnet data source with Random Attribute") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_external_network_instance_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_l3_ext_subnet" "test" { + external_network_instance_profile_dn = aci_external_network_instance_profile.test.id + ip = "%s" + } + + data "aci_l3_ext_subnet" "test" { + external_network_instance_profile_dn = aci_l3_ext_subnet.test.external_network_instance_profile_dn + ip = aci_l3_ext_subnet.test.ip + %s = "%s" + } + `, fvTenantName, l3extOutName, l3extInstPName, ip, attribute, value) + return resource +} + +func CreateAccL3ExtSubnetDSWithInvalidParentDn(fvTenantName, l3extOutName, l3extInstPName, ip, attribute, value string) string { + fmt.Println("=== STEP testing l3_ext_subnet data source creation with invalid external_network_instance_profile_dn") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_external_network_instance_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_l3_ext_subnet" "test" { + external_network_instance_profile_dn = aci_external_network_instance_profile.test.id + ip = "%s" + } + + data "aci_l3_ext_subnet" "test" { + external_network_instance_profile_dn = "${aci_l3_ext_subnet.test.external_network_instance_profile_dn}abc" + ip = aci_l3_ext_subnet.test.ip + } + `, fvTenantName, l3extOutName, l3extInstPName, ip) + return resource +} + +func CreateAccL3ExtSubnetDSUpdate(fvTenantName, l3extOutName, l3extInstPName, ip, attribute, value string) string { + fmt.Println("=== STEP testing l3_ext_subnet data source with updated resources") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_external_network_instance_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_l3_ext_subnet" "test" { + external_network_instance_profile_dn = aci_external_network_instance_profile.test.id + ip = "%s" + %s = "%s" + } + + data "aci_l3_ext_subnet" "test" { + external_network_instance_profile_dn = aci_l3_ext_subnet.test.external_network_instance_profile_dn + ip = aci_l3_ext_subnet.test.ip + } + `, fvTenantName, l3extOutName, l3extInstPName, ip, attribute, value) + return resource +} diff --git a/testacc/data_source_aci_l3extvirtuallifp_test.go b/testacc/data_source_aci_l3extvirtuallifp_test.go new file mode 100644 index 000000000..7dc416f4e --- /dev/null +++ b/testacc/data_source_aci_l3extvirtuallifp_test.go @@ -0,0 +1,403 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciL3outFloatingSVIDataSource_Basic(t *testing.T) { + resourceName := "aci_l3out_floating_svi.test" + dataSourceName := "data.aci_l3out_floating_svi.test" + node_dn := "topology/pod-1/node-111" + encap := "vlan-20" + randomParameter := acctest.RandStringFromCharSet(10, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(10) + rName := makeTestVariable(acctest.RandString(5)) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outFloatingSVIDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outFloatingSVIConfigDataSourceWithoutParentDn(rName, rName, rName, rName, node_dn, encap), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outFloatingSVIConfigDataSourceWithoutEncap(rName, rName, rName, rName, node_dn, encap), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + + { + Config: CreateAccL3outFloatingSVIConfigDataSourceWithoutNodeDn(rName, rName, rName, rName, node_dn, encap), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outFloatingSVIConfigDataSource(rName, rName, rName, rName, node_dn, encap), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "logical_interface_profile_dn", resourceName, "logical_interface_profile_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "node_dn", resourceName, "node_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "encap", resourceName, "encap"), + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "addr", resourceName, "addr"), + resource.TestCheckResourceAttrPair(dataSourceName, "autostate", resourceName, "autostate"), + resource.TestCheckResourceAttrPair(dataSourceName, "encap_scope", resourceName, "encap_scope"), + resource.TestCheckResourceAttrPair(dataSourceName, "if_inst_t", resourceName, "if_inst_t"), + resource.TestCheckResourceAttrPair(dataSourceName, "ipv6_dad", resourceName, "ipv6_dad"), + resource.TestCheckResourceAttrPair(dataSourceName, "ll_addr", resourceName, "ll_addr"), + resource.TestCheckResourceAttrPair(dataSourceName, "mac", resourceName, "mac"), + resource.TestCheckResourceAttrPair(dataSourceName, "mode", resourceName, "mode"), + resource.TestCheckResourceAttrPair(dataSourceName, "mtu", resourceName, "mtu"), + resource.TestCheckResourceAttrPair(dataSourceName, "target_dscp", resourceName, "target_dscp"), + ), + }, + { + Config: CreateAccL3outFloatingSVIDataSourceUpdate(rName, rName, rName, rName, node_dn, encap, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + + { + Config: CreateAccL3outFloatingSVIDSWithInvalidParentDn(rName, rName, rName, rName, node_dn, encap), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + { + Config: CreateAccL3outFloatingSVIDataSourceUpdatedResource(rName, rName, rName, rName, node_dn, encap, "annotation", "orchestrator:terraform-testacc"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + ), + }, + }, + }) +} + +func CreateAccL3outFloatingSVIConfigDataSource(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, node_dn, encap string) string { + fmt.Println("=== STEP testing l3out_floating_svi data source with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = "%s" + encap = "%s" + if_inst_t = "ext-svi" + } + + data "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = aci_l3out_floating_svi.test.node_dn + encap = aci_l3out_floating_svi.test.encap + depends_on = [ + aci_l3out_floating_svi.test + ] + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, node_dn, encap) + return resource +} + +func CreateAccL3outFloatingSVIConfigDataSourceWithoutParentDn(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, node_dn, encap string) string { + fmt.Println("=== STEP testing l3out_floating_svi creation data source without logical_interface_profile_dn") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = "%s" + encap = "%s" + if_inst_t = "ext-svi" + } + + data "aci_l3out_floating_svi" "test" { + node_dn = aci_l3out_floating_svi.test.node_dn + encap = aci_l3out_floating_svi.test.encap + depends_on = [ + aci_l3out_floating_svi.test + ] + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, node_dn, encap) + return resource +} + +func CreateAccL3outFloatingSVIConfigDataSourceWithoutNodeDn(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, node_dn, encap string) string { + fmt.Println("=== STEP testing l3out_floating_svi data source without node_dn") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = "%s" + encap = "%s" + if_inst_t = "ext-svi" + } + + data "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + encap = aci_l3out_floating_svi.test.encap + depends_on = [ + aci_l3out_floating_svi.test + ] + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, node_dn, encap) + return resource +} + +func CreateAccL3outFloatingSVIConfigDataSourceWithoutEncap(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, node_dn, encap string) string { + fmt.Println("=== STEP testing l3out_floating_svi data source without encap") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = "%s" + encap = "%s" + if_inst_t = "ext-svi" + } + + data "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = aci_l3out_floating_svi.test.node_dn + depends_on = [ + aci_l3out_floating_svi.test + ] + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, node_dn, encap) + return resource +} +func CreateAccL3outFloatingSVIDSWithInvalidParentDn(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, node_dn, encap string) string { + fmt.Println("=== STEP testing l3out_floating_svi data source with Invalid Parent Dn") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = "%s" + encap = "%s" + if_inst_t = "ext-svi" + } + + data "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = "${aci_logical_interface_profile.test.id}invalid" + node_dn = aci_l3out_floating_svi.test.node_dn + encap = aci_l3out_floating_svi.test.encap + depends_on = [ + aci_l3out_floating_svi.test + ] + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, node_dn, encap) + return resource +} + +func CreateAccL3outFloatingSVIDataSourceUpdatedResource(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, node_dn, encap, key, value string) string { + fmt.Println("=== STEP testing l3out_floating_svi data source with updated resource") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = "%s" + encap = "%s" + if_inst_t = "ext-svi" + %s = "%s" + } + + data "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = aci_l3out_floating_svi.test.node_dn + encap = aci_l3out_floating_svi.test.encap + depends_on = [ + aci_l3out_floating_svi.test + ] + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, node_dn, encap, key, value) + return resource +} + +func CreateAccL3outFloatingSVIDataSourceUpdate(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, node_dn, encap, key, value string) string { + fmt.Println("=== STEP testing l3out_floating_svi data source with random argument") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = "%s" + encap = "%s" + if_inst_t = "ext-svi" + } + + data "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = aci_l3out_floating_svi.test.node_dn + encap = aci_l3out_floating_svi.test.encap + %s = "%s" + depends_on = [ + aci_l3out_floating_svi.test + ] + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, node_dn, encap, key, value) + return resource +} diff --git a/testacc/data_source_aci_ospfifp_test.go b/testacc/data_source_aci_ospfifp_test.go new file mode 100644 index 000000000..455c656a1 --- /dev/null +++ b/testacc/data_source_aci_ospfifp_test.go @@ -0,0 +1,295 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciL3outOspfInterfaceProfileDataSource_Basic(t *testing.T) { + resourceName := "aci_l3out_ospf_interface_profile.test" + dataSourceName := "data.aci_l3out_ospf_interface_profile.test" + rName := acctest.RandString(5) + randomParameter := acctest.RandStringFromCharSet(10, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(10) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outOspfInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outOspfInterfaceProfileDSWithoutLogicalInterfaceProfile(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outOspfInterfaceProfileDSWithoutAuthKey(rName), + ExpectError: regexp.MustCompile(`Object may not exists`), + }, + { + Config: CreateAccL3outOspfInterfaceProfileConfigDataSource(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "auth_key", resourceName, "auth_key"), + resource.TestCheckResourceAttrPair(dataSourceName, "auth_key_id", resourceName, "auth_key_id"), + resource.TestCheckResourceAttrPair(dataSourceName, "auth_type", resourceName, "auth_type"), + resource.TestCheckResourceAttrPair(dataSourceName, "logical_interface_profile_dn", resourceName, "logical_interface_profile_dn"), + ), + }, + { + Config: CreateAccL3outOspfInterfaceProfileUpdatedConfigDataSourceRandomAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccL3outOspfInterfaceProfileUpdatedConfigDataSource(rName, "description", randomValue), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + ), + }, + { + Config: CreateAccL3outOspfInterfaceProfileDSWithInvalidLogicalInterfaceProfileDn(rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + }, + }) +} + +func CreateAccL3outOspfInterfaceProfileUpdatedConfigDataSourceRandomAttr(rName, attribute, value string) string { + fmt.Println("=== STEP Basic: Testing L3out Ospf Interface Profile data source with updated resource") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_ospf_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + auth_key = "%s" + } + + data "aci_l3out_ospf_interface_profile" "test" { + logical_interface_profile_dn = aci_l3out_ospf_interface_profile.test.logical_interface_profile_dn + auth_key = aci_l3out_ospf_interface_profile.test.auth_key + %s = "%s" + } + `, rName, rName, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccL3outOspfInterfaceProfileUpdatedConfigDataSource(rName, attribute, value string) string { + fmt.Println("=== STEP Basic: Testing L3out Ospf Interface Profile data source with updated resource") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_ospf_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + auth_key = "%s" + %s = "%s" + } + + data "aci_l3out_ospf_interface_profile" "test" { + logical_interface_profile_dn = aci_l3out_ospf_interface_profile.test.logical_interface_profile_dn + auth_key = aci_l3out_ospf_interface_profile.test.auth_key + } + + `, rName, rName, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccL3outOspfInterfaceProfileConfigDataSource(rName string) string { + fmt.Println("=== STEP Basic: L3out Ospf Interface Profile subject data source") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_ospf_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + auth_key = "%s" + } + + data "aci_l3out_ospf_interface_profile" "test" { + logical_interface_profile_dn = aci_l3out_ospf_interface_profile.test.logical_interface_profile_dn + auth_key = aci_l3out_ospf_interface_profile.test.auth_key + } + `, rName, rName, rName, rName, rName) + return resource +} + +func CreateAccL3outOspfInterfaceProfileDSWithInvalidLogicalInterfaceProfileDn(rName string) string { + fmt.Println("=== STEP Basic: testing L3out Ospf Interface Profile reading with Invalid Logical Interface Profile Dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_ospf_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + auth_key = "%s" + } + + data "aci_l3out_ospf_interface_profile" "test" { + logical_interface_profile_dn = "${aci_l3out_ospf_interface_profile.test.logical_interface_profile_dn}abc" + auth_key = aci_l3out_ospf_interface_profile.test.auth_key + } + + `, rName, rName, rName, rName, rName) + return resource +} + +func CreateAccL3outOspfInterfaceProfileDSWithoutLogicalInterfaceProfile(rName string) string { + fmt.Println("=== STEP Basic: testing L3out Ospf Interface Profile reading without giving Logical Interface Profile") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_ospf_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + auth_key = "%s" + } + + data "aci_l3out_ospf_interface_profile" "test" { + auth_key = aci_l3out_ospf_interface_profile.test.auth_key + } + `, rName, rName, rName, rName, rName) + return resource +} + +func CreateAccL3outOspfInterfaceProfileDSWithoutAuthKey(rName string) string { + fmt.Println("=== STEP Basic: testing contract subject reading without giving auth key") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_ospf_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + auth_key = "%s" + } + + data "aci_l3out_ospf_interface_profile" "test" { + logical_interface_profile_dn = "${aci_l3out_ospf_interface_profile.test.logical_interface_profile_dn}abc" + } + `, rName, rName, rName, rName, rName) + return resource +} diff --git a/testacc/data_source_aci_rtctrlprofile_test.go b/testacc/data_source_aci_rtctrlprofile_test.go new file mode 100644 index 000000000..cb392d81e --- /dev/null +++ b/testacc/data_source_aci_rtctrlprofile_test.go @@ -0,0 +1,201 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciBgpRouteControlProfileDS_Basic(t *testing.T) { + resourceName := "aci_bgp_route_control_profile.test" + dataSourceName := "data.aci_bgp_route_control_profile.test" + rName := makeTestVariable(acctest.RandString(5)) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciBgpRouteControlProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateBgpRouteControlProfileDSWithoutRequired(rName, rName, "parent_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateBgpRouteControlProfileDSWithoutRequired(rName, rName, "name"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccBgpRouteControlProfileDSConfig(rName, rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "parent_dn", resourceName, "parent_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "route_control_profile_type", resourceName, "route_control_profile_type"), + ), + }, + { + Config: CreateAccBgpRouteControlProfileDSUpdateRandomAttr(rName, rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccBgpRouteControlProfileDSWithInvalidParentDn(rName, rName), + ExpectError: regexp.MustCompile(`Object may not exists`), + }, + { + Config: CreateAccBgpRouteControlProfileDSUpdate(rName, rName, "description", randomValue), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + ), + }, + }, + }) +} + +func CreateBgpRouteControlProfileDSWithoutRequired(fvTenantName, rName, attrName string) string { + fmt.Println("=== STEP Basic: Creating bgp_route_control_profile Data Source without ", attrName) + rBlock := ` + + resource "aci_tenant" "test" { + name = "%s" + + } + resource "aci_bgp_route_control_profile" "test" { + parent_dn = aci_tenant.test.id + name = "%s" + description = "created while acceptance testing" + } + + ` + switch attrName { + case "parent_dn": + rBlock += ` + data "aci_bgp_route_control_profile" "test" { + parent_dn = aci_tenant.test.id + # name = aci_bgp_route_control_profile.test.name + depends_on = [aci_bgp_route_control_profile.test] + } + ` + case "name": + rBlock += ` + data "aci_bgp_route_control_profile" "test" { + #parent_dn = aci_tenant.test.id + name = aci_bgp_route_control_profile.test.name + depends_on = [aci_bgp_route_control_profile.test] + } + ` + } + return fmt.Sprintf(rBlock, fvTenantName, rName) +} + +func CreateAccBgpRouteControlProfileDSUpdateRandomAttr(fvTenantName, rName, attribute, value string) string { + fmt.Println("=== STEP Testing bgp_route_control_profile Data Source update with random attribute") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_bgp_route_control_profile" "test" { + parent_dn = aci_tenant.test.id + name = "%s" + } + data "aci_bgp_route_control_profile" "test" { + parent_dn = aci_tenant.test.id + name = aci_bgp_route_control_profile.test.name + %s = "%s" + depends_on = [aci_bgp_route_control_profile.test] + } + `, fvTenantName, rName, attribute, value) + return resource +} + +func CreateAccBgpRouteControlProfileDSConfig(fvTenantName, rName string) string { + + fmt.Println("=== STEP Testing bgp_route_control_profile Data Source creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_bgp_route_control_profile" "test" { + parent_dn = aci_tenant.test.id + name = "%s" + } + data "aci_bgp_route_control_profile" "test" { + parent_dn = aci_tenant.test.id + name = aci_bgp_route_control_profile.test.name + depends_on = [aci_bgp_route_control_profile.test] + } + `, fvTenantName, rName) + return resource +} + +func CreateAccBgpRouteControlProfileDSConfigL3Outside(ParentName, rName string) string { + fmt.Println("=== STEP Testing bgp_route_control_profile Data Source creation when parent is l3outside") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_bgp_route_control_profile" "test" { + parent_dn = aci_l3_outside.test.id + name = "%s" + } + data "aci_bgp_route_control_profile" "test" { + parent_dn = aci_l3_outside.test.id + name = aci_bgp_route_control_profile.test.name + depends_on = [aci_bgp_route_control_profile.test] + } + `, ParentName, ParentName, rName) + return resource +} + +func CreateAccBgpRouteControlProfileDSWithInvalidParentDn(ParentName, rName string) string { + fmt.Println("=== STEP Testing bgp_route_control_profile Data Source creation with invalid parent_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_bgp_route_control_profile" "test" { + parent_dn = aci_tenant.test.id + name = "%s" + } + data "aci_bgp_route_control_profile" "test" { + parent_dn = "${aci_tenant.test.id}xyz" + name = aci_bgp_route_control_profile.test.name + depends_on = [aci_bgp_route_control_profile.test] + } + `, ParentName, rName) + return resource +} + +func CreateAccBgpRouteControlProfileDSUpdate(fvTenantName, rName, attribute, value string) string { + fmt.Println("=== STEP Testing bgp_route_control_profile Data Source with updated resource") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_bgp_route_control_profile" "test" { + parent_dn = aci_tenant.test.id + name = "%s" + %s = "%s" + } + data "aci_bgp_route_control_profile" "test" { + parent_dn = aci_tenant.test.id + name = aci_bgp_route_control_profile.test.name + depends_on = [aci_bgp_route_control_profile.test] + } + `, fvTenantName, rName, attribute, value) + return resource +} diff --git a/testacc/data_source_aci_vzFilter_test.go b/testacc/data_source_aci_vzFilter_test.go index 9f8baffe5..20945003c 100644 --- a/testacc/data_source_aci_vzFilter_test.go +++ b/testacc/data_source_aci_vzFilter_test.go @@ -1,4 +1,4 @@ -package acctest +package testacc import ( "fmt" @@ -10,30 +10,30 @@ import ( ) func TestAccAciFilterDataSource_Basic(t *testing.T) { - resourceName := "aci_filter.test" - dataSourceName := "data.aci_filter.test" - randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + resourceName := "aci_filter.test" + dataSourceName := "data.aci_filter.test" + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") randomValue := acctest.RandString(5) rName := makeTestVariable(acctest.RandString(5)) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciFilterDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciFilterDestroy, Steps: []resource.TestStep{ { - Config: CreateAccFilterDSWithoutTenant(rName), - ExpectError: regexp.MustCompile(`Missing required argument`), + Config: CreateAccFilterDSWithoutTenant(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), }, { - Config: CreateAccFilterDSWithoutName(rName), + Config: CreateAccFilterDSWithoutName(rName), ExpectError: regexp.MustCompile(`Missing required argument`), }, { - Config: CreateAccFilterConfigDataSource(rName), + Config: CreateAccFilterConfigDataSource(rName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), - resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), - resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), resource.TestCheckResourceAttrPair(dataSourceName, "tenant_dn", resourceName, "tenant_dn"), resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), @@ -44,8 +44,8 @@ func TestAccAciFilterDataSource_Basic(t *testing.T) { ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), }, { - Config: CreateAccFilterDSWithInvalidName(rName), - ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + Config: CreateAccFilterDSWithInvalidName(rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), }, { Config: CreateAccFilterDataSourceUpdate(rName, "description", "description"), diff --git a/testacc/data_source_aci_vzbrcp_test.go b/testacc/data_source_aci_vzbrcp_test.go new file mode 100644 index 000000000..841bda747 --- /dev/null +++ b/testacc/data_source_aci_vzbrcp_test.go @@ -0,0 +1,172 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciContractDataSource_Basic(t *testing.T) { + resourceName := "aci_contract.test" + dataSourceName := "data.aci_contract.test" + rName := makeTestVariable(acctest.RandString(5)) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciContractDestroy, + Steps: []resource.TestStep{ + + { + Config: CreateAccContractDSWithoutTenant(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccContractDSWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccContractDSConfig(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "tenant_dn", resourceName, "tenant_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "prio", resourceName, "prio"), + resource.TestCheckResourceAttrPair(dataSourceName, "scope", resourceName, "scope"), + resource.TestCheckResourceAttrPair(dataSourceName, "target_dscp", resourceName, "target_dscp"), + ), + }, + { + Config: CreateAccContractUpdatedConfigDataSourceRandomAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccContractUpdatedConfigDataSource(rName, "description", randomValue), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + ), + }, + { + Config: CreateAccContractDataSourceWithInvalidName(rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + }, + }) +} + +func CreateAccContractDSWithoutTenant(rName string) string { + fmt.Println("=== STEP Basic: testing contract data source creation without creating tenant") + resource := fmt.Sprintf(` + data "aci_contract" "test" { + name = "%s" + } + `, rName) + return resource +} + +func CreateAccContractDSWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing contract data source creation without name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + data "aci_contract" "test" { + tenant_dn = aci_contract.test.tenant_dn + } + `, rName, rName) + return resource +} + +func CreateAccContractDSConfig(rName string) string { + fmt.Println("=== STEP Basic: testing contract data source creation with required arguments only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + data "aci_contract" "test" { + tenant_dn = aci_contract.test.tenant_dn + name = aci_contract.test.name + } + `, rName, rName) + return resource +} + +func CreateAccContractUpdatedConfigDataSourceRandomAttr(rName, key, value string) string { + fmt.Println("=== STEP Basic: testing contract data source creation with random attributes") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + data "aci_contract" "test" { + tenant_dn = aci_contract.test.tenant_dn + name = aci_contract.test.name + %s = "%s" + } + `, rName, rName, key, value) + return resource +} + +func CreateAccContractUpdatedConfigDataSource(rName, key, value string) string { + fmt.Println("=== STEP Basic: testing contract data source with updated resource") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + %s = "%s" + } + + data "aci_contract" "test" { + tenant_dn = aci_contract.test.tenant_dn + name = aci_contract.test.name + } + `, rName, rName, key, value) + return resource +} + +func CreateAccContractDataSourceWithInvalidName(rName string) string { + fmt.Println("=== STEP Basic: testing contract data source with invalid name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + data "aci_contract" "test" { + tenant_dn = aci_contract.test.tenant_dn + name = "${aci_contract.test.name}abc" + } + `, rName, rName) + return resource +} diff --git a/testacc/data_source_aci_vzcpif_test.go b/testacc/data_source_aci_vzcpif_test.go new file mode 100644 index 000000000..e3f8f26a8 --- /dev/null +++ b/testacc/data_source_aci_vzcpif_test.go @@ -0,0 +1,159 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciImportedContractDataSource_Basic(t *testing.T) { + resourceName := "aci_imported_contract.test" + dataSourceName := "data.aci_imported_contract.test" + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciImportedContractDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccImportedContractDSWithoutTenant(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccImportedContractDSWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccImportedContractConfigDataSource(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "tenant_dn", resourceName, "tenant_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), + ), + }, + { + Config: CreateAccImportedContractDataSourceUpdateRandomAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccImportedContractDSWithInvalidName(rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + { + Config: CreateAccImportedContractDataSourceUpdate(rName, "description", "description"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + ), + }, + }, + }) +} + +func CreateAccImportedContractDataSourceUpdateRandomAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP Basic: testing imported contract data source update for attribute: %s = %s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_imported_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + data "aci_imported_contract" "test" { + name = aci_imported_contract.test.name + tenant_dn = aci_imported_contract.test.tenant_dn + %s = "%s" + } + `, rName, rName, attribute, value) + return resource +} + +func CreateAccImportedContractDataSourceUpdate(rName, attribute, value string) string { + fmt.Printf("=== STEP Basic: testing imported contract data source update for attribute: %s = %s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_imported_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + %s = "%s" + } + data "aci_imported_contract" "test" { + name = aci_imported_contract.test.name + tenant_dn = aci_imported_contract.test.tenant_dn + } + `, rName, rName, attribute, value) + return resource +} + +func CreateAccImportedContractConfigDataSource(rName string) string { + fmt.Println("=== STEP Basic: testing imported contract creation for data source test") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_imported_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + data "aci_imported_contract" "test" { + tenant_dn = aci_tenant.test.id + name = aci_imported_contract.test.name + } + `, rName, rName) + return resource +} + +func CreateAccImportedContractDSWithInvalidName(rName string) string { + fmt.Println("=== STEP Basic: testing imported contract reading with invalid name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_imported_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + data "aci_imported_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "${aci_imported_contract.test.name}xyz" + } + `, rName, rName) + return resource +} + +func CreateAccImportedContractDSWithoutTenant(rName string) string { + fmt.Println("=== STEP Basic: testing imported contract reading without giving tenant_dn") + resource := fmt.Sprintf(` + data "aci_imported_contract" "test" { + name = "%s" + } + `, rName) + return resource +} + +func CreateAccImportedContractDSWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing imported contract reading without giving name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + data "aci_imported_contract" "test" { + tenant_dn = aci_tenant.test.id + } + `, rName) + return resource +} diff --git a/testacc/data_source_aci_vzsubj_test.go b/testacc/data_source_aci_vzsubj_test.go new file mode 100644 index 000000000..bf5149b26 --- /dev/null +++ b/testacc/data_source_aci_vzsubj_test.go @@ -0,0 +1,213 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciContractSubjectDataSource_Basic(t *testing.T) { + resourceName := "aci_contract_subject.test" + dataSourceName := "data.aci_contract_subject.test" + rName := acctest.RandString(5) + randomParameter := acctest.RandStringFromCharSet(10, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(10) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciContractSubjectDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccContractSubjectDSWithoutContract(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccContractSubjectDSWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccContractSubjectConfigDataSource(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "prio", resourceName, "prio"), + resource.TestCheckResourceAttrPair(dataSourceName, "cons_match_t", resourceName, "cons_match_t"), + resource.TestCheckResourceAttrPair(dataSourceName, "prov_match_t", resourceName, "prov_match_t"), + resource.TestCheckResourceAttrPair(dataSourceName, "rev_flt_ports", resourceName, "rev_flt_ports"), + resource.TestCheckResourceAttrPair(dataSourceName, "target_dscp", resourceName, "target_dscp"), + resource.TestCheckResourceAttrPair(dataSourceName, "contract_dn", resourceName, "contract_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), + ), + }, + { + Config: CreateAccContractSubjectUpdatedConfigDataSourceRandomAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccContractSubjectUpdatedConfigDataSource(rName, "description", randomValue), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + ), + }, + { + Config: CreateAccContractSubjectDSWithInvalidName(rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + }, + }) +} + +func CreateAccContractSubjectUpdatedConfigDataSourceRandomAttr(rName, attribute, value string) string { + fmt.Println("=== STEP Basic: Testing contract subject data source with random attribute") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract_subject" "test"{ + contract_dn = aci_contract.test.id + name = "%s" + } + + data "aci_contract_subject" "test" { + contract_dn = aci_contract.test.id + name = aci_contract_subject.test.name + %s = "%s" + } + `, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccContractSubjectUpdatedConfigDataSource(rName, attribute, value string) string { + fmt.Println("=== STEP Basic: Testing contract subject data source with updated resource") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract_subject" "test"{ + contract_dn = aci_contract.test.id + name = "%s" + %s = "%s" + } + + data "aci_contract_subject" "test" { + contract_dn = aci_contract.test.id + name = aci_contract_subject.test.name + } + `, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccContractSubjectConfigDataSource(rName string) string { + fmt.Println("=== STEP Basic: Testing contract subject data source") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract_subject" "test"{ + contract_dn = aci_contract.test.id + name = "%s" + description = "test_description" + } + + data "aci_contract_subject" "test" { + contract_dn = aci_contract.test.id + name = aci_contract_subject.test.name + } + `, rName, rName, rName) + return resource +} + +func CreateAccContractSubjectDSWithInvalidName(rName string) string { + fmt.Println("=== STEP Basic: testing contract subject reading with invalid name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract_subject" "test"{ + contract_dn = aci_contract.test.id + name = "%s" + } + + data "aci_contract_subject" "test" { + contract_dn = aci_contract.test.id + name = "${aci_contract_subject.test.name}abc" + } + `, rName, rName, rName) + return resource +} + +func CreateAccContractSubjectDSWithoutContract(rName string) string { + fmt.Println("=== STEP Basic: testing contract subject reading without giving contract_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract_subject" "test"{ + contract_dn = aci_contract.test.id + name = "%s" + } + + data "aci_contract_subject" "test" { + name = "%s" + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccContractSubjectDSWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing contract subject reading without giving name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract_subject" "test"{ + contract_dn = aci_contract.test.id + name = "%s" + } + + data "aci_contract" "test" { + contract_dn = aci_contract.test.id + } + `, rName, rName, rName) + return resource +} diff --git a/testacc/data_source_aci_vztaboo_test.go b/testacc/data_source_aci_vztaboo_test.go new file mode 100644 index 000000000..ebb636370 --- /dev/null +++ b/testacc/data_source_aci_vztaboo_test.go @@ -0,0 +1,185 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAciTabooContractDataSource_Basic(t *testing.T) { + resourceName := "aci_taboo_contract.test" + dataSourceName := "data.aci_taboo_contract.test" + randomParameter := acctest.RandStringFromCharSet(10, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(10) + rName := makeTestVariable(acctest.RandString(5)) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciTabooContractDestroy, + Steps: []resource.TestStep{ + { + Config: CreateTabooContractDSWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateTabooContractDSWithoutTenantdn(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccTabooContractConfigDataSource(rName, rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "tenant_dn", resourceName, "tenant_dn"), + resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), + ), + }, + { + Config: CreateAccTabooContractDataSourceUpdate(rName, rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + + { + Config: CreateAccTabooContractDSWithInvalidParentDn(rName, rName), + ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), + }, + { + Config: CreateAccTabooContractDataSourceUpdate(rName, rName, "annotation", "orchestrator:terraform-testacc"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), + ), + }, + }, + }) +} + +func CreateAccTabooContractConfigDataSource(fvTenantName, rName string) string { + fmt.Println("=== STEP testing taboo_contract creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_taboo_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + data "aci_taboo_contract" "test" { + tenant_dn = aci_tenant.test.id + name = aci_taboo_contract.test.name + depends_on = [ + aci_taboo_contract.test + ] + } + `, fvTenantName, rName) + return resource +} +func CreateAccTabooContractDSWithInvalidParentDn(fvTenantName, rName string) string { + fmt.Println("=== STEP testing taboo_contract creation with Invalid Parent Dn") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_taboo_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + data "aci_taboo_contract" "test" { + + tenant_dn = "${aci_tenant.test.id}_invalid" + name = aci_taboo_contract.test.name + depends_on = [ + aci_taboo_contract.test + ] + } + `, fvTenantName, rName) + return resource +} + +func CreateAccTabooContractDataSourceUpdate(fvTenantName, rName, key, value string) string { + fmt.Println("=== STEP testing taboo_contract Updation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_taboo_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + data "aci_taboo_contract" "test" { + tenant_dn = aci_tenant.test.id + name = aci_taboo_contract.test.name + %s = "%s" + depends_on = [ + aci_taboo_contract.test + ] + } + `, fvTenantName, rName, key, value) + return resource +} + +func CreateTabooContractDSWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing Taboo Contract data source reading without giving name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_taboo_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + data "aci_taboo_contract" "test" { + tenant_dn = aci_tenant.test.id + depends_on = [ + aci_taboo_contract.test + ] + } + `, rName, rName) + return resource +} + +func CreateTabooContractDSWithoutTenantdn(rName string) string { + fmt.Println("=== STEP Basic: testing Taboo Contract data source reading without giving Tenant Dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_taboo_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + data "aci_taboo_contract" "test" { + name = aci_taboo_contract.test.name + depends_on = [ + aci_taboo_contract.test + ] + } + `, rName, rName) + return resource +} diff --git a/testacc/provider_test.go b/testacc/provider_test.go index c4a27e952..ffacd0549 100644 --- a/testacc/provider_test.go +++ b/testacc/provider_test.go @@ -1,26 +1,33 @@ -package acctest +package testacc import ( - // "fmt" - // "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - // "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/terraform-providers/terraform-provider-aci/aci" + "io/ioutil" + "log" "os" - // "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/terraform-providers/terraform-provider-aci/aci" ) //TODO: check password is not showing in state file -var testAccProviders map[string]*schema.Provider +var testAccProviders map[string]func() (*schema.Provider, error) var testAccProvider *schema.Provider +var systemInfo *models.System func init() { testAccProvider = aci.Provider() - testAccProviders = map[string]*schema.Provider{ - "aci": testAccProvider, + testAccProviders = map[string]func() (*schema.Provider, error){ + "aci": func() (*schema.Provider, error) { + return testAccProvider, nil + }, } + log.SetOutput(ioutil.Discard) + systemInfo = fetchSysInfo() } func TestProvider(t *testing.T) { if err := aci.Provider().InternalValidate(); err != nil { @@ -28,6 +35,31 @@ func TestProvider(t *testing.T) { } } +func sharedAciClient() *client.Client { + config := aci.Config{ + Username: os.Getenv("ACI_USERNAME"), + Password: os.Getenv("ACI_PASSWORD"), + URL: os.Getenv("ACI_URL"), + PrivateKey: os.Getenv("ACI_PRIVATE_KEY"), + Certname: os.Getenv("ACI_CERT_NAME"), + ProxyUrl: os.Getenv("ACI_PROXY_URL"), + ProxyCreds: os.Getenv("ACI_PROXY_CREDS"), + IsInsecure: true, + } + return config.GetClient().(*client.Client) +} + +func fetchSysInfo() *models.System { + + aciClient := sharedAciClient() + topSystemCont, err := aciClient.GetViaURL("/api/node/class/topSystem.json") + if err != nil { + log.Panic("System info not found:", err) + } + + return models.SystemListFromContainer(topSystemCont)[0] +} + func TestProvider_impl(t *testing.T) { var _ *schema.Provider = aci.Provider() } diff --git a/testacc/resource_aci_aaadomain_test.go b/testacc/resource_aci_aaadomain_test.go new file mode 100644 index 000000000..4defa216a --- /dev/null +++ b/testacc/resource_aci_aaadomain_test.go @@ -0,0 +1,276 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciAAADomain_Basic(t *testing.T) { + var aaa_domain_default models.SecurityDomain + var aaa_domain_updated models.SecurityDomain + resourceName := "aci_aaa_domain.test" + rName := makeTestVariable(acctest.RandString(5)) + rNameUpdated := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciAAADomainDestroy, + Steps: []resource.TestStep{ + + { + Config: CreateAAADomainWithoutRequired(rName, "name"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccAAADomainConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciAAADomainExists(resourceName, &aaa_domain_default), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + ), + }, + { + Config: CreateAccAAADomainConfigWithOptionalValues(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciAAADomainExists(resourceName, &aaa_domain_updated), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform_testacc"), + resource.TestCheckResourceAttr(resourceName, "description", "created while acceptance testing"), + resource.TestCheckResourceAttr(resourceName, "name_alias", "test_aaa_domain"), + testAccCheckAciAAADomainIdEqual(&aaa_domain_default, &aaa_domain_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccAAADomainConfig(acctest.RandString(65)), + ExpectError: regexp.MustCompile(`property name of (.)+ failed validation`), + }, + { + Config: CreateAccAAADomainRemovingRequiredField(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccAAADomainConfig(rNameUpdated), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciAAADomainExists(resourceName, &aaa_domain_updated), + resource.TestCheckResourceAttr(resourceName, "name", rNameUpdated), + testAccCheckAciAAADomainIdNotEqual(&aaa_domain_default, &aaa_domain_updated), + ), + }, + }, + }) +} + +func TestAccAciAAADomain_Negative(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciAAADomainDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccAAADomainConfig(rName), + }, + { + Config: CreateAccAAADomainUpdatedAttr(rName, "description", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccAAADomainUpdatedAttr(rName, "annotation", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccAAADomainUpdatedAttr(rName, "name_alias", acctest.RandString(64)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccAAADomainUpdatedAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named(.)+ is not expected here.`), + }, + { + Config: CreateAccAAADomainConfig(rName), + }, + }, + }) +} + +func TestAccAciAAADomain_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciAAADomainDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccAAADomainConfigMultiple(rName), + }, + }, + }) +} + +func testAccCheckAciAAADomainExists(name string, aaa_domain *models.SecurityDomain) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("AAA Domain %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No AAA Domain dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + aaa_domainFound := models.SecurityDomainFromContainer(cont) + if aaa_domainFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("AAA Domain %s not found", rs.Primary.ID) + } + *aaa_domain = *aaa_domainFound + return nil + } +} + +func testAccCheckAciAAADomainDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing aaa_domain destroy") + client := testAccProvider.Meta().(*client.Client) + for _, rs := range s.RootModule().Resources { + if rs.Type == "aci_aaa_domain" { + cont, err := client.Get(rs.Primary.ID) + aaa_domain := models.SecurityDomainFromContainer(cont) + if err == nil { + return fmt.Errorf("AAA Domain %s Still exists", aaa_domain.DistinguishedName) + } + } else { + continue + } + } + return nil +} + +func testAccCheckAciAAADomainIdEqual(m1, m2 *models.SecurityDomain) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName != m2.DistinguishedName { + return fmt.Errorf("aaa_domain DNs are not equal") + } + return nil + } +} + +func testAccCheckAciAAADomainIdNotEqual(m1, m2 *models.SecurityDomain) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName == m2.DistinguishedName { + return fmt.Errorf("aaa_domain DNs are equal") + } + return nil + } +} + +func CreateAAADomainWithoutRequired(rName, attrName string) string { + fmt.Println("=== STEP Basic: testing aaa_domain creation without ", attrName) + rBlock := ` + + ` + switch attrName { + case "name": + rBlock += ` + resource "aci_aaa_domain" "test" { + + # name = "%s" + description = "created while acceptance testing" + } + ` + } + return fmt.Sprintf(rBlock, rName) +} + +func CreateAccAAADomainConfigMultiple(rName string) string { + fmt.Println("=== STEP testing multiple aaa_domain creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_aaa_domain" "test1" { + name = "%s" + } + + resource "aci_aaa_domain" "test2" { + name = "%s" + } + + resource "aci_aaa_domain" "test3" { + name = "%s" + } + `, rName+"1", rName+"2", rName+"3") + return resource +} + +func CreateAccAAADomainConfig(rName string) string { + fmt.Println("=== STEP testing aaa_domain creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_aaa_domain" "test" { + name = "%s" + } + `, rName) + return resource +} + +func CreateAccAAADomainConfigWithOptionalValues(rName string) string { + fmt.Println("=== STEP Basic: testing aaa_domain creation with optional parameters") + resource := fmt.Sprintf(` + + resource "aci_aaa_domain" "test" { + + name = "%s" + description = "created while acceptance testing" + annotation = "orchestrator:terraform_testacc" + name_alias = "test_aaa_domain" + } + `, rName) + + return resource +} + +func CreateAccAAADomainRemovingRequiredField() string { + fmt.Println("=== STEP Basic: testing aaa_domain creation with optional parameters") + resource := fmt.Sprintln(` + resource "aci_aaa_domain" "test" { + description = "created while acceptance testing" + annotation = "tag" + name_alias = "test_aaa_domain" + } + `) + + return resource +} + +func CreateAccAAADomainUpdatedAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP testing aaa_domain attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + + resource "aci_aaa_domain" "test" { + name = "%s" + %s = "%s" + } + `, rName, attribute, value) + return resource +} diff --git a/testacc/resource_aci_bfdifp_test.go b/testacc/resource_aci_bfdifp_test.go new file mode 100644 index 000000000..c5010a487 --- /dev/null +++ b/testacc/resource_aci_bfdifp_test.go @@ -0,0 +1,467 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciL3outBfdInterfaceProfile_Basic(t *testing.T) { + var l3out_bfd_interface_profile_default models.BFDInterfaceProfile + var l3out_bfd_interface_profile_updated models.BFDInterfaceProfile + resourceName := "aci_l3out_bfd_interface_profile.test" + rName := makeTestVariable(acctest.RandString(5)) + pNameUpdated := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outBfdInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateL3outBfdInterfaceProfileWithoutRequired(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outBfdInterfaceProfileConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outBfdInterfaceProfileExists(resourceName, &l3out_bfd_interface_profile_default), + resource.TestCheckResourceAttr(resourceName, "logical_interface_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s", rName, rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "key_id", "1"), + resource.TestCheckResourceAttr(resourceName, "interface_profile_type", "none"), + ), + }, + { + Config: CreateAccL3outBfdInterfaceProfileConfigWithOptionalValues(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outBfdInterfaceProfileExists(resourceName, &l3out_bfd_interface_profile_updated), + resource.TestCheckResourceAttr(resourceName, "logical_interface_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s", rName, rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform_testacc"), + resource.TestCheckResourceAttr(resourceName, "description", "created while acceptance testing"), + resource.TestCheckResourceAttr(resourceName, "name_alias", "test_l3out_bfd_interface_profile"), + resource.TestCheckResourceAttr(resourceName, "key", "1234"), + resource.TestCheckResourceAttr(resourceName, "key_id", "255"), + resource.TestCheckResourceAttr(resourceName, "interface_profile_type", "sha1"), + testAccCheckAciL3outBfdInterfaceProfileIdEqual(&l3out_bfd_interface_profile_default, &l3out_bfd_interface_profile_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"key"}, + }, + { + Config: CreateAccL3outBfdInterfaceProfileConfigUpdatedWithRequiredParams(rName, pNameUpdated), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outBfdInterfaceProfileExists(resourceName, &l3out_bfd_interface_profile_updated), + resource.TestCheckResourceAttr(resourceName, "logical_interface_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s", rName, rName, rName, pNameUpdated)), + testAccCheckAciL3outBfdInterfaceProfileIdNotEqual(&l3out_bfd_interface_profile_default, &l3out_bfd_interface_profile_updated), + ), + }, + { + Config: CreateAccL3outBfdInterfaceProfileConfig(rName), + }, + { + Config: CreateAccL3outBfdInterfaceProfileUpdateWithoutRequiredParams(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outBfdInterfaceProfileConfig(rName), + }, + }, + }) +} + +func TestAccAciL3outBfdInterfaceProfile_Update(t *testing.T) { + var l3out_bfd_interface_profile_default models.BFDInterfaceProfile + var l3out_bfd_interface_profile_updated models.BFDInterfaceProfile + resourceName := "aci_l3out_bfd_interface_profile.test" + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outBfdInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outBfdInterfaceProfileConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outBfdInterfaceProfileExists(resourceName, &l3out_bfd_interface_profile_default), + ), + }, + { + Config: CreateAccL3outBfdInterfaceProfileUpdatedAttr(rName, "key_id", "100"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outBfdInterfaceProfileExists(resourceName, &l3out_bfd_interface_profile_updated), + resource.TestCheckResourceAttr(resourceName, "logical_interface_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s", rName, rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "key_id", "100"), + testAccCheckAciL3outBfdInterfaceProfileIdEqual(&l3out_bfd_interface_profile_default, &l3out_bfd_interface_profile_updated), + ), + }, + }, + }) +} + +func TestAccAciL3outBfdInterfaceProfile_Negative(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := makeTestVariable(acctest.RandString(5)) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outBfdInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outBfdInterfaceProfileConfig(rName), + }, + { + Config: CreateAccL3outBfdInterfaceProfileWithInValidParentDn(rName), + ExpectError: regexp.MustCompile(` unknown property value (.)+, name dn, class bfdIfP (.)+`), + }, + { + Config: CreateAccL3outBfdInterfaceProfileUpdatedAttr(rName, "description", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outBfdInterfaceProfileUpdatedAttr(rName, "annotation", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outBfdInterfaceProfileUpdatedAttr(rName, "key", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outBfdInterfaceProfileUpdatedAttr(rName, "name_alias", acctest.RandString(64)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outBfdInterfaceProfileUpdatedAttr(rName, "key_id", randomValue), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name keyId, class bfdIfP (.)+`), + }, + { + Config: CreateAccL3outBfdInterfaceProfileUpdatedAttr(rName, "key_id", "0"), + ExpectError: regexp.MustCompile(`Property keyId of (.)+ is out of range`), + }, + { + Config: CreateAccL3outBfdInterfaceProfileUpdatedAttr(rName, "key_id", "-10"), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name keyId, class bfdIfP (.)+`), + }, + { + Config: CreateAccL3outBfdInterfaceProfileUpdatedAttr(rName, "key_id", "256"), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name keyId, class bfdIfP (.)+`), + }, + { + Config: CreateAccL3outBfdInterfaceProfileUpdatedAttr(rName, "interface_profile_type", randomValue), + ExpectError: regexp.MustCompile(`expected(.)+to be one of(.)+, got(.)+`), + }, + + { + Config: CreateAccL3outBfdInterfaceProfileUpdatedAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named(.)+is not expected here.`), + }, + { + Config: CreateAccL3outBfdInterfaceProfileConfig(rName), + }, + }, + }) +} + +func TestAccAciL3outBfdInterfaceProfile_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outBfdInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outBfdInterfaceProfileMultiple(rName), + }, + }, + }) +} + +func CreateAccL3outBfdInterfaceProfileMultiple(rName string) string { + fmt.Println("=== STEP Testing Multiple l3out_bfd_interface_profile creation") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_logical_interface_profile" "test1" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_bfd_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_bfd_interface_profile" "test1" { + logical_interface_profile_dn = aci_logical_interface_profile.test1.id + } + `, rName, rName, rName, rName, rName+"1") + return resource +} + +func testAccCheckAciL3outBfdInterfaceProfileExists(name string, l3out_bfd_interface_profile *models.BFDInterfaceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("L3out Bfd Interface Profile %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No L3out Bfd Interface Profile dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + l3out_bfd_interface_profileFound := models.BFDInterfaceProfileFromContainer(cont) + if l3out_bfd_interface_profileFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("L3out Bfd Interface Profile %s not found", rs.Primary.ID) + } + *l3out_bfd_interface_profile = *l3out_bfd_interface_profileFound + return nil + } +} + +func testAccCheckAciL3outBfdInterfaceProfileDestroy(s *terraform.State) error { + fmt.Println("=== STEP Testing l3out_bfd_interface_profile destroy") + client := testAccProvider.Meta().(*client.Client) + for _, rs := range s.RootModule().Resources { + if rs.Type == "aci_l3out_bfd_interface_profile" { + cont, err := client.Get(rs.Primary.ID) + l3out_bfd_interface_profile := models.BFDInterfaceProfileFromContainer(cont) + if err == nil { + return fmt.Errorf("L3out Bfd Interface Profile %s Still exists", l3out_bfd_interface_profile.DistinguishedName) + } + } else { + continue + } + } + return nil +} + +func testAccCheckAciL3outBfdInterfaceProfileIdEqual(m1, m2 *models.BFDInterfaceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName != m2.DistinguishedName { + return fmt.Errorf("l3out_bfd_interface_profile DNs are not equal") + } + return nil + } +} + +func testAccCheckAciL3outBfdInterfaceProfileIdNotEqual(m1, m2 *models.BFDInterfaceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName == m2.DistinguishedName { + return fmt.Errorf("l3out_bfd_interface_profile DNs are equal") + } + return nil + } +} + +func CreateL3outBfdInterfaceProfileWithoutRequired() string { + fmt.Println("=== STEP Basic: Testing l3out_bfd_interface_profile creation without required attribute") + resource := fmt.Sprintln(` + resource "aci_l3out_bfd_interface_profile" "test" { + } + `) + return resource +} + +func CreateAccL3outBfdInterfaceProfileConfigUpdatedWithRequiredParams(rName, pNameupdated string) string { + fmt.Println("=== STEP Testing l3out_bfd_interface_profile updation of required arguments") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_bfd_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + `, rName, rName, rName, pNameupdated) + return resource +} + +func CreateAccL3outBfdInterfaceProfileConfig(rName string) string { + fmt.Println("=== STEP Testing l3out_bfd_interface_profile creation with required argument only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_bfd_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccL3outBfdInterfaceProfileWithInValidParentDn(rName string) string { + fmt.Println("=== STEP Negative Case: Testing l3out_bfd_interface_profile creation with invalid parent Dn") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + + resource "aci_l3out_bfd_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_node_profile.test.id + } + `, rName, rName, rName) + return resource +} + +func CreateAccL3outBfdInterfaceProfileConfigWithOptionalValues(rName string) string { + fmt.Println("=== STEP Basic: Testing l3out_bfd_interface_profile creation with optional parameters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + resource "aci_l3out_bfd_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + description = "created while acceptance testing" + annotation = "orchestrator:terraform_testacc" + name_alias = "test_l3out_bfd_interface_profile" + key = "1234" + key_id = "255" + interface_profile_type = "sha1" + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccL3outBfdInterfaceProfileUpdateWithoutRequiredParams() string { + fmt.Println("=== STEP Basic: Testing l3out_bfd_interface_profile updation without required parameter") + resource := fmt.Sprintln(` + resource "aci_l3out_bfd_interface_profile" "test" { + description = "created while acceptance testing1" + annotation = "orchestrator:terraform_testacc1" + name_alias = "test_l3out_bfd_interface_profile" + key = "1234" + key_id = "255" + interface_profile_type = "sha1" + } + `) + return resource +} + +func CreateAccL3outBfdInterfaceProfileUpdatedAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP Testing l3out_bfd_interface_profile attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_bfd_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + %s = "%s" + } + `, rName, rName, rName, rName, attribute, value) + return resource +} diff --git a/testacc/resource_aci_fvaepg_test.go b/testacc/resource_aci_fvaepg_test.go index 97f633a6e..26445b12b 100644 --- a/testacc/resource_aci_fvaepg_test.go +++ b/testacc/resource_aci_fvaepg_test.go @@ -1,4 +1,4 @@ -package acctest +package testacc import ( "fmt" @@ -22,9 +22,9 @@ func TestAccAciApplicationEPG_Basic(t *testing.T) { longrName := acctest.RandString(65) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciApplicationEPGDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciApplicationEPGDestroy, Steps: []resource.TestStep{ { Config: CreateAccApplicationEPGWithoutApplicationProfile(rName), @@ -150,9 +150,9 @@ func TestAccAciApplicationEPG_Update(t *testing.T) { resourceName := "aci_application_epg.test" rName := acctest.RandString(5) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciApplicationEPGDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciApplicationEPGDestroy, Steps: []resource.TestStep{ { Config: CreateAccApplicationEPGConfig(rName), @@ -303,9 +303,9 @@ func TestAccAciApplicationEPG_NegativeCases(t *testing.T) { randomValue := acctest.RandString(12) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciApplicationEPGDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciApplicationEPGDestroy, Steps: []resource.TestStep{ { Config: CreateAccApplicationEPGConfig(rName), @@ -386,9 +386,9 @@ func TestAccAciApplicationEPG_RelationParameters(t *testing.T) { randomName1 := acctest.RandString(5) randomName2 := acctest.RandString(5) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciApplicationEPGDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciApplicationEPGDestroy, Steps: []resource.TestStep{ { Config: CreateAccApplicationEPGConfig(rName), @@ -511,9 +511,9 @@ func TestAccAciApplicationEPG_RelationParameters(t *testing.T) { func TestAccApplicationEpg_MultipleCreateDelete(t *testing.T) { rName := makeTestVariable(acctest.RandString(5)) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciApplicationEPGDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciApplicationEPGDestroy, Steps: []resource.TestStep{ { Config: CreateAcEPGsConfig(rName), diff --git a/testacc/resource_aci_fvany_test.go b/testacc/resource_aci_fvany_test.go new file mode 100644 index 000000000..3d5ea1205 --- /dev/null +++ b/testacc/resource_aci_fvany_test.go @@ -0,0 +1,513 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciAny_Basic(t *testing.T) { + var any_default models.Any + var any_updated models.Any + resourceName := "aci_any.test" + rName := makeTestVariable(acctest.RandString(5)) + rOther := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciAnyDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccAnyWithoutVRFdn(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccAnyConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciAnyExists(resourceName, &any_default), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "match_t", "AtleastOne"), + resource.TestCheckResourceAttr(resourceName, "pref_gr_memb", "disabled"), + resource.TestCheckResourceAttr(resourceName, "vrf_dn", fmt.Sprintf("uni/tn-%s/ctx-%s", rName, rName)), + ), + }, + { + Config: CreateAccAnyConfigWithOptionalValues(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciAnyExists(resourceName, &any_updated), + resource.TestCheckResourceAttr(resourceName, "description", "vzAny Description"), + resource.TestCheckResourceAttr(resourceName, "name_alias", "alias_any"), + resource.TestCheckResourceAttr(resourceName, "annotation", "tag_any"), + resource.TestCheckResourceAttr(resourceName, "match_t", "AtmostOne"), + resource.TestCheckResourceAttr(resourceName, "pref_gr_memb", "enabled"), + resource.TestCheckResourceAttr(resourceName, "vrf_dn", fmt.Sprintf("uni/tn-%s/ctx-%s", rName, rName)), + testAccCheckAciAnyIdEqual(&any_default, &any_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccAnyConfigWithAnotherVRFdn(rName, rOther), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciAnyExists(resourceName, &any_updated), + testAccCheckAciAnyIdNotEqual(&any_default, &any_updated), + ), + }, + { + Config: CreateAccAnyConfigUpdateWithoutVRFdn(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccAnyConfig(rName), + }, + }, + }) +} +func TestAccAciAny_Update(t *testing.T) { + var any_default models.Any + var any_updated models.Any + resourceName := "aci_any.test" + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciAnyDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccAnyConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciAnyExists(resourceName, &any_default), + ), + }, + { + Config: CreateAccAnyUpdatedAttr(rName, "match_t", "All"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciAnyExists(resourceName, &any_updated), + resource.TestCheckResourceAttr(resourceName, "match_t", "All"), + testAccCheckAciAnyIdEqual(&any_default, &any_updated), + ), + }, + { + Config: CreateAccAnyUpdatedAttr(rName, "match_t", "None"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciAnyExists(resourceName, &any_updated), + resource.TestCheckResourceAttr(resourceName, "match_t", "None"), + testAccCheckAciAnyIdEqual(&any_default, &any_updated), + ), + }, + }, + }) +} +func TestAccAciAny_NegativeCases(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + longDescAnnotation := acctest.RandString(129) + longNameAlias := acctest.RandString(64) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciAnyDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccAnyConfig(rName), + }, + { + Config: CreateAccAnyConfigWithInvaliVRFdn(rName), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class vzAny (.)+`), + }, + { + Config: CreateAccAnyUpdatedAttr(rName, "description", longDescAnnotation), + ExpectError: regexp.MustCompile(`property descr of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccAnyUpdatedAttr(rName, "annotation", longDescAnnotation), + ExpectError: regexp.MustCompile(`property annotation of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccAnyUpdatedAttr(rName, "name_alias", longNameAlias), + ExpectError: regexp.MustCompile(`property nameAlias of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccAnyUpdatedAttr(rName, "match_t", randomValue), + ExpectError: regexp.MustCompile(`expected match_t to be one of (.)+ got (.)+`), + }, + { + Config: CreateAccAnyUpdatedAttr(rName, "pref_gr_memb", randomValue), + ExpectError: regexp.MustCompile(`expected pref_gr_memb to be one of (.)+ got (.)+`), + }, + { + Config: CreateAccAnyUpdatedAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccAnyConfig(rName), + }, + }, + }) +} + +func TestAccAciAny_reltionalParameters(t *testing.T) { + var any_default models.Any + var any_rel1 models.Any + var any_rel2 models.Any + resourceName := "aci_any.test" + rName := makeTestVariable(acctest.RandString(5)) + rsRelName1 := acctest.RandString(5) + rsRelName2 := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciAnyDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccAnyConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciAnyExists(resourceName, &any_default), + ), + }, + { + Config: CreateAccAnyUpdatedAnyIntial(rName, rsRelName1), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciAnyExists(resourceName, &any_rel1), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_any_to_cons.#", "1"), + resource.TestCheckTypeSetElemAttr(resourceName, "relation_vz_rs_any_to_cons.*", fmt.Sprintf("uni/tn-%s/brc-%s", rName, rsRelName1)), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_any_to_cons_if.#", "1"), + resource.TestCheckTypeSetElemAttr(resourceName, "relation_vz_rs_any_to_cons_if.*", fmt.Sprintf("uni/tn-%s/cif-%s", rName, rsRelName1)), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_any_to_prov.#", "1"), + resource.TestCheckTypeSetElemAttr(resourceName, "relation_vz_rs_any_to_prov.*", fmt.Sprintf("uni/tn-%s/brc-%s", rName, rsRelName1)), + testAccCheckAciAnyIdEqual(&any_default, &any_rel1), + ), + }, + { + Config: CreateAccAnyUpdatedAnyFinal(rName, rsRelName1, rsRelName2), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciAnyExists(resourceName, &any_rel2), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_any_to_cons.#", "2"), + resource.TestCheckTypeSetElemAttr(resourceName, "relation_vz_rs_any_to_cons.*", fmt.Sprintf("uni/tn-%s/brc-%s", rName, rsRelName1)), + resource.TestCheckTypeSetElemAttr(resourceName, "relation_vz_rs_any_to_cons.*", fmt.Sprintf("uni/tn-%s/brc-%s", rName, rsRelName2)), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_any_to_cons_if.#", "2"), + resource.TestCheckTypeSetElemAttr(resourceName, "relation_vz_rs_any_to_cons_if.*", fmt.Sprintf("uni/tn-%s/cif-%s", rName, rsRelName1)), + resource.TestCheckTypeSetElemAttr(resourceName, "relation_vz_rs_any_to_cons_if.*", fmt.Sprintf("uni/tn-%s/cif-%s", rName, rsRelName2)), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_any_to_prov.#", "2"), + resource.TestCheckTypeSetElemAttr(resourceName, "relation_vz_rs_any_to_prov.*", fmt.Sprintf("uni/tn-%s/brc-%s", rName, rsRelName1)), + resource.TestCheckTypeSetElemAttr(resourceName, "relation_vz_rs_any_to_prov.*", fmt.Sprintf("uni/tn-%s/brc-%s", rName, rsRelName2)), + testAccCheckAciAnyIdEqual(&any_default, &any_rel1), + ), + }, + { + Config: CreateAccAnyConfig(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_any_to_cons.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_any_to_cons_if.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_any_to_prov.#", "0"), + ), + }, + }, + }) +} + +func TestAccAciAny_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciAnyDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccAnyConfigMultiple(rName), + }, + }, + }) +} + +func testAccCheckAciAnyExists(name string, any *models.Any) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("Any %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No Any dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + anyFound := models.AnyFromContainer(cont) + if anyFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("Any %s not found", rs.Primary.ID) + } + *any = *anyFound + return nil + } +} + +func testAccCheckAciAnyDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing any destroy") + client := testAccProvider.Meta().(*client.Client) + + for _, rs := range s.RootModule().Resources { + + if rs.Type == "aci_any" { + cont, err := client.Get(rs.Primary.ID) + aci := models.AnyFromContainer(cont) + if err == nil { + return fmt.Errorf("Any %s Still exists", aci.DistinguishedName) + } + + } else { + continue + } + } + + return nil +} + +func testAccCheckAciAnyIdEqual(any1, any2 *models.Any) resource.TestCheckFunc { + return func(s *terraform.State) error { + if any1.DistinguishedName != any2.DistinguishedName { + return fmt.Errorf("Any DNs are not equal") + } + return nil + } +} + +func testAccCheckAciAnyIdNotEqual(any1, any2 *models.Any) resource.TestCheckFunc { + return func(s *terraform.State) error { + if any1.DistinguishedName == any2.DistinguishedName { + return fmt.Errorf("Any DNs are equal") + } + return nil + } +} + +func CreateAccAnyWithoutVRFdn(rName string) string { + fmt.Println("=== STEP Basic: testing any creation without vrf_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = %s + } + resource "aci_vrf" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_any" "test" { + } + `, rName, rName) + return resource +} +func CreateAccAnyConfigUpdateWithoutVRFdn(rName string) string { + fmt.Println("=== STEP Basic: testing any update without required argument") + resource := fmt.Sprintln(` + resource "aci_any" "test" { + description = "vzAny Description1" + annotation = "tag_any" + match_t = "AtmostOne" + name_alias = "alias_any" + pref_gr_memb = "enabled" + } + `, rName, rName) + return resource +} +func CreateAccAnyConfigWithAnotherVRFdn(rName, rOther string) string { + fmt.Printf("=== STEP Basic: testing any creation with different vrf name %s \n", rOther) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_vrf" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_any" "test" { + vrf_dn = aci_vrf.test.id + } + `, rName, rOther) + return resource +} +func CreateAccAnyConfigWithInvaliVRFdn(rName string) string { + fmt.Printf("=== STEP Basic: testing any creation with invalid vrf_dn \n") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_vrf" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_any" "test" { + vrf_dn = aci_tenant.test.id + } + `, rName, rName) + return resource +} +func CreateAccAnyConfig(rName string) string { + fmt.Println("=== STEP testing any creation with required argument") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_vrf" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_any" "test" { + vrf_dn = aci_vrf.test.id + } + `, rName, rName) + return resource +} + +func CreateAccAnyConfigWithOptionalValues(rName string) string { + fmt.Println("=== STEP Basic: testing any creation with optional parameters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_vrf" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_any" "test" { + vrf_dn = aci_vrf.test.id + description = "vzAny Description" + annotation = "tag_any" + match_t = "AtmostOne" + name_alias = "alias_any" + pref_gr_memb = "enabled" + } + `, rName, rName) + return resource +} + +func CreateAccAnyUpdatedAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP testing attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_vrf" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_any" "test" { + vrf_dn = aci_vrf.test.id + %s = "%s" + } + `, rName, rName, attribute, value) + return resource +} + +func CreateAccAnyConfigMultiple(rName string) string { + fmt.Println("=== STEP creating multiple anys") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_vrf" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_vrf" "test1" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_vrf" "test2" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_any" "test" { + vrf_dn = aci_vrf.test.id + } + resource "aci_any" "test1" { + vrf_dn = aci_vrf.test1.id + } + resource "aci_any" "test2" { + vrf_dn = aci_vrf.test2.id + } + `, rName, rName+"1", rName+"2", rName+"3") + return resource +} + +func CreateAccAnyUpdatedAnyIntial(rName, rsRelName string) string { + fmt.Println("=== STEP Relation Parameters: testing any creation with initial relational parameters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_imported_contract" "example" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_vrf" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_any" "test" { + vrf_dn = aci_vrf.test.id + relation_vz_rs_any_to_cons = [aci_contract.test.id] + relation_vz_rs_any_to_cons_if = [aci_imported_contract.example.id] + relation_vz_rs_any_to_prov = [aci_contract.test.id] + } + `, rName, rsRelName, rsRelName, rName) + + return resource +} +func CreateAccAnyUpdatedAnyFinal(rName, rsRelName1, rsRelName2 string) string { + fmt.Println("=== STEP Relation Parameters: testing any creation with final relational parameters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_contract" "test1" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_contract" "test2" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_imported_contract" "example1" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_imported_contract" "example2" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_vrf" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_any" "test" { + vrf_dn = aci_vrf.test.id + relation_vz_rs_any_to_cons = [aci_contract.test1.id, aci_contract.test2.id] + relation_vz_rs_any_to_cons_if = [aci_imported_contract.example1.id,aci_imported_contract.example2.id] + relation_vz_rs_any_to_prov = [aci_contract.test1.id, aci_contract.test2.id] + } + `, rName, rsRelName1, rsRelName2, rsRelName1, rsRelName2, rName) + return resource +} diff --git a/testacc/resource_aci_fvap_test.go b/testacc/resource_aci_fvap_test.go index efa3c3968..098f35c50 100644 --- a/testacc/resource_aci_fvap_test.go +++ b/testacc/resource_aci_fvap_test.go @@ -1,4 +1,4 @@ -package acctest +package testacc import ( "fmt" @@ -21,22 +21,22 @@ func TestAccAciApplicationProfile_Basic(t *testing.T) { prOther := makeTestVariable(acctest.RandString(5)) // randomly created string of 5 alphanumeric characters' for another parent resource name longrName := acctest.RandString(65) // randomly created string of 65 alphanumeric characters' for negative resource name test case resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciApplicationProfileDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciApplicationProfileDestroy, Steps: []resource.TestStep{ { - // terraform will try to create application profile without required arguement tenant_dn + // terraform will try to create application profile without required argument tenant_dn Config: CreateAccApplicationProfileWithoutTenant(rName), // configuration to check creation of application profile without tenant ExpectError: regexp.MustCompile(`Missing required argument`), // test step expect error which should be match with defined regex }, { - // terraform will try to create application profile without required arguement name + // terraform will try to create application profile without required argument name Config: CreateAccApplicationProfileWithoutName(rName), // configuration to check creation of application profile without tenant ExpectError: regexp.MustCompile(`Missing required argument`), }, { - // step terraform will create application profile with only required arguements i.e. name and tenant_dn + // step terraform will create application profile with only required arguments i.e. name and tenant_dn Config: CreateAccApplicationProfileConfig(rName), // configuration to create application profile with required fields only Check: resource.ComposeTestCheckFunc( testAccCheckAciApplicationProfileExists(resourceName, &application_profile_default), // this function will check whether any resource is exist or not in state file with given resource name @@ -58,8 +58,8 @@ func TestAccAciApplicationProfile_Basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "description", "from terraform"), // comparing description with value which is given in configuration resource.TestCheckResourceAttr(resourceName, "name_alias", "test_ap"), // comparing name_alias with value which is given in configuration resource.TestCheckResourceAttr(resourceName, "relation_fv_rs_ap_mon_pol", ""), - resource.TestCheckResourceAttr(resourceName, "annotation", "tag"), // comparing annotation with value which is given in configuration - resource.TestCheckResourceAttr(resourceName, "prio", "level1"), // comparing prio with value which is given in configuration + resource.TestCheckResourceAttr(resourceName, "annotation", "tag"), // comparing annotation with value which is given in configuration + resource.TestCheckResourceAttr(resourceName, "prio", "level1"), // comparing prio with value which is given in configuration resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), testAccCheckAciApplicationProfileIdEqual(&application_profile_default, &application_profile_updated), // this function will check whether id or dn of both resource are same or not to make sure updation is performed on the same resource @@ -104,18 +104,18 @@ func TestAccAciApplicationProfile_Basic(t *testing.T) { }) } -func TestAccApplicationProfile_Update(t *testing.T) { +func TestAccAciApplicationProfile_Update(t *testing.T) { var application_profile_default models.ApplicationProfile var application_profile_updated models.ApplicationProfile resourceName := "aci_application_profile.test" rName := makeTestVariable(acctest.RandString(5)) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciApplicationProfileDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciApplicationProfileDestroy, Steps: []resource.TestStep{ { - Config: CreateAccApplicationProfileConfig(rName), // creating application profile with required arguements only + Config: CreateAccApplicationProfileConfig(rName), // creating application profile with required arguments only Check: resource.ComposeTestCheckFunc( testAccCheckAciApplicationProfileExists(resourceName, &application_profile_default), ), @@ -165,19 +165,19 @@ func TestAccApplicationProfile_Update(t *testing.T) { }) } -func TestAccApplicationProfile_NegativeCases(t *testing.T) { +func TestAccAciApplicationProfile_NegativeCases(t *testing.T) { rName := makeTestVariable(acctest.RandString(5)) longDescAnnotation := acctest.RandString(129) // creating random string of 129 characters longNameAlias := acctest.RandString(64) // creating random string of 64 characters // creating random string of 6 characters randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") // creating random string of 5 characters (to give as random parameter) randomValue := acctest.RandString(5) // creating random string of 5 characters (to give as random value of random parameter) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciApplicationProfileDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciApplicationProfileDestroy, Steps: []resource.TestStep{ { - Config: CreateAccApplicationProfileConfig(rName), // creating application profile with required arguements only + Config: CreateAccApplicationProfileConfig(rName), // creating application profile with required arguments only }, { Config: CreateAccApplicationProfileWithInValidTenantDn(rName), // checking application profile creation with invalid tenant_dn value @@ -204,13 +204,13 @@ func TestAccApplicationProfile_NegativeCases(t *testing.T) { ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), }, { - Config: CreateAccApplicationProfileConfig(rName), // creating application profile with required arguements only + Config: CreateAccApplicationProfileConfig(rName), // creating application profile with required arguments only }, }, }) } -func TestAccApplicationProfile_reltionalParameters(t *testing.T) { +func TestAccAciApplicationProfile_reltionalParameters(t *testing.T) { var application_profile_default models.ApplicationProfile var application_profile_rel1 models.ApplicationProfile var application_profile_rel2 models.ApplicationProfile @@ -219,15 +219,14 @@ func TestAccApplicationProfile_reltionalParameters(t *testing.T) { relRes1 := makeTestVariable(acctest.RandString(5)) // randomly created name for relational resoruce relRes2 := makeTestVariable(acctest.RandString(5)) // randomly created name for relational resoruce resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - - CheckDestroy: testAccCheckAciApplicationProfileDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciApplicationProfileDestroy, Steps: []resource.TestStep{ { Config: CreateAccApplicationProfileConfig(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckAciApplicationProfileExists(resourceName, &application_profile_default), // creating application profile with required arguements only + testAccCheckAciApplicationProfileExists(resourceName, &application_profile_default), // creating application profile with required arguments only resource.TestCheckResourceAttr(resourceName, "relation_fv_rs_ap_mon_pol", ""), // checking value of relation_fv_rs_ap_mon_pol parameter for given configuration ), }, @@ -257,12 +256,12 @@ func TestAccApplicationProfile_reltionalParameters(t *testing.T) { }) } -func TestAccApplicationProfile_MultipleCreateDelete(t *testing.T) { +func TestAccAciApplicationProfile_MultipleCreateDelete(t *testing.T) { rName := makeTestVariable(acctest.RandString(5)) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciApplicationProfileDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciApplicationProfileDestroy, Steps: []resource.TestStep{ { Config: CreateAccApplicationProfilesConfig(rName), @@ -378,7 +377,7 @@ func CreateAccApplicationProfileConfigWithParentAndName(prName, rName string) st } func CreateAccApplicationProfileConfig(rName string) string { - fmt.Println("=== STEP testing application profile creation with required arguements") + fmt.Println("=== STEP testing application profile creation with required arguments") resource := fmt.Sprintf(` resource "aci_tenant" "test" { name = "%s" diff --git a/testacc/resource_aci_fvbd_test.go b/testacc/resource_aci_fvbd_test.go index 0beb6c8d2..88318d98c 100644 --- a/testacc/resource_aci_fvbd_test.go +++ b/testacc/resource_aci_fvbd_test.go @@ -1,4 +1,4 @@ -package acctest +package testacc import ( "fmt" @@ -22,9 +22,9 @@ func TestAccAciBridgeDomain_Basic(t *testing.T) { longrName := acctest.RandString(65) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciBridgeDomainDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciBridgeDomainDestroy, Steps: []resource.TestStep{ { Config: CreateAccBridgeDomainWithoutTenant(rName), @@ -149,9 +149,9 @@ func TestAccAciBridgeDomain_Update(t *testing.T) { resourceName := "aci_bridge_domain.test" rName := acctest.RandString(5) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciBridgeDomainDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciBridgeDomainDestroy, Steps: []resource.TestStep{ { Config: CreateAccBridgeDomainConfig(rName), @@ -190,9 +190,9 @@ func TestAccAciBridgeDomain_NegativeCases(t *testing.T) { randomValue := acctest.RandString(10) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciBridgeDomainDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciBridgeDomainDestroy, Steps: []resource.TestStep{ { Config: CreateAccBridgeDomainConfig(rName), @@ -309,9 +309,9 @@ func TestAccAciBridgeDomain_RelationParameters(t *testing.T) { randomName1 := makeTestVariable(acctest.RandString(5)) randomName2 := makeTestVariable(acctest.RandString(5)) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciBridgeDomainDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciBridgeDomainDestroy, Steps: []resource.TestStep{ { Config: CreateAccBridgeDomainConfig(rName), @@ -389,12 +389,12 @@ func TestAccAciBridgeDomain_RelationParameters(t *testing.T) { }) } -func TestAccBridgeDomain_MultipleCreateDelete(t *testing.T) { +func TestAccAciBridgeDomain_MultipleCreateDelete(t *testing.T) { rName := makeTestVariable(acctest.RandString(5)) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciBridgeDomainDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciBridgeDomainDestroy, Steps: []resource.TestStep{ { Config: CreateAccBDsConfig(rName), diff --git a/testacc/resource_aci_fvctx_test.go b/testacc/resource_aci_fvctx_test.go index 6a9545a90..5f94d96c7 100644 --- a/testacc/resource_aci_fvctx_test.go +++ b/testacc/resource_aci_fvctx_test.go @@ -1,4 +1,4 @@ -package acctest +package testacc import ( "fmt" @@ -21,9 +21,9 @@ func TestAccAciVRF_Basic(t *testing.T) { prOther := makeTestVariable(acctest.RandString(5)) longrName := acctest.RandString(65) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciVRFDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciVRFDestroy, Steps: []resource.TestStep{ { Config: CreateAccVRFWithoutTenant(rName), @@ -120,9 +120,9 @@ func TestAccAciVRF_NegativeCases(t *testing.T) { randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") randomValue := acctest.RandString(5) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciVRFDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciVRFDestroy, Steps: []resource.TestStep{ { Config: CreateAccVRFConfig(rName), @@ -163,6 +163,10 @@ func TestAccAciVRF_NegativeCases(t *testing.T) { Config: CreateAccVRFUpdatedAttr(rName, "pc_enf_dir", randomValue), ExpectError: regexp.MustCompile(`expected pc_enf_dir to be one of (.)+, got (.)+`), }, + { + Config: CreateAccVRFUpdatedAttr(rName, "pc_enf_pref", randomValue), + ExpectError: regexp.MustCompile(`expected pc_enf_pref to be one of (.)+, got (.)+`), + }, { Config: CreateAccVRFConfig(rName), }, @@ -170,12 +174,12 @@ func TestAccAciVRF_NegativeCases(t *testing.T) { }) } -func TestAccVRF_MultipleCreateDelete(t *testing.T) { +func TestAccAciVRF_MultipleCreateDelete(t *testing.T) { rName := makeTestVariable(acctest.RandString(5)) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciVRFDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciVRFDestroy, Steps: []resource.TestStep{ { Config: CreateAccVRFsConfig(rName), @@ -184,7 +188,7 @@ func TestAccVRF_MultipleCreateDelete(t *testing.T) { }) } -func TestAccVRF_RelationParameters(t *testing.T) { +func TestAccAciVRF_RelationParameters(t *testing.T) { var vrf_default models.VRF var vrf_rel1 models.VRF var vrf_rel2 models.VRF @@ -193,9 +197,9 @@ func TestAccVRF_RelationParameters(t *testing.T) { relRes1 := makeTestVariable(acctest.RandString(5)) relRes2 := makeTestVariable(acctest.RandString(5)) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciVRFDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciVRFDestroy, Steps: []resource.TestStep{ { Config: CreateAccVRFConfig(rName), diff --git a/testacc/resource_aci_fvepselector_test.go b/testacc/resource_aci_fvepselector_test.go new file mode 100644 index 000000000..b2c516076 --- /dev/null +++ b/testacc/resource_aci_fvepselector_test.go @@ -0,0 +1,443 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciEndpointSecurityGroupSelector_Basic(t *testing.T) { + var endpoint_security_group_selector_default models.EndpointSecurityGroupSelector + var endpoint_security_group_selector_updated models.EndpointSecurityGroupSelector + resourceName := "aci_endpoint_security_group_selector.test" + rName := makeTestVariable(acctest.RandString(5)) + rOther := makeTestVariable(acctest.RandString(5)) + ip, _ := acctest.RandIpAddress("10.20.0.0/17") + ip = fmt.Sprintf("%s/17", ip) + ipother, _ := acctest.RandIpAddress("10.21.0.0/17") + ipother = fmt.Sprintf("%s/17", ipother) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciEndpointSecurityGroupSelectorDestroy, + Steps: []resource.TestStep{ + { + Config: CreateEndpointSecurityGroupSelectorWithoutRequired(rName, ip, "endpoint_security_group_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateEndpointSecurityGroupSelectorWithoutRequired(rName, ip, "matchExpression"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccEndpointSecurityGroupSelectorConfig(rName, ip), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEndpointSecurityGroupSelectorExists(resourceName, &endpoint_security_group_selector_default), + resource.TestCheckResourceAttr(resourceName, "endpoint_security_group_dn", fmt.Sprintf("uni/tn-%s/ap-%s/esg-%s", rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "match_expression", fmt.Sprintf("ip=='%s'", ip)), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "name", ""), + ), + }, + { + Config: CreateAccEndpointSecurityGroupSelectorConfigWithOptionalValues(rName, ip), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEndpointSecurityGroupSelectorExists(resourceName, &endpoint_security_group_selector_updated), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform_testacc"), + resource.TestCheckResourceAttr(resourceName, "description", "created while acceptance testing"), + resource.TestCheckResourceAttr(resourceName, "name_alias", "test_endpoint_security_group_selector"), + resource.TestCheckResourceAttr(resourceName, "endpoint_security_group_dn", fmt.Sprintf("uni/tn-%s/ap-%s/esg-%s", rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "match_expression", fmt.Sprintf("ip=='%s'", ip)), + resource.TestCheckResourceAttr(resourceName, "name", "test_endpoint_security_group_selector_name"), + testAccCheckAciEndpointSecurityGroupSelectorIdEqual(&endpoint_security_group_selector_default, &endpoint_security_group_selector_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccEndpointSecurityGroupSelectorRemovingRequiredField(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccEndpointSecurityGroupSelectorConfigWithRequiredParams(rName, rName), + ExpectError: regexp.MustCompile(`Invalid IP Address`), + }, + { + Config: CreateAccEndpointSecurityGroupSelectorConfigWithRequiredParams(rOther, ip), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEndpointSecurityGroupSelectorExists(resourceName, &endpoint_security_group_selector_updated), + resource.TestCheckResourceAttr(resourceName, "endpoint_security_group_dn", fmt.Sprintf("uni/tn-%s/ap-%s/esg-%s", rOther, rOther, rOther)), + resource.TestCheckResourceAttr(resourceName, "match_expression", fmt.Sprintf("ip=='%s'", ip)), + testAccCheckAciEndpointSecurityGroupSelectorIdNotEqual(&endpoint_security_group_selector_default, &endpoint_security_group_selector_updated), + ), + }, + { + Config: CreateAccEndpointSecurityGroupSelectorConfig(rName, ip), + }, + { + Config: CreateAccEndpointSecurityGroupSelectorConfigWithRequiredParams(rName, ipother), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEndpointSecurityGroupSelectorExists(resourceName, &endpoint_security_group_selector_updated), + resource.TestCheckResourceAttr(resourceName, "endpoint_security_group_dn", fmt.Sprintf("uni/tn-%s/ap-%s/esg-%s", rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "match_expression", fmt.Sprintf("ip=='%s'", ipother)), + testAccCheckAciEndpointSecurityGroupSelectorIdNotEqual(&endpoint_security_group_selector_default, &endpoint_security_group_selector_updated), + ), + }, + }, + }) +} + +func TestAccAciEndpointSecurityGroupSelector_Negative(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + longDescAnnotation := acctest.RandString(129) + longNameAliasName := acctest.RandString(65) + ip, _ := acctest.RandIpAddress("10.22.0.0/17") + ip = fmt.Sprintf("%s/17", ip) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciEndpointSecurityGroupSelectorDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccEndpointSecurityGroupSelectorConfig(rName, ip), + }, + { + Config: CreateAccEndpointSecurityGroupSelectorWithInValidSecurityGroup(rName, ip), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class fvEPSelector (.)+`), + }, + { + Config: CreateAccEndpointSecurityGroupSelectorUpdatedAttr(rName, ip, "description", longDescAnnotation), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccEndpointSecurityGroupSelectorUpdatedAttr(rName, ip, "annotation", longDescAnnotation), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccEndpointSecurityGroupSelectorUpdatedAttr(rName, ip, "name_alias", longNameAliasName), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccEndpointSecurityGroupSelectorUpdatedAttr(rName, ip, "name", longNameAliasName), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccEndpointSecurityGroupSelectorUpdatedAttr(rName, ip, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named(.)+ is not expected here.`), + }, + { + Config: CreateAccEndpointSecurityGroupSelectorConfig(rName, ip), + }, + }, + }) +} +func TestAccAciEndpointSecurityGroupSelector_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + ip1, _ := acctest.RandIpAddress("10.32.0.0/18") + ip1 = fmt.Sprintf("%s/18", ip1) + ip2, _ := acctest.RandIpAddress("10.33.0.0/19") + ip2 = fmt.Sprintf("%s/19", ip2) + ip3, _ := acctest.RandIpAddress("10.34.0.0/20") + ip3 = fmt.Sprintf("%s/20", ip3) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciEndpointSecurityGroupSelectorDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccEndpointSecurityGroupSelectorsConfig(rName, ip1, ip2, ip3), + }, + }, + }) +} + +func CreateAccEndpointSecurityGroupSelectorsConfig(rName, ip1, ip2, ip3 string) string { + fmt.Println("=== STEP testing endpoint_security_group_selector multiple creation") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + resource "aci_endpoint_security_group_selector" "test1" { + endpoint_security_group_dn = aci_endpoint_security_group.test.id + match_expression = "ip=='%s'" + } + + resource "aci_endpoint_security_group_selector" "test2" { + endpoint_security_group_dn = aci_endpoint_security_group.test.id + match_expression = "ip=='%s'" + } + + resource "aci_endpoint_security_group_selector" "test3" { + endpoint_security_group_dn = aci_endpoint_security_group.test.id + match_expression = "ip=='%s'" + } + `, rName, rName, rName, ip1, ip2, ip3) + return resource +} + +func testAccCheckAciEndpointSecurityGroupSelectorExists(name string, endpoint_security_group_selector *models.EndpointSecurityGroupSelector) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("Endpoint Security Group Selector %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No Endpoint Security Group Selector dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + endpoint_security_group_selectorFound := models.EndpointSecurityGroupSelectorFromContainer(cont) + if endpoint_security_group_selectorFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("Endpoint Security Group Selector %s not found", rs.Primary.ID) + } + *endpoint_security_group_selector = *endpoint_security_group_selectorFound + return nil + } +} + +func testAccCheckAciEndpointSecurityGroupSelectorDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing endpoint_security_group_selector destroy") + client := testAccProvider.Meta().(*client.Client) + for _, rs := range s.RootModule().Resources { + if rs.Type == "aci_endpoint_security_group_selector" { + cont, err := client.Get(rs.Primary.ID) + endpoint_security_group_selector := models.EndpointSecurityGroupSelectorFromContainer(cont) + if err == nil { + return fmt.Errorf("Endpoint Security Group Selector %s Still exists", endpoint_security_group_selector.DistinguishedName) + } + } else { + continue + } + } + return nil +} + +func testAccCheckAciEndpointSecurityGroupSelectorIdEqual(m1, m2 *models.EndpointSecurityGroupSelector) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName != m2.DistinguishedName { + return fmt.Errorf("endpoint_security_group_selector DNs are not equal") + } + return nil + } +} + +func testAccCheckAciEndpointSecurityGroupSelectorIdNotEqual(m1, m2 *models.EndpointSecurityGroupSelector) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName == m2.DistinguishedName { + return fmt.Errorf("endpoint_security_group_selector DNs are equal") + } + return nil + } +} + +func CreateEndpointSecurityGroupSelectorWithoutRequired(rName, ip, attrName string) string { + fmt.Println("=== STEP Basic: testing endpoint_security_group_selector creation without ", attrName) + rBlock := ` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + ` + switch attrName { + case "endpoint_security_group_dn": + rBlock += ` + resource "aci_endpoint_security_group_selector" "test" { + # endpoint_security_group_dn = aci_endpoint_security_group.test.id + match_expression = "ip=='%s'" + } + ` + case "matchExpression": + rBlock += ` + resource "aci_endpoint_security_group_selector" "test" { + endpoint_security_group_dn = aci_endpoint_security_group.test.id + # match_expression = "%s" + } + ` + } + return fmt.Sprintf(rBlock, rName, rName, rName, ip) +} + +func CreateAccEndpointSecurityGroupSelectorConfigWithRequiredParams(rName, ip string) string { + fmt.Println("=== STEP testing endpoint_security_group_selector creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + resource "aci_endpoint_security_group_selector" "test" { + endpoint_security_group_dn = aci_endpoint_security_group.test.id + match_expression = "ip=='%s'" + } + `, rName, rName, rName, ip) + return resource +} + +func CreateAccEndpointSecurityGroupSelectorConfig(rName, ip string) string { + fmt.Println("=== STEP testing endpoint_security_group_selector creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + resource "aci_endpoint_security_group_selector" "test" { + endpoint_security_group_dn = aci_endpoint_security_group.test.id + match_expression = "ip=='%s'" + } + `, rName, rName, rName, ip) + return resource +} + +func CreateAccEndpointSecurityGroupSelectorWithInValidSecurityGroup(rName, ip string) string { + fmt.Println("=== STEP Negative Case: testing endpoint_security_group_selector creation with invalid endpoint_security_group_dn") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + + resource "aci_endpoint_security_group_selector" "test" { + endpoint_security_group_dn = aci_tenant.test.id + match_expression = "ip=='%s'" + } + `, rName, ip) + return resource +} + +func CreateAccEndpointSecurityGroupSelectorConfigWithOptionalValues(rName, ip string) string { + fmt.Println("=== STEP Basic: testing endpoint_security_group_selector creation with optional parameters") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + resource "aci_endpoint_security_group_selector" "test" { + endpoint_security_group_dn = "${aci_endpoint_security_group.test.id}" + match_expression = "ip=='%s'" + description = "created while acceptance testing" + annotation = "orchestrator:terraform_testacc" + name_alias = "test_endpoint_security_group_selector" + name = "test_endpoint_security_group_selector_name" + } + `, rName, rName, rName, ip) + + return resource +} + +func CreateAccEndpointSecurityGroupSelectorRemovingRequiredField() string { + fmt.Println("=== STEP Basic: testing endpoint_security_group_selector creation with optional parameters") + resource := fmt.Sprintln(` + resource "aci_endpoint_security_group_selector" "test" { + description = "created while acceptance testing" + annotation = "tag" + name_alias = "test_endpoint_security_group_selector" + name = "test_endpoint_security_group_selector_name" + } + `) + + return resource +} + +func CreateAccEndpointSecurityGroupSelectorUpdatedAttr(rName, ip, attribute, value string) string { + fmt.Printf("=== STEP testing endpoint_security_group_selector attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + resource "aci_endpoint_security_group_selector" "test" { + endpoint_security_group_dn = aci_endpoint_security_group.test.id + match_expression = "ip==''%s" + %s = "%s" + } + `, rName, rName, rName, ip, attribute, value) + return resource +} diff --git a/testacc/resource_aci_fvesg_test.go b/testacc/resource_aci_fvesg_test.go new file mode 100644 index 000000000..24d32dd76 --- /dev/null +++ b/testacc/resource_aci_fvesg_test.go @@ -0,0 +1,508 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciEndpointSecurityGroup_Basic(t *testing.T) { + var esg_default models.EndpointSecurityGroup + var esg_updated models.EndpointSecurityGroup + resourceName := "aci_endpoint_security_group.test" + rName := makeTestVariable(acctest.RandString(5)) + rOther := makeTestVariable(acctest.RandString(5)) + prOther := makeTestVariable(acctest.RandString(5)) + longrName := acctest.RandString(65) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciEndpointSecurityGroupDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccEndpointSecurityGroupWithoutAP(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccEndpointSecurityGroupWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccEndpointSecurityGroupConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEndpointSecurityGroupExists(resourceName, &esg_default), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "application_profile_dn", fmt.Sprintf("uni/tn-%s/ap-%s", rName, rName)), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "flood_on_encap", "disabled"), + resource.TestCheckResourceAttr(resourceName, "match_t", "AtleastOne"), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "pc_enf_pref", "unenforced"), + resource.TestCheckResourceAttr(resourceName, "pref_gr_memb", "exclude"), + resource.TestCheckResourceAttr(resourceName, "prio", "unspecified"), + resource.TestCheckResourceAttr(resourceName, "relation_fv_rs_cons.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_fv_rs_cons_if.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_fv_rs_prov.#", "0"), + ), + }, + { + Config: CreateAccEndpointSecurityGroupConfigWithOptionalValues(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEndpointSecurityGroupExists(resourceName, &esg_updated), + resource.TestCheckResourceAttr(resourceName, "annotation", "test_annotation"), + resource.TestCheckResourceAttr(resourceName, "application_profile_dn", fmt.Sprintf("uni/tn-%s/ap-%s", rName, rName)), + resource.TestCheckResourceAttr(resourceName, "description", "test_description"), + resource.TestCheckResourceAttr(resourceName, "flood_on_encap", "enabled"), + resource.TestCheckResourceAttr(resourceName, "match_t", "All"), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "name_alias", "test_name_alias"), + resource.TestCheckResourceAttr(resourceName, "pc_enf_pref", "enforced"), + resource.TestCheckResourceAttr(resourceName, "pref_gr_memb", "include"), + resource.TestCheckResourceAttr(resourceName, "prio", "level1"), + resource.TestCheckResourceAttr(resourceName, "relation_fv_rs_cons.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_fv_rs_cons_if.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_fv_rs_intra_epg.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_fv_rs_prot_by.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_fv_rs_prov.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_fv_rs_sec_inherited.#", "0"), + testAccCheckAciEndpointSecurityGroupIdEqual(&esg_default, &esg_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccEndpointSecurityGroupRemovingRequiredField(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccEndpointSecurityGroupConfigWithParentAndName(rName, longrName), + ExpectError: regexp.MustCompile(fmt.Sprintf("property name of esg-%s failed validation for value '%s'", longrName, longrName)), + }, + { + Config: CreateAccEndpointSecurityGroupConfigWithParentAndName(rName, rOther), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEndpointSecurityGroupExists(resourceName, &esg_updated), + resource.TestCheckResourceAttr(resourceName, "application_profile_dn", fmt.Sprintf("uni/tn-%s/ap-%s", rName, rName)), + resource.TestCheckResourceAttr(resourceName, "name", rOther), + testAccCheckAciEndpointSecurityGroupIdNotEqual(&esg_default, &esg_updated), + ), + }, + { + Config: CreateAccEndpointSecurityGroupConfig(rName), + }, + { + Config: CreateAccEndpointSecurityGroupConfigWithParentAndName(prOther, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEndpointSecurityGroupExists(resourceName, &esg_updated), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "application_profile_dn", fmt.Sprintf("uni/tn-%s/ap-%s", prOther, prOther)), + testAccCheckAciEndpointSecurityGroupIdNotEqual(&esg_default, &esg_updated), + ), + }, + }, + }) +} + +func TestAccAciEndpointSecurityGroup_Update(t *testing.T) { + var esg_default models.EndpointSecurityGroup + var esg_updated models.EndpointSecurityGroup + resourceName := "aci_endpoint_security_group.test" + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciEndpointSecurityGroupDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccEndpointSecurityGroupConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEndpointSecurityGroupExists(resourceName, &esg_default), + ), + }, + { + Config: CreateAccEndpointSecurityGroupConfigWithUpdatedAttr(rName, "match_t", "AtmostOne"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEndpointSecurityGroupExists(resourceName, &esg_updated), + resource.TestCheckResourceAttr(resourceName, "match_t", "AtmostOne"), + testAccCheckAciEndpointSecurityGroupIdEqual(&esg_default, &esg_updated), + ), + }, + { + Config: CreateAccEndpointSecurityGroupConfigWithUpdatedAttr(rName, "prio", "level2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEndpointSecurityGroupExists(resourceName, &esg_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level2"), + testAccCheckAciEndpointSecurityGroupIdEqual(&esg_default, &esg_updated), + ), + }, + { + Config: CreateAccEndpointSecurityGroupConfigWithUpdatedAttr(rName, "prio", "level3"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEndpointSecurityGroupExists(resourceName, &esg_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level3"), + testAccCheckAciEndpointSecurityGroupIdEqual(&esg_default, &esg_updated), + ), + }, + { + Config: CreateAccEndpointSecurityGroupConfigWithUpdatedAttr(rName, "prio", "level4"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEndpointSecurityGroupExists(resourceName, &esg_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level4"), + testAccCheckAciEndpointSecurityGroupIdEqual(&esg_default, &esg_updated), + ), + }, + { + Config: CreateAccEndpointSecurityGroupConfigWithUpdatedAttr(rName, "prio", "level5"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEndpointSecurityGroupExists(resourceName, &esg_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level5"), + testAccCheckAciEndpointSecurityGroupIdEqual(&esg_default, &esg_updated), + ), + }, + { + Config: CreateAccEndpointSecurityGroupConfigWithUpdatedAttr(rName, "prio", "level6"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEndpointSecurityGroupExists(resourceName, &esg_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level6"), + testAccCheckAciEndpointSecurityGroupIdEqual(&esg_default, &esg_updated), + ), + }, + }, + }) +} + +func TestAccAciEndpointSecurityGroup_NegativeCases(t *testing.T) { + longDescAnnotation := acctest.RandString(129) + longNameAlias := acctest.RandString(64) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciEndpointSecurityGroupDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccEndpointSecurityGroupConfig(rName), + }, + { + Config: CreateAccEndpointSecurityGroupWithInValidAPDn(rName), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class fvESg (.)+`), + }, + { + Config: CreateAccEndpointSecurityGroupConfigWithUpdatedAttr(rName, "annotation", longDescAnnotation), + ExpectError: regexp.MustCompile(`property annotation of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccEndpointSecurityGroupConfigWithUpdatedAttr(rName, "description", longDescAnnotation), + ExpectError: regexp.MustCompile(`property descr of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccEndpointSecurityGroupConfigWithUpdatedAttr(rName, "name_alias", longNameAlias), + ExpectError: regexp.MustCompile(`property nameAlias of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccEndpointSecurityGroupConfigWithUpdatedAttr(rName, "flood_on_encap", randomValue), + ExpectError: regexp.MustCompile(`expected flood_on_encap to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccEndpointSecurityGroupConfigWithUpdatedAttr(rName, "match_t", randomValue), + ExpectError: regexp.MustCompile(`expected match_t to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccEndpointSecurityGroupConfigWithUpdatedAttr(rName, "pc_enf_pref", randomValue), + ExpectError: regexp.MustCompile(`expected pc_enf_pref to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccEndpointSecurityGroupConfigWithUpdatedAttr(rName, "pref_gr_memb", randomValue), + ExpectError: regexp.MustCompile(`expected pref_gr_memb to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccEndpointSecurityGroupConfigWithUpdatedAttr(rName, "prio", randomValue), + ExpectError: regexp.MustCompile(`expected prio to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccEndpointSecurityGroupConfigWithUpdatedAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccEndpointSecurityGroupConfig(rName), + }, + }, + }) +} + +func TestAccAciEndpointSecurityGroup_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciEndpointSecurityGroupDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccEndpointSecurityGroupsConfig(rName), + }, + }, + }) +} + +func CreateAccEndpointSecurityGroupsConfig(rName string) string { + fmt.Println("=== STEP Basic: testing endpoint_security_group multiple creation") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test1" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + resource "aci_endpoint_security_group" "test2" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + resource "aci_endpoint_security_group" "test3" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + `, rName, rName, rName+"1", rName+"2", rName+"3") + return resource +} + +func testAccCheckAciEndpointSecurityGroupIdNotEqual(esg1, esg2 *models.EndpointSecurityGroup) resource.TestCheckFunc { + return func(s *terraform.State) error { + if esg1.DistinguishedName == esg2.DistinguishedName { + return fmt.Errorf("Endpoint Security Group DNs are equal") + } + return nil + } +} + +func testAccCheckAciEndpointSecurityGroupIdEqual(esg1, esg2 *models.EndpointSecurityGroup) resource.TestCheckFunc { + return func(s *terraform.State) error { + if esg1.DistinguishedName != esg2.DistinguishedName { + return fmt.Errorf("Endpoint Security Group DNs are not equal") + } + return nil + } +} + +func CreateAccEndpointSecurityGroupWithInValidAPDn(rName string) string { + fmt.Println("=== STEP Negative Case: testing endpoint_security_group creation with invalid application_profile_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_tenant.test.id + } + `, rName, rName) + return resource +} + +func CreateAccEndpointSecurityGroupConfigWithParentAndName(prName, rName string) string { + fmt.Printf("=== STEP Basic: testing endpoint_security_group creation with parente resource name %s and name %s\n", prName, rName) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + annotation = "test_annotation" + description = "test_description" + flood_on_encap = "enabled" + match_t = "All" + name_alias = "test_name_alias" + pc_enf_pref = "enforced" + pref_gr_memb = "include" + prio = "level1" + } + `, prName, prName, rName) + return resource +} + +func CreateAccEndpointSecurityGroupRemovingRequiredField() string { + fmt.Println("=== STEP Basic: testing endpoint_security_group updation without required fields") + resource := fmt.Sprintln(` + resource "aci_endpoint_security_group" "test" { + annotation = "tag" + description = "test_description" + flood_on_encap = "enabled" + match_t = "All" + name_alias = "test_name_alias" + pc_enf_pref = "enforced" + pref_gr_memb = "include" + prio = "level1" + } + `) + return resource +} + +func CreateAccEndpointSecurityGroupConfigWithUpdatedAttr(rName, key, value string) string { + fmt.Printf("=== STEP testing endpoint_security_group creation with %s = %s\n", key, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + %s = "%s" + } + `, rName, rName, rName, key, value) + return resource +} + +func CreateAccEndpointSecurityGroupConfigWithOptionalValues(rName string) string { + fmt.Println("=== STEP testing endpoint_security_group creation with optional parameters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + annotation = "test_annotation" + description = "test_description" + flood_on_encap = "enabled" + match_t = "All" + name_alias = "test_name_alias" + pc_enf_pref = "enforced" + pref_gr_memb = "include" + prio = "level1" + } + `, rName, rName, rName) + return resource +} + +func CreateAccEndpointSecurityGroupConfig(rName string) string { + fmt.Println("=== STEP testing endpoint_security_group creation with required arguments only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + `, rName, rName, rName) + return resource +} + +func CreateAccEndpointSecurityGroupWithoutAP(rName string) string { + fmt.Println("=== STEP Basic: testing endpoint_security_group creation without creating application profile") + resource := fmt.Sprintf(` + resource "aci_endpoint_security_group" "test" { + name = "%s" + } + `, rName) + return resource +} + +func CreateAccEndpointSecurityGroupWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing endpoint_security_group creation without name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_endpoint_security_group" "test" { + application_profile_dn = aci_application_profile.test.id + } + `, rName, rName) + return resource +} + +func testAccCheckAciEndpointSecurityGroupExists(name string, endpoint_security_group *models.EndpointSecurityGroup) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("Endpoint Security Group %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No Endpoint Security Group dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + endpoint_security_groupFound := models.EndpointSecurityGroupFromContainer(cont) + if endpoint_security_groupFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("Endpoint Security Group %s not found", rs.Primary.ID) + } + *endpoint_security_group = *endpoint_security_groupFound + return nil + } +} + +func testAccCheckAciEndpointSecurityGroupDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing endpoint_security_group destroy") + client := testAccProvider.Meta().(*client.Client) + for _, rs := range s.RootModule().Resources { + if rs.Type == "aci_endpoint_security_group" { + cont, err := client.Get(rs.Primary.ID) + endpoint_security_group := models.EndpointSecurityGroupFromContainer(cont) + if err == nil { + return fmt.Errorf("Endpoint Security Group %s Still exists", endpoint_security_group.DistinguishedName) + } + } else { + continue + } + } + return nil +} diff --git a/testacc/resource_aci_fvrsdomatt_test.go b/testacc/resource_aci_fvrsdomatt_test.go new file mode 100644 index 000000000..0628d29dc --- /dev/null +++ b/testacc/resource_aci_fvrsdomatt_test.go @@ -0,0 +1,842 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciFVDomain_Basic(t *testing.T) { + var epg_to_domain_default models.FVDomain + var epg_to_domain_updated models.FVDomain + resourceName := "aci_epg_to_domain.test" + rName := makeTestVariable(acctest.RandString(5)) + rother := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciFVDomainDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccFVDomainWithoutTdn(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccFVDomainWithoutApplicationEPG(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccFVDomainConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciFVDomainExists(resourceName, &epg_to_domain_default), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "application_epg_dn", fmt.Sprintf("uni/tn-%s/ap-%s/epg-%s", rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "binding_type", "none"), + resource.TestCheckResourceAttr(resourceName, "allow_micro_seg", "false"), + resource.TestCheckResourceAttr(resourceName, "delimiter", ""), + resource.TestCheckResourceAttr(resourceName, "encap", "unknown"), + resource.TestCheckResourceAttr(resourceName, "encap_mode", "auto"), + resource.TestCheckResourceAttr(resourceName, "epg_cos", "Cos0"), + resource.TestCheckResourceAttr(resourceName, "epg_cos_pref", "disabled"), + resource.TestCheckResourceAttr(resourceName, "instr_imedcy", "lazy"), + resource.TestCheckResourceAttr(resourceName, "lag_policy_name", ""), + resource.TestCheckResourceAttr(resourceName, "netflow_dir", "both"), + resource.TestCheckResourceAttr(resourceName, "netflow_pref", "disabled"), + resource.TestCheckResourceAttr(resourceName, "num_ports", "0"), + resource.TestCheckResourceAttr(resourceName, "port_allocation", "none"), + resource.TestCheckResourceAttr(resourceName, "primary_encap", "unknown"), + resource.TestCheckResourceAttr(resourceName, "primary_encap_inner", "unknown"), + resource.TestCheckResourceAttr(resourceName, "res_imedcy", "lazy"), + resource.TestCheckResourceAttr(resourceName, "secondary_encap_inner", "unknown"), + resource.TestCheckResourceAttr(resourceName, "switching_mode", "native"), + resource.TestCheckResourceAttr(resourceName, "tdn", fmt.Sprintf("uni/vmmp-VMware/dom-%s", rName)), + resource.TestCheckResourceAttr(resourceName, "vmm_id", fmt.Sprintf("uni/tn-%s/ap-%s/epg-%s/rsdomAtt-[uni/vmmp-VMware/dom-%s]/sec", rName, rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "vmm_allow_promiscuous", "reject"), + resource.TestCheckResourceAttr(resourceName, "vmm_forged_transmits", "reject"), + resource.TestCheckResourceAttr(resourceName, "vmm_mac_changes", "reject"), + ), + }, + { + Config: CreateAccFVDomainConfigWithOptionalValues(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciFVDomainExists(resourceName, &epg_to_domain_updated), + resource.TestCheckResourceAttr(resourceName, "annotation", "from_terraform"), + resource.TestCheckResourceAttr(resourceName, "application_epg_dn", fmt.Sprintf("uni/tn-%s/ap-%s/epg-%s", rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "binding_type", "dynamicBinding"), + resource.TestCheckResourceAttr(resourceName, "allow_micro_seg", "true"), + resource.TestCheckResourceAttr(resourceName, "delimiter", ""), + resource.TestCheckResourceAttr(resourceName, "encap", "vlan-5"), + resource.TestCheckResourceAttr(resourceName, "epg_cos", "Cos5"), + resource.TestCheckResourceAttr(resourceName, "epg_cos_pref", "enabled"), + resource.TestCheckResourceAttr(resourceName, "instr_imedcy", "immediate"), + resource.TestCheckResourceAttr(resourceName, "lag_policy_name", "lag_policy_name"), + resource.TestCheckResourceAttr(resourceName, "netflow_dir", "ingress"), + resource.TestCheckResourceAttr(resourceName, "netflow_pref", "enabled"), + resource.TestCheckResourceAttr(resourceName, "num_ports", "3"), + resource.TestCheckResourceAttr(resourceName, "port_allocation", "fixed"), + resource.TestCheckResourceAttr(resourceName, "primary_encap", "vlan-4"), + resource.TestCheckResourceAttr(resourceName, "primary_encap_inner", "vlan-6"), + resource.TestCheckResourceAttr(resourceName, "res_imedcy", "immediate"), + resource.TestCheckResourceAttr(resourceName, "secondary_encap_inner", "vlan-7"), + resource.TestCheckResourceAttr(resourceName, "switching_mode", "AVE"), + resource.TestCheckResourceAttr(resourceName, "tdn", fmt.Sprintf("uni/vmmp-VMware/dom-%s", rName)), + resource.TestCheckResourceAttr(resourceName, "vmm_id", fmt.Sprintf("uni/tn-%s/ap-%s/epg-%s/rsdomAtt-[uni/vmmp-VMware/dom-%s]/sec", rName, rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "vmm_allow_promiscuous", "accept"), + resource.TestCheckResourceAttr(resourceName, "vmm_forged_transmits", "accept"), + resource.TestCheckResourceAttr(resourceName, "vmm_mac_changes", "accept"), + testAccCheckAciFVDomainIdEqual(&epg_to_domain_default, &epg_to_domain_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"vmm_allow_promiscuous", "vmm_forged_transmits", "vmm_mac_changes", "vmm_id"}, + }, + { + Config: CreateAccFVDomainConfigUpdateWithoutRequired(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccFVDomainConfigWithEpgAndDomainName(rName, rother), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciFVDomainExists(resourceName, &epg_to_domain_updated), + resource.TestCheckResourceAttr(resourceName, "application_epg_dn", fmt.Sprintf("uni/tn-%s/ap-%s/epg-%s", rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "tdn", fmt.Sprintf("uni/vmmp-VMware/dom-%s", rother)), + testAccCheckAciFVDomainIdNotEqual(&epg_to_domain_default, &epg_to_domain_updated), + ), + }, + { + Config: CreateAccFVDomainConfig(rName), + }, + { + Config: CreateAccFVDomainConfigWithEpgAndDomainName(rother, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciFVDomainExists(resourceName, &epg_to_domain_updated), + resource.TestCheckResourceAttr(resourceName, "application_epg_dn", fmt.Sprintf("uni/tn-%s/ap-%s/epg-%s", rother, rother, rother)), + resource.TestCheckResourceAttr(resourceName, "tdn", fmt.Sprintf("uni/vmmp-VMware/dom-%s", rName)), + testAccCheckAciFVDomainIdNotEqual(&epg_to_domain_default, &epg_to_domain_updated), + ), + }, + }, + }) +} + +func TestAccAciFVDomain_Update(t *testing.T) { + var epg_to_domain_default models.FVDomain + var epg_to_domain_updated models.FVDomain + var epg_to_domain_default_fc_domain models.FVDomain + var epg_to_domain_updated_fc_domain models.FVDomain + resourceName := "aci_epg_to_domain.test" + rName := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciFVDomainDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccFVDomainConfig(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckAciFVDomainExists(resourceName, &epg_to_domain_default), + ), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "binding_type", "staticBinding"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciFVDomainExists(resourceName, &epg_to_domain_updated), + resource.TestCheckResourceAttr(resourceName, "binding_type", "staticBinding"), + testAccCheckAciFVDomainIdEqual(&epg_to_domain_default, &epg_to_domain_updated), + ), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "binding_type", "ephemeral"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciFVDomainExists(resourceName, &epg_to_domain_updated), + resource.TestCheckResourceAttr(resourceName, "binding_type", "ephemeral"), + testAccCheckAciFVDomainIdEqual(&epg_to_domain_default, &epg_to_domain_updated), + ), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "epg_cos", "Cos1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciFVDomainExists(resourceName, &epg_to_domain_updated), + resource.TestCheckResourceAttr(resourceName, "epg_cos", "Cos1"), + testAccCheckAciFVDomainIdEqual(&epg_to_domain_default, &epg_to_domain_updated), + ), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "epg_cos", "Cos2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciFVDomainExists(resourceName, &epg_to_domain_updated), + resource.TestCheckResourceAttr(resourceName, "epg_cos", "Cos2"), + testAccCheckAciFVDomainIdEqual(&epg_to_domain_default, &epg_to_domain_updated), + ), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "epg_cos", "Cos3"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciFVDomainExists(resourceName, &epg_to_domain_updated), + resource.TestCheckResourceAttr(resourceName, "epg_cos", "Cos3"), + testAccCheckAciFVDomainIdEqual(&epg_to_domain_default, &epg_to_domain_updated), + ), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "epg_cos", "Cos4"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciFVDomainExists(resourceName, &epg_to_domain_updated), + resource.TestCheckResourceAttr(resourceName, "epg_cos", "Cos4"), + testAccCheckAciFVDomainIdEqual(&epg_to_domain_default, &epg_to_domain_updated)), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "epg_cos", "Cos6"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciFVDomainExists(resourceName, &epg_to_domain_updated), + resource.TestCheckResourceAttr(resourceName, "epg_cos", "Cos6"), + testAccCheckAciFVDomainIdEqual(&epg_to_domain_default, &epg_to_domain_updated), + ), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "epg_cos", "Cos7"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciFVDomainExists(resourceName, &epg_to_domain_updated), + resource.TestCheckResourceAttr(resourceName, "epg_cos", "Cos7"), + testAccCheckAciFVDomainIdEqual(&epg_to_domain_default, &epg_to_domain_updated), + ), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "netflow_dir", "egress"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciFVDomainExists(resourceName, &epg_to_domain_updated), + resource.TestCheckResourceAttr(resourceName, "netflow_dir", "egress"), + testAccCheckAciFVDomainIdEqual(&epg_to_domain_default, &epg_to_domain_updated), + ), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "port_allocation", "elastic"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciFVDomainExists(resourceName, &epg_to_domain_updated), + resource.TestCheckResourceAttr(resourceName, "port_allocation", "elastic"), + testAccCheckAciFVDomainIdEqual(&epg_to_domain_default, &epg_to_domain_updated), + ), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "res_imedcy", "pre-provision"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciFVDomainExists(resourceName, &epg_to_domain_updated), + resource.TestCheckResourceAttr(resourceName, "res_imedcy", "pre-provision"), + testAccCheckAciFVDomainIdEqual(&epg_to_domain_default, &epg_to_domain_updated), + ), + }, + { + Config: CreateAccFVDomainConfigFCDomain(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckAciFVDomainExists(resourceName, &epg_to_domain_default_fc_domain), + resource.TestCheckResourceAttr(resourceName, "application_epg_dn", fmt.Sprintf("uni/tn-%s/ap-%s/epg-%s", rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "tdn", fmt.Sprintf("uni/fc-%s", rName)), + ), + }, + { + Config: CreateAccFVDomainUpdatedAttrFCDomain(rName, "encap_mode", "vlan"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciFVDomainExists(resourceName, &epg_to_domain_updated_fc_domain), + resource.TestCheckResourceAttr(resourceName, "encap_mode", "vlan"), + testAccCheckAciFVDomainIdEqual(&epg_to_domain_default_fc_domain, &epg_to_domain_updated_fc_domain), + ), + }, + { + Config: CreateAccFVDomainUpdatedAttrFCDomain(rName, "encap_mode", "vxlan"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciFVDomainExists(resourceName, &epg_to_domain_updated_fc_domain), + resource.TestCheckResourceAttr(resourceName, "encap_mode", "vxlan"), + testAccCheckAciFVDomainIdEqual(&epg_to_domain_default_fc_domain, &epg_to_domain_updated_fc_domain), + ), + }, + }, + }) +} + +func TestAccAciFVDomain_NegativeCases(t *testing.T) { + rName := acctest.RandString(5) + longAnnotation := acctest.RandString(129) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciFVDomainDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccFVDomainConfig(rName), + }, + { + Config: CreateAccFVDomainWithInvalidApplicationEPG(rName), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class fvRsDomAtt (.)+`), + }, + { + Config: CreateAccFVDomainWithInvalidTDn(rName), + ExpectError: regexp.MustCompile(`Invalid target DN`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "switching_mode", "AVE"), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "encap_mode", "vlan"), + ExpectError: regexp.MustCompile(`VLAN encap mode is not allowed for AVE Non-Local switching domain`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "encap", "vlan-5"), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "encap_mode", "vxlan"), + ExpectError: regexp.MustCompile(`static vlan setting is only allowed when encap mode is vlan.`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "annotation", longAnnotation), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "binding_type", randomValue), + ExpectError: regexp.MustCompile(`expected binding_type to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "allow_micro_seg", randomValue), + ExpectError: regexp.MustCompile(`Incorrect attribute value type`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "encap", randomValue), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name encap, class fvRsDomAtt (.)+`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "encap_mode", randomValue), + ExpectError: regexp.MustCompile(`expected encap_mode to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "epg_cos", randomValue), + ExpectError: regexp.MustCompile(`expected epg_cos to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "epg_cos_pref", randomValue), + ExpectError: regexp.MustCompile(`expected epg_cos_pref to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "instr_imedcy", randomValue), + ExpectError: regexp.MustCompile(`expected instr_imedcy to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "netflow_dir", randomValue), + ExpectError: regexp.MustCompile(`expected netflow_dir to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "netflow_pref", randomValue), + ExpectError: regexp.MustCompile(`expected netflow_pref to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "lag_policy_name", acctest.RandString(513)), + ExpectError: regexp.MustCompile(`failed validation for value`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "num_ports", randomValue), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name numPorts, class fvRsDomAtt (.)+`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "port_allocation", randomValue), + ExpectError: regexp.MustCompile(`expected port_allocation to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "primary_encap", randomValue), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name primaryEncap, class fvRsDomAtt (.)+`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "primary_encap_inner", randomValue), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name primaryEncapInner, class fvRsDomAtt (.)+`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "res_imedcy", randomValue), + ExpectError: regexp.MustCompile(`expected res_imedcy to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "secondary_encap_inner", randomValue), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name secondaryEncapInner, class fvRsDomAtt (.)+`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "switching_mode", randomValue), + ExpectError: regexp.MustCompile(`expected switching_mode to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "vmm_allow_promiscuous", randomValue), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name allowPromiscuous, class vmmSecP (.)+`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "vmm_forged_transmits", randomValue), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name forgedTransmits, class vmmSecP (.)+`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, "vmm_mac_changes", randomValue), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name macChanges, class vmmSecP (.)+`), + }, + { + Config: CreateAccFVDomainUpdatedAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccFVDomainConfig(rName), + }, + }, + }) +} + +func TestAccAciFVDomain_MultipleCreateDelete(t *testing.T) { + rName := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciFVDomainDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccFVDomainConfigs(rName), + }, + }, + }) +} + +func testAccCheckAciFVDomainDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing epg_to_domain destroy") + client := testAccProvider.Meta().(*client.Client) + + for _, rs := range s.RootModule().Resources { + + if rs.Type == "aci_epg_to_domain" { + cont, err := client.Get(rs.Primary.ID) + epg_to_domain := models.FVDomainFromContainer(cont) + if err == nil { + return fmt.Errorf("EPG to Domain %s still exists", epg_to_domain.DistinguishedName) + } + } else { + continue + } + } + return nil +} + +func CreateAccFVDomainWithInvalidTDn(rName string) string { + fmt.Println("=== STEP testing epg_to_domain creation with invalid tdn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_application_epg" "test" { + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + resource "aci_epg_to_domain" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = aci_tenant.test.id + } + + `, rName, rName, rName) + return resource +} + +func CreateAccFVDomainWithInvalidApplicationEPG(rName string) string { + fmt.Println("=== STEP testing epg_to_domain creation with invalid application_epg_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_fc_domain" "test" { + name = "%s" + } + + resource "aci_epg_to_domain" "test" { + application_epg_dn = aci_tenant.test.id + tdn = aci_fc_domain.test.id + } + + `, rName, rName) + return resource +} + +func CreateAccFVDomainWithoutTdn(rName string) string { + fmt.Println("=== STEP Basic: testing epg_to_domain without tdn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_epg_to_domain" "test" { + application_epg_dn = aci_application_epg.test.id + } + `, rName, rName, rName) + return resource + +} + +func CreateAccFVDomainWithoutApplicationEPG(rName string) string { + fmt.Println("=== STEP Basic: testing aci_epg_to_domain without creating application_epg_dn") + resource := fmt.Sprintf(` + resource "aci_vmm_domain" "test" { + name = "%s" + provider_profile_dn = "uni/vmmp-VMware" + } + + resource "aci_epg_to_domain" "test" { + tdn = aci_vmm_domain.test.id + } + `, rName) + return resource + +} + +func CreateAccFVDomainConfigFCDomain(rName string) string { + fmt.Println("=== STEP testing epg_to_domain creation with required parameters only while tdn has reference of fc_domain") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_fc_domain" "test" { + name = "%s" + } + + resource "aci_epg_to_domain" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = aci_fc_domain.test.id + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccFVDomainConfigs(rName string) string { + fmt.Println("=== STEP testing mutiple epg_to_domain creation") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_vmm_domain" "test1" { + name = "%s" + provider_profile_dn = "uni/vmmp-VMware" + } + + resource "aci_vmm_domain" "test2" { + name = "%s" + provider_profile_dn = "uni/vmmp-VMware" + } + + resource "aci_vmm_domain" "test3" { + name = "%s" + provider_profile_dn = "uni/vmmp-VMware" + } + + resource "aci_epg_to_domain" "test1" { + application_epg_dn = aci_application_epg.test.id + tdn = aci_vmm_domain.test1.id + } + + resource "aci_epg_to_domain" "test2" { + application_epg_dn = aci_application_epg.test.id + tdn = aci_vmm_domain.test2.id + } + + resource "aci_epg_to_domain" "test3" { + application_epg_dn = aci_application_epg.test.id + tdn = aci_vmm_domain.test3.id + } + `, rName, rName, rName, rName+"1", rName+"2", rName+"3") + return resource +} + +func CreateAccFVDomainConfig(rName string) string { + fmt.Println("=== STEP testing epg_to_domain creation with required parameters only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_vmm_domain" "test" { + name = "%s" + provider_profile_dn = "uni/vmmp-VMware" + enable_ave = "yes" + } + + resource "aci_epg_to_domain" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = aci_vmm_domain.test.id + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccFVDomainConfigWithEpgAndDomainName(r1, r2 string) string { + fmt.Printf("=== STEP Basic: testing epg_to_domain creation with epg name %s and vmm_domain name %s\n", r1, r2) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_vmm_domain" "test" { + name = "%s" + provider_profile_dn = "uni/vmmp-VMware" + } + + resource "aci_epg_to_domain" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = aci_vmm_domain.test.id + } + `, r1, r1, r1, r2) + return resource +} + +func CreateAccFVDomainConfigUpdateWithoutRequired() string { + fmt.Println("=== STEP Basic: testing epg to domain update without required parameters") + resource := fmt.Sprintln(` + resource "aci_epg_to_domain" "test" { + annotation = "from_terraform" + binding_type = "dynamicBinding" + allow_micro_seg = "true" + delimiter = "" + encap = "vlan-5" + epg_cos = "Cos5" + epg_cos_pref = "enabled" + instr_imedcy = "immediate" + lag_policy_name = "lag_policy_name" + netflow_dir = "ingress" + netflow_pref = "enabled" + num_ports = "3" + port_allocation = "fixed" + primary_encap = "vlan-4" + primary_encap_inner = "vlan-6" + res_imedcy = "immediate" + secondary_encap_inner = "vlan-7" + switching_mode = "AVE" + vmm_allow_promiscuous = "accept" + vmm_forged_transmits = "accept" + vmm_mac_changes = "accept" + } + `) + return resource +} + +func CreateAccFVDomainConfigWithOptionalValues(rName string) string { + fmt.Println("=== STEP Basic: testing epg to domain creation with optional parameters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_vmm_domain" "test" { + name = "%s" + provider_profile_dn = "uni/vmmp-VMware" + enable_ave = "yes" + } + + resource "aci_epg_to_domain" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = aci_vmm_domain.test.id + annotation = "from_terraform" + binding_type = "dynamicBinding" + allow_micro_seg = "true" + delimiter = "" + encap = "vlan-5" + epg_cos = "Cos5" + epg_cos_pref = "enabled" + instr_imedcy = "immediate" + lag_policy_name = "lag_policy_name" + netflow_dir = "ingress" + netflow_pref = "enabled" + num_ports = "3" + port_allocation = "fixed" + primary_encap = "vlan-4" + primary_encap_inner = "vlan-6" + res_imedcy = "immediate" + secondary_encap_inner = "vlan-7" + switching_mode = "AVE" + vmm_allow_promiscuous = "accept" + vmm_forged_transmits = "accept" + vmm_mac_changes = "accept" + } + `, rName, rName, rName, rName) + return resource +} + +func testAccCheckAciFVDomainIdEqual(m1, m2 *models.FVDomain) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName != m2.DistinguishedName { + return fmt.Errorf("epg_to_domain DNs are not equal") + } + return nil + } +} + +func testAccCheckAciFVDomainIdNotEqual(m1, m2 *models.FVDomain) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName == m2.DistinguishedName { + return fmt.Errorf("epg_to_domain DNs are equal") + } + return nil + } +} + +func testAccCheckAciFVDomainExists(name string, domain *models.FVDomain) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("Domain %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No Domain dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + domainFound := models.FVDomainFromContainer(cont) + if domainFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("Domain %s not found", rs.Primary.ID) + } + *domain = *domainFound + return nil + } +} + +func CreateAccFVDomainUpdatedAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP testing epg_to_domain updation with %s = %s\n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_vmm_domain" "test" { + name = "%s" + provider_profile_dn = "uni/vmmp-VMware" + enable_ave = "yes" + } + + resource "aci_epg_to_domain" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = aci_vmm_domain.test.id + %s = "%s" + } + `, rName, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccFVDomainUpdatedAttrFCDomain(rName, attribute, value string) string { + fmt.Printf("=== STEP testing epg_to_domain updation with %s = %s while tdn having referece of fc_domain\n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_fc_domain" "test" { + name = "%s" + } + + resource "aci_epg_to_domain" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = aci_fc_domain.test.id + %s = "%s" + } + `, rName, rName, rName, rName, attribute, value) + return resource +} diff --git a/testacc/resource_aci_fvrspathatt_test.go b/testacc/resource_aci_fvrspathatt_test.go new file mode 100644 index 000000000..5db5f2c4c --- /dev/null +++ b/testacc/resource_aci_fvrspathatt_test.go @@ -0,0 +1,639 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +const tdn1 = "topology/pod-1/paths-101/pathep-[eth1/12]" +const tdn2 = "topology/pod-1/paths-101/pathep-[eth1/6]" +const multdn1 = "topology/pod-1/paths-101/pathep-[eth1/21]" +const multdn2 = "topology/pod-1/paths-101/pathep-[eth1/30]" +const multdn3 = "topology/pod-1/paths-101/pathep-[eth1/1]" + +func TestAccAciStaticPath_Basic(t *testing.T) { + var static_path_default models.StaticPath + var static_path_updated models.StaticPath + resourceName := "aci_epg_to_static_path.test" + rName := makeTestVariable(acctest.RandString(5)) + rOtherName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciStaticPathDestroy, + Steps: []resource.TestStep{ + { + Config: CreateStaticPathWithoutApplicationEpg(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateStaticPathWithoutTdn(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateStaticPathWithoutEncap(rName), + ExpectError: regexp.MustCompile(`Validation failed: Encap not specifiedRn=(.)+`), + }, + { + Config: CreateAccStaticPathConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciStaticPathExists(resourceName, &static_path_default), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "application_epg_dn", fmt.Sprintf("uni/tn-%s/ap-%s/epg-%s", rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "encap", "vlan-1"), + resource.TestCheckResourceAttr(resourceName, "instr_imedcy", "lazy"), + resource.TestCheckResourceAttr(resourceName, "mode", "regular"), + resource.TestCheckResourceAttr(resourceName, "primary_encap", "unknown"), + resource.TestCheckResourceAttr(resourceName, "tdn", tdn1), + ), + }, + { + Config: CreateAccStaticPathConfigWithOptionalParameters(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciStaticPathExists(resourceName, &static_path_updated), + resource.TestCheckResourceAttr(resourceName, "annotation", "annotation"), + resource.TestCheckResourceAttr(resourceName, "application_epg_dn", fmt.Sprintf("uni/tn-%s/ap-%s/epg-%s", rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "description", "description"), + resource.TestCheckResourceAttr(resourceName, "encap", "vlan-1"), + resource.TestCheckResourceAttr(resourceName, "instr_imedcy", "immediate"), + resource.TestCheckResourceAttr(resourceName, "mode", "native"), + resource.TestCheckResourceAttr(resourceName, "primary_encap", "vlan-5"), + resource.TestCheckResourceAttr(resourceName, "tdn", tdn1), + testAccCheckAciStaticPathIdEqual(&static_path_default, &static_path_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccStaticPathRemovingRequiredField(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccStaticPathConfigWithEpgAndTdn(rOtherName, tdn1), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciStaticPathExists(resourceName, &static_path_updated), + resource.TestCheckResourceAttr(resourceName, "application_epg_dn", fmt.Sprintf("uni/tn-%s/ap-%s/epg-%s", rOtherName, rOtherName, rOtherName)), + resource.TestCheckResourceAttr(resourceName, "tdn", tdn1), + resource.TestCheckResourceAttr(resourceName, "encap", "vlan-1"), + testAccCheckAciStaticPathIdNotEqual(&static_path_default, &static_path_updated), + ), + }, + { + Config: CreateAccStaticPathConfig(rName), + }, + { + Config: CreateAccStaticPathConfigWithEpgAndTdn(rName, tdn2), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciStaticPathExists(resourceName, &static_path_updated), + resource.TestCheckResourceAttr(resourceName, "application_epg_dn", fmt.Sprintf("uni/tn-%s/ap-%s/epg-%s", rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "tdn", tdn2), + resource.TestCheckResourceAttr(resourceName, "encap", "vlan-1"), + testAccCheckAciStaticPathIdNotEqual(&static_path_default, &static_path_updated), + ), + }, + }, + }) +} + +func TestAccAciStaticPath_Update(t *testing.T) { + var static_path_default models.StaticPath + var static_path_updated models.StaticPath + resourceName := "aci_epg_to_static_path.test" + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciStaticPathDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccStaticPathConfigForUpdate(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciStaticPathExists(resourceName, &static_path_default), + ), + }, + { + Config: CreateAccStaticPathUpdated(rName, "mode", "untagged"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciStaticPathExists(resourceName, &static_path_updated), + resource.TestCheckResourceAttr(resourceName, "mode", "untagged"), + testAccCheckAciStaticPathIdEqual(&static_path_default, &static_path_updated), + ), + }, + }, + }) +} + +func TestAccAciStaticPath_NegativCases(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + longDescAnnotation := acctest.RandString(129) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciStaticPathDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccStaticPathConfigNegative(rName), + }, + { + Config: CreateAccStaticPathWithInvalidEpgDn(rName), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class fvRsPathAtt (.)+,`), + }, + { + Config: CreateAccStaticPathWithInvalidTDn(rName, randomValue), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class fvRsPathAtt (.)+,`), + }, + { + Config: CreateAccStaticPathUpdatedNegative(rName, "annotation", longDescAnnotation), + ExpectError: regexp.MustCompile(`property annotation of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccStaticPathUpdatedNegative(rName, "description", longDescAnnotation), + ExpectError: regexp.MustCompile(`property descr of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccStaticPathUpdatedNegativeEncap(rName, randomValue), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name encap, class fvRsPathAtt (.)+`), + }, + { + Config: CreateAccStaticPathUpdatedNegative(rName, "instr_imedcy", randomValue), + ExpectError: regexp.MustCompile(`expected instr_imedcy to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccStaticPathUpdatedNegative(rName, "mode", randomValue), + ExpectError: regexp.MustCompile(`expected mode to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccStaticPathUpdatedNegative(rName, "primary_encap", randomValue), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name primaryEncap, class fvRsPathAtt (.)+`), + }, + { + Config: CreateAccStaticPathUpdatedNegative(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccStaticPathConfigNegative(rName), + }, + }, + }) +} + +func TestAccAciStaticPath_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciStaticPathDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccStaticPathsConfig(rName), + }, + }, + }) +} + +func CreateAccStaticPathsConfig(rName string) string { + fmt.Println("=== STEP Basic: testing epg_to_static_path multiple creation") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test"{ + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_epg_to_static_path" "test1" { + application_epg_dn = aci_application_epg.test.id + tdn = "%s" + encap = "vlan-101" + } + + resource "aci_epg_to_static_path" "test2" { + application_epg_dn = aci_application_epg.test.id + tdn = "%s" + encap = "vlan-102" + } + + resource "aci_epg_to_static_path" "test3" { + application_epg_dn = aci_application_epg.test.id + tdn = "%s" + encap = "vlan-103" + } + `, rName, rName, rName, multdn1, multdn2, multdn3) + return resource +} + +func CreateAccStaticPathConfigWithEpgAndTdn(rName, tdn string) string { + fmt.Printf("=== STEP Basic: testing epg_to_static_path creation with resource name %s and tdn %s\n", rName, tdn) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test"{ + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_epg_to_static_path" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = "%s" + encap = "vlan-1" + } + `, rName, rName, rName, tdn) + return resource +} + +func CreateAccStaticPathRemovingRequiredField() string { + fmt.Println("=== STEP Basic: testing epg_to_static_path updation without required parameters") + resource := fmt.Sprintln(` + + resource "aci_epg_to_static_path" "test" { + annotation = "tag" + description = "description" + instr_imedcy = "immediate" + mode = "native" + primary_encap = "vlan-500" + } + `) + return resource +} + +func CreateAccStaticPathConfigWithOptionalParameters(rName string) string { + fmt.Println("=== STEP Basic: testing epg_to_static_path creation with all optional parameters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test"{ + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_epg_to_static_path" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = "%s" + encap = "vlan-1" + annotation = "annotation" + description = "description" + instr_imedcy = "immediate" + mode = "native" + primary_encap = "vlan-5" + } + `, rName, rName, rName, tdn1) + return resource +} + +func CreateAccStaticPathWithInvalidTDn(rName, rVal string) string { + fmt.Println("=== STEP Negative cases: testing epg_to_static_path creation with invalid tdn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test"{ + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_application_epg" "test"{ + name = "%s" + application_profile_dn = aci_application_profile.test.id + } + + resource "aci_epg_to_static_path" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = "%s" + encap = "vlan-27" + } + `, rName, rName, rName, rVal) + return resource +} + +func CreateAccStaticPathWithInvalidEpgDn(rName string) string { + fmt.Println("=== STEP Negative cases: testing epg_to_static_path creation with invalid application_epg_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_epg_to_static_path" "test" { + application_epg_dn = aci_tenant.test.id + tdn = "%s" + encap = "vlan-27" + } + `, rName, tdn1) + return resource +} + +func CreateAccStaticPathUpdatedNegativeEncap(rName, encap string) string { + fmt.Printf("=== STEP Negative cases: testing epg_to_static_path creation with encap = %s\n", encap) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test"{ + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_epg_to_static_path" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = "%s" + encap = "%s" + } + `, rName, rName, rName, tdn1, encap) + return resource +} + +func CreateAccStaticPathUpdatedNegative(rName, key, value string) string { + fmt.Printf("=== STEP Negative cases: testing epg_to_static_path creation with %s = %s\n", key, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test"{ + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_epg_to_static_path" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = "%s" + encap = "vlan-27" + %s = "%s" + } + `, rName, rName, rName, tdn1, key, value) + return resource +} + +func CreateAccStaticPathUpdated(rName, key, value string) string { + fmt.Printf("=== STEP Update: testing epg_to_static_path creation with %s = %s\n", key, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test"{ + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_epg_to_static_path" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = "%s" + encap = "vlan-15" + %s = "%s" + } + `, rName, rName, rName, tdn1, key, value) + return resource +} + +func CreateAccStaticPathConfigForUpdate(rName string) string { + fmt.Println("=== STEP Update: testing epg_to_static_path creation without required parameters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test"{ + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_epg_to_static_path" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = "%s" + encap = "vlan-15" + } + `, rName, rName, rName, tdn1) + return resource +} + +func CreateAccStaticPathConfigNegative(rName string) string { + fmt.Println("=== STEP Negative cases: testing epg_to_static_path creation with required parameters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test"{ + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_epg_to_static_path" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = "%s" + encap = "vlan-27" + } + `, rName, rName, rName, tdn1) + return resource +} + +func CreateAccStaticPathConfig(rName string) string { + fmt.Println("=== STEP Basic: testing epg_to_static_path creation with required parameters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test"{ + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_epg_to_static_path" "test" { + application_epg_dn = aci_application_epg.test.id + tdn = "%s" + encap = "vlan-1" + } + `, rName, rName, rName, tdn1) + return resource +} + +func CreateStaticPathWithoutEncap(rName string) string { + fmt.Println("=== STEP Basic: testing epg_to_static_path creation without encap") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test"{ + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_epg_to_static_path" "example" { + application_epg_dn = aci_application_epg.test.id + tdn = "%s" + } + `, rName, rName, rName, tdn1) + return resource +} + +func CreateStaticPathWithoutTdn(rName string) string { + fmt.Println("=== STEP Basic: testing epg_to_static_path creation without tDn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_application_epg" "test"{ + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_epg_to_static_path" "example" { + application_epg_dn = aci_application_epg.test.id + encap = "vlan-1" + } + `, rName, rName, rName) + return resource +} + +func CreateStaticPathWithoutApplicationEpg() string { + fmt.Println("=== STEP Basic: testing epg_to_static_path creation without application_epg_dn") + resource := fmt.Sprintf(` + resource "aci_epg_to_static_path" "test" { + tdn = "%s" + encap = "vlan-1" + } + `, tdn1) + return resource +} + +func testAccCheckAciStaticPathExists(name string, static_path *models.StaticPath) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("Static Path %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No Static Path dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + static_pathFound := models.StaticPathFromContainer(cont) + if static_pathFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("Static Path %s not found", rs.Primary.ID) + } + *static_path = *static_pathFound + return nil + } +} + +func testAccCheckAciStaticPathDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing epg_to_static_path destroy") + client := testAccProvider.Meta().(*client.Client) + for _, rs := range s.RootModule().Resources { + if rs.Type == "aci_epg_to_static_path" { + cont, err := client.Get(rs.Primary.ID) + static_path := models.StaticPathFromContainer(cont) + if err == nil { + return fmt.Errorf("Static Path %s Still exists", static_path.DistinguishedName) + } + } else { + continue + } + } + return nil +} + +func testAccCheckAciStaticPathIdEqual(m1, m2 *models.StaticPath) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName != m2.DistinguishedName { + return fmt.Errorf("static_path DNs are not equal") + } + return nil + } +} + +func testAccCheckAciStaticPathIdNotEqual(m1, m2 *models.StaticPath) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName == m2.DistinguishedName { + return fmt.Errorf("static_path DNs are equal") + } + return nil + } +} diff --git a/testacc/resource_aci_fvrsproscons_test.go b/testacc/resource_aci_fvrsproscons_test.go new file mode 100644 index 000000000..ed375b3d4 --- /dev/null +++ b/testacc/resource_aci_fvrsproscons_test.go @@ -0,0 +1,900 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciEPGToContract_Basic(t *testing.T) { + var epg_to_contract_default_cons models.ContractConsumer + var epg_to_contract_updated_cons models.ContractConsumer + var epg_to_contract_default_prov models.ContractProvider + resourceName := "aci_epg_to_contract.test" + rName := makeTestVariable(acctest.RandString(5)) + rOtherName := makeTestVariable(acctest.RandString(5)) + randomValue := acctest.RandString(5) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciEPGToContractDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccEPGToContractWithoutApplicationEPG(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccEPGToContractWithoutContract(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccEPGToContractWithoutContractType(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccEPGToContractConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEPGToContractExists(resourceName, &epg_to_contract_default_cons), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "application_epg_dn", fmt.Sprintf("uni/tn-%s/ap-%s/epg-%s", rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "contract_dn", fmt.Sprintf("uni/tn-%s/brc-%s", rName, rName)), + resource.TestCheckResourceAttr(resourceName, "contract_type", "consumer"), + //resource.TestCheckResourceAttr(resourceName, "match_t", ""), + resource.TestCheckResourceAttr(resourceName, "prio", "unspecified"), + ), + }, + { + Config: CreateAccEPGToContractConfigWithOptionalValues(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEPGToContractExists(resourceName, &epg_to_contract_updated_cons), + resource.TestCheckResourceAttr(resourceName, "annotation", "test_annotation"), + resource.TestCheckResourceAttr(resourceName, "application_epg_dn", fmt.Sprintf("uni/tn-%s/ap-%s/epg-%s", rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "contract_dn", fmt.Sprintf("uni/tn-%s/brc-%s", rName, rName)), + resource.TestCheckResourceAttr(resourceName, "contract_type", "consumer"), + resource.TestCheckResourceAttr(resourceName, "match_t", "AtleastOne"), + resource.TestCheckResourceAttr(resourceName, "prio", "level1"), + testAccCheckAciEPGToContractIdEqual(&epg_to_contract_default_cons, &epg_to_contract_updated_cons), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"contract_dn", "match_t"}, + }, + { + Config: CreateAccEPGToContractConfigWithUpdatedContract(rName, rOtherName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEPGToContractExists(resourceName, &epg_to_contract_updated_cons), + resource.TestCheckResourceAttr(resourceName, "contract_dn", fmt.Sprintf("uni/tn-%s/brc-%s", rName, rOtherName)), + resource.TestCheckResourceAttr(resourceName, "id", fmt.Sprintf("uni/tn-%s/ap-%s/epg-%s/rscons-%s", rName, rName, rName, rOtherName)), + testAccCheckAciEPGToContractIdNotEqual(&epg_to_contract_default_cons, &epg_to_contract_updated_cons), + ), + }, + { + Config: CreateAccEPGToContractConfig(rName), + }, + { + Config: CreateAccEPGToContractConfigWithUpdatedApplicationEPG(rName, rOtherName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEPGToContractExists(resourceName, &epg_to_contract_updated_cons), + resource.TestCheckResourceAttr(resourceName, "application_epg_dn", fmt.Sprintf("uni/tn-%s/ap-%s/epg-%s", rName, rName, rOtherName)), + resource.TestCheckResourceAttr(resourceName, "id", fmt.Sprintf("uni/tn-%s/ap-%s/epg-%s/rscons-%s", rName, rName, rOtherName, rName)), + testAccCheckAciEPGToContractIdNotEqual(&epg_to_contract_default_cons, &epg_to_contract_updated_cons), + ), + }, + { + Config: CreateAccEPGToContractConfig(rName), + }, + { + Config: CreateAccEPGToContractConfigUpdateWithoutRequiredParameters(rName, "annotation", randomValue), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccEPGToContractConfig(rName), + }, + { + Config: CreateAccEPGToContractConfigWithUpdatedContractType(rName, "provider"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEPGToContractProviderExists(resourceName, &epg_to_contract_default_prov), + resource.TestCheckResourceAttr(resourceName, "contract_type", "provider"), + resource.TestCheckResourceAttr(resourceName, "id", fmt.Sprintf("uni/tn-%s/ap-%s/epg-%s/rsprov-%s", rName, rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "match_t", "AtleastOne"), + ), + }, + { + Config: CreateAccEPGToContractConfig(rName), + }, + }, + }) +} + +func TestAccAciEPGToContract_Update(t *testing.T) { + var epg_to_contract_default_prov models.ContractProvider + var epg_to_contract_updated_prov models.ContractProvider + resourceName := "aci_epg_to_contract.test" + rName := makeTestVariable(acctest.RandString(5)) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciEPGToContractDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccEPGToContractProvConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEPGToContractProvExists(resourceName, &epg_to_contract_default_prov), + ), + }, + { + Config: CreateAccEPGToContractProvUpdatedAttr(rName, "match_t", "All"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEPGToContractProvExists(resourceName, &epg_to_contract_updated_prov), + resource.TestCheckResourceAttr(resourceName, "match_t", "All"), + testAccCheckAciEPGToContractProvIdEqual(&epg_to_contract_default_prov, &epg_to_contract_updated_prov), + ), + }, + { + Config: CreateAccEPGToContractProvUpdatedAttr(rName, "match_t", "AtmostOne"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEPGToContractProvExists(resourceName, &epg_to_contract_updated_prov), + resource.TestCheckResourceAttr(resourceName, "match_t", "AtmostOne"), + testAccCheckAciEPGToContractProvIdEqual(&epg_to_contract_default_prov, &epg_to_contract_updated_prov), + ), + }, + { + Config: CreateAccEPGToContractProvUpdatedAttr(rName, "match_t", "None"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEPGToContractProvExists(resourceName, &epg_to_contract_updated_prov), + resource.TestCheckResourceAttr(resourceName, "match_t", "None"), + testAccCheckAciEPGToContractProvIdEqual(&epg_to_contract_default_prov, &epg_to_contract_updated_prov), + ), + }, + { + Config: CreateAccEPGToContractProvUpdatedAttr(rName, "prio", "level2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEPGToContractProvExists(resourceName, &epg_to_contract_updated_prov), + resource.TestCheckResourceAttr(resourceName, "prio", "level2"), + testAccCheckAciEPGToContractProvIdEqual(&epg_to_contract_default_prov, &epg_to_contract_updated_prov), + ), + }, + { + Config: CreateAccEPGToContractProvUpdatedAttr(rName, "prio", "level3"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEPGToContractProvExists(resourceName, &epg_to_contract_updated_prov), + resource.TestCheckResourceAttr(resourceName, "prio", "level3"), + testAccCheckAciEPGToContractProvIdEqual(&epg_to_contract_default_prov, &epg_to_contract_updated_prov), + ), + }, + { + Config: CreateAccEPGToContractProvUpdatedAttr(rName, "prio", "level4"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEPGToContractProvExists(resourceName, &epg_to_contract_updated_prov), + resource.TestCheckResourceAttr(resourceName, "prio", "level4"), + testAccCheckAciEPGToContractProvIdEqual(&epg_to_contract_default_prov, &epg_to_contract_updated_prov), + ), + }, + { + Config: CreateAccEPGToContractProvUpdatedAttr(rName, "prio", "level5"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEPGToContractProvExists(resourceName, &epg_to_contract_updated_prov), + resource.TestCheckResourceAttr(resourceName, "prio", "level5"), + testAccCheckAciEPGToContractProvIdEqual(&epg_to_contract_default_prov, &epg_to_contract_updated_prov), + ), + }, + { + Config: CreateAccEPGToContractProvUpdatedAttr(rName, "prio", "level6"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciEPGToContractProvExists(resourceName, &epg_to_contract_updated_prov), + resource.TestCheckResourceAttr(resourceName, "prio", "level6"), + testAccCheckAciEPGToContractProvIdEqual(&epg_to_contract_default_prov, &epg_to_contract_updated_prov), + ), + }, + }, + }) + +} + +func TestAccAciEPGToContract_NegativeCases(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + longAnnotationDesc := acctest.RandString(129) + randomParameter := acctest.RandStringFromCharSet(10, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(10) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciEPGToContractDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccEPGToContractConfig(rName), + }, + { + Config: CreateAccEPGToContractWithInvalidApplicationEPG(rName), + ExpectError: regexp.MustCompile(`unknown property value (.)+ name dn, class fvRsCons (.)+`), + }, + { + Config: CreateAccEPGToContractWithInvalidContractType(rName, randomValue), + ExpectError: regexp.MustCompile(`Contract Type: Value must be from (.)+`), + }, + { + Config: CreateAccEPGToContractUpdatedAttr(rName, "annotation", longAnnotationDesc), + ExpectError: regexp.MustCompile(`property annotation of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccEPGToContractUpdatedAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccEPGToContractUpdatedAttr(rName, "match_t", randomValue), + ExpectError: regexp.MustCompile(`expected match_t to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccEPGToContractUpdatedAttr(rName, "prio", randomValue), + ExpectError: regexp.MustCompile(`expected prio to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccEPGToContractConfig(rName), + }, + }, + }) +} + +func TestAccAciEPGToContracts_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + rName2 := makeTestVariable(acctest.RandString(5)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciEPGToContractDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccEPGToContractsConfig(rName, rName2), + }, + }, + }) +} + +func CreateAccEPGToContractWithoutApplicationEPG(rName string) string { + fmt.Println("=== STEP Basic: testing epg_to_contract without creating application_epg") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_type = "consumer" + contract_dn = aci_contract.test.id + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccEPGToContractWithoutContract(rName string) string { + fmt.Println("=== STEP Basic: testing epg_to_contract without creating contract") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_type = "consumer" + application_epg_dn = aci_application_epg.test.id + } + `, rName, rName, rName, rName) + return resource + +} + +func CreateAccEPGToContractWithoutContractType(rName string) string { + fmt.Println("=== STEP Basic: testing epg_to_contract without passing contract type attribute") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_epg.test.id + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccEPGToContractConfigUpdateWithoutRequiredParameters(rName, attribute, value string) string { + fmt.Printf("=== STEP Basic: testing EPG to Contract updation without Required Parameters %s = %s\n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + %s = "%s" + } + `, rName, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccEPGToContractConfig(rName string) string { + fmt.Println("=== STEP Basic: testing EPG to Contract creation with required paramters only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_epg.test.id + contract_type = "consumer" + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccEPGToContractProvConfig(rName string) string { + fmt.Println("=== STEP Basic: testing EPG to Contract creation with required paramters only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_epg.test.id + contract_type = "provider" + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccEPGToContractConfigWithOptionalValues(rName string) string { + fmt.Println("=== STEP Basic: testing EPG to Contract creation with optional paramters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_epg.test.id + contract_type = "consumer" + annotation = "test_annotation" + match_t = "AtleastOne" + prio = "level1" + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccEPGToContractConfigWithUpdatedContract(rName, rOtherName string) string { + fmt.Println("=== STEP Basic: testing EPG to Contract creation with Updated Contract") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_epg.test.id + contract_type = "consumer" + } + `, rName, rName, rName, rOtherName) + return resource +} + +func CreateAccEPGToContractConfigWithUpdatedApplicationEPG(rName, rOtherName string) string { + fmt.Println("=== STEP Basic: testing EPG to Contract creation with Updated Application EPG") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_epg.test.id + contract_type = "consumer" + } + `, rName, rName, rOtherName, rName) + return resource +} + +func CreateAccEPGToContractConfigWithUpdatedContractType(rName, contractType string) string { + fmt.Println("=== STEP Basic: testing EPG to Contract creation with Updated Contract Type") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_epg.test.id + contract_type = "%s" + } + `, rName, rName, rName, rName, contractType) + return resource +} + +func CreateAccEPGToContractUpdatedAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP Basic: testing EPG to Contract %s = %s\n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_epg.test.id + contract_type = "consumer" + %s = "%s" + } + `, rName, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccEPGToContractProvUpdatedAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP Basic: testing EPG to Contract %s = %s\n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_epg.test.id + contract_type = "provider" + %s = "%s" + } + `, rName, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccEPGToContractWithInvalidContractType(rName, randomValue string) string { + fmt.Println("=== STEP Basic: testing EPG to Contract updation with Invalid application_epg_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_profile.test.id + contract_type = "%s" + } + `, rName, rName, rName, rName, randomValue) + return resource +} +func CreateAccEPGToContractWithInvalidApplicationEPG(rName string) string { + fmt.Println("=== STEP Basic: testing EPG to Contract updation with Invalid application_epg_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_profile.test.id + contract_type = "consumer" + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccEPGToContractWithInvalidContract(rName string) string { + fmt.Println("=== STEP Basic: testing EPG to Contract updation with Invalid contract_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_tenant.test.id + application_epg_dn = aci_application_epg.test.id + contract_type = "consumer" + } + `, rName, rName, rName, rName) + return resource +} +func CreateAccEPGToContractsConfig(rName, rName2 string) string { + fmt.Println("=== STEP creating multiple epg_to_contracts") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_application_epg" "test" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_application_epg" "test1" { + application_profile_dn = aci_application_profile.test.id + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract" "test1" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_epg_to_contract" "test" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_epg.test.id + contract_type = "consumer" + } + + resource "aci_epg_to_contract" "test1" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_epg.test.id + contract_type = "provider" + } + + resource "aci_epg_to_contract" "test2" { + contract_dn = aci_contract.test1.id + application_epg_dn = aci_application_epg.test.id + contract_type = "consumer" + } + + resource "aci_epg_to_contract" "test3" { + contract_dn = aci_contract.test.id + application_epg_dn = aci_application_epg.test1.id + contract_type = "consumer" + } + `, rName, rName, rName, rName2, rName, rName2) + return resource + +} + +func testAccCheckAciEPGToContractDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing EPG To Contract destroy") + client := testAccProvider.Meta().(*client.Client) + + for _, rs := range s.RootModule().Resources { + + if rs.Type == "aci_epg_to_contract" { + cont, err := client.Get(rs.Primary.ID) + epg_to_contract := models.ContractConsumerFromContainer(cont) + if err == nil { + return fmt.Errorf("EPG To Contract %s still exists", epg_to_contract.DistinguishedName) + } + } else { + continue + } + } + return nil +} + +func testAccCheckAciEPGToContractProviderExists(name string, epg_to_contract *models.ContractProvider) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("EPG To Contract %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No EPG to Contract Dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + epg_to_contractFound := models.ContractProviderFromContainer(cont) + if epg_to_contractFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("EPG to Contract %s not found", rs.Primary.ID) + } + *epg_to_contract = *epg_to_contractFound + return nil + } +} + +func testAccCheckAciEPGToContractExists(name string, epg_to_contract *models.ContractConsumer) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("EPG To Contract %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No EPG To Contract Dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + epg_to_contractFound := models.ContractConsumerFromContainer(cont) + if epg_to_contractFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("EPG to Contract %s not found", rs.Primary.ID) + } + *epg_to_contract = *epg_to_contractFound + return nil + } +} + +func testAccCheckAciEPGToContractProvExists(name string, epg_to_contract *models.ContractProvider) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("EPG To Contract %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No EPG To Contract Dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + epg_to_contractFound := models.ContractProviderFromContainer(cont) + if epg_to_contractFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("EPG to Contract %s not found", rs.Primary.ID) + } + *epg_to_contract = *epg_to_contractFound + return nil + } +} +func testAccCheckAciEPGToContractIdNotEqual(cc1, cc2 *models.ContractConsumer) resource.TestCheckFunc { + return func(s *terraform.State) error { + if cc1.DistinguishedName == cc2.DistinguishedName { + return fmt.Errorf("EPG To Contract DNs are equal") + } + return nil + } +} + +func testAccCheckAciEPGToContractIdEqual(cc1, cc2 *models.ContractConsumer) resource.TestCheckFunc { + return func(s *terraform.State) error { + if cc1.DistinguishedName != cc2.DistinguishedName { + return fmt.Errorf("EPG to Contract DNs are no equal") + } + return nil + } +} + +func testAccCheckAciEPGToContractProvIdEqual(cc1, cc2 *models.ContractProvider) resource.TestCheckFunc { + return func(s *terraform.State) error { + if cc1.DistinguishedName != cc2.DistinguishedName { + return fmt.Errorf("EPG to Contract DNs are no equal") + } + return nil + } +} diff --git a/testacc/resource_aci_fvsubnet_test.go b/testacc/resource_aci_fvsubnet_test.go index 3a2108273..cea10cc10 100644 --- a/testacc/resource_aci_fvsubnet_test.go +++ b/testacc/resource_aci_fvsubnet_test.go @@ -1,4 +1,4 @@ -package acctest +package testacc import ( "fmt" @@ -23,9 +23,9 @@ func TestAccAciSubnet_Basic(t *testing.T) { ipother, _ := acctest.RandIpAddress("10.21.0.0/16") ipother = fmt.Sprintf("%s/16", ipother) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciSubnetDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciSubnetDestroy, Steps: []resource.TestStep{ { Config: CreateSubnetWithoutParentDn(ip), @@ -115,7 +115,7 @@ func TestAccAciSubnet_Basic(t *testing.T) { }) } -func TestAccSubnet_Update(t *testing.T) { +func TestAccAciSubnet_Update(t *testing.T) { var subnet_default models.Subnet var subnet_updated models.Subnet resourceName := "aci_subnet.test" @@ -123,9 +123,9 @@ func TestAccSubnet_Update(t *testing.T) { ip, _ := acctest.RandIpAddress("10.20.0.0/16") ip = fmt.Sprintf("%s/16", ip) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciSubnetDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciSubnetDestroy, Steps: []resource.TestStep{ { Config: CreateAccSubnetConfig(rName, ip), @@ -250,7 +250,7 @@ func TestAccSubnet_Update(t *testing.T) { }) } -func TestAccSubnet_NegativeCases(t *testing.T) { +func TestAccAciSubnet_NegativeCases(t *testing.T) { rName := makeTestVariable(acctest.RandString(5)) ip, _ := acctest.RandIpAddress("10.20.0.0/16") ip = fmt.Sprintf("%s/16", ip) @@ -259,16 +259,16 @@ func TestAccSubnet_NegativeCases(t *testing.T) { randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") randomValue := acctest.RandString(5) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciSubnetDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciSubnetDestroy, Steps: []resource.TestStep{ { Config: CreateAccSubnetConfig(rName, ip), }, { Config: CreateAccSubnetWithInValidParentDn(rName, ip), - ExpectError: regexp.MustCompile(`configured object (.)+ not found (.)+,`), + ExpectError: regexp.MustCompile(`is not valid bridge_domain_dn`), }, { Config: CreateAccSubnetUpdatedAttr(rName, ip, "description", longDescAnnotation), @@ -296,7 +296,7 @@ func TestAccSubnet_NegativeCases(t *testing.T) { }, { Config: CreateAccSubnetUpdatedAttrList(rName, ip, "scope", StringListtoString([]string{"public", "public"})), - ExpectError: regexp.MustCompile(`duplication in list`), + ExpectError: regexp.MustCompile(`duplication is not supported in list`), }, { Config: CreateAccSubnetUpdatedAttrList(rName, ip, "scope", StringListtoString([]string{"private", "public"})), @@ -312,7 +312,7 @@ func TestAccSubnet_NegativeCases(t *testing.T) { }, { Config: CreateAccSubnetUpdatedAttrList(rName, ip, "ctrl", StringListtoString([]string{"nd", "nd"})), - ExpectError: regexp.MustCompile(`duplication in list`), + ExpectError: regexp.MustCompile(`duplication is not supported in list`), }, { Config: CreateAccSubnetUpdatedAttrList(rName, ip, "ctrl", StringListtoString([]string{"unspecified", "nd"})), @@ -329,7 +329,7 @@ func TestAccSubnet_NegativeCases(t *testing.T) { }) } -func TestAccSubnet_reltionalParameters(t *testing.T) { +func TestAccAciSubnet_reltionalParameters(t *testing.T) { var subnet_default models.Subnet var subnet_rel1 models.Subnet var subnet_rel2 models.Subnet @@ -340,9 +340,9 @@ func TestAccSubnet_reltionalParameters(t *testing.T) { relRes1 := makeTestVariable(acctest.RandString(5)) relRes2 := makeTestVariable(acctest.RandString(5)) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciSubnetDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciSubnetDestroy, Steps: []resource.TestStep{ { Config: CreateAccSubnetConfig(rName, ip), @@ -386,16 +386,16 @@ func TestAccSubnet_reltionalParameters(t *testing.T) { }) } -func TestAccSubnet_MultipleCreateDelete(t *testing.T) { +func TestAccAciSubnet_MultipleCreateDelete(t *testing.T) { rName := makeTestVariable(acctest.RandString(5)) ip, _ := acctest.RandIpAddress("10.20.0.0/16") ip1 := fmt.Sprintf("%s/16", ip) ip2 := fmt.Sprintf("%s/17", ip) ip3 := fmt.Sprintf("%s/18", ip) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciSubnetDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciSubnetDestroy, Steps: []resource.TestStep{ { Config: CreateAccSubnetsConfig(rName, ip1, ip2, ip3), @@ -496,7 +496,7 @@ func CreateSubnetWithoutIP(rName string) string { } func CreateAccSubnetConfig(rName, ip string) string { - fmt.Println("=== STEP testing subnet creation with required arguements only") + fmt.Println("=== STEP testing subnet creation with required arguments only") resource := fmt.Sprintf(` resource "aci_tenant" "test"{ name = "%s" @@ -548,20 +548,15 @@ func CreateAccSubnetsConfig(rName, ip1, ip2, ip3 string) string { func CreateAccSubnetWithInValidParentDn(rName, ip string) string { fmt.Println("=== STEP Negative Case: testing subnet creation with invalid parent_dn") resource := fmt.Sprintf(` - resource "aci_tenant" "test" { - name = "%s" - } - - resource "aci_bridge_domain" "test"{ - tenant_dn = aci_tenant.test.id + resource "aci_fc_domain" "test" { name = "%s" } resource "aci_subnet" "test" { - parent_dn = "${aci_bridge_domain.test.id}xyz" + parent_dn = aci_fc_domain.test.id ip = "%s" } - `, rName, rName, ip) + `, rName, ip) return resource } diff --git a/testacc/resource_aci_fvtenant_test.go b/testacc/resource_aci_fvtenant_test.go index bf1e8a760..57c756bdf 100644 --- a/testacc/resource_aci_fvtenant_test.go +++ b/testacc/resource_aci_fvtenant_test.go @@ -1,4 +1,4 @@ -package acctest +package testacc import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/ciscoecosystem/aci-go-client/client" "github.com/ciscoecosystem/aci-go-client/models" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" @@ -21,9 +20,9 @@ func TestAccAciTenant_Basic(t *testing.T) { rOther := makeTestVariable(acctest.RandString(5)) longrName := acctest.RandString(65) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciTenantDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciTenantDestroy, Steps: []resource.TestStep{ { Config: CreateAccTenantWithoutName(), @@ -81,16 +80,16 @@ func TestAccAciTenant_Basic(t *testing.T) { }) } -func TestAccTenant_NegativeCases(t *testing.T) { +func TestAccAciTenant_NegativeCases(t *testing.T) { rName := makeTestVariable(acctest.RandString(5)) longDescAnnotation := acctest.RandString(129) longNameAlias := acctest.RandString(64) randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") randomValue := acctest.RandString(5) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciTenantDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciTenantDestroy, Steps: []resource.TestStep{ { Config: CreateAccTenantConfig(rName), @@ -118,7 +117,7 @@ func TestAccTenant_NegativeCases(t *testing.T) { }) } -func TestAccTenant_reltionalParameters(t *testing.T) { +func TestAccAciTenant_reltionalParameters(t *testing.T) { var tenant_default models.Tenant var tenant_rel1 models.Tenant var tenant_rel2 models.Tenant @@ -127,9 +126,9 @@ func TestAccTenant_reltionalParameters(t *testing.T) { rsRelName1 := acctest.RandString(5) rsRelName2 := acctest.RandString(5) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciTenantDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciTenantDestroy, Steps: []resource.TestStep{ { Config: CreateAccTenantConfig(rName), @@ -169,12 +168,12 @@ func TestAccTenant_reltionalParameters(t *testing.T) { }) } -func TestAccTenant_MultipleCreateDelete(t *testing.T) { +func TestAccAciTenant_MultipleCreateDelete(t *testing.T) { rName := makeTestVariable(acctest.RandString(5)) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciTenantDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciTenantDestroy, Steps: []resource.TestStep{ { Config: CreateAccTenantsConfig(rName), diff --git a/testacc/resource_aci_hsrpgroupp_test.go b/testacc/resource_aci_hsrpgroupp_test.go new file mode 100644 index 000000000..567378e7d --- /dev/null +++ b/testacc/resource_aci_hsrpgroupp_test.go @@ -0,0 +1,979 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciL3outHsrpInterfaceGroup_Basic(t *testing.T) { + var l3out_hsrp_interface_group_default models.HSRPGroupProfile + var l3out_hsrp_interface_group_updated models.HSRPGroupProfile + resourceName := "aci_l3out_hsrp_interface_group.test" + rName := makeTestVariable(acctest.RandString(5)) + rNameUpdated := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outHsrpInterfaceGroupDestroy, + Steps: []resource.TestStep{ + { + Config: CreateL3outHsrpInterfaceGroupWithoutRequired(rName, rName, rName, rName, rName, "l3out_hsrp_interface_profile_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateL3outHsrpInterfaceGroupWithoutRequired(rName, rName, rName, rName, rName, "name"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupConfig(rName, rName, rName, rName, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_default), + resource.TestCheckResourceAttr(resourceName, "l3out_hsrp_interface_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s/hsrpIfP", rName, rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "config_issues", "none"), + resource.TestCheckResourceAttr(resourceName, "group_af", "ipv4"), + resource.TestCheckResourceAttr(resourceName, "group_id", "0"), + resource.TestCheckResourceAttr(resourceName, "group_name", ""), + resource.TestCheckResourceAttr(resourceName, "ip", "10.20.30.40"), + resource.TestCheckResourceAttr(resourceName, "ip_obtain_mode", "admin"), + resource.TestCheckResourceAttr(resourceName, "mac", "00:00:00:00:00:00"), + resource.TestCheckResourceAttr(resourceName, "relation_hsrp_rs_group_pol", ""), + ), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupConfigWithOptionalValues(rName, rName, rName, rName, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_updated), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform_testacc"), + resource.TestCheckResourceAttr(resourceName, "description", "created while acceptance testing"), + resource.TestCheckResourceAttr(resourceName, "name_alias", "test_l3out_hsrp_interface_group"), + resource.TestCheckResourceAttr(resourceName, "config_issues", "GroupMac-Conflicts-Other-Group"), + resource.TestCheckResourceAttr(resourceName, "group_af", "ipv4"), + resource.TestCheckResourceAttr(resourceName, "group_id", "125"), + resource.TestCheckResourceAttr(resourceName, "group_name", "test"), + resource.TestCheckResourceAttr(resourceName, "ip", "10.20.30.50"), + resource.TestCheckResourceAttr(resourceName, "ip_obtain_mode", "admin"), + resource.TestCheckResourceAttr(resourceName, "mac", "02:10:45:00:00:56"), + resource.TestCheckResourceAttr(resourceName, "l3out_hsrp_interface_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s/hsrpIfP", rName, rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "relation_hsrp_rs_group_pol", ""), + testAccCheckAciL3outHsrpInterfaceGroupIdEqual(&l3out_hsrp_interface_group_default, &l3out_hsrp_interface_group_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccL3outHsrpInterfaceGroupRemovingRequiredField(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupConfigWithRequiredParams(rName, acctest.RandString(65)), + ExpectError: regexp.MustCompile(`property name of (.)+ failed validation`), + }, + + { + Config: CreateAccL3outHsrpInterfaceGroupConfigWithRequiredParams(rNameUpdated, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_updated), + resource.TestCheckResourceAttr(resourceName, "l3out_hsrp_interface_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s/hsrpIfP", rNameUpdated, rNameUpdated, rNameUpdated, rNameUpdated)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + testAccCheckAciL3outHsrpInterfaceGroupIdNotEqual(&l3out_hsrp_interface_group_default, &l3out_hsrp_interface_group_updated), + ), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupConfig(rName, rName, rName, rName, rName), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupConfigWithRequiredParams(rName, rNameUpdated), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_updated), + resource.TestCheckResourceAttr(resourceName, "l3out_hsrp_interface_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s/hsrpIfP", rName, rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "name", rNameUpdated), + testAccCheckAciL3outHsrpInterfaceGroupIdNotEqual(&l3out_hsrp_interface_group_default, &l3out_hsrp_interface_group_updated), + ), + }, + }, + }) +} + +func TestAccAciL3outHsrpInterfaceGroup_Update(t *testing.T) { + var l3out_hsrp_interface_group_default models.HSRPGroupProfile + var l3out_hsrp_interface_group_updated models.HSRPGroupProfile + resourceName := "aci_l3out_hsrp_interface_group.test" + rName1 := makeTestVariable(acctest.RandString(5)) + rName2 := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outHsrpInterfaceGroupDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outHsrpInterfaceGroupConfigWithIPObtainModeLearn(rName1, rName1, rName1, rName1, rName1), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_default), + resource.TestCheckResourceAttr(resourceName, "ip_obtain_mode", "learn"), + ), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "config_issues", "GroupName-Conflicts-Other-Group"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_updated), + resource.TestCheckResourceAttr(resourceName, "config_issues", "GroupName-Conflicts-Other-Group"), + testAccCheckAciL3outHsrpInterfaceGroupIdEqual(&l3out_hsrp_interface_group_default, &l3out_hsrp_interface_group_updated), + ), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "config_issues", "GroupVIP-Conflicts-Other-Group"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_updated), + resource.TestCheckResourceAttr(resourceName, "config_issues", "GroupVIP-Conflicts-Other-Group"), + testAccCheckAciL3outHsrpInterfaceGroupIdEqual(&l3out_hsrp_interface_group_default, &l3out_hsrp_interface_group_updated), + ), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "config_issues", "Multiple-Version-On-Interface"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_updated), + resource.TestCheckResourceAttr(resourceName, "config_issues", "Multiple-Version-On-Interface"), + testAccCheckAciL3outHsrpInterfaceGroupIdEqual(&l3out_hsrp_interface_group_default, &l3out_hsrp_interface_group_updated), + ), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "config_issues", "Secondary-vip-conflicts-if-ip"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_updated), + resource.TestCheckResourceAttr(resourceName, "config_issues", "Secondary-vip-conflicts-if-ip"), + testAccCheckAciL3outHsrpInterfaceGroupIdEqual(&l3out_hsrp_interface_group_default, &l3out_hsrp_interface_group_updated), + ), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "config_issues", "Secondary-vip-subnet-mismatch"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_updated), + resource.TestCheckResourceAttr(resourceName, "config_issues", "Secondary-vip-subnet-mismatch"), + testAccCheckAciL3outHsrpInterfaceGroupIdEqual(&l3out_hsrp_interface_group_default, &l3out_hsrp_interface_group_updated), + ), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "config_issues", "group-vip-conflicts-if-ip"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_updated), + resource.TestCheckResourceAttr(resourceName, "config_issues", "group-vip-conflicts-if-ip"), + testAccCheckAciL3outHsrpInterfaceGroupIdEqual(&l3out_hsrp_interface_group_default, &l3out_hsrp_interface_group_updated), + ), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "config_issues", "group-vip-subnet-mismatch"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_updated), + resource.TestCheckResourceAttr(resourceName, "config_issues", "group-vip-subnet-mismatch"), + testAccCheckAciL3outHsrpInterfaceGroupIdEqual(&l3out_hsrp_interface_group_default, &l3out_hsrp_interface_group_updated), + ), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "group_id", "255"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_updated), + resource.TestCheckResourceAttr(resourceName, "group_id", "255"), + testAccCheckAciL3outHsrpInterfaceGroupIdEqual(&l3out_hsrp_interface_group_default, &l3out_hsrp_interface_group_updated), + ), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "group_id", "4095"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_updated), + resource.TestCheckResourceAttr(resourceName, "group_id", "4095"), + testAccCheckAciL3outHsrpInterfaceGroupIdEqual(&l3out_hsrp_interface_group_default, &l3out_hsrp_interface_group_updated), + ), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "group_id", "2025"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_updated), + resource.TestCheckResourceAttr(resourceName, "group_id", "2025"), + testAccCheckAciL3outHsrpInterfaceGroupIdEqual(&l3out_hsrp_interface_group_default, &l3out_hsrp_interface_group_updated), + ), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupConfigWithIPObtainModeAuto(rName2, rName2, rName2, rName2, rName2), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_default), + resource.TestCheckResourceAttr(resourceName, "ip_obtain_mode", "auto"), + resource.TestCheckResourceAttr(resourceName, "group_af", "ipv6"), + ), + }, + }, + }) +} + +func TestAccAciL3outHsrpInterfaceGroup_Negative(t *testing.T) { + rName1 := makeTestVariable(acctest.RandString(5)) + rName2 := makeTestVariable(acctest.RandString(5)) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outHsrpInterfaceGroupDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outHsrpInterfaceGroupConfig(rName1, rName1, rName1, rName1, rName1), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupWithInValidParentDn(rName1), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class hsrpGroupP (.)+`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "description", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "annotation", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "name_alias", acctest.RandString(64)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "config_issues", randomValue), + ExpectError: regexp.MustCompile(`expected (.)+ to be one of(.)+, got(.)+`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "group_af", randomValue), + ExpectError: regexp.MustCompile(`expected (.)+ to be one of(.)+, got(.)+`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "ip_obtain_mode", randomValue), + ExpectError: regexp.MustCompile(`expected(.)+ to be one of(.)+, got(.)+`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "group_name", acctest.RandString(513)), + ExpectError: regexp.MustCompile(`property groupName of (.)+ failed validation`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "ip", randomValue), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "group_id", "-1"), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "group_id", "256"), + ExpectError: regexp.MustCompile(`Invalid Configuration HSRP V1 group id range is 0-255`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, "group_id", "4096"), + ExpectError: regexp.MustCompile(`Property (.)+ of (.)+ is out of range`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupUpdatedAttr(rName1, rName1, rName1, rName1, rName1, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named(.)+ is not expected here.`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupForAdmin(rName2, rName2, rName2, rName1, rName1), + ExpectError: regexp.MustCompile(`Invalid Configuration VIP Address cannot be empty with Admin Mode`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupForAuto(rName2, rName2, rName2, rName1, rName1), + ExpectError: regexp.MustCompile(`Invalid Configuration VIP configuration should be NULL, if learn/auto configuration is enabled.`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupForLearn(rName2, rName2, rName2, rName2, rName2), + ExpectError: regexp.MustCompile(`Invalid Configuration VIP configuration should be NULL, if learn/auto configuration is enabled.`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupForAdminAF6(rName2, rName2, rName2, rName2, rName2), + ExpectError: regexp.MustCompile(`Invalid Configuration HSRP V1 group is V4 only group`), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupConfig(rName1, rName1, rName1, rName1, rName1), + }, + }, + }) +} + +func TestAccAciL3outHsrpInterfaceGroup_RelationParameter(t *testing.T) { + relName1 := makeTestVariable(acctest.RandString(5)) + relName2 := makeTestVariable(acctest.RandString(5)) + var l3out_hsrp_interface_group_default models.HSRPGroupProfile + var l3out_hsrp_interface_group_updated models.HSRPGroupProfile + resourceName := "aci_l3out_hsrp_interface_group.test" + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outHsrpInterfaceGroupDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outHsrpInterfaceGroupConfig(rName, rName, rName, rName, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_default), + resource.TestCheckResourceAttr(resourceName, "relation_hsrp_rs_group_pol", ""), + ), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupConfigRel(rName, rName, rName, rName, rName, relName1), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_updated), + resource.TestCheckResourceAttr(resourceName, "relation_hsrp_rs_group_pol", fmt.Sprintf("uni/tn-%s/hsrpGroupPol-%s", rName, relName1)), + testAccCheckAciL3outHsrpInterfaceGroupIdEqual(&l3out_hsrp_interface_group_default, &l3out_hsrp_interface_group_updated), + ), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupConfigRel(rName, rName, rName, rName, rName, relName2), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_updated), + resource.TestCheckResourceAttr(resourceName, "relation_hsrp_rs_group_pol", fmt.Sprintf("uni/tn-%s/hsrpGroupPol-%s", rName, relName2)), + testAccCheckAciL3outHsrpInterfaceGroupIdEqual(&l3out_hsrp_interface_group_default, &l3out_hsrp_interface_group_updated), + ), + }, + { + Config: CreateAccL3outHsrpInterfaceGroupConfig(rName, rName, rName, rName, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHsrpInterfaceGroupExists(resourceName, &l3out_hsrp_interface_group_default), + resource.TestCheckResourceAttr(resourceName, "relation_hsrp_rs_group_pol", ""), + testAccCheckAciL3outHsrpInterfaceGroupIdEqual(&l3out_hsrp_interface_group_default, &l3out_hsrp_interface_group_updated), + ), + }, + }, + }) +} + +func TestAccAciL3outHsrpInterfaceGroup_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outHsrpInterfaceGroupDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outHsrpInterfaceGroupConfigs(rName), + }, + }, + }) +} + +func testAccCheckAciL3outHsrpInterfaceGroupExists(name string, l3out_hsrp_interface_group *models.HSRPGroupProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("L3out Hsrp Interface Group %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No L3out Hsrp Interface Group dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + l3out_hsrp_interface_groupFound := models.HSRPGroupProfileFromContainer(cont) + if l3out_hsrp_interface_groupFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("L3out Hsrp Interface Group %s not found", rs.Primary.ID) + } + *l3out_hsrp_interface_group = *l3out_hsrp_interface_groupFound + return nil + } +} + +func testAccCheckAciL3outHsrpInterfaceGroupDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing l3out_hsrp_interface_group destroy") + client := testAccProvider.Meta().(*client.Client) + for _, rs := range s.RootModule().Resources { + if rs.Type == "aci_l3out_hsrp_interface_group" { + cont, err := client.Get(rs.Primary.ID) + l3out_hsrp_interface_group := models.HSRPGroupProfileFromContainer(cont) + if err == nil { + return fmt.Errorf("L3out Hsrp Interface Group %s Still exists", l3out_hsrp_interface_group.DistinguishedName) + } + } else { + continue + } + } + return nil +} + +func testAccCheckAciL3outHsrpInterfaceGroupIdEqual(m1, m2 *models.HSRPGroupProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName != m2.DistinguishedName { + return fmt.Errorf("l3out_hsrp_interface_group DNs are not equal") + } + return nil + } +} + +func testAccCheckAciL3outHsrpInterfaceGroupIdNotEqual(m1, m2 *models.HSRPGroupProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName == m2.DistinguishedName { + return fmt.Errorf("l3out_hsrp_interface_group DNs are equal") + } + return nil + } +} + +func CreateL3outHsrpInterfaceGroupWithoutRequired(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName, attrName string) string { + fmt.Println("=== STEP Basic: testing l3out_hsrp_interface_group creation without ", attrName) + rBlock := ` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + ` + switch attrName { + case "l3out_hsrp_interface_profile_dn": + rBlock += ` + resource "aci_l3out_hsrp_interface_group" "test" { + # l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + } + ` + case "name": + rBlock += ` + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + # name = "%s" + } + ` + } + return fmt.Sprintf(rBlock, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName) +} + +func CreateAccL3outHsrpInterfaceGroupConfigWithRequiredParams(prName, rName string) string { + fmt.Printf("=== STEP testing l3out_hsrp_interface_group creation with parent resources name %s and resource name %s \n", prName, rName) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip = "10.20.30.50" + } + `, prName, prName, prName, prName, rName) + return resource +} + +func CreateAccL3outHsrpInterfaceGroupConfigs(rName string) string { + fmt.Println("=== STEP testing l3out_hsrp_interface_group muliple creation") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test1" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip = "10.20.30.50" + } + + resource "aci_l3out_hsrp_interface_group" "test2" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip = "10.20.30.50" + } + + resource "aci_l3out_hsrp_interface_group" "test3" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip = "10.20.30.50" + } + `, rName, rName, rName, rName, rName+"1", rName+"2", rName+"3") + return resource +} + +func CreateAccL3outHsrpInterfaceGroupConfigRel(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName, relName string) string { + fmt.Printf("=== STEP testing l3out_hsrp_interface_group creation with relation resource name %s\n", relName) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip = "10.20.30.40" + relation_hsrp_rs_group_pol = aci_hsrp_group_policy.test.id + } + + resource "aci_hsrp_group_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName, relName) + return resource +} + +func CreateAccL3outHsrpInterfaceGroupConfig(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName string) string { + fmt.Println("=== STEP testing l3out_hsrp_interface_group creation with required arguments and ip") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip = "10.20.30.40" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName) + return resource +} + +func CreateAccL3outHsrpInterfaceGroupWithInValidParentDn(rName string) string { + fmt.Println("=== STEP Negative Case: testing l3out_hsrp_interface_group creation with invalid parent Dn") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_tenant.test.id + name = "%s" + } + `, rName, rName) + return resource +} + +func CreateAccL3outHsrpInterfaceGroupConfigWithOptionalValues(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName string) string { + fmt.Println("=== STEP Basic: testing l3out_hsrp_interface_group creation with optional parameters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + description = "created while acceptance testing" + annotation = "orchestrator:terraform_testacc" + name_alias = "test_l3out_hsrp_interface_group" + config_issues = "GroupMac-Conflicts-Other-Group" + group_af = "ipv4" + group_id = "125" + group_name = "test" + ip = "10.20.30.50" + ip_obtain_mode = "admin" + mac = "02:10:45:00:00:56" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName) + + return resource +} + +func CreateAccL3outHsrpInterfaceGroupConfigWithIPObtainModeAuto(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName string) string { + fmt.Println("=== STEP Basic: testing l3out_hsrp_interface_group creation with ip_obtain_mode = auto and group_af = ipv6") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip_obtain_mode = "auto" + group_af = "ipv6" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName) + + return resource +} + +func CreateAccL3outHsrpInterfaceGroupConfigWithIPObtainModeLearn(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName string) string { + fmt.Println("=== STEP Basic: testing l3out_hsrp_interface_group creation with ip_obtain_mode = learn and required arguments") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + version = "v2" + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip_obtain_mode = "learn" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName) + + return resource +} + +func CreateAccL3outHsrpInterfaceGroupRemovingRequiredField() string { + fmt.Println("=== STEP Basic: testing l3out_hsrp_interface_group updation without required parameters") + resource := fmt.Sprintln(` + resource "aci_l3out_hsrp_interface_group" "test" { + description = "created while acceptance testing" + annotation = "tag" + name_alias = "test_l3out_hsrp_interface_group" + config_issues = "GroupMac-Conflicts-Other-Group" + group_af = "ipv6" + group_id = "1" + group_name = "test" + ip_obtain_mode = "auto" + } + `) + + return resource +} + +func CreateAccL3outHsrpInterfaceGroupForLearn(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName string) string { + fmt.Println("=== STEP testing l3out_hsrp_interface_group when ip_obtain_mode is learn and ip provided") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip_obtain_mode = "learn" + ip = "1.2.3.4" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName) + return resource +} + +func CreateAccL3outHsrpInterfaceGroupForAuto(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName string) string { + fmt.Println("=== STEP testing l3out_hsrp_interface_group when ip_obtain_mode is admin and ip provided") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip_obtain_mode = "auto" + ip = "1.2.3.4" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName) + return resource +} + +func CreateAccL3outHsrpInterfaceGroupForAdminAF6(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName string) string { + fmt.Println("=== STEP testing l3out_hsrp_interface_group when ip_obtain_mode is admin and group_af is ipv6") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip_obtain_mode = "admin" + group_af = "ipv6" + ip = "2001:0db8:85a3:0000:0000:8a2e:0370:7334" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName) + return resource +} + +func CreateAccL3outHsrpInterfaceGroupForAdmin(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName string) string { + fmt.Println("=== STEP testing l3out_hsrp_interface_group when ip_obtain_mode is admin and no ip provided") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip_obtain_mode = "admin" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName) + return resource +} + +func CreateAccL3outHsrpInterfaceGroupUpdatedAttr(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName, attribute, value string) string { + fmt.Printf("=== STEP testing l3out_hsrp_interface_group attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + %s = "%s" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, rName, attribute, value) + return resource +} diff --git a/testacc/resource_aci_hsrpifp_test.go b/testacc/resource_aci_hsrpifp_test.go new file mode 100644 index 000000000..a83db00db --- /dev/null +++ b/testacc/resource_aci_hsrpifp_test.go @@ -0,0 +1,531 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciL3outHSRPInterfaceProfile_Basic(t *testing.T) { + var l3out_hsrp_interface_profile_default models.L3outHSRPInterfaceProfile + var l3out_hsrp_interface_profile_updated models.L3outHSRPInterfaceProfile + resourceName := "aci_l3out_hsrp_interface_profile.test" + rName := makeTestVariable(acctest.RandString(5)) + rNameUpdated := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outHSRPInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateL3outHSRPInterfaceProfileWithoutRequired(rName, rName, rName, rName, "logical_interface_profile_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outHSRPInterfaceProfileConfig(rName, rName, rName, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHSRPInterfaceProfileExists(resourceName, &l3out_hsrp_interface_profile_default), + resource.TestCheckResourceAttr(resourceName, "logical_interface_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s", rName, rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "version", "v1"), + resource.TestCheckResourceAttr(resourceName, "relation_hsrp_rs_if_pol", ""), + ), + }, + { + Config: CreateAccL3outHSRPInterfaceProfileConfigWithOptionalValues(rName, rName, rName, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHSRPInterfaceProfileExists(resourceName, &l3out_hsrp_interface_profile_updated), + resource.TestCheckResourceAttr(resourceName, "logical_interface_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s", rName, rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform_testacc"), + resource.TestCheckResourceAttr(resourceName, "description", "created while acceptance testing"), + resource.TestCheckResourceAttr(resourceName, "name_alias", "test_l3out_hsrp_interface_profile"), + resource.TestCheckResourceAttr(resourceName, "version", "v2"), + resource.TestCheckResourceAttr(resourceName, "relation_hsrp_rs_if_pol", ""), + testAccCheckAciL3outHSRPInterfaceProfileIdEqual(&l3out_hsrp_interface_profile_default, &l3out_hsrp_interface_profile_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccL3outHSRPInterfaceProfileRemovingRequiredField(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outHSRPInterfaceProfileConfigWithRequiredParams(rNameUpdated), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHSRPInterfaceProfileExists(resourceName, &l3out_hsrp_interface_profile_updated), + resource.TestCheckResourceAttr(resourceName, "logical_interface_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s", rNameUpdated, rNameUpdated, rNameUpdated, rNameUpdated)), + testAccCheckAciL3outHSRPInterfaceProfileIdNotEqual(&l3out_hsrp_interface_profile_default, &l3out_hsrp_interface_profile_updated), + ), + }, + { + Config: CreateAccL3outHSRPInterfaceProfileConfig(rName, rName, rName, rName), + }, + }, + }) +} + +func TestAccAciL3outHSRPInterfaceProfile_Negative(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outHSRPInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outHSRPInterfaceProfileConfig(rName, rName, rName, rName), + }, + { + Config: CreateAccL3outHSRPInterfaceProfileWithInValidParentDn(rName), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class hsrpIfP (.)+`), + }, + { + Config: CreateAccL3outHSRPInterfaceProfileUpdatedAttr(rName, rName, rName, rName, "description", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outHSRPInterfaceProfileUpdatedAttr(rName, rName, rName, rName, "annotation", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outHSRPInterfaceProfileUpdatedAttr(rName, rName, rName, rName, "name_alias", acctest.RandString(64)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outHSRPInterfaceProfileUpdatedAttr(rName, rName, rName, rName, "version", randomValue), + ExpectError: regexp.MustCompile(`expected(.)+ to be one of (.)+, got(.)+`), + }, + + { + Config: CreateAccL3outHSRPInterfaceProfileUpdatedAttr(rName, rName, rName, rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccL3outHSRPInterfaceProfileConfig(rName, rName, rName, rName), + }, + }, + }) +} + +func TestAccAciL3outHSRPInterfaceProfile_RelationParameters(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + relName1 := makeTestVariable(acctest.RandString(5)) + relName2 := makeTestVariable(acctest.RandString(5)) + var l3out_hsrp_interface_profile_default models.L3outHSRPInterfaceProfile + var l3out_hsrp_interface_profile_updated models.L3outHSRPInterfaceProfile + resourceName := "aci_l3out_hsrp_interface_profile.test" + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outHSRPInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outHSRPInterfaceProfileConfig(rName, rName, rName, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHSRPInterfaceProfileExists(resourceName, &l3out_hsrp_interface_profile_default), + resource.TestCheckResourceAttr(resourceName, "relation_hsrp_rs_if_pol", ""), + ), + }, + { + Config: CreateAccL3outHSRPInterfaceProfileConfigRelParameter(rName, relName1), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHSRPInterfaceProfileExists(resourceName, &l3out_hsrp_interface_profile_updated), + resource.TestCheckResourceAttr(resourceName, "relation_hsrp_rs_if_pol", fmt.Sprintf("uni/tn-%s/hsrpIfPol-%s", rName, relName1)), + testAccCheckAciL3outHSRPInterfaceProfileIdEqual(&l3out_hsrp_interface_profile_default, &l3out_hsrp_interface_profile_updated), + ), + }, + { + Config: CreateAccL3outHSRPInterfaceProfileConfigRelParameter(rName, relName2), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHSRPInterfaceProfileExists(resourceName, &l3out_hsrp_interface_profile_updated), + resource.TestCheckResourceAttr(resourceName, "relation_hsrp_rs_if_pol", fmt.Sprintf("uni/tn-%s/hsrpIfPol-%s", rName, relName2)), + testAccCheckAciL3outHSRPInterfaceProfileIdEqual(&l3out_hsrp_interface_profile_default, &l3out_hsrp_interface_profile_updated), + ), + }, + { + Config: CreateAccL3outHSRPInterfaceProfileConfig(rName, rName, rName, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHSRPInterfaceProfileExists(resourceName, &l3out_hsrp_interface_profile_default), + resource.TestCheckResourceAttr(resourceName, "relation_hsrp_rs_if_pol", ""), + ), + }, + }, + }) +} + +func TestAccAciL3outHSRPInterfaceProfile_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outHSRPInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outHSRPInterfaceProfileConfigs(rName), + }, + }, + }) +} + +func testAccCheckAciL3outHSRPInterfaceProfileExists(name string, l3out_hsrp_interface_profile *models.L3outHSRPInterfaceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("L3out HSRP Interface Profile %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No L3out HSRP Interface Profile dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + l3out_hsrp_interface_profileFound := models.L3outHSRPInterfaceProfileFromContainer(cont) + if l3out_hsrp_interface_profileFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("L3out HSRP Interface Profile %s not found", rs.Primary.ID) + } + *l3out_hsrp_interface_profile = *l3out_hsrp_interface_profileFound + return nil + } +} + +func testAccCheckAciL3outHSRPInterfaceProfileDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing l3out_hsrp_interface_profile destroy") + client := testAccProvider.Meta().(*client.Client) + for _, rs := range s.RootModule().Resources { + if rs.Type == "aci_l3out_hsrp_interface_profile" { + cont, err := client.Get(rs.Primary.ID) + l3out_hsrp_interface_profile := models.L3outHSRPInterfaceProfileFromContainer(cont) + if err == nil { + return fmt.Errorf("L3out HSRP Interface Profile %s Still exists", l3out_hsrp_interface_profile.DistinguishedName) + } + } else { + continue + } + } + return nil +} + +func testAccCheckAciL3outHSRPInterfaceProfileIdEqual(m1, m2 *models.L3outHSRPInterfaceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName != m2.DistinguishedName { + return fmt.Errorf("l3out_hsrp_interface_profile DNs are not equal") + } + return nil + } +} + +func testAccCheckAciL3outHSRPInterfaceProfileIdNotEqual(m1, m2 *models.L3outHSRPInterfaceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName == m2.DistinguishedName { + return fmt.Errorf("l3out_hsrp_interface_profile DNs are equal") + } + return nil + } +} + +func CreateL3outHSRPInterfaceProfileWithoutRequired(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, attrName string) string { + fmt.Println("=== STEP Basic: testing l3out_hsrp_interface_profile creation without ", attrName) + rBlock := ` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + ` + switch attrName { + case "logical_interface_profile_dn": + rBlock += ` + resource "aci_l3out_hsrp_interface_profile" "test" { + # logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + ` + + } + return fmt.Sprintf(rBlock, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName) +} + +func CreateAccL3outHSRPInterfaceProfileConfigWithRequiredParams(rName string) string { + fmt.Println("=== STEP testing l3out_hsrp_interface_profile creation with updated resource name", rName) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccL3outHSRPInterfaceProfileConfigs(rName string) string { + fmt.Println("=== STEP testing l3out_hsrp_interface_profile multiple creation with required arguments") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test1" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_logical_interface_profile" "test2" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_logical_interface_profile" "test3" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test1" { + logical_interface_profile_dn = aci_logical_interface_profile.test1.id + } + + resource "aci_l3out_hsrp_interface_profile" "test2" { + logical_interface_profile_dn = aci_logical_interface_profile.test2.id + } + + resource "aci_l3out_hsrp_interface_profile" "test3" { + logical_interface_profile_dn = aci_logical_interface_profile.test3.id + } + `, rName, rName, rName, rName+"1", rName+"2", rName+"3") + return resource +} + +func CreateAccL3outHSRPInterfaceProfileConfig(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName string) string { + fmt.Println("=== STEP testing l3out_hsrp_interface_profile creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName) + return resource +} + +func CreateAccL3outHSRPInterfaceProfileConfigRelParameter(rName, relName string) string { + fmt.Printf("=== STEP testing l3out_hsrp_interface_profile creation with resource name %s and relation resource name %s\n", rName, relName) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_hsrp_interface_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + relation_hsrp_rs_if_pol = aci_hsrp_interface_policy.test.id + } + `, rName, rName, rName, rName, relName) + return resource +} + +func CreateAccL3outHSRPInterfaceProfileWithInValidParentDn(rName string) string { + fmt.Println("=== STEP Negative Case: testing l3out_hsrp_interface_profile creation with invalid logical_interface_profile_dn") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_tenant.test.id + } + `, rName) + return resource +} + +func CreateAccL3outHSRPInterfaceProfileConfigWithOptionalValues(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName string) string { + fmt.Println("=== STEP Basic: testing l3out_hsrp_interface_profile creation with optional parameters") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = "${aci_logical_interface_profile.test.id}" + description = "created while acceptance testing" + annotation = "orchestrator:terraform_testacc" + name_alias = "test_l3out_hsrp_interface_profile" + version = "v2" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName) + + return resource +} + +func CreateAccL3outHSRPInterfaceProfileRemovingRequiredField() string { + fmt.Println("=== STEP Basic: testing l3out_hsrp_interface_profile updation without required parameter") + resource := fmt.Sprintln(` + resource "aci_l3out_hsrp_interface_profile" "test" { + description = "created while acceptance testing" + annotation = "orchestrator:terraform_testacc" + name_alias = "test_l3out_hsrp_interface_profile" + version = "v2" + } + `) + + return resource +} + +func CreateAccL3outHSRPInterfaceProfileUpdatedAttr(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, attribute, value string) string { + fmt.Printf("=== STEP testing l3out_hsrp_interface_profile attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + %s = "%s" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, attribute, value) + return resource +} diff --git a/testacc/resource_aci_hsrpifpol_test.go b/testacc/resource_aci_hsrpifpol_test.go new file mode 100644 index 000000000..87dfced0a --- /dev/null +++ b/testacc/resource_aci_hsrpifpol_test.go @@ -0,0 +1,519 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciHsrpInterfacePolicy_Basic(t *testing.T) { + var hsrp_interface_policy_default models.HSRPInterfacePolicy + var hsrp_interface_policy_updated models.HSRPInterfacePolicy + resourceName := "aci_hsrp_interface_policy.test" + rName := makeTestVariable(acctest.RandString(5)) + rNameUpdated := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciHsrpInterfacePolicyDestroy, + Steps: []resource.TestStep{ + { + Config: CreateHsrpInterfacePolicyWithoutRequired(rName, rName, "tenant_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateHsrpInterfacePolicyWithoutRequired(rName, rName, "name"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccHsrpInterfacePolicyConfig(rName, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciHsrpInterfacePolicyExists(resourceName, &hsrp_interface_policy_default), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "ctrl.#", "0"), + resource.TestCheckResourceAttr(resourceName, "delay", "0"), + resource.TestCheckResourceAttr(resourceName, "reload_delay", "0"), + ), + }, + { + Config: CreateAccHsrpInterfacePolicyConfigWithOptionalValues(rName, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciHsrpInterfacePolicyExists(resourceName, &hsrp_interface_policy_updated), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform_testacc"), + resource.TestCheckResourceAttr(resourceName, "description", "created while acceptance testing"), + resource.TestCheckResourceAttr(resourceName, "name_alias", "test_hsrp_interface_policy"), + resource.TestCheckResourceAttr(resourceName, "ctrl.#", "1"), + resource.TestCheckResourceAttr(resourceName, "ctrl.0", "bfd"), + resource.TestCheckResourceAttr(resourceName, "delay", "1"), + resource.TestCheckResourceAttr(resourceName, "reload_delay", "1"), + testAccCheckAciHsrpInterfacePolicyIdEqual(&hsrp_interface_policy_default, &hsrp_interface_policy_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccHsrpInterfacePolicyConfigInvalidName(rName, acctest.RandString(65)), + ExpectError: regexp.MustCompile(`property name of (.)* failed validation`), + }, + + { + Config: CreateAccHsrpInterfacePolicyConfigWithUpdatedRequiredParams(rNameUpdated, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciHsrpInterfacePolicyExists(resourceName, &hsrp_interface_policy_updated), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rNameUpdated)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + testAccCheckAciHsrpInterfacePolicyIdNotEqual(&hsrp_interface_policy_default, &hsrp_interface_policy_updated), + ), + }, + { + Config: CreateAccHsrpInterfacePolicyConfig(rName, rName), + }, + { + Config: CreateAccHsrpInterfacePolicyConfigWithUpdatedRequiredParams(rName, rNameUpdated), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciHsrpInterfacePolicyExists(resourceName, &hsrp_interface_policy_updated), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + resource.TestCheckResourceAttr(resourceName, "name", rNameUpdated), + testAccCheckAciHsrpInterfacePolicyIdNotEqual(&hsrp_interface_policy_default, &hsrp_interface_policy_updated), + ), + }, + { + Config: CreateAccHsrpInterfacePolicyConfigUpdateWithoutRequiredArguments(rName, "description", acctest.RandString(5)), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccHsrpInterfacePolicyConfig(rName, rName), + }, + }, + }) +} + +func TestAccAciHsrpInterfacePolicy_Update(t *testing.T) { + var hsrp_interface_policy_default models.HSRPInterfacePolicy + var hsrp_interface_policy_updated models.HSRPInterfacePolicy + resourceName := "aci_hsrp_interface_policy.test" + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciHsrpInterfacePolicyDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccHsrpInterfacePolicyConfig(rName, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciHsrpInterfacePolicyExists(resourceName, &hsrp_interface_policy_default), + ), + }, + { + Config: CreateAccHsrpInterfacePolicyUpdatedAttrList(rName, rName, "ctrl", StringListtoString([]string{"bia"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciHsrpInterfacePolicyExists(resourceName, &hsrp_interface_policy_updated), + resource.TestCheckResourceAttr(resourceName, "ctrl.#", "1"), + resource.TestCheckResourceAttr(resourceName, "ctrl.0", "bia"), + testAccCheckAciHsrpInterfacePolicyIdEqual(&hsrp_interface_policy_default, &hsrp_interface_policy_updated), + ), + }, + { + Config: CreateAccHsrpInterfacePolicyUpdatedAttrList(rName, rName, "ctrl", StringListtoString([]string{"bia", "bfd"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciHsrpInterfacePolicyExists(resourceName, &hsrp_interface_policy_updated), + resource.TestCheckResourceAttr(resourceName, "ctrl.#", "2"), + resource.TestCheckResourceAttr(resourceName, "ctrl.0", "bia"), + resource.TestCheckResourceAttr(resourceName, "ctrl.1", "bfd"), + testAccCheckAciHsrpInterfacePolicyIdEqual(&hsrp_interface_policy_default, &hsrp_interface_policy_updated), + ), + }, + { + Config: CreateAccHsrpInterfacePolicyUpdatedAttrList(rName, rName, "ctrl", StringListtoString([]string{"bfd", "bia"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciHsrpInterfacePolicyExists(resourceName, &hsrp_interface_policy_updated), + resource.TestCheckResourceAttr(resourceName, "ctrl.#", "2"), + resource.TestCheckResourceAttr(resourceName, "ctrl.0", "bfd"), + resource.TestCheckResourceAttr(resourceName, "ctrl.1", "bia"), + testAccCheckAciHsrpInterfacePolicyIdEqual(&hsrp_interface_policy_default, &hsrp_interface_policy_updated), + ), + }, + { + Config: CreateAccHsrpInterfacePolicyUpdatedAttr(rName, rName, "delay", "5000"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciHsrpInterfacePolicyExists(resourceName, &hsrp_interface_policy_updated), + resource.TestCheckResourceAttr(resourceName, "delay", "5000"), + testAccCheckAciHsrpInterfacePolicyIdEqual(&hsrp_interface_policy_default, &hsrp_interface_policy_updated), + ), + }, + { + Config: CreateAccHsrpInterfacePolicyUpdatedAttr(rName, rName, "delay", "10000"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciHsrpInterfacePolicyExists(resourceName, &hsrp_interface_policy_updated), + resource.TestCheckResourceAttr(resourceName, "delay", "10000"), + testAccCheckAciHsrpInterfacePolicyIdEqual(&hsrp_interface_policy_default, &hsrp_interface_policy_updated), + ), + }, + { + Config: CreateAccHsrpInterfacePolicyUpdatedAttr(rName, rName, "reload_delay", "5000"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciHsrpInterfacePolicyExists(resourceName, &hsrp_interface_policy_updated), + resource.TestCheckResourceAttr(resourceName, "reload_delay", "5000"), + testAccCheckAciHsrpInterfacePolicyIdEqual(&hsrp_interface_policy_default, &hsrp_interface_policy_updated), + ), + }, + { + Config: CreateAccHsrpInterfacePolicyUpdatedAttr(rName, rName, "reload_delay", "10000"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciHsrpInterfacePolicyExists(resourceName, &hsrp_interface_policy_updated), + resource.TestCheckResourceAttr(resourceName, "reload_delay", "10000"), + testAccCheckAciHsrpInterfacePolicyIdEqual(&hsrp_interface_policy_default, &hsrp_interface_policy_updated), + ), + }, + }, + }) +} + +func TestAccAciHsrpInterfacePolicy_Negative(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := makeTestVariable(acctest.RandString(5)) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciHsrpInterfacePolicyDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccHsrpInterfacePolicyConfig(rName, rName), + }, + { + Config: CreateAccHsrpInterfacePolicyWithInvalidParentDn(rName, rName), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + { + Config: CreateAccHsrpInterfacePolicyUpdatedAttr(rName, rName, "description", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccHsrpInterfacePolicyUpdatedAttr(rName, rName, "annotation", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccHsrpInterfacePolicyUpdatedAttr(rName, rName, "name_alias", acctest.RandString(64)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccHsrpInterfacePolicyUpdatedAttrList(rName, rName, "ctrl", StringListtoString([]string{randomValue})), + ExpectError: regexp.MustCompile(`expected(.*)to be one of(.)*, got(.)*`), + }, + { + Config: CreateAccHsrpInterfacePolicyUpdatedAttrList(rName, rName, "ctrl", StringListtoString([]string{"bfd", "bfd"})), + ExpectError: regexp.MustCompile(`duplication is not supported in list`), + }, + { + Config: CreateAccHsrpInterfacePolicyUpdatedAttr(rName, rName, "delay", randomValue), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + { + Config: CreateAccHsrpInterfacePolicyUpdatedAttr(rName, rName, "reload_delay", randomValue), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + { + Config: CreateAccHsrpInterfacePolicyUpdatedAttr(rName, rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named(.)*is not expected here.`), + }, + { + Config: CreateAccHsrpInterfacePolicyConfig(rName, rName), + }, + }, + }) +} + +func TestAccHsrpInterfacePolicy_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciHsrpInterfacePolicyDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccAciHsrpInterfaceProfilesConfig(rName), + }, + }, + }) +} + +func testAccCheckAciHsrpInterfacePolicyExists(name string, hsrp_interface_policy *models.HSRPInterfacePolicy) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("Hsrp Interface Policy %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No Hsrp Interface Policy dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + hsrp_interface_policyFound := models.HSRPInterfacePolicyFromContainer(cont) + if hsrp_interface_policyFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("Hsrp Interface Policy %s not found", rs.Primary.ID) + } + *hsrp_interface_policy = *hsrp_interface_policyFound + return nil + } +} + +func testAccCheckAciHsrpInterfacePolicyDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing hsrp_interface_policy destroy") + client := testAccProvider.Meta().(*client.Client) + for _, rs := range s.RootModule().Resources { + if rs.Type == "aci_hsrp_interface_policy" { + cont, err := client.Get(rs.Primary.ID) + hsrp_interface_policy := models.HSRPInterfacePolicyFromContainer(cont) + if err == nil { + return fmt.Errorf("Hsrp Interface Policy %s Still exists", hsrp_interface_policy.DistinguishedName) + } + } else { + continue + } + } + return nil +} + +func testAccCheckAciHsrpInterfacePolicyIdEqual(m1, m2 *models.HSRPInterfacePolicy) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName != m2.DistinguishedName { + return fmt.Errorf("hsrp_interface_policy DNs are not equal") + } + return nil + } +} + +func testAccCheckAciHsrpInterfacePolicyIdNotEqual(m1, m2 *models.HSRPInterfacePolicy) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName == m2.DistinguishedName { + return fmt.Errorf("hsrp_interface_policy DNs are equal") + } + return nil + } +} + +func CreateAccAciHsrpInterfaceProfilesConfig(rName string) string { + fmt.Println("=== STEP creating multiple Hrsp Interface Profiles") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_hsrp_interface_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_hsrp_interface_policy" "test1" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_hsrp_interface_policy" "test2" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_hsrp_interface_policy" "test3" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, rName, rName, rName+"1", rName+"2", rName+"3") + return resource + +} +func CreateHsrpInterfacePolicyWithoutRequired(fvTenantName, rName, attrName string) string { + fmt.Println("=== STEP Basic: testing hsrp_interface_policy creation without Required Parameters ", attrName) + rBlock := ` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + ` + switch attrName { + case "tenant_dn": + rBlock += ` + resource "aci_hsrp_interface_policy" "test" { + # tenant_dn = aci_tenant.test.id + name = "%s" + } + ` + case "name": + rBlock += ` + resource "aci_hsrp_interface_policy" "test" { + tenant_dn = aci_tenant.test.id + # name = "%s" + } + ` + } + return fmt.Sprintf(rBlock, fvTenantName, rName) +} + +func CreateAccHsrpInterfacePolicyConfigWithUpdatedRequiredParams(rName, rName2 string) string { + fmt.Println("=== STEP testing hsrp_interface_policy updation of required arguments") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + + resource "aci_hsrp_interface_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, rName, rName2) + return resource +} + +func CreateAccHsrpInterfacePolicyConfigUpdateWithoutRequiredArguments(rName, attribute, value string) string { + fmt.Println("=== STEP testing hsrp_interface_policy updation without required arguments") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + + resource "aci_hsrp_interface_policy" "test" { + %s = "%s" + } + `, rName, attribute, value) + return resource +} + +func CreateAccHsrpInterfacePolicyConfigInvalidName(prName, rName string) string { + fmt.Println("=== STEP testing hsrp_interface_policy creation with Invalid Name") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + + resource "aci_hsrp_interface_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, prName, rName) + return resource +} + +func CreateAccHsrpInterfacePolicyConfig(fvTenantName, rName string) string { + fmt.Println("=== STEP testing hsrp_interface_policy creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + + resource "aci_hsrp_interface_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, fvTenantName, rName) + return resource +} + +func CreateAccHsrpInterfacePolicyWithInvalidParentDn(fvTenantName, rName string) string { + fmt.Println("=== STEP Negative Case: testing hsrp_interface_policy creation with invalid parent Dn") + resource := fmt.Sprintf(` + + resource "aci_aaa_domain" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + + resource "aci_hsrp_interface_policy" "test" { + tenant_dn = aci_aaa_domain.test.id + name = "%s" + } + `, fvTenantName, rName) + return resource +} + +func CreateAccHsrpInterfacePolicyConfigWithOptionalValues(fvTenantName, rName string) string { + fmt.Println("=== STEP Basic: testing hsrp_interface_policy creation with optional parameters") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + + resource "aci_hsrp_interface_policy" "test" { + tenant_dn = "${aci_tenant.test.id}" + name = "%s" + description = "created while acceptance testing" + annotation = "orchestrator:terraform_testacc" + name_alias = "test_hsrp_interface_policy" + ctrl = ["bfd"] + delay = "1" + reload_delay = "1" + } + `, fvTenantName, rName) + + return resource +} + +func CreateAccHsrpInterfacePolicyUpdatedAttr(fvTenantName, rName, attribute, value string) string { + fmt.Printf("=== STEP testing hsrp_interface_policy attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + + resource "aci_hsrp_interface_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + %s = "%s" + } + `, fvTenantName, rName, attribute, value) + return resource +} + +func CreateAccHsrpInterfacePolicyUpdatedAttrList(fvTenantName, rName, attribute, value string) string { + fmt.Printf("=== STEP testing hsrp_interface_policy attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + + resource "aci_hsrp_interface_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + %s = %s + } + `, fvTenantName, rName, attribute, value) + return resource +} diff --git a/testacc/resource_aci_hsrpsecvip_test.go b/testacc/resource_aci_hsrpsecvip_test.go new file mode 100644 index 000000000..1265ab09c --- /dev/null +++ b/testacc/resource_aci_hsrpsecvip_test.go @@ -0,0 +1,625 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciL3outHSRPSecondaryVIP_Basic(t *testing.T) { + var l3out_hsrp_secondary_vip_default models.L3outHSRPSecondaryVIP + var l3out_hsrp_secondary_vip_updated models.L3outHSRPSecondaryVIP + resourceName := "aci_l3out_hsrp_secondary_vip.test" + rName := makeTestVariable(acctest.RandString(5)) + rNameUpdated := makeTestVariable(acctest.RandString(5)) + ip, _ := acctest.RandIpAddress("10.1.0.0/16") + ipUpdated, _ := acctest.RandIpAddress("10.2.0.0/16") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outHSRPSecondaryVIPDestroy, + Steps: []resource.TestStep{ + { + Config: CreateL3outHSRPSecondaryVIPWithoutRequired(rName, rName, rName, rName, rName, ip, "l3out_hsrp_interface_group_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateL3outHSRPSecondaryVIPWithoutRequired(rName, rName, rName, rName, rName, ip, "ip"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPConfig(rName, rName, rName, rName, rName, ip), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHSRPSecondaryVIPExists(resourceName, &l3out_hsrp_secondary_vip_default), + resource.TestCheckResourceAttr(resourceName, "l3out_hsrp_interface_group_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s/hsrpIfP/hsrpGroupP-%s", rName, rName, rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "ip", ip), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "config_issues", "none"), + ), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPConfigWithOptionalValues(rName, rName, rName, rName, rName, ip), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHSRPSecondaryVIPExists(resourceName, &l3out_hsrp_secondary_vip_updated), + resource.TestCheckResourceAttr(resourceName, "l3out_hsrp_interface_group_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s/hsrpIfP/hsrpGroupP-%s", rName, rName, rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "ip", ip), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform_testacc"), + resource.TestCheckResourceAttr(resourceName, "description", "created while acceptance testing"), + resource.TestCheckResourceAttr(resourceName, "name_alias", "test_l3out_hsrp_secondary_vip"), + resource.TestCheckResourceAttr(resourceName, "config_issues", "GroupMac-Conflicts-Other-Group"), + testAccCheckAciL3outHSRPSecondaryVIPIdEqual(&l3out_hsrp_secondary_vip_default, &l3out_hsrp_secondary_vip_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccL3outHSRPSecondaryVIPWithInvalidIP(rName), + ExpectError: regexp.MustCompile(`unknown property value (.)+`), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPRemovingRequiredField(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPConfigWithRequiredParams(rNameUpdated, ip), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHSRPSecondaryVIPExists(resourceName, &l3out_hsrp_secondary_vip_updated), + resource.TestCheckResourceAttr(resourceName, "l3out_hsrp_interface_group_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s/hsrpIfP/hsrpGroupP-%s", rNameUpdated, rNameUpdated, rNameUpdated, rNameUpdated, rNameUpdated)), + resource.TestCheckResourceAttr(resourceName, "ip", ip), + testAccCheckAciL3outHSRPSecondaryVIPIdNotEqual(&l3out_hsrp_secondary_vip_default, &l3out_hsrp_secondary_vip_updated), + ), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPConfig(rName, rName, rName, rName, rName, ip), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPConfigWithRequiredParams(rName, ipUpdated), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHSRPSecondaryVIPExists(resourceName, &l3out_hsrp_secondary_vip_updated), + resource.TestCheckResourceAttr(resourceName, "l3out_hsrp_interface_group_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s/hsrpIfP/hsrpGroupP-%s", rName, rName, rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "ip", ipUpdated), + testAccCheckAciL3outHSRPSecondaryVIPIdNotEqual(&l3out_hsrp_secondary_vip_default, &l3out_hsrp_secondary_vip_updated), + ), + }, + }, + }) +} + +func TestAccAciL3outHSRPSecondaryVIP_Update(t *testing.T) { + var l3out_hsrp_secondary_vip_default models.L3outHSRPSecondaryVIP + var l3out_hsrp_secondary_vip_updated models.L3outHSRPSecondaryVIP + resourceName := "aci_l3out_hsrp_secondary_vip.test" + rName := makeTestVariable(acctest.RandString(5)) + ip, _ := acctest.RandIpAddress("10.3.0.0/16") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outHSRPSecondaryVIPDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outHSRPSecondaryVIPConfig(rName, rName, rName, rName, rName, ip), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHSRPSecondaryVIPExists(resourceName, &l3out_hsrp_secondary_vip_default), + ), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPUpdatedAttr(rName, rName, rName, rName, rName, ip, "config_issues", "GroupName-Conflicts-Other-Group"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHSRPSecondaryVIPExists(resourceName, &l3out_hsrp_secondary_vip_updated), + resource.TestCheckResourceAttr(resourceName, "config_issues", "GroupName-Conflicts-Other-Group"), + testAccCheckAciL3outHSRPSecondaryVIPIdEqual(&l3out_hsrp_secondary_vip_default, &l3out_hsrp_secondary_vip_updated), + ), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPUpdatedAttr(rName, rName, rName, rName, rName, ip, "config_issues", "GroupVIP-Conflicts-Other-Group"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHSRPSecondaryVIPExists(resourceName, &l3out_hsrp_secondary_vip_updated), + resource.TestCheckResourceAttr(resourceName, "config_issues", "GroupVIP-Conflicts-Other-Group"), + testAccCheckAciL3outHSRPSecondaryVIPIdEqual(&l3out_hsrp_secondary_vip_default, &l3out_hsrp_secondary_vip_updated), + ), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPUpdatedAttr(rName, rName, rName, rName, rName, ip, "config_issues", "Multiple-Version-On-Interface"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHSRPSecondaryVIPExists(resourceName, &l3out_hsrp_secondary_vip_updated), + resource.TestCheckResourceAttr(resourceName, "config_issues", "Multiple-Version-On-Interface"), + testAccCheckAciL3outHSRPSecondaryVIPIdEqual(&l3out_hsrp_secondary_vip_default, &l3out_hsrp_secondary_vip_updated), + ), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPUpdatedAttr(rName, rName, rName, rName, rName, ip, "config_issues", "Secondary-vip-conflicts-if-ip"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHSRPSecondaryVIPExists(resourceName, &l3out_hsrp_secondary_vip_updated), + resource.TestCheckResourceAttr(resourceName, "config_issues", "Secondary-vip-conflicts-if-ip"), + testAccCheckAciL3outHSRPSecondaryVIPIdEqual(&l3out_hsrp_secondary_vip_default, &l3out_hsrp_secondary_vip_updated), + ), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPUpdatedAttr(rName, rName, rName, rName, rName, ip, "config_issues", "Secondary-vip-subnet-mismatch"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHSRPSecondaryVIPExists(resourceName, &l3out_hsrp_secondary_vip_updated), + resource.TestCheckResourceAttr(resourceName, "config_issues", "Secondary-vip-subnet-mismatch"), + testAccCheckAciL3outHSRPSecondaryVIPIdEqual(&l3out_hsrp_secondary_vip_default, &l3out_hsrp_secondary_vip_updated), + ), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPUpdatedAttr(rName, rName, rName, rName, rName, ip, "config_issues", "group-vip-conflicts-if-ip"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHSRPSecondaryVIPExists(resourceName, &l3out_hsrp_secondary_vip_updated), + resource.TestCheckResourceAttr(resourceName, "config_issues", "group-vip-conflicts-if-ip"), + testAccCheckAciL3outHSRPSecondaryVIPIdEqual(&l3out_hsrp_secondary_vip_default, &l3out_hsrp_secondary_vip_updated), + ), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPUpdatedAttr(rName, rName, rName, rName, rName, ip, "config_issues", "group-vip-subnet-mismatch"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outHSRPSecondaryVIPExists(resourceName, &l3out_hsrp_secondary_vip_updated), + resource.TestCheckResourceAttr(resourceName, "config_issues", "group-vip-subnet-mismatch"), + testAccCheckAciL3outHSRPSecondaryVIPIdEqual(&l3out_hsrp_secondary_vip_default, &l3out_hsrp_secondary_vip_updated), + ), + }, + }, + }) +} + +func TestAccAciL3outHSRPSecondaryVIP_Negative(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + ip, _ := acctest.RandIpAddress("10.4.0.0/16") + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outHSRPSecondaryVIPDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outHSRPSecondaryVIPConfig(rName, rName, rName, rName, rName, ip), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPWithInValidParentDn(rName, ip), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class hsrpSecVip (.)+`), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPUpdatedAttr(rName, rName, rName, rName, rName, ip, "description", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPUpdatedAttr(rName, rName, rName, rName, rName, ip, "annotation", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPUpdatedAttr(rName, rName, rName, rName, rName, ip, "name_alias", acctest.RandString(64)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPUpdatedAttr(rName, rName, rName, rName, rName, ip, "config_issues", randomValue), + ExpectError: regexp.MustCompile(`expected (.)+ to be one of (.)+, got(.)+`), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPUpdatedAttr(rName, rName, rName, rName, rName, ip, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccL3outHSRPSecondaryVIPConfig(rName, rName, rName, rName, rName, ip), + }, + }, + }) +} + +func TestAccAciL3outHSRPSecondaryVIP_MulipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + ip1, _ := acctest.RandIpAddress("10.5.0.0/16") + ip2, _ := acctest.RandIpAddress("10.6.0.0/16") + ip3, _ := acctest.RandIpAddress("10.7.0.0/16") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outHSRPSecondaryVIPDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outHSRPSecondaryVIPConfigs(rName, rName, rName, rName, rName, ip1, ip2, ip3), + }, + }, + }) +} + +func CreateAccL3outHSRPSecondaryVIPWithInvalidIP(rName string) string { + fmt.Println("=== STEP Basic: testing l3out_hsrp_secondary_vip creation with invalid IP") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip_obtain_mode = "learn" + } + + resource "aci_l3out_hsrp_secondary_vip" "test" { + l3out_hsrp_interface_group_dn = aci_l3out_hsrp_interface_group.test.id + ip = "%s" + } + `, rName, rName, rName, rName, rName, rName) + return resource +} + +func testAccCheckAciL3outHSRPSecondaryVIPExists(name string, l3out_hsrp_secondary_vip *models.L3outHSRPSecondaryVIP) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("L3out HSRP Secondary VIP %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No L3out HSRP Secondary VIP dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + l3out_hsrp_secondary_vipFound := models.L3outHSRPSecondaryVIPFromContainer(cont) + if l3out_hsrp_secondary_vipFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("L3out HSRP Secondary VIP %s not found", rs.Primary.ID) + } + *l3out_hsrp_secondary_vip = *l3out_hsrp_secondary_vipFound + return nil + } +} + +func testAccCheckAciL3outHSRPSecondaryVIPDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing l3out_hsrp_secondary_vip destroy") + client := testAccProvider.Meta().(*client.Client) + for _, rs := range s.RootModule().Resources { + if rs.Type == "aci_l3out_hsrp_secondary_vip" { + cont, err := client.Get(rs.Primary.ID) + l3out_hsrp_secondary_vip := models.L3outHSRPSecondaryVIPFromContainer(cont) + if err == nil { + return fmt.Errorf("L3out HSRP Secondary VIP %s Still exists", l3out_hsrp_secondary_vip.DistinguishedName) + } + } else { + continue + } + } + return nil +} + +func testAccCheckAciL3outHSRPSecondaryVIPIdEqual(m1, m2 *models.L3outHSRPSecondaryVIP) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName != m2.DistinguishedName { + return fmt.Errorf("l3out_hsrp_secondary_vip DNs are not equal") + } + return nil + } +} + +func testAccCheckAciL3outHSRPSecondaryVIPIdNotEqual(m1, m2 *models.L3outHSRPSecondaryVIP) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName == m2.DistinguishedName { + return fmt.Errorf("l3out_hsrp_secondary_vip DNs are equal") + } + return nil + } +} + +func CreateL3outHSRPSecondaryVIPWithoutRequired(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip, attrName string) string { + fmt.Println("=== STEP Basic: testing l3out_hsrp_secondary_vip creation without ", attrName) + rBlock := ` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip_obtain_mode = "learn" + } + + ` + switch attrName { + case "l3out_hsrp_interface_group_dn": + rBlock += ` + resource "aci_l3out_hsrp_secondary_vip" "test" { + # l3out_hsrp_interface_group_dn = aci_l3out_hsrp_interface_group.test.id + ip = "%s" + } + ` + case "ip": + rBlock += ` + resource "aci_l3out_hsrp_secondary_vip" "test" { + l3out_hsrp_interface_group_dn = aci_l3out_hsrp_interface_group.test.id + # ip = "%s" + } + ` + } + return fmt.Sprintf(rBlock, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip) +} + +func CreateAccL3outHSRPSecondaryVIPConfigWithRequiredParams(rName, ip string) string { + fmt.Printf("=== STEP testing l3out_hsrp_secondary_vip creation with parent resources name %s and ip %s\n", rName, ip) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip_obtain_mode = "learn" + } + + resource "aci_l3out_hsrp_secondary_vip" "test" { + l3out_hsrp_interface_group_dn = aci_l3out_hsrp_interface_group.test.id + ip = "%s" + } + `, rName, rName, rName, rName, rName, ip) + return resource +} + +func CreateAccL3outHSRPSecondaryVIPConfig(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip string) string { + fmt.Println("=== STEP testing l3out_hsrp_secondary_vip creation with required arguments only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip_obtain_mode = "learn" + } + resource "aci_l3out_hsrp_secondary_vip" "test" { + l3out_hsrp_interface_group_dn = aci_l3out_hsrp_interface_group.test.id + ip = "%s" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip) + return resource +} + +func CreateAccL3outHSRPSecondaryVIPConfigs(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip1, ip2, ip3 string) string { + fmt.Println("=== STEP testing l3out_hsrp_secondary_vip multiple creation") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip_obtain_mode = "learn" + } + resource "aci_l3out_hsrp_secondary_vip" "test1" { + l3out_hsrp_interface_group_dn = aci_l3out_hsrp_interface_group.test.id + ip = "%s" + } + resource "aci_l3out_hsrp_secondary_vip" "test2" { + l3out_hsrp_interface_group_dn = aci_l3out_hsrp_interface_group.test.id + ip = "%s" + } + resource "aci_l3out_hsrp_secondary_vip" "test3" { + l3out_hsrp_interface_group_dn = aci_l3out_hsrp_interface_group.test.id + ip = "%s" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip1, ip2, ip3) + return resource +} + +func CreateAccL3outHSRPSecondaryVIPWithInValidParentDn(rName, ip string) string { + fmt.Println("=== STEP Negative Case: testing l3out_hsrp_secondary_vip creation with invalid parent Dn") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3out_hsrp_secondary_vip" "test" { + l3out_hsrp_interface_group_dn = aci_tenant.test.id + ip = "%s" + } + `, rName, ip) + return resource +} + +func CreateAccL3outHSRPSecondaryVIPConfigWithOptionalValues(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip string) string { + fmt.Println("=== STEP Basic: testing l3out_hsrp_secondary_vip creation with optional parameters") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip_obtain_mode = "learn" + } + + resource "aci_l3out_hsrp_secondary_vip" "test" { + l3out_hsrp_interface_group_dn = aci_l3out_hsrp_interface_group.test.id + ip = "%s" + description = "created while acceptance testing" + annotation = "orchestrator:terraform_testacc" + name_alias = "test_l3out_hsrp_secondary_vip" + config_issues = "GroupMac-Conflicts-Other-Group" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip) + + return resource +} + +func CreateAccL3outHSRPSecondaryVIPRemovingRequiredField() string { + fmt.Println("=== STEP Basic: testing l3out_hsrp_secondary_vip updation without required parameters") + resource := fmt.Sprintln(` + resource "aci_l3out_hsrp_secondary_vip" "test" { + description = "created while acceptance testing" + annotation = "tag" + name_alias = "test_l3out_hsrp_secondary_vip" + config_issues = "GroupMac-Conflicts-Other-Group" + } + `) + + return resource +} + +func CreateAccL3outHSRPSecondaryVIPUpdatedAttr(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip, attribute, value string) string { + fmt.Printf("=== STEP testing l3out_hsrp_secondary_vip attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_hsrp_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + } + + resource "aci_l3out_hsrp_interface_group" "test" { + l3out_hsrp_interface_profile_dn = aci_l3out_hsrp_interface_profile.test.id + name = "%s" + ip_obtain_mode = "learn" + } + + resource "aci_l3out_hsrp_secondary_vip" "test" { + l3out_hsrp_interface_group_dn = aci_l3out_hsrp_interface_group.test.id + ip = "%s" + %s = "%s" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, hsrpGroupPName, ip, attribute, value) + return resource +} diff --git a/testacc/resource_aci_l3extOut_test.go b/testacc/resource_aci_l3extOut_test.go new file mode 100644 index 000000000..76871b734 --- /dev/null +++ b/testacc/resource_aci_l3extOut_test.go @@ -0,0 +1,777 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciL3Outside_Basic(t *testing.T) { + var l3outside_default models.L3Outside + var l3outside_updated models.L3Outside + resourceName := "aci_l3_outside.test" + rName := makeTestVariable(acctest.RandString(5)) + rOther := makeTestVariable(acctest.RandString(5)) + prOther := makeTestVariable(acctest.RandString(5)) + longrName := acctest.RandString(65) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3OutsideDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3OutsideWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3OutsideWithoutTenantDn(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3OutsideConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_default), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "enforce_rtctrl.#", "1"), + resource.TestCheckResourceAttr(resourceName, "enforce_rtctrl.0", "export"), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "unspecified"), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_dampening_pol.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_interleak_pol", ""), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_l3_dom_att", ""), + ), + }, + { + Config: CreateAccL3OutsideConfigWithOptionalValues(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "annotation", "tag_l3out"), + resource.TestCheckResourceAttr(resourceName, "description", "from terraform"), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "name_alias", "alias_out"), + resource.TestCheckResourceAttr(resourceName, "enforce_rtctrl.#", "2"), + resource.TestCheckResourceAttr(resourceName, "enforce_rtctrl.0", "export"), + resource.TestCheckResourceAttr(resourceName, "enforce_rtctrl.1", "import"), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS0"), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_dampening_pol.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_interleak_pol", ""), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_l3_dom_att", ""), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_out_to_bd_public_subnet_holder.#", "0"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccl3outsideConfigWithAnotherName(rName, rOther), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + testAccCheckAciL3OutsideIdNotEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideConfig(rName), + }, + { + Config: CreateAccl3outsideConfigWithAnotherTenantDn(prOther, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + testAccCheckAciL3OutsideIdNotEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccl3outsideConfigUpdateWithoutTenantdn(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccl3outsideConfigUpdateWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccl3outsideConfigUpdateWithInvalidName(rName, longrName), + ExpectError: regexp.MustCompile(fmt.Sprintf("property name of out-%s failed validation for value '%s'", longrName, longrName)), + }, + { + Config: CreateAccL3OutsideConfig(rName), + }, + }, + }) +} + +func TestAccAciL3Outside_Update(t *testing.T) { + var l3outside_default models.L3Outside + var l3outside_updated models.L3Outside + resourceName := "aci_l3_outside.test" + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3OutsideDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3OutsideConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_default), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "CS1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS1"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "AF11"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF11"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "AF12"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF12"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "AF13"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF13"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "CS2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS2"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "AF21"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF21"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "AF22"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF22"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "AF23"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF23"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "CS3"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS3"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "AF31"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF31"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "AF32"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF32"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "AF33"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF33"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "CS4"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS4"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "AF41"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF41"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "AF42"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF42"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "AF43"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF43"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "CS5"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS5"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "VA"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "VA"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "EF"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "EF"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "CS6"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS6"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", "CS7"), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS7"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideUpdatedAttrList(rName, "enforce_rtctrl", StringListtoString([]string{"import", "export"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "enforce_rtctrl.#", "2"), + resource.TestCheckResourceAttr(resourceName, "enforce_rtctrl.0", "import"), + resource.TestCheckResourceAttr(resourceName, "enforce_rtctrl.1", "export"), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + }, + }) +} +func TestAccAciL3Outside_NegativeCases(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + longDescAnnotation := acctest.RandString(129) + longNameAlias := acctest.RandString(64) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3OutsideDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3OutsideConfig(rName), + }, + { + Config: CreateAccL3OutsideUpdatedAttrList(rName, "enforce_rtctrl", StringListtoString([]string{"import"})), + ExpectError: regexp.MustCompile(`Invalid Configuration Unenforced Route Control is not supported for Export direction.`), + }, + { + Config: CreateAccl3outsideConfigWithInvalidTenantdn(rName), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class l3extOut (.)+`), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "annotation", longDescAnnotation), + ExpectError: regexp.MustCompile(`property annotation of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "description", longDescAnnotation), + ExpectError: regexp.MustCompile(`property descr of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "name_alias", longNameAlias), + ExpectError: regexp.MustCompile(`property nameAlias of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3OutsideUpdatedAttrList(rName, "enforce_rtctrl", StringListtoString([]string{randomValue})), + ExpectError: regexp.MustCompile(`expected enforce_rtctrl.0 to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccL3OutsideUpdatedAttrList(rName, "enforce_rtctrl", StringListtoString([]string{"export", "export"})), + ExpectError: regexp.MustCompile(`duplication is not supported in list`), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, "target_dscp", randomValue), + ExpectError: regexp.MustCompile(`expected target_dscp to be one of (.)+ got (.)+`), + }, + { + Config: CreateAccL3OutsideUpdatedAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccL3OutsideConfig(rName), + }, + }, + }) +} + +func TestAccAciL3Outside_reltionalParameters(t *testing.T) { + var l3outside_default models.L3Outside + var l3outside_updated models.L3Outside + resourceName := "aci_l3_outside.test" + rName := makeTestVariable(acctest.RandString(5)) + rsRelName1 := acctest.RandString(5) + rsRelName2 := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3OutsideDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3OutsideConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_default), + ), + }, + { + Config: CreateAccL3OutsidUpdatedL3OutsideIntial(rName, rsRelName1), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_out_to_bd_public_subnet_holder.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_l3_dom_att", ""), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_interleak_pol", fmt.Sprintf("uni/tn-%s/prof-%s", rName, rsRelName1)), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_ectx", fmt.Sprintf("uni/tn-%s/ctx-%s", rName, rsRelName1)), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_dampening_pol.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "relation_l3ext_rs_dampening_pol.*", map[string]string{ + "af": "ipv4-ucast", + "tn_rtctrl_profile_name": fmt.Sprintf("uni/tn-%s/prof-%s", rName, rsRelName1), + }), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsidUpdatedL3OutsideFinal(rName, rsRelName1, rsRelName2), + Check: resource.ComposeTestCheckFunc( + testAccCheckl3OutsideExists(resourceName, &l3outside_updated), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_out_to_bd_public_subnet_holder.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_l3_dom_att", ""), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_interleak_pol", fmt.Sprintf("uni/tn-%s/prof-%s", rName, rsRelName2)), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_ectx", fmt.Sprintf("uni/tn-%s/ctx-%s", rName, rsRelName2)), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_dampening_pol.#", "2"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "relation_l3ext_rs_dampening_pol.*", map[string]string{ + "af": "ipv4-ucast", + "tn_rtctrl_profile_name": fmt.Sprintf("uni/tn-%s/prof-%s", rName, rsRelName1), + }), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "relation_l3ext_rs_dampening_pol.*", map[string]string{ + "af": "ipv6-ucast", + "tn_rtctrl_profile_name": fmt.Sprintf("uni/tn-%s/prof-%s", rName, rsRelName2), + }), + testAccCheckAciL3OutsideIdEqual(&l3outside_default, &l3outside_updated), + ), + }, + { + Config: CreateAccL3OutsideConfig(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_out_to_bd_public_subnet_holder.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_l3_dom_att", ""), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_interleak_pol", ""), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_ectx", ""), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_dampening_pol.#", "0"), + ), + }, + }, + }) +} + +func TestAccAciL3Outside_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3OutsideDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3OutsideConfigMultiple(rName), + }, + }, + }) +} + +func testAccCheckl3OutsideExists(name string, l3Outside *models.L3Outside) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("l3Outside %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No l3Outside dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + l3OutsideFound := models.L3OutsideFromContainer(cont) + if l3OutsideFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("l3Outside %s not found", rs.Primary.ID) + } + *l3Outside = *l3OutsideFound + return nil + } +} + +func testAccCheckAciL3OutsideDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing L3Outside destroy") + client := testAccProvider.Meta().(*client.Client) + + for _, rs := range s.RootModule().Resources { + + if rs.Type == "aci_l3_outside" { + cont, err := client.Get(rs.Primary.ID) + aci := models.L3OutsideFromContainer(cont) + if err == nil { + return fmt.Errorf("L3Outside %s Still exists", aci.DistinguishedName) + } + + } else { + continue + } + } + + return nil +} + +func testAccCheckAciL3OutsideIdEqual(l3outside1, l3outside2 *models.L3Outside) resource.TestCheckFunc { + return func(s *terraform.State) error { + if l3outside1.DistinguishedName != l3outside2.DistinguishedName { + return fmt.Errorf("L3Outside DNs are not equal") + } + return nil + } +} + +func testAccCheckAciL3OutsideIdNotEqual(l3outside1, l3outside2 *models.L3Outside) resource.TestCheckFunc { + return func(s *terraform.State) error { + if l3outside1.DistinguishedName == l3outside2.DistinguishedName { + return fmt.Errorf("L3Outside DNs are equal") + } + return nil + } +} + +func CreateAccL3OutsideWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing L3Outside creation without giving Name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + } + `, rName) + return resource +} + +func CreateAccL3OutsideWithoutTenantDn(rName string) string { + fmt.Println("=== STEP Basic: testing L3Outside creation without giving Tenant dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + name = "%s" + } + `, rName, rName) + return resource +} + +func CreateAccl3outsideConfigUpdateWithoutTenantdn(rName string) string { + fmt.Println("=== STEP Basic: testing L3outside update without giving Tenant Dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + name = "%s" + } + `, rName, rName) + return resource +} + +func CreateAccl3outsideConfigUpdateWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing L3outside update without giving Name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + } + `, rName) + return resource +} + +func CreateAccl3outsideConfigUpdateWithInvalidName(parentName, rName string) string { + fmt.Printf("=== STEP Basic: testing L3outside creation with parent resource name %s and name %s\n", parentName, rName) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name= "%s" + } + `, parentName, rName) + return resource +} + +func CreateAccl3outsideConfigWithAnotherName(parentName, rName string) string { + fmt.Printf("=== STEP Basic: testing l3outside creation with different l3outside name %s \n", rName) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + `, parentName, rName) + return resource +} + +func CreateAccl3outsideConfigWithAnotherTenantDn(parentName, rName string) string { + fmt.Printf("=== STEP Basic: testing l3outside creation with different parent %s \n", parentName) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + `, parentName, rName) + return resource +} + +func CreateAccl3outsideConfigWithInvalidTenantdn(rName string) string { + fmt.Printf("=== STEP Basic: testing l3outside creation with invalid tenant dn \n") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource"aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_application_profile.test.id + } + `, rName, rName, rName) + return resource +} + +func CreateAccL3OutsideConfig(rName string) string { + fmt.Println("=== STEP testing L3Outside creation with required parameters only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, rName, rName) + return resource +} + +func CreateAccL3OutsideConfigWithOptionalValues(rName string) string { + fmt.Println("=== STEP Basic: testing l3outside creation with optional parameters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + description = "from terraform" + annotation = "tag_l3out" + enforce_rtctrl = ["export","import"] + name_alias = "alias_out" + target_dscp = "CS0" + } + `, rName, rName) + return resource +} + +func CreateAccL3OutsideUpdatedAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP testing attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + %s = "%s" + } + `, rName, rName, attribute, value) + return resource +} + +func CreateAccL3OutsideUpdatedAttrList(rName, attribute, value string) string { + fmt.Printf("=== STEP testing attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + %s = %s + } + `, rName, rName, attribute, value) + return resource +} + +func CreateAccL3OutsideConfigMultiple(rName string) string { + fmt.Println("=== STEP creating multiple l3Outside") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_l3_outside" "test1" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_l3_outside" "test2" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, rName, rName+"1", rName+"2", rName+"3") + return resource +} + +func CreateAccL3OutsidUpdatedL3OutsideIntial(rName, rsRelName string) string { + fmt.Println("=== STEP Relation Parameters: testing l3outside creation with initial relational parameters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_bgp_route_control_profile" "test" { + parent_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_vrf" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + relation_l3ext_rs_dampening_pol { + af = "ipv4-ucast" + tn_rtctrl_profile_name = aci_bgp_route_control_profile.test.id + } + relation_l3ext_rs_ectx = aci_vrf.test.id + relation_l3ext_rs_interleak_pol = aci_bgp_route_control_profile.test.id + } + `, rName, rsRelName, rsRelName, rName) + + return resource +} +func CreateAccL3OutsidUpdatedL3OutsideFinal(rName, rsRelName1, rsRelName2 string) string { + fmt.Println("=== STEP Relation Parameters: testing l3outside creation with final relational parameters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_bgp_route_control_profile" "test" { + parent_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_bgp_route_control_profile" "test1" { + parent_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_vrf" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + relation_l3ext_rs_dampening_pol { + af = "ipv4-ucast" + tn_rtctrl_profile_name = aci_bgp_route_control_profile.test.id + } + relation_l3ext_rs_dampening_pol { + af = "ipv6-ucast" + tn_rtctrl_profile_name = aci_bgp_route_control_profile.test1.id + } + relation_l3ext_rs_ectx = aci_vrf.test.id + relation_l3ext_rs_interleak_pol = aci_bgp_route_control_profile.test1.id +} + `, rName, rsRelName1, rsRelName2, rsRelName2, rName) + return resource +} diff --git a/testacc/resource_aci_l3extinstp_test.go b/testacc/resource_aci_l3extinstp_test.go new file mode 100644 index 000000000..6bf3924d9 --- /dev/null +++ b/testacc/resource_aci_l3extinstp_test.go @@ -0,0 +1,702 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciExternalNetworkInstanceProfile_Basic(t *testing.T) { + var external_network_instance_profile_default models.ExternalNetworkInstanceProfile + var external_network_instance_profile_update models.ExternalNetworkInstanceProfile + resourceName := "aci_external_network_instance_profile.test" + rName := makeTestVariable(acctest.RandString(5)) + rOther := makeTestVariable(acctest.RandString(5)) + longrName := acctest.RandString(65) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciExternalNetworkInstanceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccExternalNetworkInstanceProfileWithoutL3Out(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccExternalNetworkInstanceProfileWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccExternalNetworkInstanceProfileConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_default), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "exception_tag", ""), + resource.TestCheckResourceAttr(resourceName, "flood_on_encap", "disabled"), + resource.TestCheckResourceAttr(resourceName, "l3_outside_dn", fmt.Sprintf("uni/tn-%s/out-%s", rName, rName)), + resource.TestCheckResourceAttr(resourceName, "match_t", "AtleastOne"), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "pref_gr_memb", "exclude"), + resource.TestCheckResourceAttr(resourceName, "prio", "unspecified"), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_inst_p_to_nat_mapping_epg", ""), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_inst_p_to_profile.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_l3_inst_p_to_dom_p", ""), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "unspecified"), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileConfigWithOptionalValues(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "annotation", "annotation"), + resource.TestCheckResourceAttr(resourceName, "description", "description"), + resource.TestCheckResourceAttr(resourceName, "exception_tag", "0"), + resource.TestCheckResourceAttr(resourceName, "flood_on_encap", "enabled"), + resource.TestCheckResourceAttr(resourceName, "l3_outside_dn", fmt.Sprintf("uni/tn-%s/out-%s", rName, rName)), + resource.TestCheckResourceAttr(resourceName, "match_t", "All"), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "name_alias", "name_alias"), + resource.TestCheckResourceAttr(resourceName, "pref_gr_memb", "include"), + resource.TestCheckResourceAttr(resourceName, "prio", "level1"), + resource.TestCheckResourceAttr(resourceName, "relation_fv_rs_cons.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_fv_rs_cons_if.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_fv_rs_intra_epg.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_fv_rs_prov.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_fv_rs_sec_inherited.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_inst_p_to_nat_mapping_epg", ""), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_inst_p_to_profile.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_l3_inst_p_to_dom_p", ""), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS0"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccExternalNetworkInstanceProfileRemovingRequiredField(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccExternalNetworkInstanceProfileConfigWithParentAndName(rName, longrName), + ExpectError: regexp.MustCompile(fmt.Sprintf("property name of instP-%s failed validation for value '%s'", longrName, longrName)), + }, + { + Config: CreateAccExternalNetworkInstanceProfileConfigWithParentAndName(rName, rOther), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "name", rOther), + resource.TestCheckResourceAttr(resourceName, "l3_outside_dn", fmt.Sprintf("uni/tn-%s/out-%s", rName, rName)), + testAccCheckAciExternalNetworkInstanceProfileIdNotEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileConfig(rName), + }, + { + Config: CreateAccExternalNetworkInstanceProfileConfigWithParentAndName(rOther, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "l3_outside_dn", fmt.Sprintf("uni/tn-%s/out-%s", rOther, rOther)), + testAccCheckAciExternalNetworkInstanceProfileIdNotEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + }, + }) +} + +func TestAccAciExternalNetworkInstanceProfile_Update(t *testing.T) { + var external_network_instance_profile_default models.ExternalNetworkInstanceProfile + var external_network_instance_profile_update models.ExternalNetworkInstanceProfile + resourceName := "aci_external_network_instance_profile.test" + rName := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciExternalNetworkInstanceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccExternalNetworkInstanceProfileConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_default), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "exception_tag", "512"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "exception_tag", "512"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "match_t", "AtmostOne"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "match_t", "AtmostOne"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "match_t", "None"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "match_t", "None"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "prio", "level2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "prio", "level2"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "prio", "level3"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "prio", "level3"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "prio", "level4"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "prio", "level4"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "prio", "level5"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "prio", "level5"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "prio", "level6"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "prio", "level6"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "CS1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS1"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "AF11"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF11"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "AF12"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF12"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "AF13"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF13"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "CS2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS2"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "AF21"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF21"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "AF22"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF22"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "AF23"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF23"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "CS3"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS3"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "AF31"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF31"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "AF32"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF32"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "AF33"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF33"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "CS4"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS4"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "AF41"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF41"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "AF42"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF42"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "AF43"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF43"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "CS5"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS5"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "VA"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "VA"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "EF"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "EF"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "CS6"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS6"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", "CS7"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciExternalNetworkInstanceProfileExists(resourceName, &external_network_instance_profile_update), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS7"), + testAccCheckAciExternalNetworkInstanceProfileIdEqual(&external_network_instance_profile_default, &external_network_instance_profile_update), + ), + }, + }, + }) +} + +func TestAccAciExternalNetworkInstanceProfile_Negative(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + longAnnotationDesc := acctest.RandString(129) + longNameAlias := acctest.RandString(65) + randomParameter := acctest.RandStringFromCharSet(10, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(10) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciExternalNetworkInstanceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccExternalNetworkInstanceProfileConfig(rName), + }, + { + Config: CreateAccExternalNetworkInstanceProfileConfigWithInvalidL3Out(rName), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class l3extInstP (.)+`), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "exception_tag", "-1"), + ExpectError: regexp.MustCompile(`property is out of range`), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "exception_tag", "513"), + ExpectError: regexp.MustCompile(`property is out of range`), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "annotation", longAnnotationDesc), + ExpectError: regexp.MustCompile(`property annotation of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "flood_on_encap", randomValue), + ExpectError: regexp.MustCompile(`expected flood_on_encap to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "match_t", randomValue), + ExpectError: regexp.MustCompile(`expected match_t to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "name_alias", longNameAlias), + ExpectError: regexp.MustCompile(`property nameAlias of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "description", longAnnotationDesc), + ExpectError: regexp.MustCompile(`property descr of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "pref_gr_memb", randomValue), + ExpectError: regexp.MustCompile(`expected pref_gr_memb to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "prio", randomValue), + ExpectError: regexp.MustCompile(`expected prio to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, "target_dscp", randomValue), + ExpectError: regexp.MustCompile(`expected target_dscp to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccExternalNetworkInstanceProfileConfig(rName), + }, + }, + }) +} + +func TestAccAciExternalNetworkInstanceProfile_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciExternalNetworkInstanceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccExternalNetworkInstanceProfileConfigs(rName), + }, + }, + }) +} + +func CreateAccExternalNetworkInstanceProfileConfigWithInvalidL3Out(rName string) string { + fmt.Println("=== STEP testing external_network_instance_profile updation with invalid l3_outside_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_external_network_instance_profile" "test" { + l3_outside_dn = aci_tenant.test.id + name = "%s" + } + `, rName, rName) + return resource +} + +func CreateAccExternalNetworkInstanceProfileUpdatedAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP testing external_network_instance_profile attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_l3_outside" "test"{ + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_external_network_instance_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + %s = "%s" + } + `, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccExternalNetworkInstanceProfileConfigWithParentAndName(prName, rName string) string { + fmt.Printf("=== STEP Basic: testing external_network_instance_profile creation with l3_outside name %s name %s\n", prName, rName) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_l3_outside" "test"{ + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_external_network_instance_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + `, prName, prName, rName) + return resource +} + +func CreateAccExternalNetworkInstanceProfileRemovingRequiredField() string { + fmt.Println("=== STEP Basic: testing external_network_instance_profile updation without required fields") + resource := fmt.Sprintln(` + resource "aci_external_network_instance_profile" "test" { + annotation = "tag" + description = "description" + exception_tag = "0" + flood_on_encap = "enabled" + match_t = "All" + name_alias = "name_alias" + pref_gr_memb = "include" + prio = "level1" + target_dscp = "CS0" + } + `) + return resource +} + +func CreateAccExternalNetworkInstanceProfileConfigWithOptionalValues(rName string) string { + fmt.Println("=== STEP testing external_network_instance_profile creation with optional parameters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_l3_outside" "test"{ + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_external_network_instance_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + annotation = "annotation" + description = "description" + exception_tag = "0" + flood_on_encap = "enabled" + match_t = "All" + name_alias = "name_alias" + pref_gr_memb = "include" + prio = "level1" + target_dscp = "CS0" + } + `, rName, rName, rName) + return resource +} + +func CreateAccExternalNetworkInstanceProfileConfigs(rName string) string { + fmt.Println("=== STEP creating multiple external_network_instance_profile") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_l3_outside" "test"{ + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_external_network_instance_profile" "test1" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + + resource "aci_external_network_instance_profile" "test2" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + + resource "aci_external_network_instance_profile" "test3" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + `, rName, rName, rName+"1", rName+"2", rName+"3") + return resource +} + +func CreateAccExternalNetworkInstanceProfileConfig(rName string) string { + fmt.Println("=== STEP testing external_network_instance_profile creation with required arguments only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_l3_outside" "test"{ + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_external_network_instance_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + `, rName, rName, rName) + return resource +} + +func CreateAccExternalNetworkInstanceProfileWithoutL3Out(rName string) string { + fmt.Println("=== STEP Basic: testing external_network_instance_profile creation without creating l3_outside") + resource := fmt.Sprintf(` + resource "aci_external_network_instance_profile" "test" { + name = "%s" + } + `, rName) + return resource +} + +func CreateAccExternalNetworkInstanceProfileWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing external_network_instance_profile creation without name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_l3_outside" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_external_network_instance_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + } + `, rName, rName) + return resource +} + +func testAccCheckAciExternalNetworkInstanceProfileExists(name string, external_network_instance_profile *models.ExternalNetworkInstanceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("External Network Instance Profile %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No External Network Instance Profile dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + external_network_instance_profileFound := models.ExternalNetworkInstanceProfileFromContainer(cont) + if external_network_instance_profileFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("External Network Instance Profile %s not found", rs.Primary.ID) + } + *external_network_instance_profile = *external_network_instance_profileFound + return nil + } +} + +func testAccCheckAciExternalNetworkInstanceProfileDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing external_network_instance_profile destroy") + client := testAccProvider.Meta().(*client.Client) + + for _, rs := range s.RootModule().Resources { + + if rs.Type == "aci_external_network_instance_profile" { + cont, err := client.Get(rs.Primary.ID) + external_network_instance_profile := models.ExternalNetworkInstanceProfileFromContainer(cont) + if err == nil { + return fmt.Errorf("External Network Instance Profile %s Still exists", external_network_instance_profile.DistinguishedName) + } + + } else { + continue + } + } + + return nil +} + +func testAccCheckAciExternalNetworkInstanceProfileIdEqual(enip1, enip2 *models.ExternalNetworkInstanceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if enip1.DistinguishedName != enip2.DistinguishedName { + return fmt.Errorf("ExternalNetworkInstanceProfile DNs are not equal") + } + return nil + } +} + +func testAccCheckAciExternalNetworkInstanceProfileIdNotEqual(enip1, enip2 *models.ExternalNetworkInstanceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if enip1.DistinguishedName == enip2.DistinguishedName { + return fmt.Errorf("ExternalNetworkInstanceProfile DNs are equal") + } + return nil + } +} diff --git a/testacc/resource_aci_l3extlifp_test.go b/testacc/resource_aci_l3extlifp_test.go new file mode 100644 index 000000000..619c764a6 --- /dev/null +++ b/testacc/resource_aci_l3extlifp_test.go @@ -0,0 +1,606 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciLogicalInterfaceProfile_Basic(t *testing.T) { + var logicalInterfaceProfile_default models.LogicalInterfaceProfile + var logicalInterfaceProfile_updated models.LogicalInterfaceProfile + resourceName := "aci_logical_interface_profile.test" + rName := makeTestVariable(acctest.RandString(5)) + rOther := makeTestVariable(acctest.RandString(5)) + prOther := makeTestVariable(acctest.RandString(5)) + longrName := acctest.RandString(65) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciLogicalInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccLogicalInterfaceProfileWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccLogicalInterfaceProfileWithoutLogicalNodeProfileDn(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccLogicalInterfaceProfileConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalInterfaceProfileExists(resourceName, &logicalInterfaceProfile_default), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "logical_node_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s", rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "prio", "unspecified"), + resource.TestCheckResourceAttrSet(resourceName, "tag"), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_l_if_p_to_netflow_monitor_pol.#", "0"), + ), + }, + { + Config: CreateAccLogicalInterfaceProfileConfigWithOptionalValues(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalInterfaceProfileExists(resourceName, &logicalInterfaceProfile_updated), + resource.TestCheckResourceAttr(resourceName, "annotation", "tag_prof"), + resource.TestCheckResourceAttr(resourceName, "description", "Sample logical interface profile"), + resource.TestCheckResourceAttr(resourceName, "logical_node_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s", rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "name_alias", "alias_prof"), + resource.TestCheckResourceAttr(resourceName, "prio", "level1"), + resource.TestCheckResourceAttr(resourceName, "tag", "navy"), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_l_if_p_to_netflow_monitor_pol.#", "0"), + testAccCheckAciLogicalInterfaceProfileIdEqual(&logicalInterfaceProfile_default, &logicalInterfaceProfile_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccLogicalInterfaceProfileConfigWithAnotherName(rName, rOther), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalInterfaceProfileExists(resourceName, &logicalInterfaceProfile_updated), + testAccCheckAciLogicalInterfaceIdNotEqual(&logicalInterfaceProfile_default, &logicalInterfaceProfile_updated), + ), + }, + { + Config: CreateAccLogicalInterfaceProfileConfig(rName), + }, + { + Config: CreateAccLogicalInterfaceProfileConfigWithAnotherLogicalNodeProfileDn(prOther, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalInterfaceProfileExists(resourceName, &logicalInterfaceProfile_updated), + testAccCheckAciLogicalInterfaceIdNotEqual(&logicalInterfaceProfile_default, &logicalInterfaceProfile_updated), + ), + }, + { + Config: CreateAccLogicalInterfaceProfileConfigUpdateWithoutRequiredAttri(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccLogicalInterfaceProfileConfigUpdateWithInvalidName(rName, longrName), + ExpectError: regexp.MustCompile(fmt.Sprintf("property name of lifp-%s failed validation for value '%s'", longrName, longrName)), + }, + { + Config: CreateAccLogicalInterfaceProfileConfig(rName), + }, + }, + }) +} + +func TestAccAciLogicalInterfaceProfile_Update(t *testing.T) { + var logicalInterfaceProfile_default models.LogicalInterfaceProfile + var logicalInterfaceProfile_updated models.LogicalInterfaceProfile + resourceName := "aci_logical_interface_profile.test" + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciLogicalInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccLogicalInterfaceProfileConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalInterfaceProfileExists(resourceName, &logicalInterfaceProfile_default), + ), + }, + { + Config: CreateAccLogicalInterfaceProfileUpdatedAttr(rName, "prio", "level2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalInterfaceProfileExists(resourceName, &logicalInterfaceProfile_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level2"), + testAccCheckAciLogicalInterfaceProfileIdEqual(&logicalInterfaceProfile_default, &logicalInterfaceProfile_updated), + ), + }, + { + Config: CreateAccLogicalInterfaceProfileUpdatedAttr(rName, "prio", "level3"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalInterfaceProfileExists(resourceName, &logicalInterfaceProfile_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level3"), + testAccCheckAciLogicalInterfaceProfileIdEqual(&logicalInterfaceProfile_default, &logicalInterfaceProfile_updated), + ), + }, + { + Config: CreateAccLogicalInterfaceProfileUpdatedAttr(rName, "prio", "level4"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalInterfaceProfileExists(resourceName, &logicalInterfaceProfile_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level4"), + testAccCheckAciLogicalInterfaceProfileIdEqual(&logicalInterfaceProfile_default, &logicalInterfaceProfile_updated), + ), + }, + { + Config: CreateAccLogicalInterfaceProfileUpdatedAttr(rName, "prio", "level5"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalInterfaceProfileExists(resourceName, &logicalInterfaceProfile_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level5"), + testAccCheckAciLogicalInterfaceProfileIdEqual(&logicalInterfaceProfile_default, &logicalInterfaceProfile_updated), + ), + }, + { + Config: CreateAccLogicalInterfaceProfileUpdatedAttr(rName, "prio", "level6"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalInterfaceProfileExists(resourceName, &logicalInterfaceProfile_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level6"), + testAccCheckAciLogicalInterfaceProfileIdEqual(&logicalInterfaceProfile_default, &logicalInterfaceProfile_updated), + ), + }, + { + Config: CreateAccLogicalInterfaceProfileUpdatedAttr(rName, "tag", "blue"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalInterfaceProfileExists(resourceName, &logicalInterfaceProfile_updated), + resource.TestCheckResourceAttr(resourceName, "tag", "blue"), + testAccCheckAciLogicalInterfaceProfileIdEqual(&logicalInterfaceProfile_default, &logicalInterfaceProfile_updated), + ), + }, + { + Config: CreateAccLogicalInterfaceProfileUpdatedAttr(rName, "tag", "green"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalInterfaceProfileExists(resourceName, &logicalInterfaceProfile_updated), + resource.TestCheckResourceAttr(resourceName, "tag", "green"), + testAccCheckAciLogicalInterfaceProfileIdEqual(&logicalInterfaceProfile_default, &logicalInterfaceProfile_updated), + ), + }, + { + Config: CreateAccLogicalInterfaceProfileUpdatedAttr(rName, "tag", "lime"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalInterfaceProfileExists(resourceName, &logicalInterfaceProfile_updated), + resource.TestCheckResourceAttr(resourceName, "tag", "lime"), + testAccCheckAciLogicalInterfaceProfileIdEqual(&logicalInterfaceProfile_default, &logicalInterfaceProfile_updated), + ), + }, + { + Config: CreateAccLogicalInterfaceProfileUpdatedAttr(rName, "tag", "indigo"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalInterfaceProfileExists(resourceName, &logicalInterfaceProfile_updated), + resource.TestCheckResourceAttr(resourceName, "tag", "indigo"), + testAccCheckAciLogicalInterfaceProfileIdEqual(&logicalInterfaceProfile_default, &logicalInterfaceProfile_updated), + ), + }, + { + Config: CreateAccLogicalInterfaceProfileUpdatedAttr(rName, "tag", "purple"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalInterfaceProfileExists(resourceName, &logicalInterfaceProfile_updated), + resource.TestCheckResourceAttr(resourceName, "tag", "purple"), + testAccCheckAciLogicalInterfaceProfileIdEqual(&logicalInterfaceProfile_default, &logicalInterfaceProfile_updated), + ), + }, + { + Config: CreateAccLogicalInterfaceProfileUpdatedAttr(rName, "tag", "gray"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalInterfaceProfileExists(resourceName, &logicalInterfaceProfile_updated), + resource.TestCheckResourceAttr(resourceName, "tag", "gray"), + testAccCheckAciLogicalInterfaceProfileIdEqual(&logicalInterfaceProfile_default, &logicalInterfaceProfile_updated), + ), + }, + { + Config: CreateAccLogicalInterfaceProfileUpdatedAttr(rName, "tag", "yellow"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalInterfaceProfileExists(resourceName, &logicalInterfaceProfile_updated), + resource.TestCheckResourceAttr(resourceName, "tag", "yellow"), + testAccCheckAciLogicalInterfaceProfileIdEqual(&logicalInterfaceProfile_default, &logicalInterfaceProfile_updated), + ), + }, + { + Config: CreateAccLogicalInterfaceProfileUpdatedAttr(rName, "tag", "white"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalInterfaceProfileExists(resourceName, &logicalInterfaceProfile_updated), + resource.TestCheckResourceAttr(resourceName, "tag", "white"), + testAccCheckAciLogicalInterfaceProfileIdEqual(&logicalInterfaceProfile_default, &logicalInterfaceProfile_updated), + ), + }, + }, + }) +} +func TestAccAciLogicalInterfaceProfile_NegativeCases(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + longDescAnnotation := acctest.RandString(129) + longNameAlias := acctest.RandString(64) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciLogicalInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccLogicalInterfaceProfileConfig(rName), + }, + { + Config: CreateAccLogicalInterfaceProfileConfigWithInvalidLogicalNodeProfiledn(rName), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class l3extLIfP (.)+`), + }, + { + Config: CreateAccLogicalInterfaceProfileUpdatedAttr(rName, "annotation", longDescAnnotation), + ExpectError: regexp.MustCompile(`property annotation of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccLogicalInterfaceProfileUpdatedAttr(rName, "description", longDescAnnotation), + ExpectError: regexp.MustCompile(`property descr of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccLogicalInterfaceProfileUpdatedAttr(rName, "name_alias", longNameAlias), + ExpectError: regexp.MustCompile(`property nameAlias of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccLogicalInterfaceProfileUpdatedAttr(rName, "prio", randomValue), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name prio, class l3extLIfP (.)+`), + }, + { + Config: CreateAccLogicalInterfaceProfileUpdatedAttr(rName, "tag", randomValue), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name tag, class l3extLIfP (.)+`), + }, + { + Config: CreateAccLogicalInterfaceProfileUpdatedAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccLogicalInterfaceProfileConfig(rName), + }, + }, + }) +} + +func TestAccAciLogicalInterfaceProfile_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciLogicalInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccLogicalInterfaceProfileConfigMultiple(rName), + }, + }, + }) +} + +func CreateAccLogicalInterfaceProfileConfigUpdateWithInvalidName(parentName, rName string) string { + fmt.Println("=== STEP Basic: testing LogicalInterfaceProfile update with invalid Name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + description = "from terraform" + name = "%s" + } + + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + `, parentName, parentName, parentName, rName) + return resource +} + +func testAccCheckLogicalInterfaceProfileExists(name string, logicalInterfaceProfile *models.LogicalInterfaceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("LogicalInterfaceProfile %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No LogicalInterfaceProfile dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + logicalInterfaceProfileFound := models.LogicalInterfaceProfileFromContainer(cont) + if logicalInterfaceProfileFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("LogicalInterfaceProfile %s not found", rs.Primary.ID) + } + *logicalInterfaceProfile = *logicalInterfaceProfileFound + return nil + } +} + +func testAccCheckAciLogicalInterfaceProfileDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing LogicalInterfaceProfile destroy") + client := testAccProvider.Meta().(*client.Client) + + for _, rs := range s.RootModule().Resources { + + if rs.Type == "aci_logical_interface_profile" { + cont, err := client.Get(rs.Primary.ID) + aci := models.LogicalInterfaceProfileFromContainer(cont) + if err == nil { + return fmt.Errorf("LogicalInterfaceProfile %s Still exists", aci.DistinguishedName) + } + + } else { + continue + } + } + + return nil +} + +func testAccCheckAciLogicalInterfaceProfileIdEqual(logicalInterfaceProfile1, logicalInterfaceProfile2 *models.LogicalInterfaceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if logicalInterfaceProfile1.DistinguishedName != logicalInterfaceProfile2.DistinguishedName { + return fmt.Errorf("LogicalInterfaceProfile DNs are not equal") + } + return nil + } +} + +func testAccCheckAciLogicalInterfaceIdNotEqual(logicalInterfaceProfile1, logicalInterfaceProfile2 *models.LogicalInterfaceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if logicalInterfaceProfile1.DistinguishedName == logicalInterfaceProfile2.DistinguishedName { + return fmt.Errorf("LogicalInterfaceProfile DNs are equal") + } + return nil + } +} + +func CreateAccLogicalInterfaceProfileWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing LogicalInterfaceProfile creation without giving Name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + description = "from terraform" + name = "%s" + } + + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + } + `, rName, rName, rName) + return resource +} + +func CreateAccLogicalInterfaceProfileWithoutLogicalNodeProfileDn(rName string) string { + fmt.Println("=== STEP Basic: testing LogicalInterfaceProfile creation without giving LogicalNodeProfile dn") + resource := fmt.Sprintf(` + resource "aci_logical_interface_profile" "test" { + name = "%s" + } + `, rName) + return resource +} + +func CreateAccLogicalInterfaceProfileConfigUpdateWithoutRequiredAttri() string { + fmt.Println("=== STEP Basic: testing LogicalInterfaceProfile update without giving required Attributes") + resource := fmt.Sprintf(` + resource "aci_logical_interface_profile" "test" { + description = "Sample logical interface profile" + annotation = "tag_prof" + name_alias = "alias_prof" + prio = "level1" + tag = "navy" + } + `) + return resource +} + +func CreateAccLogicalInterfaceProfileConfigWithAnotherName(parentName, rName string) string { + fmt.Printf("=== STEP Basic: testing LogicalInterfaceProfile creation with different LogicalInterfaceProfile name %s \n", rName) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + description = "from terraform" + name = "%s" + } + + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + `, parentName, parentName, parentName, rName) + return resource +} + +func CreateAccLogicalInterfaceProfileConfigWithAnotherLogicalNodeProfileDn(parentName, rName string) string { + fmt.Printf("=== STEP Basic: testing LogicalInterfaceProfile creation with different parent %s \n", parentName) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + description = "from terraform" + name = "%s" + } + + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + `, parentName, parentName, parentName, rName) + return resource +} + +func CreateAccLogicalInterfaceProfileConfigWithInvalidLogicalNodeProfiledn(rName string) string { + fmt.Printf("=== STEP Basic: testing LogicalInterfaceProfile creation with invalid Logical Node Profile dn \n") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_tenant.test.id + name = "%s" + description = "Sample logical interface profile" + annotation = "tag_prof" + name_alias = "alias_prof" + prio = "level1" + tag = "navy" + } + `, rName, rName) + return resource +} + +func CreateAccLogicalInterfaceProfileConfig(rName string) string { + fmt.Println("=== STEP testing LogicalInterfaceProfile creation with required attributes") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + description = "from terraform" + name = "%s" + } + + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccLogicalInterfaceProfileConfigWithOptionalValues(rName string) string { + fmt.Println("=== STEP Basic: testing logicalInterfaceProfile creation with optional parameters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + description = "from terraform" + name = "%s" + } + + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + description = "Sample logical interface profile" + annotation = "tag_prof" + name_alias = "alias_prof" + prio = "level1" + tag = "navy" + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccLogicalInterfaceProfileUpdatedAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP testing attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + description = "from terraform" + name = "%s" + } + + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + %s = "%s" + } + `, rName, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccLogicalInterfaceProfileConfigMultiple(rName string) string { + fmt.Println("=== STEP Creating Multiple LogicalInterfaceProfile") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + description = "from terraform" + name = "%s" + } + + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + resource "aci_logical_interface_profile" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + resource "aci_logical_interface_profile" "test1" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + resource "aci_logical_interface_profile" "test2" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + resource "aci_logical_interface_profile" "test3" { + logical_node_profile_dn = aci_logical_node_profile.test.id + name = "%s" + } + `, rName, rName, rName, rName, rName+"1", rName+"2", rName+"3") + return resource +} diff --git a/testacc/resource_aci_l3extlnodep_test.go b/testacc/resource_aci_l3extlnodep_test.go new file mode 100644 index 000000000..134683f1b --- /dev/null +++ b/testacc/resource_aci_l3extlnodep_test.go @@ -0,0 +1,577 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciLogicalNodeProfile_Basic(t *testing.T) { + var LogicalNodeProfile_default models.LogicalNodeProfile + var LogicalNodeProfile_updated models.LogicalNodeProfile + resourceName := "aci_logical_node_profile.test" + rName := makeTestVariable(acctest.RandString(5)) + rOther := makeTestVariable(acctest.RandString(5)) + prOther := makeTestVariable(acctest.RandString(5)) + longrName := acctest.RandString(65) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciLogicalNodeProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccLogicalNodeProfileWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccLogicalNodeProfileWithoutParentDn(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccLogicalNodeProfileConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalNodeProfileExists(resourceName, &LogicalNodeProfile_default), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttrSet(resourceName, "tag"), + resource.TestCheckResourceAttrSet(resourceName, "config_issues"), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "unspecified"), + resource.TestCheckResourceAttr(resourceName, "l3_outside_dn", fmt.Sprintf("uni/tn-%s/out-%s", rName, rName)), + ), + }, + { + Config: CreateAccLogicalNodeProfileConfigWithOptionalValues(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalNodeProfileExists(resourceName, &LogicalNodeProfile_updated), + resource.TestCheckResourceAttr(resourceName, "annotation", "tag_node"), + resource.TestCheckResourceAttr(resourceName, "description", "sample logical node profile"), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "name_alias", "alias_node"), + resource.TestCheckResourceAttr(resourceName, "tag", "black"), + resource.TestCheckResourceAttrSet(resourceName, "config_issues"), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS0"), + resource.TestCheckResourceAttr(resourceName, "l3_outside_dn", fmt.Sprintf("uni/tn-%s/out-%s", rName, rName)), + + testAccCheckAciLogicalNodeProfileIdEqual(&LogicalNodeProfile_default, &LogicalNodeProfile_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccLogicalNodeProfileConfigWithAnotherName(rName, rOther), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalNodeProfileExists(resourceName, &LogicalNodeProfile_updated), + testAccCheckAciLogicalNodeProfileIdNotEqual(&LogicalNodeProfile_default, &LogicalNodeProfile_updated), + ), + }, + { + Config: CreateAccLogicalNodeProfileConfig(rName), + }, + { + Config: CreateAccLogicalNodeProfileConfigWithAnotherParentDn(prOther, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalNodeProfileExists(resourceName, &LogicalNodeProfile_updated), + testAccCheckAciLogicalNodeProfileIdNotEqual(&LogicalNodeProfile_default, &LogicalNodeProfile_updated), + ), + }, + { + Config: CreateAccLogicalNodeProfileConfigUpdateWithoutParentdn(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccLogicalNodeProfileConfigUpdateWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccLogicalNodeProfileConfigUpdateWithInvalidName(rName, longrName), + ExpectError: regexp.MustCompile("failed validation for value"), + }, + { + Config: CreateAccLogicalNodeProfileConfig(rName), + }, + }, + }) +} + +func TestAccAciLogicalNodeProfile_NegativeCases(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + longDescAnnotation := acctest.RandString(129) + longNameAlias := acctest.RandString(64) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciLogicalNodeProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccLogicalNodeProfileConfig(rName), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, "tag", longDescAnnotation), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, "annotation", longDescAnnotation), + ExpectError: regexp.MustCompile(`property annotation of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, "description", longDescAnnotation), + ExpectError: regexp.MustCompile(`property descr of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, "name_alias", longNameAlias), + ExpectError: regexp.MustCompile(`property nameAlias of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, "target_dscp", randomValue), + ExpectError: regexp.MustCompile(`expected target_dscp to be one of (.)+ got (.)+`), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccLogicalNodeProfileConfig(rName), + }, + }, + }) +} +func TestAccAciLogicalNodeProfile_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciLogicalNodeProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccLogicalNodeProfileConfigMultiple(rName), + }, + }, + }) +} + +func TestAccAciLogicalNodeProfile_Update(t *testing.T) { + var LogicalNodeProfile_default models.LogicalNodeProfile + var LogicalNodeProfile_updated models.LogicalNodeProfile + resourceName := "aci_logical_node_profile.test" + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciLogicalNodeProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccLogicalNodeProfileConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalNodeProfileExists(resourceName, &LogicalNodeProfile_default), + ), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, "target_dscp", "CS1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalNodeProfileExists(resourceName, &LogicalNodeProfile_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS1"), + testAccCheckAciLogicalNodeProfileIdEqual(&LogicalNodeProfile_default, &LogicalNodeProfile_updated), + ), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, "target_dscp", "AF11"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalNodeProfileExists(resourceName, &LogicalNodeProfile_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF11"), + testAccCheckAciLogicalNodeProfileIdEqual(&LogicalNodeProfile_default, &LogicalNodeProfile_updated), + ), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, "target_dscp", "AF12"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalNodeProfileExists(resourceName, &LogicalNodeProfile_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF12"), + testAccCheckAciLogicalNodeProfileIdEqual(&LogicalNodeProfile_default, &LogicalNodeProfile_updated), + ), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, "target_dscp", "AF13"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalNodeProfileExists(resourceName, &LogicalNodeProfile_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF13"), + testAccCheckAciLogicalNodeProfileIdEqual(&LogicalNodeProfile_default, &LogicalNodeProfile_updated), + ), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, "target_dscp", "CS2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalNodeProfileExists(resourceName, &LogicalNodeProfile_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS2"), + testAccCheckAciLogicalNodeProfileIdEqual(&LogicalNodeProfile_default, &LogicalNodeProfile_updated), + ), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, "target_dscp", "AF21"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalNodeProfileExists(resourceName, &LogicalNodeProfile_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF21"), + testAccCheckAciLogicalNodeProfileIdEqual(&LogicalNodeProfile_default, &LogicalNodeProfile_updated), + ), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, "target_dscp", "AF22"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalNodeProfileExists(resourceName, &LogicalNodeProfile_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF22"), + testAccCheckAciLogicalNodeProfileIdEqual(&LogicalNodeProfile_default, &LogicalNodeProfile_updated), + ), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, "target_dscp", "AF23"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalNodeProfileExists(resourceName, &LogicalNodeProfile_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF23"), + testAccCheckAciLogicalNodeProfileIdEqual(&LogicalNodeProfile_default, &LogicalNodeProfile_updated), + ), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, "target_dscp", "CS3"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalNodeProfileExists(resourceName, &LogicalNodeProfile_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS3"), + testAccCheckAciLogicalNodeProfileIdEqual(&LogicalNodeProfile_default, &LogicalNodeProfile_updated), + ), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, "tag", "pink"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalNodeProfileExists(resourceName, &LogicalNodeProfile_updated), + resource.TestCheckResourceAttr(resourceName, "tag", "pink"), + testAccCheckAciLogicalNodeProfileIdEqual(&LogicalNodeProfile_default, &LogicalNodeProfile_updated), + ), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, "tag", "chartreuse"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalNodeProfileExists(resourceName, &LogicalNodeProfile_updated), + resource.TestCheckResourceAttr(resourceName, "tag", "chartreuse"), + testAccCheckAciLogicalNodeProfileIdEqual(&LogicalNodeProfile_default, &LogicalNodeProfile_updated), + ), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, "tag", "plum"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalNodeProfileExists(resourceName, &LogicalNodeProfile_updated), + resource.TestCheckResourceAttr(resourceName, "tag", "plum"), + testAccCheckAciLogicalNodeProfileIdEqual(&LogicalNodeProfile_default, &LogicalNodeProfile_updated), + ), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, "tag", "dark-orchid"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalNodeProfileExists(resourceName, &LogicalNodeProfile_updated), + resource.TestCheckResourceAttr(resourceName, "tag", "dark-orchid"), + testAccCheckAciLogicalNodeProfileIdEqual(&LogicalNodeProfile_default, &LogicalNodeProfile_updated), + ), + }, + { + Config: CreateAccLogicalNodeProfileUpdatedAttr(rName, "tag", "lime-green"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLogicalNodeProfileExists(resourceName, &LogicalNodeProfile_updated), + resource.TestCheckResourceAttr(resourceName, "tag", "lime-green"), + testAccCheckAciLogicalNodeProfileIdEqual(&LogicalNodeProfile_default, &LogicalNodeProfile_updated), + ), + }, + }, + }) +} + +func testAccCheckLogicalNodeProfileExists(name string, LogicalNodeProfile *models.LogicalNodeProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("LogicalNodeProfile %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No LogicalNodeProfile dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + LogicalNodeProfileFound := models.LogicalNodeProfileFromContainer(cont) + if LogicalNodeProfileFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("LogicalNodeProfile %s not found", rs.Primary.ID) + } + *LogicalNodeProfile = *LogicalNodeProfileFound + return nil + } +} +func CreateAccLogicalNodeProfileConfigMultiple(rName string) string { + fmt.Println("=== STEP creating multiple LogicalNodeProfiles") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test1" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test2" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + `, rName, rName, rName+"1", rName+"2", rName+"3") + return resource +} + +func testAccCheckAciLogicalNodeProfileDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing LogicalNodeProfile destroy") + client := testAccProvider.Meta().(*client.Client) + + for _, rs := range s.RootModule().Resources { + + if rs.Type == "aci_logical_node_profile" { + cont, err := client.Get(rs.Primary.ID) + aci := models.LogicalNodeProfileFromContainer(cont) + if err == nil { + return fmt.Errorf("LogicalNodeProfile %s Still exists", aci.DistinguishedName) + } + + } else { + continue + } + } + + return nil +} + +func testAccCheckAciLogicalNodeProfileIdEqual(LogicalNodeProfile1, LogicalNodeProfile2 *models.LogicalNodeProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if LogicalNodeProfile1.DistinguishedName != LogicalNodeProfile2.DistinguishedName { + return fmt.Errorf("LogicalNodeProfile DNs are not equal") + } + return nil + } +} + +func testAccCheckAciLogicalNodeProfileIdNotEqual(LogicalNodeProfile1, LogicalNodeProfile2 *models.LogicalNodeProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if LogicalNodeProfile1.DistinguishedName == LogicalNodeProfile2.DistinguishedName { + return fmt.Errorf("LogicalNodeProfile DNs are equal") + } + return nil + } +} + +func CreateAccLogicalNodeProfileWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing LogicalNodeProfile creation without giving Name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + } + `, rName, rName) + return resource +} + +func CreateAccLogicalNodeProfileWithoutParentDn(rName string) string { + fmt.Println("=== STEP Basic: testing LogicalNodeProfile creation without giving parent dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + name = "%s" + } + resource "aci_logical_node_profile" "test" { + name = "%s" + } + `, rName, rName, rName) + return resource +} + +func CreateAccLogicalNodeProfileConfigUpdateWithoutParentdn(rName string) string { + fmt.Println("=== STEP Basic: testing LogicalNodeProfile update without giving Parent Dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + name = "%s" + } + resource "aci_logical_interface_profile" "test" { + name = "%s" + annotation = "tag" + name_alias = "alias_node" + tag = "black" + target_dscp = "CS0" + } + `, rName, rName, rName) + return resource +} + +func CreateAccLogicalNodeProfileConfigUpdateWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing LogicalNodeProfile update without giving Name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name ="%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + annotation = "tag" + name_alias = "alias_node" + tag = "black" + target_dscp = "CS0" + } + `, rName, rName) + return resource +} + +func CreateAccLogicalNodeProfileConfigUpdateWithInvalidName(parentName, rName string) string { + fmt.Println("=== STEP Basic: testing LogicalNodeProfile update with invalid Name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name= "%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + `, parentName, parentName, rName) + return resource +} + +func CreateAccLogicalNodeProfileConfigWithAnotherName(parentName, rName string) string { + fmt.Printf("=== STEP Basic: testing LogicalNodeProfile creation with different LogicalNodeProfile name %s \n", rName) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + `, parentName, parentName, rName) + return resource +} + +func CreateAccLogicalNodeProfileConfigWithAnotherParentDn(parentName, rName string) string { + fmt.Printf("=== STEP Basic: testing LogicalNodeProfile creation with different parent %s \n", parentName) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + `, parentName, parentName, rName) + return resource +} + +func CreateAccLogicalNodeProfileConfig(rName string) string { + fmt.Println("=== STEP testing LogicalNodeProfile creation with required attributes") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + } + `, rName, rName, rName) + return resource +} + +func CreateAccLogicalNodeProfileConfigWithOptionalValues(rName string) string { + fmt.Println("=== STEP Basic: testing LogicalNodeProfile creation with optional parameters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + description = "sample logical node profile" + name = "%s" + annotation = "tag_node" + name_alias = "alias_node" + tag = "black" + target_dscp = "CS0" + } + `, rName, rName, rName) + return resource +} + +func CreateAccLogicalNodeProfileUpdatedAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP testing attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name = "%s" + %s = "%s" + } + `, rName, rName, rName, attribute, value) + return resource +} diff --git a/testacc/resource_aci_l3extloopbackifp_test.go b/testacc/resource_aci_l3extloopbackifp_test.go new file mode 100644 index 000000000..a92e5e6e4 --- /dev/null +++ b/testacc/resource_aci_l3extloopbackifp_test.go @@ -0,0 +1,422 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +var fabricNodeDn1 string = "topology/pod-1/node-201" +var fabricNodeDn2 string = "topology/pod-1/node-101" +var fabricNodeDn3 string = "topology/pod-1/node-111" +var fabricNodeDn4 string = "topology/pod-1/node-1" + +func TestAccAcil3extLoopBackIfP_Basic(t *testing.T) { + var aci_l3out_loopback_interface_profile_default models.LoopBackInterfaceProfile + var aci_l3out_loopback_interface_profile_updated models.LoopBackInterfaceProfile + resourceName := "aci_l3out_loopback_interface_profile.test" + rName := makeTestVariable(acctest.RandString(5)) + addr, _ := acctest.RandIpAddress("2.2.0.0/16") + addrOther, _ := acctest.RandIpAddress("3.3.0.0/16") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciLoopBackInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateLoopBackInterfaceProfileWithoutRequired(rName, fabricNodeDn1, addr, addr, "fabric_node_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateLoopBackInterfaceProfileWithoutRequired(rName, fabricNodeDn1, addr, addr, "addr"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccLoopBackInterfaceProfileConfig(rName, fabricNodeDn1, addr, addr), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciLoopBackInterfaceProfileExists(resourceName, &aci_l3out_loopback_interface_profile_default), + resource.TestCheckResourceAttr(resourceName, "fabric_node_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/rsnodeL3OutAtt-[%s]", rName, rName, rName, fabricNodeDn1)), + resource.TestCheckResourceAttr(resourceName, "addr", addr), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + ), + }, + { + Config: CreateAccLoopBackInterfaceProfileConfigWithOptionalValues(rName, fabricNodeDn1, addr, addr), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciLoopBackInterfaceProfileExists(resourceName, &aci_l3out_loopback_interface_profile_updated), + resource.TestCheckResourceAttr(resourceName, "fabric_node_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/rsnodeL3OutAtt-[%s]", rName, rName, rName, fabricNodeDn1)), + resource.TestCheckResourceAttr(resourceName, "addr", addr), + resource.TestCheckResourceAttr(resourceName, "annotation", "example"), + resource.TestCheckResourceAttr(resourceName, "description", "from terraform"), + resource.TestCheckResourceAttr(resourceName, "name_alias", "example"), + testAccCheckAciLoopBackInterfaceProfileIdEqual(&aci_l3out_loopback_interface_profile_default, &aci_l3out_loopback_interface_profile_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccLoopBackInterfaceProfileRemovingRequiredField(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccLoopBackInterfaceProfileWithInvalidIP(rName, fabricNodeDn1, addr), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + { + Config: CreateAccLoopBackInterfaceProfileConfigWithRequiredParams(rName, fabricNodeDn2, addr, addr), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciLoopBackInterfaceProfileExists(resourceName, &aci_l3out_loopback_interface_profile_updated), + resource.TestCheckResourceAttr(resourceName, "fabric_node_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/rsnodeL3OutAtt-[%s]", rName, rName, rName, fabricNodeDn2)), + resource.TestCheckResourceAttr(resourceName, "addr", addr), + testAccCheckAciLoopBackInterfaceProfileIdNotEqual(&aci_l3out_loopback_interface_profile_default, &aci_l3out_loopback_interface_profile_updated), + ), + }, + { + Config: CreateAccLoopBackInterfaceProfileConfig(rName, fabricNodeDn1, addr, addr), + }, + { + Config: CreateAccLoopBackInterfaceProfileConfigWithRequiredParams(rName, fabricNodeDn1, addr, addrOther), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciLoopBackInterfaceProfileExists(resourceName, &aci_l3out_loopback_interface_profile_updated), + resource.TestCheckResourceAttr(resourceName, "fabric_node_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/rsnodeL3OutAtt-[%s]", rName, rName, rName, fabricNodeDn1)), + resource.TestCheckResourceAttr(resourceName, "addr", addrOther), + testAccCheckAciLoopBackInterfaceProfileIdNotEqual(&aci_l3out_loopback_interface_profile_default, &aci_l3out_loopback_interface_profile_updated), + ), + }, + }, + }) +} + +func TestAccAcil3extLoopBackIfP_Negative(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + addr, _ := acctest.RandIpAddress("4.4.0.0/16") + longDescAnnotation := acctest.RandString(129) + longNameAlias := acctest.RandString(64) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciLoopBackInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccLoopBackInterfaceProfileConfig(rName, fabricNodeDn3, addr, addr), + }, + { + Config: CreateAccLoopBackInterfaceProfileConfigWithInvalidParentDn(rName, addr), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class l3extLoopBackIfP (.)+`), + }, + { + Config: CreateAccLoopBackInterfaceProfileConfigUpdatedAttr(rName, fabricNodeDn3, addr, addr, "annotation", longDescAnnotation), + ExpectError: regexp.MustCompile(`property annotation of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccLoopBackInterfaceProfileConfigUpdatedAttr(rName, fabricNodeDn3, addr, addr, "description", longDescAnnotation), + ExpectError: regexp.MustCompile(`property descr of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccLoopBackInterfaceProfileConfigUpdatedAttr(rName, fabricNodeDn3, addr, addr, "name_alias", longNameAlias), + ExpectError: regexp.MustCompile(`property nameAlias of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccLoopBackInterfaceProfileConfigUpdatedAttr(rName, fabricNodeDn3, addr, addr, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccLoopBackInterfaceProfileConfig(rName, fabricNodeDn3, addr, addr), + }, + }, + }) +} + +func CreateAccLoopBackInterfaceProfileRemovingRequiredField() string { + fmt.Println("=== STEP Basic: testing LoopBackInterfaceProfile updation without required parameters") + resource := fmt.Sprintln(` + resource "aci_l3out_route_tag_policy" "test" { + description = "created while acceptance testing" + annotation = "orchestrator:terraform_testacc" + name_alias = "test_l3out_route_tag_policy" + } + `) + + return resource +} + +func CreateAccLoopBackInterfaceProfileConfigWithOptionalValues(rName, tdn, parent_addr, addr string) string { + fmt.Println("=== STEP Basic: testing l3out_route_tag_policy creation with optional parameters") + resource := fmt.Sprintf(` + + + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name ="%s" + } + resource "aci_logical_node_to_fabric_node" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + tdn = "%s" + rtr_id ="%s" + } + resource "aci_l3out_loopback_interface_profile" "test" { + fabric_node_dn = aci_logical_node_to_fabric_node.test.id + addr = "%s" + description = "from terraform" + annotation = "example" + name_alias = "example" + } + `, rName, rName, rName, tdn, addr, addr) + + return resource +} + +func CreateAccLoopBackInterfaceProfileWithInvalidIP(rName, tdn, parent_addr string) string { + fmt.Println("=== STEP testing LoopBackInterfaceProfile creation with invalid ip", rName) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name ="%s" + } + resource "aci_logical_node_to_fabric_node" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + tdn = "%s" + rtr_id = "%s" + } + resource "aci_l3out_loopback_interface_profile" "test" { + fabric_node_dn = aci_logical_node_to_fabric_node.test.id + addr = "%s" + } + `, rName, rName, rName, tdn, parent_addr, rName) + return resource +} + +func CreateAccLoopBackInterfaceProfileConfigWithRequiredParams(rName, tdn, parent_addr, addr string) string { + fmt.Printf("=== STEP testing LoopBackInterfaceProfile creation with tdn %s and addr %s\n", tdn, addr) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name ="%s" + } + resource "aci_logical_node_to_fabric_node" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + tdn = "%s" + rtr_id = "%s" + } + resource "aci_l3out_loopback_interface_profile" "test" { + fabric_node_dn = aci_logical_node_to_fabric_node.test.id + addr = "%s" + } + `, rName, rName, rName, tdn, parent_addr, addr) + return resource +} + +func CreateAccLoopBackInterfaceProfileConfigUpdatedAttr(rName, tdn, parent_addr, addr, key, value string) string { + fmt.Printf("=== STEP testing LoopBackInterfaceProfile updation for %s = %s\n", key, value) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name ="%s" + } + resource "aci_logical_node_to_fabric_node" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + tdn = "%s" + rtr_id = "%s" + } + resource "aci_l3out_loopback_interface_profile" "test" { + fabric_node_dn = aci_logical_node_to_fabric_node.test.id + addr = "%s" + %s = "%s" + } + `, rName, rName, rName, tdn, addr, addr, key, value) + return resource +} + +func CreateAccLoopBackInterfaceProfileConfigWithInvalidParentDn(rName, addr string) string { + fmt.Println("=== STEP testing LoopBackInterfaceProfile creation invalid fabric_node_dn") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3out_loopback_interface_profile" "test" { + fabric_node_dn = aci_tenant.test.id + addr = "%s" + } + `, rName, addr) + return resource +} + +func CreateAccLoopBackInterfaceProfileConfig(rName, tdn, parent_addr, addr string) string { + fmt.Println("=== STEP testing LoopBackInterfaceProfile creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name ="%s" + } + resource "aci_logical_node_to_fabric_node" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + tdn = "%s" + rtr_id = "%s" + } + resource "aci_l3out_loopback_interface_profile" "test" { + fabric_node_dn = aci_logical_node_to_fabric_node.test.id + addr = "%s" + } + `, rName, rName, rName, tdn, addr, addr) + return resource +} + +func CreateLoopBackInterfaceProfileWithoutRequired(rName, tdn, parent_addr, addr, attrName string) string { + fmt.Println("=== STEP Basic: testing LoopBackInterfaceProfile creation without ", attrName) + rBlock := ` + + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_logical_node_profile" "test" { + l3_outside_dn = aci_l3_outside.test.id + name ="%s" + } + resource "aci_logical_node_to_fabric_node" "test" { + logical_node_profile_dn = aci_logical_node_profile.test.id + tdn = "%s" + rtr_id ="%s" + } + + ` + switch attrName { + case "fabric_node_dn": + rBlock += ` + resource "aci_l3out_loopback_interface_profile" "test" { + #fabric_node_dn = aci_logical_node_to_fabric_node.test.id + addr = "%s" + } + ` + case "addr": + rBlock += ` + resource "aci_l3out_loopback_interface_profile" "test" { + fabric_node_dn = aci_logical_node_to_fabric_node.test.id + # addr = "%s" + } ` + } + + return fmt.Sprintf(rBlock, rName, rName, rName, tdn, parent_addr, addr) +} + +func testAccCheckAciLoopBackInterfaceProfileExists(name string, loop_back_interface_profile *models.LoopBackInterfaceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("L3out Loopback Interface Profile %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No L3out Loopback Interface Profile dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + loop_back_interface_profileFound := models.LoopBackInterfaceProfileFromContainer(cont) + if loop_back_interface_profileFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("L3out Loopback Interface Profile %s not found", rs.Primary.ID) + } + *loop_back_interface_profile = *loop_back_interface_profileFound + return nil + } +} + +func testAccCheckAciLoopBackInterfaceProfileDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing L3out Loopback Interface Profile destroy") + client := testAccProvider.Meta().(*client.Client) + + for _, rs := range s.RootModule().Resources { + + if rs.Type == "aci_l3out_loopback_interface_profile" { + cont, err := client.Get(rs.Primary.ID) + loop_back_interface_profile := models.LoopBackInterfaceProfileFromContainer(cont) + if err == nil { + return fmt.Errorf("L3out Loopback Interface Profile %s Still exists", loop_back_interface_profile.DistinguishedName) + } + + } else { + continue + } + } + + return nil +} + +func testAccCheckAciLoopBackInterfaceProfileIdEqual(m1, m2 *models.LoopBackInterfaceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName != m2.DistinguishedName { + return fmt.Errorf("LoopBackInterfaceProfile DNs are not equal") + } + return nil + } +} +func testAccCheckAciLoopBackInterfaceProfileIdNotEqual(m1, m2 *models.LoopBackInterfaceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName == m2.DistinguishedName { + return fmt.Errorf("LoopBackInterfaceProfile DNs are equal") + } + return nil + } +} diff --git a/testacc/resource_aci_l3extroutetagpol_test.go b/testacc/resource_aci_l3extroutetagpol_test.go new file mode 100644 index 000000000..4010ae31d --- /dev/null +++ b/testacc/resource_aci_l3extroutetagpol_test.go @@ -0,0 +1,392 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciL3outRouteTagPolicy_Basic(t *testing.T) { + var l3out_route_tag_policy_default models.L3outRouteTagPolicy + var l3out_route_tag_policy_updated models.L3outRouteTagPolicy + resourceName := "aci_l3out_route_tag_policy.test" + rName := makeTestVariable(acctest.RandString(5)) + longrName := acctest.RandString(65) + rNameUpdated := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outRouteTagPolicyDestroy, + Steps: []resource.TestStep{ + { + Config: CreateL3outRouteTagPolicyWithoutRequired(rName, rName, "tenant_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateL3outRouteTagPolicyWithoutRequired(rName, rName, "name"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outRouteTagPolicyConfig(rName, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outRouteTagPolicyExists(resourceName, &l3out_route_tag_policy_default), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "tag", "4294967295"), + ), + }, + { + + Config: CreateAccL3outRouteTagPolicyConfigWithOptionalValues(rName, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outRouteTagPolicyExists(resourceName, &l3out_route_tag_policy_updated), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform_testacc"), + resource.TestCheckResourceAttr(resourceName, "description", "created while acceptance testing"), + resource.TestCheckResourceAttr(resourceName, "name_alias", "test_l3out_route_tag_policy"), + resource.TestCheckResourceAttr(resourceName, "tag", "6546738"), + testAccCheckAciL3outRouteTagPolicyIdEqual(&l3out_route_tag_policy_default, &l3out_route_tag_policy_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + + { + Config: CreateAccL3outRouteTagPolicyRemovingRequiredField(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outRouteTagPolicyConfigUpdateWithInvalidName(rName, longrName), + ExpectError: regexp.MustCompile(`property name of (.)+ failed validation`), + }, + { + Config: CreateAccL3outRouteTagPolicyConfigWithRequiredParams(rNameUpdated, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outRouteTagPolicyExists(resourceName, &l3out_route_tag_policy_updated), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rNameUpdated)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + testAccCheckAciL3outRouteTagPolicyIdNotEqual(&l3out_route_tag_policy_default, &l3out_route_tag_policy_updated), + ), + }, + + { + Config: CreateAccL3outRouteTagPolicyConfig(rName, rName), + }, + { + Config: CreateAccL3outRouteTagPolicyConfigWithRequiredParams(rName, rNameUpdated), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outRouteTagPolicyExists(resourceName, &l3out_route_tag_policy_updated), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + resource.TestCheckResourceAttr(resourceName, "name", rNameUpdated), + testAccCheckAciL3outRouteTagPolicyIdNotEqual(&l3out_route_tag_policy_default, &l3out_route_tag_policy_updated), + ), + }, + }, + }) +} + +func TestAccAciL3outRouteTagPolicy_Negative(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := makeTestVariable(acctest.RandString(5)) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outRouteTagPolicyDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outRouteTagPolicyConfig(rName, rName), + }, + { + Config: CreateAccL3outRouteTagPolicyWithInValidParentDn(rName), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class l3extRouteTagPol (.)+`), + }, + { + Config: CreateAccL3outRouteTagPolicyUpdatedAttr(rName, rName, "description", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outRouteTagPolicyUpdatedAttr(rName, rName, "annotation", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outRouteTagPolicyUpdatedAttr(rName, rName, "name_alias", acctest.RandString(64)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outRouteTagPolicyUpdatedAttr(rName, rName, "tag", randomValue), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + + { + Config: CreateAccL3outRouteTagPolicyUpdatedAttr(rName, rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccL3outRouteTagPolicyConfig(rName, rName), + }, + }, + }) +} +func TestAccAciL3outRouteTagPolicy_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outRouteTagPolicyDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outRouteTagPolicyConfigMultiple(rName), + }, + }, + }) +} + +func CreateAccL3outRouteTagPolicyConfigMultiple(rName string) string { + fmt.Println("=== STEP creating multiple L3outRouteTagPolicy") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3out_route_tag_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_l3out_route_tag_policy" "test1" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + resource "aci_l3out_route_tag_policy" "test2" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, rName, rName+"1", rName+"2", rName+"3") + return resource +} +func CreateAccL3outRouteTagPolicyConfigUpdateWithInvalidName(parentName, rName string) string { + fmt.Printf("=== STEP Basic: testing L3outRouteTagPolicy creation with parent resource name %s and name %s\n", parentName, rName) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_l3out_route_tag_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, parentName, rName) + return resource +} +func testAccCheckAciL3outRouteTagPolicyExists(name string, l3out_route_tag_policy *models.L3outRouteTagPolicy) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("L3out Route Tag Policy %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No L3out Route Tag Policy dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + l3out_route_tag_policyFound := models.L3outRouteTagPolicyFromContainer(cont) + if l3out_route_tag_policyFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("L3out Route Tag Policy %s not found", rs.Primary.ID) + } + *l3out_route_tag_policy = *l3out_route_tag_policyFound + return nil + } +} + +func testAccCheckAciL3outRouteTagPolicyDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing l3out_route_tag_policy destroy") + client := testAccProvider.Meta().(*client.Client) + for _, rs := range s.RootModule().Resources { + if rs.Type == "aci_l3out_route_tag_policy" { + cont, err := client.Get(rs.Primary.ID) + l3out_route_tag_policy := models.L3outRouteTagPolicyFromContainer(cont) + if err == nil { + return fmt.Errorf("L3out Route Tag Policy %s Still exists", l3out_route_tag_policy.DistinguishedName) + } + } else { + continue + } + } + return nil +} + +func testAccCheckAciL3outRouteTagPolicyIdEqual(m1, m2 *models.L3outRouteTagPolicy) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName != m2.DistinguishedName { + return fmt.Errorf("l3out_route_tag_policy DNs are not equal") + } + return nil + } +} + +func testAccCheckAciL3outRouteTagPolicyIdNotEqual(m1, m2 *models.L3outRouteTagPolicy) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName == m2.DistinguishedName { + return fmt.Errorf("l3out_route_tag_policy DNs are equal") + } + return nil + } +} + +func CreateL3outRouteTagPolicyWithoutRequired(fvTenantName, rName, attrName string) string { + fmt.Println("=== STEP Basic: testing l3out_route_tag_policy creation without ", attrName) + rBlock := ` + + resource "aci_tenant" "test" { + name = "%s" + + } + + ` + switch attrName { + case "tenant_dn": + rBlock += ` + resource "aci_l3out_route_tag_policy" "test" { + # tenant_dn = aci_tenant.test.id + name = "%s" + } + ` + case "name": + rBlock += ` + resource "aci_l3out_route_tag_policy" "test" { + tenant_dn = aci_tenant.test.id + # name = "%s" + } ` + } + + return fmt.Sprintf(rBlock, fvTenantName, rName) +} + +func CreateAccL3outRouteTagPolicyConfigWithRequiredParams(fvTenantName, rName string) string { + fmt.Printf("=== STEP testing L3outRouteTagPolicy creation with parent resource name %s and name %s\n", fvTenantName, rName) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3out_route_tag_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, fvTenantName, rName) + return resource +} + +func CreateAccL3outRouteTagPolicyConfig(fvTenantName, rName string) string { + fmt.Println("=== STEP testing l3out_route_tag_policy creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3out_route_tag_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, fvTenantName, rName) + return resource +} + +func CreateAccL3outRouteTagPolicyWithInValidParentDn(rName string) string { + fmt.Println("=== STEP Negative Case: testing l3out_route_tag_policy creation with invalid parent Dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_l3out_route_tag_policy" "test" { + tenant_dn = "aci_application_profile.test.id" + name = "%s" + } + `, rName, rName, rName) + return resource +} + +func CreateAccL3outRouteTagPolicyConfigWithOptionalValues(fvTenantName, rName string) string { + fmt.Println("=== STEP Basic: testing l3out_route_tag_policy creation with optional parameters") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3out_route_tag_policy" "test" { + tenant_dn = "${aci_tenant.test.id}" + name = "%s" + description = "created while acceptance testing" + annotation = "orchestrator:terraform_testacc" + name_alias = "test_l3out_route_tag_policy" + tag = "6546738" + } + `, fvTenantName, rName) + + return resource +} + +func CreateAccL3outRouteTagPolicyRemovingRequiredField() string { + fmt.Println("=== STEP Basic: testing l3out_route_tag_policy updation without required parameters") + resource := fmt.Sprintln(` + resource "aci_l3out_route_tag_policy" "test" { + description = "created while acceptance testing" + annotation = "orchestrator:terraform_testacc" + name_alias = "test_l3out_route_tag_policy" + tag = "686789" + } + `) + + return resource +} + +func CreateAccL3outRouteTagPolicyUpdatedAttr(fvTenantName, rName, attribute, value string) string { + fmt.Printf("=== STEP testing l3out_route_tag_policy attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3out_route_tag_policy" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + %s = "%s" + } + `, fvTenantName, rName, attribute, value) + return resource +} diff --git a/testacc/resource_aci_l3extsubnet_test.go b/testacc/resource_aci_l3extsubnet_test.go new file mode 100644 index 000000000..2f4a93017 --- /dev/null +++ b/testacc/resource_aci_l3extsubnet_test.go @@ -0,0 +1,740 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciL3ExtSubnet_Basic(t *testing.T) { + var l3_ext_subnet_default models.L3ExtSubnet + var l3_ext_subnet_updated models.L3ExtSubnet + resourceName := "aci_l3_ext_subnet.test" + rName := makeTestVariable(acctest.RandString(5)) + rNameUpdated := makeTestVariable(acctest.RandString(5)) + ip, _ := acctest.RandIpAddress("10.0.1.0/16") + ip = fmt.Sprintf("%s/16", ip) + ipUpdated, _ := acctest.RandIpAddress("10.0.2.0/17") + ipUpdated = fmt.Sprintf("%s/17", ipUpdated) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3ExtSubnetDestroy, + Steps: []resource.TestStep{ + { + Config: CreateL3ExtSubnetWithoutRequired(rName, rName, rName, ip, "external_network_instance_profile_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateL3ExtSubnetWithoutRequired(rName, rName, rName, ip, "ip"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3ExtSubnetConfig(rName, rName, rName, ip), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_default), + resource.TestCheckResourceAttr(resourceName, "external_network_instance_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/instP-%s", rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "ip", ip), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "aggregate", ""), + resource.TestCheckResourceAttr(resourceName, "scope.#", "1"), + resource.TestCheckResourceAttr(resourceName, "scope.0", "import-security"), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_subnet_to_profile.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_subnet_to_rt_summ", ""), + ), + }, + { + Config: CreateAccL3ExtSubnetConfigWithOptionalValues(rName, rName, rName, ip), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform_testacc"), + resource.TestCheckResourceAttr(resourceName, "description", "created while acceptance testing"), + resource.TestCheckResourceAttr(resourceName, "name_alias", "test_l3_ext_subnet"), + resource.TestCheckResourceAttr(resourceName, "aggregate", "shared-rtctrl"), + resource.TestCheckResourceAttr(resourceName, "scope.#", "1"), + resource.TestCheckResourceAttr(resourceName, "scope.0", "export-rtctrl"), + resource.TestCheckResourceAttr(resourceName, "external_network_instance_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/instP-%s", rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "ip", ip), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_subnet_to_profile.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_subnet_to_rt_summ", ""), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccL3ExtSubnetRemovingRequiredField(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3ExtSubnetWithInavalidIP(rName, ip), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class l3extSubnet (.)+`), + }, + { + Config: CreateAccL3ExtSubnetConfigWithRequiredParams(rNameUpdated, ip), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "external_network_instance_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/instP-%s", rNameUpdated, rNameUpdated, rNameUpdated)), + resource.TestCheckResourceAttr(resourceName, "ip", ip), + testAccCheckAciL3ExtSubnetIdNotEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + Config: CreateAccL3ExtSubnetConfig(rName, rName, rName, ip), + }, + { + Config: CreateAccL3ExtSubnetConfigWithRequiredParams(rName, ipUpdated), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "external_network_instance_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/instP-%s", rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "ip", ipUpdated), + testAccCheckAciL3ExtSubnetIdNotEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + }, + }) +} + +func TestAccAciL3ExtSubnet_Update(t *testing.T) { + var l3_ext_subnet_default models.L3ExtSubnet + var l3_ext_subnet_updated models.L3ExtSubnet + resourceName := "aci_l3_ext_subnet.test" + rName := makeTestVariable(acctest.RandString(5)) + ip := "0.0.0.0/0" + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3ExtSubnetDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3ExtSubnetConfig(rName, rName, rName, ip), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_default), + ), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttr(rName, rName, rName, ip, "aggregate", "import-rtctrl"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "aggregate", "import-rtctrl"), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttr(rName, rName, rName, ip, "aggregate", "export-rtctrl"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "aggregate", "export-rtctrl"), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{"import-rtctrl"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "scope.#", "1"), + resource.TestCheckResourceAttr(resourceName, "scope.0", "import-rtctrl"), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{"shared-rtctrl"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "scope.#", "1"), + resource.TestCheckResourceAttr(resourceName, "scope.0", "shared-rtctrl"), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{"import-rtctrl", "export-rtctrl"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "scope.#", "2"), + resource.TestCheckResourceAttr(resourceName, "scope.0", "import-rtctrl"), + resource.TestCheckResourceAttr(resourceName, "scope.1", "export-rtctrl"), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{"import-rtctrl", "import-security"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "scope.#", "2"), + resource.TestCheckResourceAttr(resourceName, "scope.0", "import-rtctrl"), + resource.TestCheckResourceAttr(resourceName, "scope.1", "import-security"), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{"import-rtctrl", "shared-rtctrl"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "scope.#", "2"), + resource.TestCheckResourceAttr(resourceName, "scope.0", "import-rtctrl"), + resource.TestCheckResourceAttr(resourceName, "scope.1", "shared-rtctrl"), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{"export-rtctrl", "import-security"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "scope.#", "2"), + resource.TestCheckResourceAttr(resourceName, "scope.0", "export-rtctrl"), + resource.TestCheckResourceAttr(resourceName, "scope.1", "import-security"), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{"export-rtctrl", "shared-rtctrl"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "scope.#", "2"), + resource.TestCheckResourceAttr(resourceName, "scope.0", "export-rtctrl"), + resource.TestCheckResourceAttr(resourceName, "scope.1", "shared-rtctrl"), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{"import-security", "shared-security"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "scope.#", "2"), + resource.TestCheckResourceAttr(resourceName, "scope.0", "import-security"), + resource.TestCheckResourceAttr(resourceName, "scope.1", "shared-security"), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{"import-security", "shared-rtctrl"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "scope.#", "2"), + resource.TestCheckResourceAttr(resourceName, "scope.0", "import-security"), + resource.TestCheckResourceAttr(resourceName, "scope.1", "shared-rtctrl"), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{"import-rtctrl", "export-rtctrl", "import-security"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "scope.#", "3"), + resource.TestCheckResourceAttr(resourceName, "scope.0", "import-rtctrl"), + resource.TestCheckResourceAttr(resourceName, "scope.1", "export-rtctrl"), + resource.TestCheckResourceAttr(resourceName, "scope.2", "import-security"), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{"import-security", "shared-security", "shared-rtctrl"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "scope.#", "3"), + resource.TestCheckResourceAttr(resourceName, "scope.0", "import-security"), + resource.TestCheckResourceAttr(resourceName, "scope.1", "shared-security"), + resource.TestCheckResourceAttr(resourceName, "scope.2", "shared-rtctrl"), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{"import-rtctrl", "export-rtctrl", "shared-rtctrl"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "scope.#", "3"), + resource.TestCheckResourceAttr(resourceName, "scope.0", "import-rtctrl"), + resource.TestCheckResourceAttr(resourceName, "scope.1", "export-rtctrl"), + resource.TestCheckResourceAttr(resourceName, "scope.2", "shared-rtctrl"), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{"import-rtctrl", "import-security", "shared-security"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "scope.#", "3"), + resource.TestCheckResourceAttr(resourceName, "scope.0", "import-rtctrl"), + resource.TestCheckResourceAttr(resourceName, "scope.1", "import-security"), + resource.TestCheckResourceAttr(resourceName, "scope.2", "shared-security"), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{"import-rtctrl", "import-security", "shared-rtctrl"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "scope.#", "3"), + resource.TestCheckResourceAttr(resourceName, "scope.0", "import-rtctrl"), + resource.TestCheckResourceAttr(resourceName, "scope.1", "import-security"), + resource.TestCheckResourceAttr(resourceName, "scope.2", "shared-rtctrl"), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{"export-rtctrl", "import-security", "shared-security"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "scope.#", "3"), + resource.TestCheckResourceAttr(resourceName, "scope.0", "export-rtctrl"), + resource.TestCheckResourceAttr(resourceName, "scope.1", "import-security"), + resource.TestCheckResourceAttr(resourceName, "scope.2", "shared-security"), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{"export-rtctrl", "import-security", "shared-rtctrl"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "scope.#", "3"), + resource.TestCheckResourceAttr(resourceName, "scope.0", "export-rtctrl"), + resource.TestCheckResourceAttr(resourceName, "scope.1", "import-security"), + resource.TestCheckResourceAttr(resourceName, "scope.2", "shared-rtctrl"), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{"import-rtctrl", "export-rtctrl", "import-security", "shared-security", "shared-rtctrl"})), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3ExtSubnetExists(resourceName, &l3_ext_subnet_updated), + resource.TestCheckResourceAttr(resourceName, "scope.#", "5"), + resource.TestCheckResourceAttr(resourceName, "scope.0", "import-rtctrl"), + resource.TestCheckResourceAttr(resourceName, "scope.1", "export-rtctrl"), + resource.TestCheckResourceAttr(resourceName, "scope.2", "import-security"), + resource.TestCheckResourceAttr(resourceName, "scope.3", "shared-security"), + resource.TestCheckResourceAttr(resourceName, "scope.4", "shared-rtctrl"), + testAccCheckAciL3ExtSubnetIdEqual(&l3_ext_subnet_default, &l3_ext_subnet_updated), + ), + }, + }, + }) +} + +func TestAccAciL3ExtSubnet_Negative(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + ip, _ := acctest.RandIpAddress("10.0.3.0/18") + ip = fmt.Sprintf("%s/18", ip) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3ExtSubnetDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3ExtSubnetConfig(rName, rName, rName, ip), + }, + { + Config: CreateAccL3ExtSubnetWithInValidParentDn(rName, ip), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class l3extSubnet (.)+`), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttr(rName, rName, rName, ip, "description", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttr(rName, rName, rName, ip, "annotation", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttr(rName, rName, rName, ip, "name_alias", acctest.RandString(64)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttr(rName, rName, rName, ip, "aggregate", randomValue), + ExpectError: regexp.MustCompile(`expected(.)+ to be one of(.)+, got(.)+`), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{randomValue})), + ExpectError: regexp.MustCompile(`expected(.)+ to be one of(.)+, got(.)+`), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{"export-rtctrl", "export-rtctrl"})), + ExpectError: regexp.MustCompile(`duplication is not supported in list`), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttrList(rName, rName, rName, ip, "scope", StringListtoString([]string{"shared-security", "shared-rtctrl"})), + ExpectError: regexp.MustCompile(`shared_security scope also needs import_security`), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttr(rName, rName, rName, ip, "aggregate", "import-rtctrl"), + ExpectError: regexp.MustCompile(`Invalid Configuration - Import/Export Subnet Aggregation Supported Only`), + }, + { + Config: CreateAccL3ExtSubnetUpdatedAttr(rName, rName, rName, ip, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named(.)+ is not expected here.`), + }, + { + Config: CreateAccL3ExtSubnetConfig(rName, rName, rName, ip), + }, + }, + }) +} + +func TestAccAciL3ExtSubnet_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + ip, _ := acctest.RandIpAddress("10.0.4.0/19") + ip = fmt.Sprintf("%s/19", ip) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3ExtSubnetDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3ExtSubnetsConfig(rName, rName, rName, ip), + }, + }, + }) +} + +func CreateAccL3ExtSubnetsConfig(fvTenantName, l3extOutName, l3extInstPName, ip string) string { + fmt.Println("=== STEP testing multiple l3_ext_subnet creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_external_network_instance_profile" "test1" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_external_network_instance_profile" "test2" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_external_network_instance_profile" "test3" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_l3_ext_subnet" "test1" { + external_network_instance_profile_dn = aci_external_network_instance_profile.test1.id + ip = "%s" + } + + resource "aci_l3_ext_subnet" "test2" { + external_network_instance_profile_dn = aci_external_network_instance_profile.test2.id + ip = "%s" + } + + resource "aci_l3_ext_subnet" "test3" { + external_network_instance_profile_dn = aci_external_network_instance_profile.test3.id + ip = "%s" + } + `, fvTenantName, l3extOutName, l3extInstPName+"1", l3extInstPName+"2", l3extInstPName+"3", ip, ip, ip) + return resource +} + +func CreateAccL3ExtSubnetWithInavalidIP(rName, ip string) string { + fmt.Println("=== STEP Basic: testing l3_ext_subnet creation with invalid IP") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_external_network_instance_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_l3_ext_subnet" "test" { + external_network_instance_profile_dn = "${aci_external_network_instance_profile.test.id}" + ip = "%s0" + } + `, rName, rName, rName, ip) + return resource +} + +func testAccCheckAciL3ExtSubnetExists(name string, l3_ext_subnet *models.L3ExtSubnet) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("L3 Ext Subnet %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No L3 Ext Subnet dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + l3_ext_subnetFound := models.L3ExtSubnetFromContainer(cont) + if l3_ext_subnetFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("L3 Ext Subnet %s not found", rs.Primary.ID) + } + *l3_ext_subnet = *l3_ext_subnetFound + return nil + } +} + +func testAccCheckAciL3ExtSubnetDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing l3_ext_subnet destroy") + client := testAccProvider.Meta().(*client.Client) + for _, rs := range s.RootModule().Resources { + if rs.Type == "aci_l3_ext_subnet" { + cont, err := client.Get(rs.Primary.ID) + l3_ext_subnet := models.L3ExtSubnetFromContainer(cont) + if err == nil { + return fmt.Errorf("L3 Ext Subnet %s Still exists", l3_ext_subnet.DistinguishedName) + } + } else { + continue + } + } + return nil +} + +func testAccCheckAciL3ExtSubnetIdEqual(m1, m2 *models.L3ExtSubnet) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName != m2.DistinguishedName { + return fmt.Errorf("l3_ext_subnet DNs are not equal") + } + return nil + } +} + +func testAccCheckAciL3ExtSubnetIdNotEqual(m1, m2 *models.L3ExtSubnet) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName == m2.DistinguishedName { + return fmt.Errorf("l3_ext_subnet DNs are equal") + } + return nil + } +} + +func CreateL3ExtSubnetWithoutRequired(fvTenantName, l3extOutName, l3extInstPName, ip, attrName string) string { + fmt.Println("=== STEP Basic: testing l3_ext_subnet creation without ", attrName) + rBlock := ` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_external_network_instance_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + ` + switch attrName { + case "external_network_instance_profile_dn": + rBlock += ` + resource "aci_l3_ext_subnet" "test" { + # external_network_instance_profile_dn = aci_external_network_instance_profile.test.id + ip = "%s" + } + ` + case "ip": + rBlock += ` + resource "aci_l3_ext_subnet" "test" { + external_network_instance_profile_dn = aci_external_network_instance_profile.test.id + # ip = "%s" + } + ` + } + return fmt.Sprintf(rBlock, fvTenantName, l3extOutName, l3extInstPName, ip) +} + +func CreateAccL3ExtSubnetConfigWithRequiredParams(rName, ip string) string { + fmt.Println("=== STEP testing l3_ext_subnet creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_external_network_instance_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_l3_ext_subnet" "test" { + external_network_instance_profile_dn = aci_external_network_instance_profile.test.id + ip = "%s" + } + `, rName, rName, rName, ip) + return resource +} + +func CreateAccL3ExtSubnetConfig(fvTenantName, l3extOutName, l3extInstPName, ip string) string { + fmt.Println("=== STEP testing l3_ext_subnet creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_external_network_instance_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_l3_ext_subnet" "test" { + external_network_instance_profile_dn = aci_external_network_instance_profile.test.id + ip = "%s" + } + `, fvTenantName, l3extOutName, l3extInstPName, ip) + return resource +} + +func CreateAccL3ExtSubnetWithInValidParentDn(rName, ip string) string { + fmt.Println("=== STEP Negative Case: testing l3_ext_subnet creation with invalid parent Dn") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_ext_subnet" "test" { + external_network_instance_profile_dn = aci_tenant.test.id + ip = "%s" + } + `, rName, ip) + return resource +} + +func CreateAccL3ExtSubnetConfigWithOptionalValues(fvTenantName, l3extOutName, l3extInstPName, ip string) string { + fmt.Println("=== STEP Basic: testing l3_ext_subnet creation with optional parameters") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_external_network_instance_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_l3_ext_subnet" "test" { + external_network_instance_profile_dn = "${aci_external_network_instance_profile.test.id}" + ip = "%s" + description = "created while acceptance testing" + annotation = "orchestrator:terraform_testacc" + name_alias = "test_l3_ext_subnet" + scope = ["export-rtctrl"] + aggregate = "shared-rtctrl" + } + `, fvTenantName, l3extOutName, l3extInstPName, ip) + + return resource +} + +func CreateAccL3ExtSubnetRemovingRequiredField() string { + fmt.Println("=== STEP Basic: testing l3_ext_subnet updation without required parameters") + resource := fmt.Sprintln(` + resource "aci_l3_ext_subnet" "test" { + description = "created while acceptance testing" + annotation = "tag" + name_alias = "test_l3_ext_subnet" + aggregate = "export-rtctrl" + scope = ["export-rtctrl"] + } + `) + + return resource +} + +func CreateAccL3ExtSubnetUpdatedAttr(fvTenantName, l3extOutName, l3extInstPName, ip, attribute, value string) string { + fmt.Printf("=== STEP testing l3_ext_subnet attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_external_network_instance_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_l3_ext_subnet" "test" { + external_network_instance_profile_dn = aci_external_network_instance_profile.test.id + ip = "%s" + %s = "%s" + } + `, fvTenantName, l3extOutName, l3extInstPName, ip, attribute, value) + return resource +} + +func CreateAccL3ExtSubnetUpdatedAttrList(fvTenantName, l3extOutName, l3extInstPName, ip, attribute, value string) string { + fmt.Printf("=== STEP testing l3_ext_subnet attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_l3_outside" "test" { + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_external_network_instance_profile" "test" { + name = "%s" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_l3_ext_subnet" "test" { + external_network_instance_profile_dn = aci_external_network_instance_profile.test.id + ip = "%s" + %s = %s + } + `, fvTenantName, l3extOutName, l3extInstPName, ip, attribute, value) + return resource +} diff --git a/testacc/resource_aci_l3extvirtuallifp_test.go b/testacc/resource_aci_l3extvirtuallifp_test.go new file mode 100644 index 000000000..d626815d5 --- /dev/null +++ b/testacc/resource_aci_l3extvirtuallifp_test.go @@ -0,0 +1,869 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciL3outFloatingSVI_Basic(t *testing.T) { + var l3out_floating_svi_default models.VirtualLogicalInterfaceProfile + var l3out_floating_svi_updated models.VirtualLogicalInterfaceProfile + resourceName := "aci_l3out_floating_svi.test" + rName := makeTestVariable(acctest.RandString(5)) + rNameUpdated := makeTestVariable(acctest.RandString(5)) + nodeDn := "topology/pod-1/node-111" + nodeDnUpdated := "topology/pod-1/node-101" + encap := "vlan-20" + encapUpdated := "vlan-60" + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outFloatingSVIDestroy, + Steps: []resource.TestStep{ + { + Config: CreateL3outFloatingSVIWithoutRequired(rName, rName, rName, rName, nodeDn, encap, "logical_interface_profile_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateL3outFloatingSVIWithoutRequired(rName, rName, rName, rName, nodeDn, encap, "encap"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + + { + Config: CreateL3outFloatingSVIWithoutRequired(rName, rName, rName, rName, nodeDn, encap, "nodeDn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outFloatingSVIConfig(rName, rName, rName, rName, nodeDn, encap), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_default), + resource.TestCheckResourceAttr(resourceName, "logical_interface_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s", rName, rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "node_dn", nodeDn), + resource.TestCheckResourceAttr(resourceName, "encap", encap), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "addr", "0.0.0.0"), + resource.TestCheckResourceAttr(resourceName, "autostate", "disabled"), + resource.TestCheckResourceAttr(resourceName, "encap_scope", "local"), + resource.TestCheckResourceAttr(resourceName, "if_inst_t", "ext-svi"), + resource.TestCheckResourceAttr(resourceName, "ipv6_dad", "enabled"), + resource.TestCheckResourceAttr(resourceName, "ll_addr", "::"), + resource.TestCheckResourceAttr(resourceName, "mode", "regular"), + resource.TestCheckResourceAttr(resourceName, "mtu", "inherit"), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "unspecified"), + ), + }, + { + Config: CreateAccL3outFloatingSVIConfigWithOptionalValues(rName, rName, rName, rName, nodeDn, encap), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "logical_interface_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s", rName, rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "node_dn", nodeDn), + resource.TestCheckResourceAttr(resourceName, "encap", encap), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform_testacc"), + resource.TestCheckResourceAttr(resourceName, "description", "created while acceptance testing"), + resource.TestCheckResourceAttr(resourceName, "addr", "1.2.1.1/16"), + resource.TestCheckResourceAttr(resourceName, "autostate", "enabled"), + resource.TestCheckResourceAttr(resourceName, "encap_scope", "ctx"), + resource.TestCheckResourceAttr(resourceName, "if_inst_t", "ext-svi"), + resource.TestCheckResourceAttr(resourceName, "ipv6_dad", "disabled"), + resource.TestCheckResourceAttr(resourceName, "ll_addr", "fe80::1"), + resource.TestCheckResourceAttr(resourceName, "mac", "00:22:BD:F8:19:F0"), + resource.TestCheckResourceAttr(resourceName, "mode", "native"), + resource.TestCheckResourceAttr(resourceName, "mtu", "577"), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS0"), + resource.TestCheckResourceAttr(resourceName, "relation_l3ext_rs_dyn_path_att.#", "0"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccL3outFloatingSVIConfigWithUpdatedRequiredParams(rNameUpdated, nodeDn, encap), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "logical_interface_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s", rNameUpdated, rNameUpdated, rNameUpdated, rNameUpdated)), + resource.TestCheckResourceAttr(resourceName, "node_dn", nodeDn), + resource.TestCheckResourceAttr(resourceName, "encap", encap), + testAccCheckAciL3outFloatingSVIIdNotEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIConfig(rName, rName, rName, rName, nodeDn, encap), + }, + { + Config: CreateAccL3outFloatingSVIConfigWithUpdatedRequiredParams(rName, nodeDnUpdated, encap), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "logical_interface_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s", rName, rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "node_dn", nodeDnUpdated), + resource.TestCheckResourceAttr(resourceName, "encap", encap), + testAccCheckAciL3outFloatingSVIIdNotEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIConfig(rName, rName, rName, rName, nodeDn, encap), + }, + { + Config: CreateAccL3outFloatingSVIConfigWithUpdatedRequiredParams(rName, nodeDn, encapUpdated), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "logical_interface_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s", rName, rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "node_dn", nodeDn), + resource.TestCheckResourceAttr(resourceName, "encap", encapUpdated), + testAccCheckAciL3outFloatingSVIIdNotEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIConfigUpdateWithoutRequiredParameters(rName, rName, rName, rName, "description", "test_coverage"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outFloatingSVIConfig(rName, rName, rName, rName, nodeDn, encap), + }, + }, + }) +} + +func TestAccAciL3outFloatingSVI_Update(t *testing.T) { + var l3out_floating_svi_default models.VirtualLogicalInterfaceProfile + var l3out_floating_svi_updated models.VirtualLogicalInterfaceProfile + resourceName := "aci_l3out_floating_svi.test" + rName := makeTestVariable(acctest.RandString(5)) + nodeDn := "topology/pod-1/node-111" + encap := "vlan-20" + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outFloatingSVIDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outFloatingSVIConfig(rName, rName, rName, rName, nodeDn, encap), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_default), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "mode", "untagged"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "mode", "untagged"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "CS1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS1"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "CS2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS2"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "CS3"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS3"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "CS4"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS4"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "CS5"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS5"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "CS6"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS6"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "CS7"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS7"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "EF"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "EF"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "VA"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "VA"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "AF11"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF11"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "AF12"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF12"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "AF13"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF13"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "AF21"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF21"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "AF22"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF22"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "AF23"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF23"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "AF31"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF31"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "AF32"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF32"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "AF33"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF33"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "AF41"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF41"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "AF42"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF42"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", "AF43"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF43"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "mtu", "576"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "mtu", "576"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "mtu", "9216"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outFloatingSVIExists(resourceName, &l3out_floating_svi_updated), + resource.TestCheckResourceAttr(resourceName, "mtu", "9216"), + testAccCheckAciL3outFloatingSVIIdEqual(&l3out_floating_svi_default, &l3out_floating_svi_updated), + ), + }, + { + Config: CreateAccL3outFloatingSVIConfig(rName, rName, rName, rName, nodeDn, encap), + }, + }, + }) +} + +func TestAccAciL3outFloatingSVI_Negative(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + nodeDn := "topology/pod-1/node-111" + encap := "vlan-20" + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := makeTestVariable(acctest.RandString(5)) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outFloatingSVIDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outFloatingSVIConfig(rName, rName, rName, rName, nodeDn, encap), + }, + { + Config: CreateAccL3outFloatingSVIWithInValidParentDn(rName, rName, rName, nodeDn, encap), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + { + Config: CreateAccL3outFloatingSVIConfig(rName, rName, rName, rName, nodeDn, randomValue), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + { + Config: CreateAccL3outFloatingSVIConfig(rName, rName, rName, rName, randomValue, encap), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "description", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "annotation", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "addr", randomValue), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "addr", "1.1.1.1/32"), + ExpectError: regexp.MustCompile(`Invalid External Interface Address`), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "autostate", randomValue), + ExpectError: regexp.MustCompile(`expected(.)*to be one of(.)*, got(.)*`), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "encap_scope", randomValue), + ExpectError: regexp.MustCompile(`expected(.)*to be one of(.)*, got(.)*`), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "ipv6_dad", randomValue), + ExpectError: regexp.MustCompile(`expected(.)*to be one of(.)*, got(.)*`), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "ll_addr", randomValue), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "mode", randomValue), + ExpectError: regexp.MustCompile(`expected(.)*to be one of(.)*, got(.)*`), + }, + // mac attribute negative test case not possible due to server side issue + // { + // Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "if_inst_t", randomValue), + // ExpectError: regexp.MustCompile(`expected(.)*to be one of(.)*, got(.)*`), + // }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "mtu", randomValue), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "mtu", "100"), + ExpectError: regexp.MustCompile(`Property mtu of (.)+ is out of range`), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, "target_dscp", randomValue), + ExpectError: regexp.MustCompile(`expected(.)*to be one of(.)*, got(.)*`), + }, + { + Config: CreateAccL3outFloatingSVIUpdatedAttr(rName, rName, rName, rName, nodeDn, encap, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named(.)*is not expected here.`), + }, + { + Config: CreateAccL3outFloatingSVIConfig(rName, rName, rName, rName, nodeDn, encap), + }, + }, + }) +} + +func TestAccAciL3outFloatingSVI_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + node_dn := "topology/pod-1/node-111" + encap := "vlan-" + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outFloatingSVIDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outFloatingSVIsConfig(rName, rName, rName, rName, node_dn, encap), + }, + }, + }) +} + +func testAccCheckAciL3outFloatingSVIExists(name string, l3out_floating_svi *models.VirtualLogicalInterfaceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("L3out Floating SVI %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No L3out Floating SVI dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + l3out_floating_sviFound := models.VirtualLogicalInterfaceProfileFromContainer(cont) + if l3out_floating_sviFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("L3out Floating SVI %s not found", rs.Primary.ID) + } + *l3out_floating_svi = *l3out_floating_sviFound + return nil + } +} + +func testAccCheckAciL3outFloatingSVIDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing l3out_floating_svi destroy") + client := testAccProvider.Meta().(*client.Client) + for _, rs := range s.RootModule().Resources { + if rs.Type == "aci_l3out_floating_svi" { + cont, err := client.Get(rs.Primary.ID) + l3out_floating_svi := models.VirtualLogicalInterfaceProfileFromContainer(cont) + if err == nil { + return fmt.Errorf("L3out Floating SVI %s Still exists", l3out_floating_svi.DistinguishedName) + } + } else { + continue + } + } + return nil +} + +func testAccCheckAciL3outFloatingSVIIdEqual(m1, m2 *models.VirtualLogicalInterfaceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName != m2.DistinguishedName { + return fmt.Errorf("l3out_floating_svi DNs are not equal") + } + return nil + } +} + +func testAccCheckAciL3outFloatingSVIIdNotEqual(m1, m2 *models.VirtualLogicalInterfaceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName == m2.DistinguishedName { + return fmt.Errorf("l3out_floating_svi DNs are equal") + } + return nil + } +} + +func CreateL3outFloatingSVIWithoutRequired(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, nodeDn, encap, attrName string) string { + fmt.Println("=== STEP Basic: testing l3out_floating_svi creation without required parameter", attrName) + rBlock := ` + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + ` + switch attrName { + case "logical_interface_profile_dn": + rBlock += ` + resource "aci_l3out_floating_svi" "test" { + # logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = "%s" + encap = "%s" + if_inst_t = "ext-svi" + } + ` + case "nodeDn": + rBlock += ` + resource "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + # node_dn = "%s" + encap = "%s" + if_inst_t = "ext-svi" + } + ` + case "encap": + rBlock += ` + resource "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = "%s" + # encap = "%s" + if_inst_t = "ext-svi" + } + ` + } + return fmt.Sprintf(rBlock, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, nodeDn, encap) +} + +func CreateAccL3outFloatingSVIConfigWithUpdatedRequiredParams(rName, nodeDn, encap string) string { + fmt.Println("=== STEP testing l3out_floating_svi updation of required arguments") + resource := fmt.Sprintf( + ` + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = "%s" + encap = "%s" + if_inst_t = "ext-svi" + } + `, rName, rName, rName, rName, nodeDn, encap) + return resource +} + +func CreateAccL3outFloatingSVIConfig(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, nodeDn, encap string) string { + fmt.Println("=== STEP testing l3out_floating_svi creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = "%s" + encap = "%s" + if_inst_t = "ext-svi" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, nodeDn, encap) + return resource +} + +func CreateAccL3outFloatingSVIsConfig(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, nodeDn, encap string) string { + fmt.Println("=== STEP testing Multiple l3out_floating_svi creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = "%s" + encap = "%s" + if_inst_t = "ext-svi" + } + + resource "aci_l3out_floating_svi" "test1" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = "%s" + encap = "%s" + if_inst_t = "ext-svi" + } + + resource "aci_l3out_floating_svi" "test2" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = "%s" + encap = "%s" + if_inst_t = "ext-svi" + } + + resource "aci_l3out_floating_svi" "test3" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = "%s" + encap = "%s" + if_inst_t = "ext-svi" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, nodeDn, encap+"10", nodeDn, encap+"20", nodeDn, encap+"30", nodeDn, encap+"40") + return resource +} + +func CreateAccL3outFloatingSVIWithInValidParentDn(fvTenantName, l3extOutName, l3extLNodePName, nodeDn, encap string) string { + fmt.Println("=== STEP Negative Case: testing l3out_floating_svi creation with invalid parent Dn") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = "aci_logical_node_profile.test.id" + node_dn = "%s" + encap = "%s" + if_inst_t = "ext-svi" + } + `, fvTenantName, l3extOutName, l3extLNodePName, nodeDn, encap) + return resource +} + +func CreateAccL3outFloatingSVIConfigWithOptionalValues(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, nodeDn, encap string) string { + fmt.Println("=== STEP Basic: testing l3out_floating_svi creation with optional parameters") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = "${aci_logical_interface_profile.test.id}" + node_dn = "%s" + encap = "%s" + description = "created while acceptance testing" + annotation = "orchestrator:terraform_testacc" + addr = "1.2.1.1/16" + autostate = "enabled" + encap_scope = "ctx" + if_inst_t = "ext-svi" + ipv6_dad = "disabled" + ll_addr = "fe80::1" + mac = "00:22:BD:F8:19:F0" + mode = "native" + mtu = "577" + target_dscp = "CS0" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, nodeDn, encap) + return resource +} + +func CreateAccL3outFloatingSVIUpdatedAttr(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, nodeDn, encap, attribute, value string) string { + fmt.Printf("=== STEP testing l3out_floating_svi updation with attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_floating_svi" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + node_dn = "%s" + encap = "%s" + if_inst_t = "ext-svi" + %s = "%s" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, nodeDn, encap, attribute, value) + return resource +} + +func CreateAccL3outFloatingSVIConfigUpdateWithoutRequiredParameters(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, attribute, value string) string { + fmt.Printf("=== STEP testing l3out_floating_svi updation with attribute: %s=%s without required arguments\n", attribute, value) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_floating_svi" "test" { + %s = "%s" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, attribute, value) + return resource +} diff --git a/testacc/resource_aci_ospfifp_test.go b/testacc/resource_aci_ospfifp_test.go new file mode 100644 index 000000000..a90171505 --- /dev/null +++ b/testacc/resource_aci_ospfifp_test.go @@ -0,0 +1,500 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciL3outOspfInterfaceProfile_Basic(t *testing.T) { + var l3out_ospf_interface_profile_default models.OSPFInterfaceProfile + var l3out_ospf_interface_profile_updated models.OSPFInterfaceProfile + resourceName := "aci_l3out_ospf_interface_profile.test" + rName := makeTestVariable(acctest.RandString(5)) + rNameUpdated := makeTestVariable(acctest.RandString(5)) + randomValue := acctest.RandString(5) + randomValueUpdated := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outOspfInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateL3outOspfInterfaceProfileWithoutRequired(rName, rName, rName, rName, "logical_interface_profile_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateL3outOspfInterfaceProfileWithoutRequired(rName, rName, rName, rName, "auth_key"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outOspfInterfaceProfileConfig(rName, rName, rName, rName, randomValue), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outOspfInterfaceProfileExists(resourceName, &l3out_ospf_interface_profile_default), + resource.TestCheckResourceAttr(resourceName, "logical_interface_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s", rName, rName, rName, rName)), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "auth_key", randomValue), + resource.TestCheckResourceAttr(resourceName, "auth_key_id", "1"), + resource.TestCheckResourceAttr(resourceName, "auth_type", "none"), + resource.TestCheckResourceAttr(resourceName, "relation_ospf_rs_if_pol", ""), + ), + }, + { + // in this step all optional attribute expect realational attribute are given for the same resource and then compared + Config: CreateAccL3outOspfInterfaceProfileConfigWithOptionalValues(rName, rName, rName, rName, randomValueUpdated), // configuration to update optional filelds + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outOspfInterfaceProfileExists(resourceName, &l3out_ospf_interface_profile_updated), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform_testacc"), + resource.TestCheckResourceAttr(resourceName, "description", "created while acceptance testing"), + resource.TestCheckResourceAttr(resourceName, "name_alias", "test_l3out_ospf_interface_profile"), + resource.TestCheckResourceAttr(resourceName, "auth_key", randomValueUpdated), + resource.TestCheckResourceAttr(resourceName, "auth_key_id", "2"), + resource.TestCheckResourceAttr(resourceName, "auth_type", "md5"), + resource.TestCheckResourceAttr(resourceName, "relation_ospf_rs_if_pol", ""), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"auth_key"}, + }, + { + Config: CreateAccL3outOspfInterfaceProfileConfigWithRequiredParams(rNameUpdated, randomValue), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outOspfInterfaceProfileExists(resourceName, &l3out_ospf_interface_profile_updated), + resource.TestCheckResourceAttr(resourceName, "logical_interface_profile_dn", fmt.Sprintf("uni/tn-%s/out-%s/lnodep-%s/lifp-%s", rNameUpdated, rNameUpdated, rNameUpdated, rNameUpdated)), + testAccCheckAciL3outOspfInterfaceProfileIdNotEqual(&l3out_ospf_interface_profile_default, &l3out_ospf_interface_profile_updated), + ), + }, + { + Config: CreateAccL3outOspfInterfaceProfileConfigUpdateWithoutRequiredParameters(rName, "description", "test_coverage"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccL3outOspfInterfaceProfileConfig(rName, rName, rName, rName, randomValue), + }, + }, + }) +} + +func TestAccAciL3outOspfInterfaceProfile_Update(t *testing.T) { + var l3out_ospf_interface_profile_default models.OSPFInterfaceProfile + var l3out_ospf_interface_profile_updated models.OSPFInterfaceProfile + resourceName := "aci_l3out_ospf_interface_profile.test" + rName := makeTestVariable(acctest.RandString(5)) + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outOspfInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outOspfInterfaceProfileConfig(rName, rName, rName, rName, randomValue), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outOspfInterfaceProfileExists(resourceName, &l3out_ospf_interface_profile_default), + ), + }, + { + Config: CreateAccL3outOspfInterfaceProfileUpdatedAttr(rName, "auth_type", "simple"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciL3outOspfInterfaceProfileExists(resourceName, &l3out_ospf_interface_profile_updated), + resource.TestCheckResourceAttr(resourceName, "auth_type", "simple"), + testAccCheckAciL3outOspfInterfaceProfileIdEqual(&l3out_ospf_interface_profile_default, &l3out_ospf_interface_profile_updated), + ), + }, + { + Config: CreateAccL3outOspfInterfaceProfileConfig(rName, rName, rName, rName, randomValue), + }, + }, + }) +} + +func TestAccAciL3outOspfInterfaceProfile_Negative(t *testing.T) { + + rName := makeTestVariable(acctest.RandString(5)) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := makeTestVariable(acctest.RandString(5)) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciL3outOspfInterfaceProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccL3outOspfInterfaceProfileConfig(rName, rName, rName, rName, randomValue), + }, + { + Config: CreateAccL3outOspfInterfaceProfileWithInValidParentDn(rName, rName, rName, rName), + ExpectError: regexp.MustCompile(`configured object (.)+ not found (.)+,`), + }, + { + Config: CreateAccL3outOspfInterfaceProfileUpdatedAttr(rName, "description", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outOspfInterfaceProfileUpdatedAttr(rName, "annotation", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outOspfInterfaceProfileUpdatedAttr(rName, "name_alias", acctest.RandString(64)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccL3outOspfInterfaceProfileUpdatedAttr(rName, "auth_key_id", randomValue), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + { + Config: CreateAccL3outOspfInterfaceProfileUpdatedAttr(rName, "auth_type", randomValue), + ExpectError: regexp.MustCompile(`expected(.)*to be one of(.)*, got(.)*`), + }, + { + Config: CreateAccL3outOspfInterfaceProfileUpdatedAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named(.)*is not expected here.`), + }, + { + Config: CreateAccL3outOspfInterfaceProfileConfig(rName, rName, rName, rName, randomValue), + }, + }, + }) +} + +func testAccCheckAciL3outOspfInterfaceProfileExists(name string, l3out_ospf_interface_profile *models.OSPFInterfaceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("L3out Ospf Interface Profile %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No L3out Ospf Interface Profile dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + l3out_ospf_interface_profileFound := models.OSPFInterfaceProfileFromContainer(cont) + if l3out_ospf_interface_profileFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("L3out Ospf Interface Profile %s not found", rs.Primary.ID) + } + *l3out_ospf_interface_profile = *l3out_ospf_interface_profileFound + return nil + } +} + +func testAccCheckAciL3outOspfInterfaceProfileDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing l3out_ospf_interface_profile destroy") + client := testAccProvider.Meta().(*client.Client) + for _, rs := range s.RootModule().Resources { + if rs.Type == "aci_l3out_ospf_interface_profile" { + cont, err := client.Get(rs.Primary.ID) + l3out_ospf_interface_profile := models.OSPFInterfaceProfileFromContainer(cont) + if err == nil { + return fmt.Errorf("L3out Ospf Interface Profile %s Still exists", l3out_ospf_interface_profile.DistinguishedName) + } + } else { + continue + } + } + return nil +} + +func testAccCheckAciL3outOspfInterfaceProfileIdEqual(m1, m2 *models.OSPFInterfaceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName != m2.DistinguishedName { + return fmt.Errorf("l3out_ospf_interface_profile DNs are not equal") + } + return nil + } +} + +func testAccCheckAciL3outOspfInterfaceProfileIdNotEqual(m1, m2 *models.OSPFInterfaceProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName == m2.DistinguishedName { + return fmt.Errorf("l3out_ospf_interface_profile DNs are equal") + } + return nil + } +} + +func CreateL3outOspfInterfaceProfileWithoutRequired(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, attrName string) string { + fmt.Println("=== STEP Basic: testing l3out_ospf_interface_profile creation without ", attrName) + rBlock := ` + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + ` + switch attrName { + case "logical_interface_profile_dn": + rBlock += ` + resource "aci_l3out_ospf_interface_profile" "test" { + # logical_interface_profile_dn = aci_logical_interface_profile.test.id + auth_key = "random" + description = "created while acceptance testing" + } + ` + case "auth_key": + rBlock += ` + resource "aci_l3out_ospf_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + #auth_key = "random" + description = "created while acceptance testing" + }` + } + return fmt.Sprintf(rBlock, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName) +} + +func CreateAccL3outOspfInterfaceProfileConfigWithRequiredParams(rName, randomValue string) string { + fmt.Println("=== STEP testing l3out_ospf_interface_profile creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_ospf_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + auth_key = "%s" + } + `, rName, rName, rName, rName, randomValue) + return resource +} + +func CreateAccL3outOspfInterfaceProfileUpdatedAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP testing l3out_ospf_interface_profile creation with : %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_ospf_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + auth_key = "%s" + %s = "%s" + } + `, rName, rName, rName, rName, value, attribute, value) + return resource +} + +func CreateAccL3outOspfInterfaceProfileConfigUpdateWithoutRequiredParameters(rName, attribute, value string) string { + fmt.Println("=== STEP testing l3out_ospf_interface_profile updation without required arguments") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_ospf_interface_profile" "test" { + auth_key = "random" + %s = "%s" + } + `, rName, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccL3outOspfInterfaceProfileConfig(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, randomValue string) string { + fmt.Println("=== STEP testing l3out_ospf_interface_profile creation with required arguments only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_ospf_interface_profile" "test" { + logical_interface_profile_dn = aci_logical_interface_profile.test.id + auth_key = "%s" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, randomValue) + return resource +} + +func CreateAccL3outOspfInterfaceProfileWithInValidParentDn(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName string) string { + fmt.Println("=== STEP Negative Case: testing l3out_ospf_interface_profile creation with invalid parent Dn") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_ospf_interface_profile" "test" { + logical_interface_profile_dn = "${aci_logical_interface_profile.test.id}invalid" + auth_key = "random" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName) + return resource +} + +func CreateAccL3outOspfInterfaceProfileConfigWithOptionalValues(fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, randomValue string) string { + fmt.Println("=== STEP Basic: testing l3out_ospf_interface_profile creation with optional parameters") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_l3_outside" "test" { + name = "%s" + description = "l3_outside created while acceptance testing" + tenant_dn = aci_tenant.test.id + } + + resource "aci_logical_node_profile" "test" { + name = "%s" + description = "logical_node_profile created while acceptance testing" + l3_outside_dn = aci_l3_outside.test.id + } + + resource "aci_logical_interface_profile" "test" { + name = "%s" + description = "logical_interface_profile created while acceptance testing" + logical_node_profile_dn = aci_logical_node_profile.test.id + } + + resource "aci_l3out_ospf_interface_profile" "test" { + logical_interface_profile_dn = "${aci_logical_interface_profile.test.id}" + description = "created while acceptance testing" + annotation = "orchestrator:terraform_testacc" + name_alias = "test_l3out_ospf_interface_profile" + auth_key = "%s" + auth_key_id = "2" + auth_type = "md5" + } + `, fvTenantName, l3extOutName, l3extLNodePName, l3extLIfPName, randomValue) + + return resource +} diff --git a/testacc/resource_aci_rtctrlprofile_test.go b/testacc/resource_aci_rtctrlprofile_test.go new file mode 100644 index 000000000..1448d6895 --- /dev/null +++ b/testacc/resource_aci_rtctrlprofile_test.go @@ -0,0 +1,448 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciBgpRouteControlProfile_Basic(t *testing.T) { + var bgp_route_control_profile_default models.RouteControlProfile + var bgp_route_control_profile_updated models.RouteControlProfile + resourceName := "aci_bgp_route_control_profile.test" + rName := makeTestVariable(acctest.RandString(5)) + rNameUpdated := makeTestVariable(acctest.RandString(5)) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciBgpRouteControlProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateBgpRouteControlProfileWithoutRequired(rName, rName, "parent_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateBgpRouteControlProfileWithoutRequired(rName, rName, "name"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccBgpRouteControlProfileConfig(rName, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciBgpRouteControlProfileExists(resourceName, &bgp_route_control_profile_default), + resource.TestCheckResourceAttr(resourceName, "parent_dn", fmt.Sprintf("uni/tn-%s", rName)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "route_control_profile_type", "combinable"), + ), + }, + { + Config: CreateAccBgpRouteControlProfileConfigWithOptionalValues(rName, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciBgpRouteControlProfileExists(resourceName, &bgp_route_control_profile_updated), + resource.TestCheckResourceAttr(resourceName, "parent_dn", fmt.Sprintf("uni/tn-%s", rName)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform_testacc"), + resource.TestCheckResourceAttr(resourceName, "description", "created while acceptance testing"), + resource.TestCheckResourceAttr(resourceName, "name_alias", "test_route_control_profile"), + resource.TestCheckResourceAttr(resourceName, "route_control_profile_type", "global"), + testAccCheckAciBgpRouteControlProfileIdEqual(&bgp_route_control_profile_default, &bgp_route_control_profile_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccBgpRouteControlProfileConfigUpdatedName(rName, acctest.RandString(65)), + ExpectError: regexp.MustCompile(`property name of (.)+ failed validation`), + }, + + { + Config: CreateAccBgpRouteControlProfileConfigWithRequiredParams(rNameUpdated, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciBgpRouteControlProfileExists(resourceName, &bgp_route_control_profile_updated), + resource.TestCheckResourceAttr(resourceName, "parent_dn", fmt.Sprintf("uni/tn-%s", rNameUpdated)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + testAccCheckAciBgpRouteControlProfileIdNotEqual(&bgp_route_control_profile_default, &bgp_route_control_profile_updated), + ), + }, + { + Config: CreateAccBgpRouteControlProfileConfig(rName, rName), + }, + { + Config: CreateAccBgpRouteControlProfileConfigWithRequiredParams(rName, rNameUpdated), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciBgpRouteControlProfileExists(resourceName, &bgp_route_control_profile_updated), + resource.TestCheckResourceAttr(resourceName, "parent_dn", fmt.Sprintf("uni/tn-%s", rName)), + resource.TestCheckResourceAttr(resourceName, "name", rNameUpdated), + testAccCheckAciBgpRouteControlProfileIdNotEqual(&bgp_route_control_profile_default, &bgp_route_control_profile_updated), + ), + }, + { + Config: CreateAccBgpRouteControlProfileUpdateWithoutRequiredAttr(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccBgpRouteControlProfileConfigL3Outside(rName, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciBgpRouteControlProfileExists(resourceName, &bgp_route_control_profile_updated), + resource.TestCheckResourceAttr(resourceName, "parent_dn", fmt.Sprintf("uni/tn-%s/out-%s", rName, rName)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "route_control_profile_type", "combinable"), + testAccCheckAciBgpRouteControlProfileIdNotEqual(&bgp_route_control_profile_default, &bgp_route_control_profile_updated), + ), + }, + }, + }) +} + +func TestAccAciBgpRouteControlProfile_Negative(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := makeTestVariable(acctest.RandString(5)) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciBgpRouteControlProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccBgpRouteControlProfileConfig(rName, rName), + }, + { + Config: CreateAccBgpRouteControlProfileWithInValidParentDn(rName, rName), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class rtctrlProfile (.)+`), + }, + { + Config: CreateAccBgpRouteControlProfileUpdatedAttr(rName, rName, "description", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccBgpRouteControlProfileUpdatedAttr(rName, rName, "annotation", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccBgpRouteControlProfileUpdatedAttr(rName, rName, "name_alias", acctest.RandString(64)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccBgpRouteControlProfileUpdatedAttr(rName, rName, "route_control_profile_type", randomValue), + ExpectError: regexp.MustCompile(`expected(.)+to be one of(.)+, got(.)+`), + }, + + { + Config: CreateAccBgpRouteControlProfileUpdatedAttr(rName, rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named(.)+is not expected here.`), + }, + { + Config: CreateAccBgpRouteControlProfileConfig(rName, rName), + }, + }, + }) +} + +func TestAccAciBgpRouteControlProfile_Multiple(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciBgpRouteControlProfileDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccBgpRouteControlProfileConfigs(rName, rName), + }, + }, + }) +} + +func CreateAccBgpRouteControlProfileConfigs(fvTenantName, rName string) string { + fmt.Println("=== STEP Testing Multiple route_control_profile creation") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_bgp_route_control_profile" "test" { + parent_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_bgp_route_control_profile" "test1" { + parent_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_bgp_route_control_profile" "test2" { + parent_dn = aci_tenant.test.id + name = "%s" + } + `, fvTenantName, rName, rName+"1", rName+"2") + return resource +} + +func testAccCheckAciBgpRouteControlProfileExists(name string, bgp_route_control_profile *models.RouteControlProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("Bgp Route Control Profile %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No Bgp Route Control Profile dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + bgp_route_control_profileFound := models.RouteControlProfileFromContainer(cont) + if bgp_route_control_profileFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("Bgp Route Control Profile %s not found", rs.Primary.ID) + } + *bgp_route_control_profile = *bgp_route_control_profileFound + return nil + } +} + +func testAccCheckAciBgpRouteControlProfileDestroy(s *terraform.State) error { + fmt.Println("=== STEP Testing bgp_route_control_profile destroy") + client := testAccProvider.Meta().(*client.Client) + for _, rs := range s.RootModule().Resources { + if rs.Type == "aci_bgp_route_control_profile" { + cont, err := client.Get(rs.Primary.ID) + bgp_route_control_profile := models.RouteControlProfileFromContainer(cont) + if err == nil { + return fmt.Errorf("Bgp Route Control Profile %s Still exists", bgp_route_control_profile.DistinguishedName) + } + } else { + continue + } + } + return nil +} + +func testAccCheckAciBgpRouteControlProfileIdEqual(m1, m2 *models.RouteControlProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName != m2.DistinguishedName { + return fmt.Errorf("bgp_route_control_profile DNs are not equal") + } + return nil + } +} + +func testAccCheckAciBgpRouteControlProfileIdNotEqual(m1, m2 *models.RouteControlProfile) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName == m2.DistinguishedName { + return fmt.Errorf("bgp_route_control_profile DNs are equal") + } + return nil + } +} + +func CreateBgpRouteControlProfileWithoutRequired(fvTenantName, rName, attrName string) string { + fmt.Println("=== STEP Basic: Testing bgp_route_control_profile creation without ", attrName) + rBlock := ` + + resource "aci_tenant" "test" { + name = "%s" + + } + + ` + switch attrName { + case "parent_dn": + rBlock += ` + resource "aci_bgp_route_control_profile" "test" { + # parent_dn = aci_tenant.test.id + name = "%s" + } + ` + case "name": + rBlock += ` + resource "aci_bgp_route_control_profile" "test" { + parent_dn = aci_tenant.test.id + # name = "%s" + } + ` + } + return fmt.Sprintf(rBlock, fvTenantName, rName) +} + +func CreateAccBgpRouteControlProfileConfigWithRequiredParams(ParentName, rName string) string { + fmt.Printf("=== STEP Testing bgp_route_control_profile creation with tenant name = %s and bgp_route_control_profile name = %s\n", ParentName, rName) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + + } + + resource "aci_bgp_route_control_profile" "test" { + parent_dn = aci_tenant.test.id + name = "%s" + } + `, ParentName, rName) + return resource +} + +func CreateAccBgpRouteControlProfileConfigL3Outside(ParentName, rName string) string { + fmt.Println("=== STEP Testing bgp_route_control_profile creation when parent is l3outside") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + + } + resource "aci_l3_outside" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_bgp_route_control_profile" "test" { + parent_dn = aci_l3_outside.test.id + name = "%s" + } + `, ParentName, ParentName, rName) + return resource +} + +func CreateAccBgpRouteControlProfileConfig(fvTenantName, rName string) string { + fmt.Println("=== STEP Testing bgp_route_control_profile creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + + } + + resource "aci_bgp_route_control_profile" "test" { + parent_dn = aci_tenant.test.id + name = "%s" + } + `, fvTenantName, rName) + return resource +} + +func CreateAccBgpRouteControlProfileConfigUpdatedName(fvTenantName, rName string) string { + fmt.Println("=== STEP Testing bgp_route_control_profile creation with Invalid Long Name") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + + } + + resource "aci_bgp_route_control_profile" "test" { + parent_dn = aci_tenant.test.id + name = "%s" + } + `, fvTenantName, rName) + return resource +} + +func CreateAccBgpRouteControlProfileWithInValidParentDn(ParentName, rName string) string { + fmt.Println("=== STEP Negative Case: Testing bgp_route_control_profile creation with invalid parent Dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + + } + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_bgp_route_control_profile" "test" { + parent_dn = aci_application_profile.test.id + name = "%s" + } + `, ParentName, ParentName, rName) + return resource +} + +func CreateAccBgpRouteControlProfileConfigWithOptionalValues(fvTenantName, rName string) string { + fmt.Println("=== STEP Basic: Testing bgp_route_control_profile creation with optional parameters") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + + } + + resource "aci_bgp_route_control_profile" "test" { + parent_dn = "${aci_tenant.test.id}" + name = "%s" + description = "created while acceptance testing" + annotation = "orchestrator:terraform_testacc" + name_alias = "test_route_control_profile" + route_control_profile_type = "global" + } + `, fvTenantName, rName) + + return resource +} + +func CreateAccBgpRouteControlProfileUpdateWithoutRequiredAttr() string { + fmt.Println("=== STEP Basic: Testing bgp_route_control_profile updation without required attributes") + resource := fmt.Sprintln(` + resource "aci_bgp_route_control_profile" "test" { + description = "created while acceptance testing" + annotation = "orchestrator:terraform_testacc" + name_alias = "test_route_control_profile" + route_control_profile_type = "global" + } + `) + + return resource +} + +func CreateAccBgpRouteControlProfileRemovingRequiredField() string { + fmt.Println("=== STEP Basic: Testing bgp_route_control_profile creation with optional parameters") + resource := fmt.Sprintln(` + resource "aci_bgp_route_control_profile" "test" { + description = "created while acceptance testing" + annotation = "orchestrator:terraform_testacc" + name_alias = "test_route_control_profile" + route_control_profile_type = "global" + } + `) + + return resource +} + +func CreateAccBgpRouteControlProfileUpdatedAttr(fvTenantName, rName, attribute, value string) string { + fmt.Printf("=== STEP Testing bgp_route_control_profile attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + + } + + resource "aci_bgp_route_control_profile" "test" { + parent_dn = aci_tenant.test.id + name = "%s" + %s = "%s" + } + `, fvTenantName, rName, attribute, value) + return resource +} diff --git a/testacc/resource_aci_vzbrcp_test.go b/testacc/resource_aci_vzbrcp_test.go new file mode 100644 index 000000000..ee418315a --- /dev/null +++ b/testacc/resource_aci_vzbrcp_test.go @@ -0,0 +1,1360 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciContract_Basic(t *testing.T) { + var contract_default models.Contract + var contract_updated models.Contract + resourceName := "aci_contract.test" + rName := makeTestVariable(acctest.RandString(5)) + rOther := makeTestVariable(acctest.RandString(5)) + prOther := makeTestVariable(acctest.RandString(5)) + longrName := acctest.RandString(65) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciContractDestroy, + Steps: []resource.TestStep{ + + { + Config: CreateAccContractWithoutTenant(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccContractWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccContractConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_default), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "filter.#", "0"), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "prio", "unspecified"), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_graph_att", ""), + resource.TestCheckResourceAttr(resourceName, "scope", "context"), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "unspecified"), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + ), + }, + { + Config: CreateAccContractConfigOptionalWithoutFilterParameter(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "annotation", "test_annotation"), + resource.TestCheckResourceAttr(resourceName, "description", "test_description"), + resource.TestCheckResourceAttr(resourceName, "filter.#", "0"), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "name_alias", "test_alias"), + resource.TestCheckResourceAttr(resourceName, "prio", "level1"), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_graph_att", ""), + resource.TestCheckResourceAttr(resourceName, "scope", "tenant"), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS0"), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccContractConfigOptional(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "annotation", "test_annotation"), + resource.TestCheckResourceAttr(resourceName, "description", "test_description"), + resource.TestCheckResourceAttr(resourceName, "filter.#", "1"), + resource.TestCheckResourceAttr(resourceName, "filter.0.annotation", ""), + resource.TestCheckResourceAttr(resourceName, "filter.0.description", ""), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_name", rName), + resource.TestCheckResourceAttr(resourceName, "filter.0.name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.apply_to_frag", "no"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.arp_opc", "unspecified"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.d_from_port", "0"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.d_to_port", "0"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.entry_annotation", ""), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.entry_description", ""), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.entry_name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.ether_t", "unspecified"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.filter_entry_name", rName), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.icmpv4_t", "unspecified"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.icmpv6_t", "unspecified"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.match_dscp", "unspecified"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.prot", "unspecified"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.s_from_port", "0"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.s_to_port", "0"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.stateful", "no"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.tcp_rules", "unspecified"), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "name_alias", "test_alias"), + resource.TestCheckResourceAttr(resourceName, "prio", "level1"), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_graph_att", ""), + resource.TestCheckResourceAttr(resourceName, "scope", "tenant"), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS0"), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractRemovingRequiredField(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccContractWithoutRequiredFieldFilter(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccContractWithoutRequiredFieldFilterEntry(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + + { + Config: CreateAccContractConfigWithFilterResourcesOptional(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.annotation", "filter_annotation"), + resource.TestCheckResourceAttr(resourceName, "filter.0.description", "filter_description"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_name", rName), + resource.TestCheckResourceAttr(resourceName, "filter.0.name_alias", "filter_name_alias"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.apply_to_frag", "no"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.arp_opc", "unspecified"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.d_from_port", "443"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.d_to_port", "443"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.entry_annotation", "entry_annotation"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.entry_description", "entry_description"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.entry_name_alias", "entry_name_alias"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.ether_t", "ip"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.filter_entry_name", rName), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.icmpv4_t", "echo-rep"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.icmpv6_t", "dst-unreach"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.match_dscp", "CS0"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.prot", "tcp"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.s_from_port", "443"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.s_to_port", "443"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.stateful", "yes"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.tcp_rules", "est"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractConfigWithParentAndName(rName, longrName), + ExpectError: regexp.MustCompile(fmt.Sprintf("property name of brc-%s failed validation for value '%s'", longrName, longrName)), + }, + { + Config: CreateAccContractConfigWithParentAndName(rName, rOther), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "name", rOther), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + testAccCheckAciContrctIdNotEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractConfig(rName), + }, + { + Config: CreateAccContractConfigWithParentAndName(prOther, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", prOther)), + testAccCheckAciContrctIdNotEqual(&contract_default, &contract_updated), + ), + }, + }, + }) +} + +func TestAccAciContract_Update(t *testing.T) { + var contract_default models.Contract + var contract_updated models.Contract + resourceName := "aci_contract.test" + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciContractDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccContractConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_default), + ), + }, + { + Config: CreateAccContractUpdatedAttr(rName, "prio", "level2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level2"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttr(rName, "prio", "level3"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level3"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttr(rName, "prio", "level4"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level4"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttr(rName, "prio", "level5"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level5"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttr(rName, "prio", "level6"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level6"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttr(rName, "scope", "global"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "scope", "global"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttr(rName, "scope", "application-profile"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "scope", "application-profile"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttr(rName, "target_dscp", "CS1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS1"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttr(rName, "target_dscp", "AF11"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF11"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttr(rName, "target_dscp", "CS2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS2"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttr(rName, "target_dscp", "AF21"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF21"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttr(rName, "target_dscp", "VA"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "VA"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttr(rName, "target_dscp", "EF"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "EF"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "ether_t", "ip"), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "apply_to_frag", "yes"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.apply_to_frag", "yes"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "apply_to_frag", "no"), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "ether_t", "arp"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.ether_t", "arp"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "arp_opc", "req"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.arp_opc", "req"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "arp_opc", "reply"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.arp_opc", "reply"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "arp_opc", "unspecified"), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "ether_t", "ipv4"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.ether_t", "ipv4"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "ether_t", "trill"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.ether_t", "trill"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "ether_t", "mpls_ucast"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.ether_t", "mpls_ucast"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "ether_t", "mac_security"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.ether_t", "mac_security"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "ether_t", "fcoe"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.ether_t", "fcoe"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "ether_t", "ipv6"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.ether_t", "ipv6"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "icmpv4_t", "dst-unreach"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.icmpv4_t", "dst-unreach"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "icmpv4_t", "echo"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.icmpv4_t", "echo"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "icmpv4_t", "time-exceeded"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.icmpv4_t", "time-exceeded"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "icmpv4_t", "src-quench"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.icmpv4_t", "src-quench"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "icmpv6_t", "time-exceeded"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.icmpv6_t", "time-exceeded"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "icmpv6_t", "echo-req"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.icmpv6_t", "echo-req"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "icmpv6_t", "echo-rep"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.icmpv6_t", "echo-rep"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "icmpv6_t", "nbr-solicit"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.icmpv6_t", "nbr-solicit"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "icmpv6_t", "nbr-advert"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.icmpv6_t", "nbr-advert"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "icmpv6_t", "redirect"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.icmpv6_t", "redirect"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "match_dscp", "CS1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.match_dscp", "CS1"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "match_dscp", "AF11"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.match_dscp", "AF11"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "match_dscp", "CS2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.match_dscp", "CS2"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "match_dscp", "AF21"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.match_dscp", "AF21"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "match_dscp", "VA"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.match_dscp", "VA"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "match_dscp", "EF"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.match_dscp", "EF"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "prot", "icmp"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.prot", "icmp"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "prot", "igmp"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.prot", "igmp"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "prot", "egp"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.prot", "egp"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "prot", "igp"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.prot", "igp"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "prot", "icmpv6"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.prot", "icmpv6"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "prot", "eigrp"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.prot", "eigrp"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "prot", "ospfigp"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.prot", "ospfigp"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "prot", "pim"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.prot", "pim"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "prot", "l2tp"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.prot", "l2tp"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "prot", "udp"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.prot", "udp"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "prot", "tcp"), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "tcp_rules", "syn"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.tcp_rules", "syn"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "tcp_rules", "ack"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.tcp_rules", "ack"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "tcp_rules", "fin"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.tcp_rules", "fin"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "tcp_rules", "rst"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.tcp_rules", "rst"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntryForPortAttr(rName, "ftpData"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.d_from_port", "20"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.d_to_port", "20"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.s_from_port", "20"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.s_to_port", "20"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntryForPortAttr(rName, "smtp"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.d_from_port", "25"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.d_to_port", "25"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.s_from_port", "25"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.s_to_port", "25"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntryForPortAttr(rName, "dns"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.d_from_port", "53"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.d_to_port", "53"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.s_from_port", "53"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.s_to_port", "53"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntryForPortAttr(rName, "http"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.d_from_port", "80"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.d_to_port", "80"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.s_from_port", "80"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.s_to_port", "80"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntryForPortAttr(rName, "pop3"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.d_from_port", "110"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.d_to_port", "110"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.s_from_port", "110"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.s_to_port", "110"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntryForPortAttr(rName, "rtsp"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractExists(resourceName, &contract_updated), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.d_from_port", "554"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.d_to_port", "554"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.s_from_port", "554"), + resource.TestCheckResourceAttr(resourceName, "filter.0.filter_entry.0.s_to_port", "554"), + testAccCheckAciContractdEqual(&contract_default, &contract_updated), + ), + }, + }, + }) +} + +func TestAccAciContract_NegativeCases(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + longAnnotationDesc := acctest.RandString(129) + longNameAlias := acctest.RandString(65) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + longrName := acctest.RandString(65) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciContractDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccContractConfig(rName), + }, + { + Config: CreateAccContractWithInValidTenantDn(rName), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class vzBrCP (.)+`), + }, + { + Config: CreateAccContractUpdatedAttr(rName, "description", longAnnotationDesc), + ExpectError: regexp.MustCompile(`property descr of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccContractUpdatedAttr(rName, "annotation", longAnnotationDesc), + ExpectError: regexp.MustCompile(`property annotation of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccContractUpdatedAttr(rName, "name_alias", longNameAlias), + ExpectError: regexp.MustCompile(`property nameAlias of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccContractUpdatedAttr(rName, "prio", randomValue), + ExpectError: regexp.MustCompile(`expected prio to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccContractUpdatedAttr(rName, "target_dscp", randomValue), + ExpectError: regexp.MustCompile(`expected target_dscp to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccContractUpdatedAttr(rName, "scope", randomValue), + ExpectError: regexp.MustCompile(`expected scope to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccContractUpdatedAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccContractUpdatedFilterAttr(rName, "description", longAnnotationDesc), + ExpectError: regexp.MustCompile(`property descr of (.)+ failed validation for value (.)+`), + }, + { + Config: CreateAccContractUpdatedFilterAttr(rName, "annotation", longAnnotationDesc), + ExpectError: regexp.MustCompile(`property annotation of (.)+ failed validation for value (.)+`), + }, + { + Config: CreateAccContractUpdatedFilterAttr(rName, "name_alias", longNameAlias), + ExpectError: regexp.MustCompile(`property nameAlias of (.)+ failed validation for value (.)+`), + }, + { + Config: CreateAccContractUpdatedFilterAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`Unsupported argument`), + }, + { + Config: CreateAccContractFilterWithInvalidName(rName, longrName), + ExpectError: regexp.MustCompile(fmt.Sprintf("property name of flt-%s failed validation for value '%s'", longrName, longrName)), + }, + { + Config: CreateAccContractFilterEntryWithInvalidName(rName, longrName), + ExpectError: regexp.MustCompile(fmt.Sprintf("property name of e-%s failed validation for value '%s'", longrName, longrName)), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "entry_annotation", longAnnotationDesc), + ExpectError: regexp.MustCompile(`property annotation of (.)+ failed validation for value (.)+`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "entry_description", longAnnotationDesc), + ExpectError: regexp.MustCompile(`property descr of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "entry_name_alias", longNameAlias), + ExpectError: regexp.MustCompile(`property nameAlias of (.)+ failed validation for value (.)+`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "apply_to_frag", randomValue), + ExpectError: regexp.MustCompile(`expected (.)+ to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "arp_opc", randomValue), + ExpectError: regexp.MustCompile(`expected (.)+ to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "ether_t", randomValue), + ExpectError: regexp.MustCompile(`expected (.)+ to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "icmpv4_t", randomValue), + ExpectError: regexp.MustCompile(`expected (.)+ to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "icmpv6_t", randomValue), + ExpectError: regexp.MustCompile(`expected (.)+ to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "match_dscp", randomValue), + ExpectError: regexp.MustCompile(`expected (.)+ to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "prot", randomValue), + ExpectError: regexp.MustCompile(`expected (.)+ to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "stateful", randomValue), + ExpectError: regexp.MustCompile(`expected (.)+ to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "tcp_rules", randomValue), + ExpectError: regexp.MustCompile(`expected (.)+ to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`Unsupported argument`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "ether_t", "ip"), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "prot", "tcp"), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "d_from_port", "65536"), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "d_to_port", "65536"), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "s_from_port", "65536"), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "s_to_port", "65536"), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "arp_opc", "req"), + ExpectError: regexp.MustCompile(`ArpOpcode cannot be combined with non arp Ethertype`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "arp_opc", "reply"), + ExpectError: regexp.MustCompile(`ArpOpcode cannot be combined with non arp Ethertype`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "apply_to_frag", "yes"), + ExpectError: regexp.MustCompile(`non-IP Ethertype cannot be combined with other l4 properties`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "prot", "unspecified"), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "d_from_port", "http"), + ExpectError: regexp.MustCompile(`non-IP Ethertype cannot be combined with other l4 properties`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "d_to_port", "http"), + ExpectError: regexp.MustCompile(`non-IP Ethertype cannot be combined with other l4 properties`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "s_from_port", "http"), + ExpectError: regexp.MustCompile(`non-IP Ethertype cannot be combined with other l4 properties`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "s_to_port", "http"), + ExpectError: regexp.MustCompile(`non-IP Ethertype cannot be combined with other l4 properties`), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "ether_t", "unspecified"), + }, + { + Config: CreateAccContractUpdatedAttrFilterEntry(rName, "tcp_rules", "est"), + ExpectError: regexp.MustCompile(`non-IP Ethertype cannot be combined with other l4 properties`), + }, + { + Config: CreateAccContractConfig(rName), + }, + }, + }) +} + +func TestAccAciContract_MultipleCreateDestroy(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciContractDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccContractConfigMultiple(rName), + }, + }, + }) +} + +func CreateAccContractFilterEntryWithInvalidName(rName, longrName string) string { + fmt.Printf("=== STEP testing contract's filter_entry creation with name = %s\n", longrName) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + filter{ + filter_name = "%s" + filter_entry{ + filter_entry_name = "%s" + } + } + } + + `, rName, rName, rName, longrName) + return resource +} + +func CreateAccContractFilterWithInvalidName(rName, longrName string) string { + fmt.Printf("=== STEP testing contract's filter creation with name = %s\n", longrName) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + filter{ + filter_name = "%s" + } + } + + `, rName, rName, longrName) + return resource +} + +func CreateAccContractUpdatedFilterAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP testing contract's filter updation with %s = %s\n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + filter{ + filter_name = "%s" + %s = "%s" + } + } + + `, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccContractWithInValidTenantDn(rName string) string { + fmt.Println("=== STEP Negative Case: testing contract creation with invalid tenant_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_application_profile.test.id + name = "%s" + } + `, rName, rName, rName) + return resource +} + +func CreateAccContractUpdatedAttrFilterEntryForPortAttr(rName, value string) string { + fmt.Printf("=== STEP testing contract by updating filter_entry ports %s\n", value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + filter { + filter_name = "%s" + filter_entry { + filter_entry_name = "%s" + prot = "tcp" + d_from_port = "%s" + d_to_port = "%s" + s_from_port = "%s" + s_to_port = "%s" + } + } + } + + `, rName, rName, rName, rName, value, value, value, value) + return resource +} + +func CreateAccContractUpdatedAttrFilterEntry(rName, attribute, value string) string { + fmt.Printf("=== STEP testing contract by updating filter_entry's attribute with %s = %s\n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + filter { + filter_name = "%s" + filter_entry { + filter_entry_name = "%s" + %s = "%s" + } + } + } + + `, rName, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccContractUpdatedAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP testing contract updation with %s = %s\n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + %s = "%s" + } + + `, rName, rName, attribute, value) + return resource +} + +func CreateAccContractConfigWithFilterResourcesOptional(rName string) string { + fmt.Println("=== STEP testing contract creation with optional parameters of filter resources") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + filter { + filter_name = "%s" + annotation = "filter_annotation" + description = "filter_description" + name_alias = "filter_name_alias" + filter_entry { + filter_entry_name = "%s" + apply_to_frag = "no" + arp_opc = "unspecified" + d_from_port = "https" + d_to_port = "https" + entry_annotation = "entry_annotation" + entry_description = "entry_description" + entry_name_alias = "entry_name_alias" + ether_t = "ip" + icmpv4_t = "echo-rep" + icmpv6_t = "dst-unreach" + match_dscp = "CS0" + prot = "tcp" + s_from_port = "https" + s_to_port = "https" + stateful = "yes" + tcp_rules = "est" + } + } + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccContractConfigWithParentAndName(prName, rName string) string { + fmt.Printf("=== STEP Basic: testing contract creation with tenant name %s name %s\n", prName, rName) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, prName, rName) + return resource +} + +func CreateAccContractRemovingRequiredField() string { + fmt.Println("=== STEP Basic: testing contract updation without required fields") + resource := fmt.Sprintln(` + resource "aci_contract" "test" { + annotation = "tag" + description = "test_description" + name_alias = "test_alias" + prio = "level1" + scope = "tenant" + target_dscp = "CS0" + } + `) + return resource +} + +func CreateAccContractConfigWithFilterResources(rName string) string { + fmt.Println("=== STEP testing contract creation with filter resources") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + filter { + filter_name = "%s" + filter_entry { + filter_entry_name = "%s" + } + } + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccContractConfigOptionalWithoutFilterParameter(rName string) string { + fmt.Println("=== STEP testing contract creation with optional parameters without filter parameter") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + annotation = "test_annotation" + description = "test_description" + name_alias = "test_alias" + prio = "level1" + scope = "tenant" + target_dscp = "CS0" + } + `, rName, rName) + return resource +} + +func CreateAccContractConfigOptional(rName string) string { + fmt.Println("=== STEP testing contract creation with optional parameters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + annotation = "test_annotation" + description = "test_description" + name_alias = "test_alias" + prio = "level1" + scope = "tenant" + target_dscp = "CS0" + filter { + filter_name = "%s" + filter_entry { + filter_entry_name = "%s" + } + } + } + `, rName, rName, rName, rName) + return resource +} + +func CreateAccContractConfig(rName string) string { + fmt.Println("=== STEP testing contract creation with required arguments only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, rName, rName) + return resource +} + +func CreateAccContractConfigMultiple(rName string) string { + fmt.Println("=== STEP testing multiple contract creation with required arguments only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test1" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract" "test2" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract" "test3" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, rName, rName+"1", rName+"2", rName+"3") + return resource +} + +func CreateAccContractWithoutRequiredFieldFilterEntry(rName string) string { + fmt.Println("=== STEP Basic: testing contract's filter_entry without required parameter") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + filter{ + filter_name = "%s" + filter_entry{ + + } + } + } + `, rName, rName) + return resource +} + +func CreateAccContractWithoutRequiredFieldFilter(rName string) string { + fmt.Println("=== STEP Basic: testing contract's filter without required parameter") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + filter{} + } + `, rName) + return resource +} + +func CreateAccContractWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing contract creation without name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test" { + tenant_dn = aci_tenant.test.id + } + `, rName) + return resource +} + +func CreateAccContractWithoutTenant(rName string) string { + fmt.Println("=== STEP Basic: testing contract creation without creating tenant") + resource := fmt.Sprintf(` + resource "aci_contract" "test" { + name = "%s" + } + `, rName) + return resource +} + +func testAccCheckAciContractExists(name string, contract *models.Contract) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("Contract %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No Contract dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + contractFound := models.ContractFromContainer(cont) + if contractFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("Contract %s not found", rs.Primary.ID) + } + *contract = *contractFound + return nil + } +} + +func testAccCheckAciContractDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing contract destroy") + client := testAccProvider.Meta().(*client.Client) + + for _, rs := range s.RootModule().Resources { + + if rs.Type == "aci_contract" { + cont, err := client.Get(rs.Primary.ID) + contract := models.ContractFromContainer(cont) + if err == nil { + return fmt.Errorf("Contract %s Still exists", contract.DistinguishedName) + } + + } else { + continue + } + } + + return nil +} + +func testAccCheckAciContrctIdNotEqual(c1, c2 *models.Contract) resource.TestCheckFunc { + return func(s *terraform.State) error { + if c1.DistinguishedName == c2.DistinguishedName { + return fmt.Errorf("Contract DNs are equal") + } + return nil + } +} + +func testAccCheckAciContractdEqual(c1, c2 *models.Contract) resource.TestCheckFunc { + return func(s *terraform.State) error { + if c1.DistinguishedName != c2.DistinguishedName { + return fmt.Errorf("Contract DNs are not equal") + } + return nil + } +} diff --git a/testacc/resource_aci_vzcpif_test.go b/testacc/resource_aci_vzcpif_test.go new file mode 100644 index 000000000..eeede2324 --- /dev/null +++ b/testacc/resource_aci_vzcpif_test.go @@ -0,0 +1,359 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciImportedContract_Basic(t *testing.T) { + var imported_contract_default models.ImportedContract + var imported_contract_updated models.ImportedContract + resourceName := "aci_imported_contract.test" + rName := makeTestVariable(acctest.RandString(5)) + rOther := makeTestVariable(acctest.RandString(5)) + prOther := makeTestVariable(acctest.RandString(5)) + longrName := acctest.RandString(65) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciImportedContractDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccImportedContractWithoutTenant(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccImportedContractWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccImportedContractConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciImportedContractExists(resourceName, &imported_contract_default), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_if", ""), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + ), + }, + { + Config: CreateAccImportedContractConfigWithOptionalValues(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciImportedContractExists(resourceName, &imported_contract_updated), + resource.TestCheckResourceAttr(resourceName, "annotation", "tag_imported_contract"), + resource.TestCheckResourceAttr(resourceName, "description", "from terraform"), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "name_alias", "example"), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + testAccCheckAciImportedContractIdEqual(&imported_contract_default, &imported_contract_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccImportedContractRemovingRequiredField(), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccImportedContractConfigWithParentAndName(rName, longrName), + ExpectError: regexp.MustCompile(`failed validation for value`), + }, + { + Config: CreateAccImportedContractConfigWithParentAndName(rName, rOther), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciImportedContractExists(resourceName, &imported_contract_updated), + resource.TestCheckResourceAttr(resourceName, "name", rOther), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + testAccCheckAciImportedContractIdNotEqual(&imported_contract_default, &imported_contract_updated), + ), + }, + { + Config: CreateAccImportedContractConfig(rName), + }, + { + Config: CreateAccImportedContractConfigWithParentAndName(prOther, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciImportedContractExists(resourceName, &imported_contract_updated), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", prOther)), + testAccCheckAciImportedContractIdNotEqual(&imported_contract_default, &imported_contract_updated), + ), + }, + }, + }) +} + +func TestAccAciImportedContract_NegativeCases(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + longDescAnnotation := acctest.RandString(129) + longNameAlias := acctest.RandString(64) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciImportedContractDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccImportedContractConfig(rName), + }, + { + Config: CreateAccImportedContractWithInValidTenantDn(rName), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class vzCPIf (.)+`), + }, + { + Config: CreateAccImportedContractUpdatedAttr(rName, "description", longDescAnnotation), + ExpectError: regexp.MustCompile(`property descr of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccImportedContractUpdatedAttr(rName, "annotation", longDescAnnotation), + ExpectError: regexp.MustCompile(`property annotation of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccImportedContractUpdatedAttr(rName, "name_alias", longNameAlias), + ExpectError: regexp.MustCompile(`property nameAlias of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccImportedContractUpdatedAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + + { + Config: CreateAccImportedContractConfig(rName), + }, + }, + }) +} + +func TestAccAciImportedContract_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciImportedContractDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccImportedContractsConfig(rName), + }, + }, + }) +} + +func CreateAccImportedContractsConfig(rName string) string { + fmt.Println("=== STEP creating multiple imported contract") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_imported_contract" "test1"{ + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_imported_contract" "test2"{ + name = "%s" + tenant_dn = aci_tenant.test.id + } + + resource "aci_imported_contract" "test3"{ + name = "%s" + tenant_dn = aci_tenant.test.id + } + `, rName, rName+"1", rName+"2", rName+"3") + return resource +} + +func CreateAccImportedContractUpdatedAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP testing imported contract attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_imported_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + %s = "%s" + } + `, rName, rName, attribute, value) + return resource +} + +func CreateAccImportedContractWithInValidTenantDn(rName string) string { + fmt.Println("=== STEP Negative Case: testing imported contract creation with invalid tenant_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_application_profile" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_imported_contract" "test"{ + tenant_dn = aci_application_profile.test.id + name = "%s" + } + `, rName, rName, rName) + return resource +} +func testAccCheckAciImportedContractExists(name string, imported_contract *models.ImportedContract) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("Imported Contract %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No Imported Contract dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + imported_contractFound := models.ImportedContractFromContainer(cont) + if imported_contractFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("Imported Contract %s not found", rs.Primary.ID) + } + *imported_contract = *imported_contractFound + return nil + } +} + +func testAccCheckAciImportedContractDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing imported contract destroy") + client := testAccProvider.Meta().(*client.Client) + + for _, rs := range s.RootModule().Resources { + + if rs.Type == "aci_imported_contract" { + cont, err := client.Get(rs.Primary.ID) + imported_contract := models.ImportedContractFromContainer(cont) + if err == nil { + return fmt.Errorf("Imported Contract %s Still exists", imported_contract.DistinguishedName) + } + + } else { + continue + } + } + + return nil +} + +func CreateAccImportedContractWithoutTenant(rName string) string { + fmt.Println("=== STEP Basic: testing imported_contract creation without creating tenant") + resource := fmt.Sprintf(` + resource "aci_imported_contract" "test" { + name = "%s" + } + `, rName) + return resource +} +func CreateAccImportedContractWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing imported_contract creation without name") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_imported_contract" "test" { + tenant_dn = aci_tenant.test.id + } + `, rName) + return resource +} +func CreateAccImportedContractConfig(rName string) string { + fmt.Println("=== STEP testing imported contract creation with required arguments only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_imported_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, rName, rName) + return resource +} +func CreateAccImportedContractConfigWithOptionalValues(rName string) string { + fmt.Println("=== STEP testing imported contract creation with optional parameters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_imported_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + annotation = "tag_imported_contract" + description = "from terraform" + name_alias = "example" + } + `, rName, rName) + return resource +} +func testAccCheckAciImportedContractIdEqual(ic1, ic2 *models.ImportedContract) resource.TestCheckFunc { + return func(s *terraform.State) error { + if ic1.DistinguishedName != ic2.DistinguishedName { + return fmt.Errorf("imported contract imported contracts are not equal") + } + return nil + } +} +func CreateAccImportedContractRemovingRequiredField() string { + fmt.Println("=== STEP Basic: testing imported contract updation without required fields") + resource := fmt.Sprintln(` + + resource "aci_imported_contract" "test" { + annotation = "tag_imported_contract" + description = "from terraform" + name_alias = "example" + } + `) + return resource +} + +func testAccCheckAciImportedContractIdNotEqual(c1, c2 *models.ImportedContract) resource.TestCheckFunc { + return func(s *terraform.State) error { + if c1.DistinguishedName == c2.DistinguishedName { + return fmt.Errorf("imported contract DNs are equal") + } + return nil + } +} + +func CreateAccImportedContractConfigWithParentAndName(prName, rName string) string { + fmt.Printf("=== STEP Basic: testing imported contract creation with tenant name %s name %s\n", prName, rName) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_imported_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, prName, rName) + return resource +} diff --git a/testacc/resource_aci_vzfilter_test.go b/testacc/resource_aci_vzfilter_test.go index 2b0895def..e3e50b6eb 100644 --- a/testacc/resource_aci_vzfilter_test.go +++ b/testacc/resource_aci_vzfilter_test.go @@ -1,4 +1,4 @@ -package acctest +package testacc import ( "fmt" @@ -22,10 +22,10 @@ func TestAccAciFilter_Basic(t *testing.T) { longrName := acctest.RandString(65) prOther := makeTestVariable(acctest.RandString(5)) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciFilterDestroy, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciFilterDestroy, Steps: []resource.TestStep{ { Config: CreateAccFilterWithoutName(rName), @@ -36,33 +36,33 @@ func TestAccAciFilter_Basic(t *testing.T) { ExpectError: regexp.MustCompile(`Missing required argument`), }, { - - Config: CreateAccFilterConfig(rName), + + Config: CreateAccFilterConfig(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckAciFilterExists(resourceName, &filter_default), - resource.TestCheckResourceAttr(resourceName, "description", ""), + testAccCheckAciFilterExists(resourceName, &filter_default), + resource.TestCheckResourceAttr(resourceName, "description", ""), resource.TestCheckResourceAttr(resourceName, "name_alias", ""), resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_filt_graph_att", ""), resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_fwd_r_flt_p_att", ""), - resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_rev_r_flt_p_att", ""), - resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_rev_r_flt_p_att", ""), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), ), }, { - Config: CreateAccFilterConfigWithOptionalValues(rName), + Config: CreateAccFilterConfigWithOptionalValues(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAciFilterExists(resourceName, &filter_updated), - resource.TestCheckResourceAttr(resourceName, "description", "From Terraform"), - resource.TestCheckResourceAttr(resourceName, "name_alias", "alias_filter"), + resource.TestCheckResourceAttr(resourceName, "description", "From Terraform"), + resource.TestCheckResourceAttr(resourceName, "name_alias", "alias_filter"), resource.TestCheckResourceAttr(resourceName, "annotation", "tag_filter"), resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_filt_graph_att", ""), resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_fwd_r_flt_p_att", ""), resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_rev_r_flt_p_att", ""), resource.TestCheckResourceAttr(resourceName, "name", rName), - resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), - testAccCheckAciFilterIdEqual(&filter_default, &filter_updated), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + testAccCheckAciFilterIdEqual(&filter_default, &filter_updated), ), }, { @@ -75,28 +75,28 @@ func TestAccAciFilter_Basic(t *testing.T) { ExpectError: regexp.MustCompile(`Missing required argument`), }, { - Config: CreateAccFilterConfigUpdatedName(rName, longrName), + Config: CreateAccFilterConfigUpdatedName(rName, longrName), ExpectError: regexp.MustCompile(fmt.Sprintf("property name of flt-%s failed validation for value '%s'", longrName, longrName)), }, { - Config: CreateAccFilterConfigWithParentAndName(rName, rOther), + Config: CreateAccFilterConfigWithParentAndName(rName, rOther), Check: resource.ComposeTestCheckFunc( testAccCheckAciFilterExists(resourceName, &filter_updated), - resource.TestCheckResourceAttr(resourceName, "name", rOther), - resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), - testAccCheckAciFilterIdNotEqual(&filter_default, &filter_updated), + resource.TestCheckResourceAttr(resourceName, "name", rOther), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + testAccCheckAciFilterIdNotEqual(&filter_default, &filter_updated), ), }, { - Config: CreateAccFilterConfig(rName), + Config: CreateAccFilterConfig(rName), }, { - Config: CreateAccFilterConfigWithParentAndName(prOther, rName), + Config: CreateAccFilterConfigWithParentAndName(prOther, rName), Check: resource.ComposeTestCheckFunc( testAccCheckAciFilterExists(resourceName, &filter_updated), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", prOther)), - testAccCheckAciFilterIdNotEqual(&filter_default, &filter_updated), + testAccCheckAciFilterIdNotEqual(&filter_default, &filter_updated), ), }, }, @@ -104,54 +104,54 @@ func TestAccAciFilter_Basic(t *testing.T) { ) } -func TestAccFilter_NegativeCases(t *testing.T) { +func TestAccAciFilter_NegativeCases(t *testing.T) { rName := makeTestVariable(acctest.RandString(5)) - longDescAnnotation := acctest.RandString(129) - longNameAlias := acctest.RandString(64) - randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") - randomValue := acctest.RandString(5) + longDescAnnotation := acctest.RandString(129) + longNameAlias := acctest.RandString(64) + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(5) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciFilterDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciFilterDestroy, Steps: []resource.TestStep{ { - Config: CreateAccFilterConfig(rName), + Config: CreateAccFilterConfig(rName), }, { - Config: CreateAccFilterWithInValidTenantDn(rName), - ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class vzFilter (.)+`), + Config: CreateAccFilterWithInValidTenantDn(rName), + ExpectError: regexp.MustCompile(`unknown property value (.)+, name dn, class vzFilter (.)+`), }, { - Config: CreateAccFilterUpdatedAttr(rName, "description", longDescAnnotation), + Config: CreateAccFilterUpdatedAttr(rName, "description", longDescAnnotation), ExpectError: regexp.MustCompile(`property descr of (.)+ failed validation for value '(.)+'`), }, { - Config: CreateAccFilterUpdatedAttr(rName, "annotation", longDescAnnotation), + Config: CreateAccFilterUpdatedAttr(rName, "annotation", longDescAnnotation), ExpectError: regexp.MustCompile(`property annotation of (.)+ failed validation for value '(.)+'`), }, { - Config: CreateAccFilterUpdatedAttr(rName, "name_alias", longNameAlias), + Config: CreateAccFilterUpdatedAttr(rName, "name_alias", longNameAlias), ExpectError: regexp.MustCompile(`property nameAlias of (.)+ failed validation for value '(.)+'`), }, { - Config: CreateAccFilterUpdatedAttr(rName, randomParameter, randomValue), + Config: CreateAccFilterUpdatedAttr(rName, randomParameter, randomValue), ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), }, { - Config: CreateAccFilterConfig(rName), + Config: CreateAccFilterConfig(rName), }, }, }) } -func TestAccFilter_MultipleCreateDelete(t *testing.T) { +func TestAccAciFilter_MultipleCreateDelete(t *testing.T) { rName := makeTestVariable(acctest.RandString(5)) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAciFilterDestroy, + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciFilterDestroy, Steps: []resource.TestStep{ { Config: CreateAccFiltersConfig(rName), @@ -275,7 +275,7 @@ func CreateAccFilterWithoutName(rName string) string { } func CreateAccFilterWithoutTenant(rName string) string { - fmt.Println("=== STEP Basic: testing filter creation without giving name") + fmt.Println("=== STEP Basic: testing filter creation without giving tenant_dn") resource := fmt.Sprintf(` resource "aci_filter" "test" { @@ -288,15 +288,19 @@ func CreateAccFilterWithoutTenant(rName string) string { func CreateAccFilterWithoutFilter(rName string) string { fmt.Println("=== STEP Basic: testing filter creation without creating tenant") resource := fmt.Sprintf(` - resource "aci_filter" "test" { + resource "aci_tenant" "test"{ name = "%s" } + + resource "aci_filter" "test" { + tenant_dn = + } `, rName) return resource } func CreateAccFilterConfig(rName string) string { - fmt.Println("=== STEP testing filter creation with required arguements") + fmt.Println("=== STEP testing filter creation with required arguments") resource := fmt.Sprintf(` resource "aci_tenant" "test" { name = "%s" @@ -329,7 +333,7 @@ func CreateAccFilterConfigWithOptionalValues(rName string) string { } func CreateAccFilterRemovingRequiredField() string { - fmt.Println("=== STEP Basic: testing filter creation with optional parameters") + fmt.Println("=== STEP Basic: testing filter updation without optional parameters") resource := fmt.Sprintln(` resource "aci_filter" "test" { diff --git a/testacc/resource_aci_vzsubj_test.go b/testacc/resource_aci_vzsubj_test.go new file mode 100644 index 000000000..22ec17941 --- /dev/null +++ b/testacc/resource_aci_vzsubj_test.go @@ -0,0 +1,834 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciContractSubject_Basic(t *testing.T) { + var contract_subject_default models.ContractSubject + var contract_subject_updated models.ContractSubject + resourceName := "aci_contract_subject.test" + rName := makeTestVariable(acctest.RandString(5)) + rOtherName := makeTestVariable(acctest.RandString(5)) + parentOtherName := makeTestVariable(acctest.RandString(5)) + longerName := acctest.RandString(65) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciContractSubjectDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccContractSubjectWithoutContract(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccContractSubjectWithoutName(rName), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccContractSubjectConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_default), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "cons_match_t", "AtleastOne"), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + resource.TestCheckResourceAttr(resourceName, "prio", "unspecified"), + resource.TestCheckResourceAttr(resourceName, "prov_match_t", "AtleastOne"), + resource.TestCheckResourceAttr(resourceName, "rev_flt_ports", "yes"), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "unspecified"), + resource.TestCheckResourceAttr(resourceName, "contract_dn", fmt.Sprintf("uni/tn-%s/brc-%s", rName, rName)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_sdwan_pol", ""), + // resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_subj_filt_att.#", "0"), giving null on initial apply + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_subj_graph_att", ""), + ), + }, + { + Config: CreateAccContractSubjectConfigWithOptionalValues(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "description", "test_description"), + resource.TestCheckResourceAttr(resourceName, "annotation", "test_annotation"), + resource.TestCheckResourceAttr(resourceName, "cons_match_t", "All"), + resource.TestCheckResourceAttr(resourceName, "name_alias", "test_name_alias"), + resource.TestCheckResourceAttr(resourceName, "prio", "level1"), + resource.TestCheckResourceAttr(resourceName, "prov_match_t", "All"), + resource.TestCheckResourceAttr(resourceName, "rev_flt_ports", "no"), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS0"), + resource.TestCheckResourceAttr(resourceName, "contract_dn", fmt.Sprintf("uni/tn-%s/brc-%s", rName, rName)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_sdwan_pol", ""), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_subj_filt_att.#", "0"), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_subj_graph_att", ""), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccContractSubjectUpdatedName(rName, longerName), + ExpectError: regexp.MustCompile(fmt.Sprintf("property name of subj-%s failed validation for value '%s'", longerName, longerName)), + }, + { + Config: CreateAccContractSubjectConfigWithParentAndName(rName, rOtherName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "contract_dn", fmt.Sprintf("uni/tn-%s/brc-%s", rName, rName)), + resource.TestCheckResourceAttr(resourceName, "name", rOtherName), + testAccCheckAciContractSubjectIdNotEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectConfig(rName), + }, + { + Config: CreateAccContractSubjectConfigWithParentAndName(parentOtherName, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "contract_dn", fmt.Sprintf("uni/tn-%s/brc-%s", parentOtherName, parentOtherName)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + testAccCheckAciContractSubjectIdNotEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + }, + }) +} + +func TestAccAciContractSubject_Update(t *testing.T) { + var contract_subject_default models.ContractSubject + var contract_subject_updated models.ContractSubject + resourceName := "aci_contract_subject.test" + rName := makeTestVariable(acctest.RandString(5)) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciContractSubjectDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccContractSubjectConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_default), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "cons_match_t", "None"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "cons_match_t", "None"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "cons_match_t", "AtmostOne"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "cons_match_t", "AtmostOne"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "prio", "level2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level2"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "prio", "level3"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level3"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "prio", "level4"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level4"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "prio", "level5"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level5"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "prio", "level6"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "prio", "level6"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "prov_match_t", "None"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "prov_match_t", "None"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "prov_match_t", "AtmostOne"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "prov_match_t", "AtmostOne"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "CS1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS1"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "AF11"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF11"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "AF12"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF12"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "AF13"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF13"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "CS2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS2"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "AF21"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF21"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "AF22"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF22"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "AF23"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF23"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "CS3"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS3"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "AF31"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF31"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "AF32"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF32"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "AF33"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF33"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "CS4"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS4"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "AF41"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF41"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "AF42"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF42"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "AF43"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "AF43"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "CS5"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS5"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "VA"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "VA"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "EF"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "EF"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "CS6"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS6"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", "CS7"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_updated), + resource.TestCheckResourceAttr(resourceName, "target_dscp", "CS7"), + testAccCheckAciContractSubjectIdEqual(&contract_subject_default, &contract_subject_updated), + ), + }, + }, + }) +} + +func TestAccAciContractSubject_NegativeCases(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + longAnnotationDesc := acctest.RandString(129) + longNameAlias := acctest.RandString(65) + randomParameter := acctest.RandStringFromCharSet(10, "abcdefghijklmnopqrstuvwxyz") + randomValue := acctest.RandString(10) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciContractSubjectDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccContractSubjectConfig(rName), + }, + { + Config: CreateAccContractSubjectWithInvalidContract(rName), + ExpectError: regexp.MustCompile(`Invalid request. dn '(.)+' is not valid for class vzSubj`), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "description", longAnnotationDesc), + ExpectError: regexp.MustCompile(`property descr of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "annotation", longAnnotationDesc), + ExpectError: regexp.MustCompile(`property annotation of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "name_alias", longNameAlias), + ExpectError: regexp.MustCompile(`property nameAlias of (.)+ failed validation for value '(.)+'`), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "cons_match_t", randomValue), + ExpectError: regexp.MustCompile(`expected cons_match_t to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "prov_match_t", randomValue), + ExpectError: regexp.MustCompile(`expected prov_match_t to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "prio", randomValue), + ExpectError: regexp.MustCompile(`expected prio to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "rev_flt_ports", randomValue), + ExpectError: regexp.MustCompile(`expected rev_flt_ports to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, "target_dscp", randomValue), + ExpectError: regexp.MustCompile(`expected target_dscp to be one of (.)+, got (.)+`), + }, + { + Config: CreateAccContractSubjectUpdatedAttr(rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), + }, + { + Config: CreateAccContractSubjectConfig(rName), + }, + }, + }) +} + +func TestAccAciContractSubject_RelationParameters(t *testing.T) { + var contract_subject_default models.ContractSubject + var contract_subject_rel1 models.ContractSubject + var contract_subject_rel2 models.ContractSubject + resourceName := "aci_contract_subject.test" + rName := makeTestVariable(acctest.RandString(5)) + randomName1 := makeTestVariable(acctest.RandString(5)) + randomName2 := makeTestVariable(acctest.RandString(5)) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciContractSubjectDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccContractSubjectConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_default), + ), + }, + { + Config: CreateAccContractSubjectConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_default), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_sdwan_pol", ""), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_subj_graph_att", ""), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_subj_filt_att.#", "0"), + ), + }, + { + Config: CreateAccContractSubjectRelConfigInitial(rName, randomName1), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_rel1), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_subj_graph_att", fmt.Sprintf("uni/tn-%s/AbsGraph-%s", rName, randomName1)), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_subj_filt_att.#", "1"), + resource.TestCheckTypeSetElemAttr(resourceName, "relation_vz_rs_subj_filt_att.*", fmt.Sprintf("uni/tn-%s/flt-%s", rName, randomName1)), + ), + }, + { + Config: CreateAccContractSubjectRelConfigFinal(rName, randomName1, randomName2), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_rel2), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_subj_graph_att", fmt.Sprintf("uni/tn-%s/AbsGraph-%s", rName, randomName2)), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_subj_filt_att.#", "2"), + resource.TestCheckTypeSetElemAttr(resourceName, "relation_vz_rs_subj_filt_att.*", fmt.Sprintf("uni/tn-%s/flt-%s", rName, randomName1)), + resource.TestCheckTypeSetElemAttr(resourceName, "relation_vz_rs_subj_filt_att.*", fmt.Sprintf("uni/tn-%s/flt-%s", rName, randomName2)), + ), + }, + { + Config: CreateAccContractSubjectConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciContractSubjectExists(resourceName, &contract_subject_default), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_sdwan_pol", ""), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_subj_graph_att", ""), + resource.TestCheckResourceAttr(resourceName, "relation_vz_rs_subj_filt_att.#", "0"), + ), + }, + }, + }) +} + +func TestAccAciContractSubject_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciContractSubjectDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccContractSubjectsConfig(rName), + }, + }, + }) +} + +func CreateAccContractSubjectWithoutContract(rName string) string { + fmt.Println("=== STEP Basic: testing contract subject without creating contract") + resource := fmt.Sprintf(` + resource "aci_contract_subject" "test" { + name = "%s" + } + `, rName) + return resource + +} + +func CreateAccContractSubjectWithoutName(rName string) string { + fmt.Println("=== STEP Basic: testing contract subject without passing name attribute") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract_subject" "test"{ + contract_dn = aci_contract.test.id + } + `, rName, rName) + return resource +} + +func CreateAccContractSubjectConfig(rName string) string { + fmt.Println("=== STEP Basic: testing contract subject creation with required paramters only") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract_subject" "test"{ + contract_dn = aci_contract.test.id + name = "%s" + } + `, rName, rName, rName) + return resource +} + +func CreateAccContractSubjectConfigWithOptionalValues(rName string) string { + fmt.Println("=== STEP Basic: testing contract subject creation with optional paramters") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract_subject" "test"{ + contract_dn = aci_contract.test.id + name = "%s" + description = "test_description" + annotation = "test_annotation" + cons_match_t = "All" + name_alias = "test_name_alias" + prio = "level1" + prov_match_t = "All" + rev_flt_ports = "no" + target_dscp = "CS0" + } + `, rName, rName, rName) + return resource +} + +func CreateAccContractSubjectUpdatedName(rName, longerName string) string { + fmt.Println("=== STEP Basic: testing contract subject creation with invalid name with long lenght") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract_subject" "test"{ + contract_dn = aci_contract.test.id + name = "%s" + } + `, rName, rName, longerName) + return resource +} + +func CreateAccContractSubjectConfigWithParentAndName(parentName, rName string) string { + fmt.Printf("=== STEP Basic: testing contract subject creation with contract name %s and contract subject name %s\n", parentName, rName) + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract_subject" "test"{ + contract_dn = aci_contract.test.id + name = "%s" + } + `, parentName, parentName, rName) + return resource +} + +func CreateAccContractSubjectUpdatedAttr(rName, attribute, value string) string { + fmt.Printf("=== STEP Basic: testing contract subject %s = %s\n", attribute, value) + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract_subject" "test"{ + contract_dn = aci_contract.test.id + name = "%s" + %s = "%s" + } + `, rName, rName, rName, attribute, value) + return resource +} + +func CreateAccContractSubjectWithInvalidContract(rName string) string { + fmt.Println("=== STEP Basic: testing contract subject updation with Invalid contract_dn") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract_subject" "test"{ + contract_dn = aci_tenant.test.id + name = "%s" + } + `, rName, rName, rName) + return resource +} + +func CreateAccContractSubjectRelConfigInitial(rName, relName1 string) string { + fmt.Printf("=== STEP Basic: testing contract subject relation") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract_subject" "test"{ + contract_dn = aci_contract.test.id + name = "%s" + relation_vz_rs_subj_graph_att = aci_l4_l7_service_graph_template.test.id + relation_vz_rs_subj_filt_att = [aci_filter.test.id] + } + + resource "aci_l4_l7_service_graph_template" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_filter" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, rName, rName, rName, relName1, relName1) + return resource +} + +func CreateAccContractSubjectRelConfigFinal(rName, relName1, relName2 string) string { + fmt.Printf("=== STEP Basic: testing contract subject relations") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract_subject" "test"{ + contract_dn = aci_contract.test.id + name = "%s" + relation_vz_rs_subj_graph_att = aci_l4_l7_service_graph_template.test.id + relation_vz_rs_subj_filt_att = [aci_filter.test.id,aci_filter.test1.id] + } + + resource "aci_l4_l7_service_graph_template" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_filter" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_filter" "test1" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, rName, rName, rName, relName2, relName1, relName2) + return resource +} + +func CreateAccContractSubjectsConfig(rName string) string { + fmt.Println("=== STEP creating multiple Contract Subjects") + resource := fmt.Sprintf(` + resource "aci_tenant" "test"{ + name = "%s" + } + + resource "aci_contract" "test"{ + tenant_dn = aci_tenant.test.id + name = "%s" + } + + resource "aci_contract_subject" "test"{ + contract_dn = aci_contract.test.id + name = "%s" + } + + resource "aci_contract_subject" "test1"{ + contract_dn = aci_contract.test.id + name = "%s" + } + + resource "aci_contract_subject" "test2"{ + contract_dn = aci_contract.test.id + name = "%s" + } + + resource "aci_contract_subject" "test3"{ + contract_dn = aci_contract.test.id + name = "%s" + } + + `, rName, rName, rName, rName+"1", rName+"2", rName+"3") + return resource + +} + +func testAccCheckAciContractSubjectDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing Contract Subject destroy") + client := testAccProvider.Meta().(*client.Client) + + for _, rs := range s.RootModule().Resources { + + if rs.Type == "aci_contract_subject" { + cont, err := client.Get(rs.Primary.ID) + contract_subject := models.ContractSubjectFromContainer(cont) + if err == nil { + return fmt.Errorf("Contract Subject %s still exists", contract_subject.DistinguishedName) + } + } else { + continue + } + } + return nil +} + +func testAccCheckAciContractSubjectExists(name string, contract_subject *models.ContractSubject) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("Contract Subject %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No Contract Subject Dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + contract_subjectFound := models.ContractSubjectFromContainer(cont) + if contract_subjectFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("Contract Subject %s not found", rs.Primary.ID) + } + *contract_subject = *contract_subjectFound + return nil + } +} + +func testAccCheckAciContractSubjectIdNotEqual(cs1, cs2 *models.ContractSubject) resource.TestCheckFunc { + return func(s *terraform.State) error { + if cs1.DistinguishedName == cs2.DistinguishedName { + return fmt.Errorf("Contract Subject DNs are equal") + } + return nil + } +} + +func testAccCheckAciContractSubjectIdEqual(cs1, cs2 *models.ContractSubject) resource.TestCheckFunc { + return func(s *terraform.State) error { + if cs1.DistinguishedName != cs2.DistinguishedName { + return fmt.Errorf("Contract Subject DNs are no equal") + } + return nil + } +} diff --git a/testacc/resource_aci_vztaboo_test.go b/testacc/resource_aci_vztaboo_test.go new file mode 100644 index 000000000..e40842dca --- /dev/null +++ b/testacc/resource_aci_vztaboo_test.go @@ -0,0 +1,401 @@ +package testacc + +import ( + "fmt" + "regexp" + "testing" + + "github.com/ciscoecosystem/aci-go-client/client" + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAciTabooContract_Basic(t *testing.T) { + var taboo_contract_default models.TabooContract + var taboo_contract_updated models.TabooContract + resourceName := "aci_taboo_contract.test" + rName := makeTestVariable(acctest.RandString(5)) + rNameUpdated := makeTestVariable(acctest.RandString(5)) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciTabooContractDestroy, + Steps: []resource.TestStep{ + { + Config: CreateTabooContractWithoutRequired(rName, rName, "tenant_dn"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateTabooContractWithoutRequired(rName, rName, "name"), + ExpectError: regexp.MustCompile(`Missing required argument`), + }, + { + Config: CreateAccTabooContractConfig(rName, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciTabooContractExists(resourceName, &taboo_contract_default), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "name_alias", ""), + ), + }, + { + Config: CreateAccTabooContractConfigWithOptionalValues(rName, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciTabooContractExists(resourceName, &taboo_contract_updated), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "annotation", "orchestrator:terraform_testacc"), + resource.TestCheckResourceAttr(resourceName, "description", "created while acceptance testing"), + resource.TestCheckResourceAttr(resourceName, "name_alias", "test_taboo_contract"), + testAccCheckAciTabooContractIdEqual(&taboo_contract_default, &taboo_contract_updated), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: CreateAccTabooContractConfigUpdatedName(rName, acctest.RandString(65)), + ExpectError: regexp.MustCompile(`property name of (.)+ failed validation`), + }, + + { + Config: CreateAccTabooContractConfigWithRequiredParams(rNameUpdated, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciTabooContractExists(resourceName, &taboo_contract_updated), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rNameUpdated)), + resource.TestCheckResourceAttr(resourceName, "name", rName), + testAccCheckAciTabooContractIdNotEqual(&taboo_contract_default, &taboo_contract_updated), + ), + }, + { + Config: CreateAccTabooContractConfig(rName, rName), + }, + { + Config: CreateAccTabooContractConfigWithRequiredParams(rName, rNameUpdated), + Check: resource.ComposeTestCheckFunc( + testAccCheckAciTabooContractExists(resourceName, &taboo_contract_updated), + resource.TestCheckResourceAttr(resourceName, "tenant_dn", fmt.Sprintf("uni/tn-%s", rName)), + resource.TestCheckResourceAttr(resourceName, "name", rNameUpdated), + testAccCheckAciTabooContractIdNotEqual(&taboo_contract_default, &taboo_contract_updated), + ), + }, + }, + }) +} + +func TestAccAciTabooContract_Negative(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + + randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz") + randomValue := makeTestVariable(acctest.RandString(5)) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciTabooContractDestroy, + Steps: []resource.TestStep{ + { + Config: CreateAccTabooContractConfig(rName, rName), + }, + { + Config: CreateAccTabooContractWithInValidParentDn(rName, rName), + ExpectError: regexp.MustCompile(`unknown property value`), + }, + { + Config: CreateAccTabooContractUpdatedAttr(rName, rName, "description", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccTabooContractUpdatedAttr(rName, rName, "annotation", acctest.RandString(129)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + { + Config: CreateAccTabooContractUpdatedAttr(rName, rName, "name_alias", acctest.RandString(64)), + ExpectError: regexp.MustCompile(`failed validation for value '(.)+'`), + }, + + { + Config: CreateAccTabooContractUpdatedAttr(rName, rName, randomParameter, randomValue), + ExpectError: regexp.MustCompile(`An argument named(.)+is not expected here.`), + }, + { + Config: CreateAccTabooContractConfig(rName, rName), + }, + }, + }) +} + +func TestAccAciTabooContract_MultipleCreateDelete(t *testing.T) { + rName := makeTestVariable(acctest.RandString(5)) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckAciTabooContractDestroy, + Steps: []resource.TestStep{ + + { + Config: CreateAccTabooContractConfigs(rName), + }, + }, + }) +} + +func testAccCheckAciTabooContractExists(name string, taboo_contract *models.TabooContract) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + + if !ok { + return fmt.Errorf("Taboo Contract %s not found", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No Taboo Contract dn was set") + } + + client := testAccProvider.Meta().(*client.Client) + + cont, err := client.Get(rs.Primary.ID) + if err != nil { + return err + } + + taboo_contractFound := models.TabooContractFromContainer(cont) + if taboo_contractFound.DistinguishedName != rs.Primary.ID { + return fmt.Errorf("Taboo Contract %s not found", rs.Primary.ID) + } + *taboo_contract = *taboo_contractFound + return nil + } +} + +func testAccCheckAciTabooContractDestroy(s *terraform.State) error { + fmt.Println("=== STEP testing taboo_contract destroy") + client := testAccProvider.Meta().(*client.Client) + for _, rs := range s.RootModule().Resources { + if rs.Type == "aci_taboo_contract" { + cont, err := client.Get(rs.Primary.ID) + taboo_contract := models.TabooContractFromContainer(cont) + if err == nil { + return fmt.Errorf("Taboo Contract %s Still exists", taboo_contract.DistinguishedName) + } + } else { + continue + } + } + return nil +} + +func testAccCheckAciTabooContractIdEqual(m1, m2 *models.TabooContract) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName != m2.DistinguishedName { + return fmt.Errorf("taboo_contract DNs are not equal") + } + return nil + } +} + +func testAccCheckAciTabooContractIdNotEqual(m1, m2 *models.TabooContract) resource.TestCheckFunc { + return func(s *terraform.State) error { + if m1.DistinguishedName == m2.DistinguishedName { + return fmt.Errorf("taboo_contract DNs are equal") + } + return nil + } +} + +func CreateTabooContractWithoutRequired(fvTenantName, rName, attrName string) string { + fmt.Println("=== STEP Basic: testing taboo_contract creation without ", attrName) + rBlock := ` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + ` + switch attrName { + case "tenant_dn": + rBlock += ` + resource "aci_taboo_contract" "test" { +# tenant_dn = aci_tenant.test.id + name = "%s" + + } + ` + case "name": + rBlock += ` + resource "aci_taboo_contract" "test" { + tenant_dn = aci_tenant.test.id +# name = "%s" + + } + ` + } + return fmt.Sprintf(rBlock, fvTenantName, rName) +} + +func CreateAccTabooContractConfigWithRequiredParams(fvTenantName, rName string) string { + fmt.Println("=== STEP testing taboo_contract creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_taboo_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, fvTenantName, rName) + return resource +} + +func CreateAccTabooContractConfig(fvTenantName, rName string) string { + fmt.Println("=== STEP testing taboo_contract creation with required arguments only") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_taboo_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + + } + `, fvTenantName, rName) + return resource +} + +func CreateAccTabooContractConfigs(rName string) string { + fmt.Println("=== STEP testing taboo_contract multiple creation") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_taboo_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + + } + resource "aci_taboo_contract" "test1" { + tenant_dn = aci_tenant.test.id + name = "%s" + + } + resource "aci_taboo_contract" "test2" { + tenant_dn = aci_tenant.test.id + name = "%s" + + } + `, rName, rName, rName+"1", rName+"2") + return resource +} + +func CreateAccTabooContractWithInValidParentDn(rName, prName string) string { + fmt.Println("=== STEP Negative Case: testing taboo_contract creation with invalid parent Dn") + resource := fmt.Sprintf(` + + resource "aci_aaa_domain" "test" { + name = "%s" + } + + resource "aci_taboo_contract" "test" { + tenant_dn = aci_aaa_domain.test.id + name = "%s" + + } + `, prName, rName) + return resource +} + +func CreateAccTabooContractConfigWithOptionalValues(fvTenantName, rName string) string { + fmt.Println("=== STEP Basic: testing taboo_contract creation with optional parameters") + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_taboo_contract" "test" { + tenant_dn = "${aci_tenant.test.id}" + name = "%s" + description = "created while acceptance testing" + annotation = "orchestrator:terraform_testacc" + name_alias = "test_taboo_contract" + + } + `, fvTenantName, rName) + + return resource +} + +func CreateAccTabooContractRemovingRequiredField() string { + fmt.Println("=== STEP Basic: testing taboo_contract creation with optional parameters") + resource := fmt.Sprintf(` + resource "aci_taboo_contract" "test" { + description = "created while acceptance testing" + annotation = "orchestrator:terraform_testacc" + name_alias = "test_taboo_contract" + + } + `) + + return resource +} + +func CreateAccTabooContractConfigUpdatedName(rName, longerName string) string { + fmt.Println("=== STEP Basic: testing Tabboo Contract Updation with invalid name of long length") + resource := fmt.Sprintf(` + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_taboo_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + } + `, rName, longerName) + return resource +} + +func CreateAccTabooContractUpdatedAttr(fvTenantName, rName, attribute, value string) string { + fmt.Printf("=== STEP testing taboo_contract attribute: %s=%s \n", attribute, value) + resource := fmt.Sprintf(` + + resource "aci_tenant" "test" { + name = "%s" + description = "tenant created while acceptance testing" + + } + + resource "aci_taboo_contract" "test" { + tenant_dn = aci_tenant.test.id + name = "%s" + %s = "%s" + + } + `, fvTenantName, rName, attribute, value) + return resource +} diff --git a/testacc/sweeper_test.go b/testacc/sweeper_test.go new file mode 100644 index 000000000..1df18639a --- /dev/null +++ b/testacc/sweeper_test.go @@ -0,0 +1,37 @@ +package testacc + +import ( + "strings" + "testing" + + "github.com/ciscoecosystem/aci-go-client/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestMain(m *testing.M) { + resource.TestMain(m) +} + +func init() { + resource.AddTestSweepers("aci_tenant", + &resource.Sweeper{ + Name: "aci_tenant", + F: aciTenantSweeper, + }) +} + +func aciTenantSweeper(_ string) error { + aciClient := sharedAciClient() + cont, _ := aciClient.GetViaURL("/api/node/class/fvTenant.json") + instances := models.TenantListFromContainer(cont) + for _, instance := range instances { + dn := instance.DistinguishedName + if strings.HasPrefix(GetMOName(dn), "acctest") { + err := aciClient.DeleteByDn(dn, "fvTenant") + if err != nil { + return err + } + } + } + return nil +} diff --git a/testacc/utils.go b/testacc/utils.go index bf6043dc9..d76fefc06 100644 --- a/testacc/utils.go +++ b/testacc/utils.go @@ -1,4 +1,4 @@ -package acctest +package testacc import ( "fmt" diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/aaaLdapProvider_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/aaaLdapProvider_service.go index 85c1b2877..d7e22e736 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/aaaLdapProvider_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/aaaLdapProvider_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -70,7 +71,7 @@ func (sm *ServiceManager) CreateRelationaaaRsProvToEpp(parentDn, annotation, tDn if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -116,7 +117,7 @@ func (sm *ServiceManager) CreateRelationaaaRsSecProvToEpg(parentDn, annotation, if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/aaaUserEp_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/aaaUserEp_service.go index ff3406dba..ec526f551 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/aaaUserEp_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/aaaUserEp_service.go @@ -1,27 +1,23 @@ package client - - import ( - "fmt" + "log" - "github.com/ciscoecosystem/aci-go-client/models" "github.com/ciscoecosystem/aci-go-client/container" - + "github.com/ciscoecosystem/aci-go-client/models" ) - -func (sm *ServiceManager) CreateUserManagement(description string, nameAlias string, aaaUserEpAttr models.UserManagementAttributes) (*models.UserManagement, error) { - rn := fmt.Sprintf(models.RnaaaUserEp , ) - parentDn := fmt.Sprintf(models.ParentDnaaaUserEp, ) +func (sm *ServiceManager) CreateUserManagement(description string, nameAlias string, aaaUserEpAttr models.UserManagementAttributes) (*models.UserManagement, error) { + rn := fmt.Sprintf(models.RnaaaUserEp) + parentDn := fmt.Sprintf(models.ParentDnaaaUserEp) aaaUserEp := models.NewUserManagement(rn, parentDn, description, nameAlias, aaaUserEpAttr) err := sm.Save(aaaUserEp) return aaaUserEp, err } func (sm *ServiceManager) ReadUserManagement() (*models.UserManagement, error) { - dn := fmt.Sprintf(models.DnaaaUserEp, ) + dn := fmt.Sprintf(models.DnaaaUserEp) cont, err := sm.Get(dn) if err != nil { return nil, err @@ -31,22 +27,22 @@ func (sm *ServiceManager) ReadUserManagement() (*models.UserManagement, error) { } func (sm *ServiceManager) DeleteUserManagement() error { - dn := fmt.Sprintf(models.DnaaaUserEp, ) + dn := fmt.Sprintf(models.DnaaaUserEp) return sm.DeleteByDn(dn, models.AaauserepClassName) } func (sm *ServiceManager) UpdateUserManagement(description string, nameAlias string, aaaUserEpAttr models.UserManagementAttributes) (*models.UserManagement, error) { - rn := fmt.Sprintf(models.RnaaaUserEp , ) - parentDn := fmt.Sprintf(models.ParentDnaaaUserEp, ) + rn := fmt.Sprintf(models.RnaaaUserEp) + parentDn := fmt.Sprintf(models.ParentDnaaaUserEp) aaaUserEp := models.NewUserManagement(rn, parentDn, description, nameAlias, aaaUserEpAttr) - aaaUserEp.Status = "modified" + aaaUserEp.Status = "modified" err := sm.Save(aaaUserEp) return aaaUserEp, err } -func (sm *ServiceManager) ListUserManagement() ([]*models.UserManagement, error) { +func (sm *ServiceManager) ListUserManagement() ([]*models.UserManagement, error) { dnUrl := fmt.Sprintf("%s/uni/aaaUserEp.json", models.BaseurlStr) - cont, err := sm.GetViaURL(dnUrl) + cont, err := sm.GetViaURL(dnUrl) list := models.UserManagementListFromContainer(cont) return list, err } @@ -63,7 +59,6 @@ func (sm *ServiceManager) CreateRelationaaaRsToUserEp(parentDn, annotation, tDn } }`, "aaaRsToUserEp", dn, annotation, tDn)) - jsonPayload, err := container.ParseJSON(containerJSON) if err != nil { return err @@ -76,25 +71,24 @@ func (sm *ServiceManager) CreateRelationaaaRsToUserEp(parentDn, annotation, tDn if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } -func (sm *ServiceManager) DeleteRelationaaaRsToUserEp(parentDn string) error{ +func (sm *ServiceManager) DeleteRelationaaaRsToUserEp(parentDn string) error { dn := fmt.Sprintf("%s/rstoUserEp", parentDn) - return sm.DeleteByDn(dn , "aaaRsToUserEp") + return sm.DeleteByDn(dn, "aaaRsToUserEp") } -func (sm *ServiceManager) ReadRelationaaaRsToUserEp(parentDn string) (interface{},error) { - dnUrl := fmt.Sprintf("%s/%s/%s.json",models.BaseurlStr,parentDn,"aaaRsToUserEp") +func (sm *ServiceManager) ReadRelationaaaRsToUserEp(parentDn string) (interface{}, error) { + dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "aaaRsToUserEp") cont, err := sm.GetViaURL(dnUrl) - contList := models.ListFromContainer(cont,"aaaRsToUserEp") - - if len(contList) > 0 { + contList := models.ListFromContainer(cont, "aaaRsToUserEp") + + if len(contList) > 0 { dat := models.G(contList[0], "tDn") return dat, err } else { return nil, err } } - diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/bfdIfP_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/bfdIfP_service.go index 88bd81cbe..0cd067702 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/bfdIfP_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/bfdIfP_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationbfdRsIfPolFromInterfaceProfile(parentDn, if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/bgpPeerP_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/bgpPeerP_service.go index 1d92e8ad2..143e5b1c3 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/bgpPeerP_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/bgpPeerP_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationbgpRsPeerPfxPolFromBgpPeerConnectivityPr if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -125,7 +126,7 @@ func (sm *ServiceManager) CreateRelationbgpRsPeerToProfile(parentDn, annotation, if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/bgpProtP_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/bgpProtP_service.go index 22a9e710a..96a37c154 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/bgpProtP_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/bgpProtP_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationbgpRsBgpNodeCtxPolFromL3outBGPProtocolPr if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/cloudRouterP_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/cloudRouterP_service.go index 5a5ddbfa1..8d9260243 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/cloudRouterP_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/cloudRouterP_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationcloudRsToVpnGwPolFromCloudVpnGateway(par if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -123,7 +124,7 @@ func (sm *ServiceManager) CreateRelationcloudRsToDirectConnPolFromCloudVpnGatewa if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -168,7 +169,7 @@ func (sm *ServiceManager) CreateRelationcloudRsToHostRouterPolFromCloudVpnGatewa if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/dhcpLbl_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/dhcpLbl_service.go index 69b255095..5a7338847 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/dhcpLbl_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/dhcpLbl_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationdhcpRsDhcpOptionPolFromBDDHCPLabel(paren if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/dhcpRelayP_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/dhcpRelayP_service.go index d97cad8e7..c200291d6 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/dhcpRelayP_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/dhcpRelayP_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -80,7 +81,7 @@ func (sm *ServiceManager) CreateRelationdhcpRsProvFromDHCPRelayPolicy(parentDn, if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/fileRemotePath_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/fileRemotePath_service.go index e0c3b8509..c2bc14c69 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/fileRemotePath_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/fileRemotePath_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -70,7 +71,7 @@ func (sm *ServiceManager) CreateRelationfileRsARemoteHostToEpg(parentDn, annotat if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -116,7 +117,7 @@ func (sm *ServiceManager) CreateRelationfileRsARemoteHostToEpp(parentDn, annotat if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/fvEPgSelector_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/fvEPgSelector_service.go index ddf70a963..5c375f9f6 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/fvEPgSelector_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/fvEPgSelector_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -70,7 +71,7 @@ func (sm *ServiceManager) CreateRelationfvRsMatchEPg(parentDn, annotation, tDn s if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/fvESg_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/fvESg_service.go index fcbd36785..2943fe32e 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/fvESg_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/fvESg_service.go @@ -3,6 +3,7 @@ package client import ( "encoding/json" "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -100,7 +101,7 @@ func (sm *ServiceManager) CreateRelationfvRsCons(parentDn, annotation, prio stri if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -176,7 +177,7 @@ func (sm *ServiceManager) CreateRelationfvRsConsIf(parentDn, annotation, prio st if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -224,7 +225,7 @@ func (sm *ServiceManager) CreateRelationfvRsCustQosPol(parentDn, annotation, tnQ if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -270,7 +271,7 @@ func (sm *ServiceManager) CreateRelationfvRsIntraEpg(parentDn, annotation, tnVzB if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -318,7 +319,7 @@ func (sm *ServiceManager) CreateRelationfvRsProtBy(parentDn, annotation, tnVzTab if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -395,7 +396,7 @@ func (sm *ServiceManager) CreateRelationfvRsProv(parentDn, annotation, matchT st if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -444,7 +445,7 @@ func (sm *ServiceManager) CreateRelationfvRsScope(parentDn, annotation, tnFvCtxN if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -490,7 +491,7 @@ func (sm *ServiceManager) CreateRelationfvRsSecInherited(parentDn, annotation, t if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/hsrpGroupP_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/hsrpGroupP_service.go index b4b4861ec..fe0c6eb39 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/hsrpGroupP_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/hsrpGroupP_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -77,7 +78,7 @@ func (sm *ServiceManager) CreateRelationhsrpRsGroupPolFromHSRPGroupProfile(paren if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/hsrpIfP_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/hsrpIfP_service.go index 0bb4723e4..aacc6dce6 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/hsrpIfP_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/hsrpIfP_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -79,7 +80,7 @@ func (sm *ServiceManager) CreateRelationhsrpRsIfPolFromL3outHSRPInterfaceProfile if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/infraAccNodePGrp_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/infraAccNodePGrp_service.go index 5ff3c46a1..51eff76e5 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/infraAccNodePGrp_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/infraAccNodePGrp_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -70,7 +71,7 @@ func (sm *ServiceManager) CreateRelationinfraRsBfdIpv4InstPol(parentDn, annotati if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -116,7 +117,7 @@ func (sm *ServiceManager) CreateRelationinfraRsBfdIpv6InstPol(parentDn, annotati if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -162,7 +163,7 @@ func (sm *ServiceManager) CreateRelationinfraRsBfdMhIpv4InstPol(parentDn, annota if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -208,7 +209,7 @@ func (sm *ServiceManager) CreateRelationinfraRsBfdMhIpv6InstPol(parentDn, annota if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -254,7 +255,7 @@ func (sm *ServiceManager) CreateRelationinfraRsEquipmentFlashConfigPol(parentDn, if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -300,7 +301,7 @@ func (sm *ServiceManager) CreateRelationinfraRsFcFabricPol(parentDn, annotation, if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -346,7 +347,7 @@ func (sm *ServiceManager) CreateRelationinfraRsFcInstPol(parentDn, annotation, t if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -392,7 +393,7 @@ func (sm *ServiceManager) CreateRelationinfraRsIaclLeafProfile(parentDn, annotat if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -438,7 +439,7 @@ func (sm *ServiceManager) CreateRelationinfraRsL2NodeAuthPol(parentDn, annotatio if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -484,7 +485,7 @@ func (sm *ServiceManager) CreateRelationinfraRsLeafCoppProfile(parentDn, annotat if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -530,7 +531,7 @@ func (sm *ServiceManager) CreateRelationinfraRsLeafPGrpToCdpIfPol(parentDn, anno if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -576,7 +577,7 @@ func (sm *ServiceManager) CreateRelationinfraRsLeafPGrpToLldpIfPol(parentDn, ann if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -622,7 +623,7 @@ func (sm *ServiceManager) CreateRelationinfraRsMonNodeInfraPol(parentDn, annotat if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -668,7 +669,7 @@ func (sm *ServiceManager) CreateRelationinfraRsMstInstPol(parentDn, annotation, if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -714,7 +715,7 @@ func (sm *ServiceManager) CreateRelationinfraRsNetflowNodePol(parentDn, annotati if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -760,7 +761,7 @@ func (sm *ServiceManager) CreateRelationinfraRsPoeInstPol(parentDn, annotation, if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -806,7 +807,7 @@ func (sm *ServiceManager) CreateRelationinfraRsTopoctrlFastLinkFailoverInstPol(p if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -852,7 +853,7 @@ func (sm *ServiceManager) CreateRelationinfraRsTopoctrlFwdScaleProfPol(parentDn, if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/infraBrkoutPortGrp_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/infraBrkoutPortGrp_service.go index 8c58602cf..9603a1c47 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/infraBrkoutPortGrp_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/infraBrkoutPortGrp_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationinfraRsMonBrkoutInfraPolFromLeafBreakout if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/infraFexBndlGrp_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/infraFexBndlGrp_service.go index 77abf1697..a4f766b81 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/infraFexBndlGrp_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/infraFexBndlGrp_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -79,7 +80,7 @@ func (sm *ServiceManager) CreateRelationinfraRsMonFexInfraPolFromFexBundleGroup( if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -123,7 +124,7 @@ func (sm *ServiceManager) CreateRelationinfraRsFexBndlGrpToAggrIfFromFexBundleGr if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/infraGeneric_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/infraGeneric_service.go index abeef4f72..ce25c37e9 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/infraGeneric_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/infraGeneric_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationinfraRsFuncToEpgFromAccessGeneric(parent if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/infraSpAccPortGrp_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/infraSpAccPortGrp_service.go index a3594235f..3dafe04c6 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/infraSpAccPortGrp_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/infraSpAccPortGrp_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationinfraRsHIfPolFromSpineAccessPortPolicyGr if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -123,7 +124,7 @@ func (sm *ServiceManager) CreateRelationinfraRsCdpIfPolFromSpineAccessPortPolicy if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -168,7 +169,7 @@ func (sm *ServiceManager) CreateRelationinfraRsCoppIfPolFromSpineAccessPortPolic if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -213,7 +214,7 @@ func (sm *ServiceManager) CreateRelationinfraRsAttEntPFromSpineAccessPortPolicyG if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -263,7 +264,7 @@ func (sm *ServiceManager) CreateRelationinfraRsMacsecIfPolFromSpineAccessPortPol if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/infraSpineAccNodePGrp_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/infraSpineAccNodePGrp_service.go index a778777d3..dea873430 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/infraSpineAccNodePGrp_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/infraSpineAccNodePGrp_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -70,7 +71,7 @@ func (sm *ServiceManager) CreateRelationinfraRsIaclSpineProfile(parentDn, annota if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -116,7 +117,7 @@ func (sm *ServiceManager) CreateRelationinfraRsSpineBfdIpv4InstPol(parentDn, ann if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -162,7 +163,7 @@ func (sm *ServiceManager) CreateRelationinfraRsSpineBfdIpv6InstPol(parentDn, ann if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -208,7 +209,7 @@ func (sm *ServiceManager) CreateRelationinfraRsSpineCoppProfile(parentDn, annota if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -254,7 +255,7 @@ func (sm *ServiceManager) CreateRelationinfraRsSpinePGrpToCdpIfPol(parentDn, ann if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -300,7 +301,7 @@ func (sm *ServiceManager) CreateRelationinfraRsSpinePGrpToLldpIfPol(parentDn, an if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/infraSpineP_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/infraSpineP_service.go index a37491049..20f7f7551 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/infraSpineP_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/infraSpineP_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationinfraRsSpAccPortPFromSpineProfile(parent if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/infraSpineS_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/infraSpineS_service.go index 3eea0858f..09148b323 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/infraSpineS_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/infraSpineS_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -79,7 +80,7 @@ func (sm *ServiceManager) CreateRelationinfraRsSpineAccNodePGrpFromSwitchAssocia if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/ipNexthopP_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/ipNexthopP_service.go index 3e7f5c513..3731e79a9 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/ipNexthopP_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/ipNexthopP_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationipRsNexthopRouteTrackFromL3outStaticRout if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -128,7 +129,7 @@ func (sm *ServiceManager) CreateRelationipRsNHTrackMemberFromL3outStaticRouteNex if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/ipRouteP_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/ipRouteP_service.go index 6f22e87c5..845f59fdd 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/ipRouteP_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/ipRouteP_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationipRsRouteTrackFromL3outStaticRoute(paren if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/l2extDomP_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/l2extDomP_service.go index 4da2e551e..890a06eaf 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/l2extDomP_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/l2extDomP_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -81,7 +82,7 @@ func (sm *ServiceManager) CreateRelationinfraRsVlanNsFromL2Domain(parentDn, tnFv if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -131,7 +132,7 @@ func (sm *ServiceManager) CreateRelationinfraRsVlanNsDefFromL2Domain(parentDn, t if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -176,7 +177,7 @@ func (sm *ServiceManager) CreateRelationinfraRsVipAddrNsFromL2Domain(parentDn, t if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -225,7 +226,7 @@ func (sm *ServiceManager) CreateRelationextnwRsOutFromL2Domain(parentDn, tDn str if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -272,7 +273,7 @@ func (sm *ServiceManager) CreateRelationinfraRsDomVxlanNsDefFromL2Domain(parentD if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/l2extInstP_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/l2extInstP_service.go index 2ccffc009..fcbb223f4 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/l2extInstP_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/l2extInstP_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -80,7 +81,7 @@ func (sm *ServiceManager) CreateRelationfvRsSecInheritedFromL2outExternalEpg(par if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -133,7 +134,7 @@ func (sm *ServiceManager) CreateRelationfvRsProvFromL2outExternalEpg(parentDn, t if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -186,7 +187,7 @@ func (sm *ServiceManager) CreateRelationfvRsConsIfFromL2outExternalEpg(parentDn, if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -240,7 +241,7 @@ func (sm *ServiceManager) CreateRelationfvRsCustQosPolFromL2outExternalEpg(paren if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -286,7 +287,7 @@ func (sm *ServiceManager) CreateRelationfvRsConsFromL2outExternalEpg(parentDn, t if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -338,7 +339,7 @@ func (sm *ServiceManager) CreateRelationl2extRsL2InstPToDomPFromL2outExternalEpg if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -384,7 +385,7 @@ func (sm *ServiceManager) CreateRelationfvRsProtByFromL2outExternalEpg(parentDn, if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -437,7 +438,7 @@ func (sm *ServiceManager) CreateRelationfvRsIntraEpgFromL2outExternalEpg(parentD if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/l2extOut_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/l2extOut_service.go index 1db8cb9cb..71c19b1a9 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/l2extOut_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/l2extOut_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationl2extRsEBdFromL2Outside(parentDn, tnFvBD if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -123,7 +124,7 @@ func (sm *ServiceManager) CreateRelationl2extRsL2DomAttFromL2Outside(parentDn, t if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/l3extVirtualLIfP_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/l3extVirtualLIfP_service.go index 37c1a9347..16dc51578 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/l3extVirtualLIfP_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/l3extVirtualLIfP_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationl3extRsDynPathAttFromLogicalInterfacePro if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/maintMaintGrp_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/maintMaintGrp_service.go index d2b669dd7..e79f05efe 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/maintMaintGrp_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/maintMaintGrp_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -165,7 +166,7 @@ func (sm *ServiceManager) CreateRelationmaintRsMgrppFromMaintGrp(parentDn, tnMai if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/maintMaintP_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/maintMaintP_service.go index c160fe991..0d3bf076c 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/maintMaintP_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/maintMaintP_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -258,7 +259,7 @@ func (sm *ServiceManager) CreateRelationmaintRsPolSchedulerFromMaintP(parentDn, if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/mgmtInBZone_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/mgmtInBZone_service.go index be3d17205..ac31fd11d 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/mgmtInBZone_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/mgmtInBZone_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -70,7 +71,7 @@ func (sm *ServiceManager) CreateRelationmgmtRsAddrInstFrommgmtInBZone(parentDn, if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -116,7 +117,7 @@ func (sm *ServiceManager) CreateRelationmgmtRsInB(parentDn, annotation, tDn stri if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -162,7 +163,7 @@ func (sm *ServiceManager) CreateRelationmgmtRsInbEpg(parentDn, annotation, tDn s if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/mgmtInB_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/mgmtInB_service.go index 6a34c2bd9..601cab4ad 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/mgmtInB_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/mgmtInB_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -79,7 +80,7 @@ func (sm *ServiceManager) CreateRelationfvRsSecInheritedFromInBandManagementEPg( if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -131,7 +132,7 @@ func (sm *ServiceManager) CreateRelationfvRsProvFromInBandManagementEPg(parentDn if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -183,7 +184,7 @@ func (sm *ServiceManager) CreateRelationfvRsConsIfFromInBandManagementEPg(parent if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -235,7 +236,7 @@ func (sm *ServiceManager) CreateRelationfvRsCustQosPolFromInBandManagementEPg(pa if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -280,7 +281,7 @@ func (sm *ServiceManager) CreateRelationmgmtRsMgmtBDFromInBandManagementEPg(pare if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -325,7 +326,7 @@ func (sm *ServiceManager) CreateRelationfvRsConsFromInBandManagementEPg(parentDn if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -377,7 +378,7 @@ func (sm *ServiceManager) CreateRelationfvRsProtByFromInBandManagementEPg(parent if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -429,7 +430,7 @@ func (sm *ServiceManager) CreateRelationmgmtRsInBStNodeFromInBandManagementEPg(p if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -481,7 +482,7 @@ func (sm *ServiceManager) CreateRelationfvRsIntraEpgFromInBandManagementEPg(pare if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/mgmtOoBZone_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/mgmtOoBZone_service.go index 50646713a..67a5474b6 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/mgmtOoBZone_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/mgmtOoBZone_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -70,7 +71,7 @@ func (sm *ServiceManager) CreateRelationmgmtRsAddrInst(parentDn, annotation, tDn if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -116,7 +117,7 @@ func (sm *ServiceManager) CreateRelationmgmtRsOoB(parentDn, annotation, tDn stri if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -162,7 +163,7 @@ func (sm *ServiceManager) CreateRelationmgmtRsOobEpg(parentDn, annotation, tDn s if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/mgmtOoB_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/mgmtOoB_service.go index 502029dcf..e94254e84 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/mgmtOoB_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/mgmtOoB_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -79,7 +80,7 @@ func (sm *ServiceManager) CreateRelationmgmtRsOoBProvFromOutOfBandManagementEPg( if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -131,7 +132,7 @@ func (sm *ServiceManager) CreateRelationmgmtRsOoBStNodeFromOutOfBandManagementEP if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -182,7 +183,7 @@ func (sm *ServiceManager) CreateRelationmgmtRsOoBCtxFromOutOfBandManagementEPg(p if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/ospfIfP_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/ospfIfP_service.go index 71d93d74e..3f0975e96 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/ospfIfP_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/ospfIfP_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationospfRsIfPolFromInterfaceProfile(parentDn if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return CheckForErrors(cont, "POST", sm.client.skipLoggingPayload) } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/rtctrlCtxP_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/rtctrlCtxP_service.go index 70f84f8b2..68bc95439 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/rtctrlCtxP_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/rtctrlCtxP_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -96,7 +97,7 @@ func (sm *ServiceManager) CreateRelationrtctrlRsCtxPToSubjP(parentDn, annotation if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/rtctrlScope_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/rtctrlScope_service.go index 7860b7fad..1c156df84 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/rtctrlScope_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/rtctrlScope_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -70,7 +71,7 @@ func (sm *ServiceManager) CreateRelationrtctrlRsScopeToAttrP(parentDn, annotatio if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/tacacsSrc_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/tacacsSrc_service.go index ee1a3fb08..acbb3b96e 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/tacacsSrc_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/tacacsSrc_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -70,7 +71,7 @@ func (sm *ServiceManager) CreateRelationtacacsRsDestGroup(parentDn, annotation, if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/vmmCtrlrP_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/vmmCtrlrP_service.go index d903c07a1..42bfc1d27 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/vmmCtrlrP_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/vmmCtrlrP_service.go @@ -3,6 +3,7 @@ package client import ( "encoding/json" "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -72,7 +73,7 @@ func (sm *ServiceManager) CreateRelationvmmRsAcc(parentDn, annotation, tDn strin if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -118,7 +119,7 @@ func (sm *ServiceManager) CreateRelationvmmRsCtrlrPMonPol(parentDn, annotation, if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -164,7 +165,7 @@ func (sm *ServiceManager) CreateRelationvmmRsMcastAddrNs(parentDn, annotation, t if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -210,7 +211,7 @@ func (sm *ServiceManager) CreateRelationvmmRsMgmtEPg(parentDn, annotation, tDn s if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -256,7 +257,7 @@ func (sm *ServiceManager) CreateRelationvmmRsToExtDevMgr(parentDn, annotation, t if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -332,7 +333,7 @@ func (sm *ServiceManager) CreateRelationvmmRsVmmCtrlrP(parentDn, annotation, epg if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -380,7 +381,7 @@ func (sm *ServiceManager) CreateRelationvmmRsVxlanNs(parentDn, annotation, tDn s if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -425,7 +426,7 @@ func (sm *ServiceManager) CreateRelationvmmRsVxlanNsDef(parentDn, annotation, tD if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/vmmVSwitchPolicyCont_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/vmmVSwitchPolicyCont_service.go index 1e4ff017f..7b1beffab 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/vmmVSwitchPolicyCont_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/vmmVSwitchPolicyCont_service.go @@ -3,6 +3,7 @@ package client import ( "encoding/json" "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -101,7 +102,7 @@ func (sm *ServiceManager) CreateRelationvmmRsVswitchExporterPol(parentDn, annota if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -151,7 +152,7 @@ func (sm *ServiceManager) CreateRelationvmmRsVswitchOverrideCdpIfPol(parentDn, a if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -197,7 +198,7 @@ func (sm *ServiceManager) CreateRelationvmmRsVswitchOverrideFwPol(parentDn, anno if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -243,7 +244,7 @@ func (sm *ServiceManager) CreateRelationvmmRsVswitchOverrideLacpPol(parentDn, an if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -289,7 +290,7 @@ func (sm *ServiceManager) CreateRelationvmmRsVswitchOverrideLldpIfPol(parentDn, if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -335,7 +336,7 @@ func (sm *ServiceManager) CreateRelationvmmRsVswitchOverrideMcpIfPol(parentDn, a if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -381,7 +382,7 @@ func (sm *ServiceManager) CreateRelationvmmRsVswitchOverrideMtuPol(parentDn, ann if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -427,7 +428,7 @@ func (sm *ServiceManager) CreateRelationvmmRsVswitchOverrideStpPol(parentDn, ann if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsAbsConnection_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsAbsConnection_service.go index 2359136d3..f9037108a 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsAbsConnection_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsAbsConnection_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationvnsRsAbsCopyConnectionFromConnection(par if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return CheckForErrors(cont, "POST", sm.client.skipLoggingPayload) } @@ -129,7 +130,7 @@ func (sm *ServiceManager) CreateRelationvnsRsAbsConnectionConnsFromConnection(pa if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return CheckForErrors(cont, "POST", sm.client.skipLoggingPayload) } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsAbsFuncConn_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsAbsFuncConn_service.go index 0ef163a64..d44cca419 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsAbsFuncConn_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsAbsFuncConn_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationvnsRsConnToCtxTermFromFunctionConnector( if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -128,7 +129,7 @@ func (sm *ServiceManager) CreateRelationvnsRsConnToFltFromFunctionConnector(pare if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -178,7 +179,7 @@ func (sm *ServiceManager) CreateRelationvnsRsMConnAttFromFunctionConnector(paren if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -228,7 +229,7 @@ func (sm *ServiceManager) CreateRelationvnsRsConnToAConnFromFunctionConnector(pa if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsAbsNode_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsAbsNode_service.go index 41e59baf7..3625ec243 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsAbsNode_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsAbsNode_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationvnsRsNodeToAbsFuncProfFromFunctionNode(p if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -128,7 +129,7 @@ func (sm *ServiceManager) CreateRelationvnsRsNodeToLDevFromFunctionNode(parentDn if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -178,7 +179,7 @@ func (sm *ServiceManager) CreateRelationvnsRsNodeToMFuncFromFunctionNode(parentD if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -228,7 +229,7 @@ func (sm *ServiceManager) CreateRelationvnsRsDefaultScopeToTermFromFunctionNode( if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -278,7 +279,7 @@ func (sm *ServiceManager) CreateRelationvnsRsNodeToCloudLDevFromFunctionNode(par if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsLDevCtx_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsLDevCtx_service.go index 9490bbe0a..45a3d0ab5 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsLDevCtx_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsLDevCtx_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationvnsRsLDevCtxToLDevFromLogicalDeviceConte if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -128,7 +129,7 @@ func (sm *ServiceManager) CreateRelationvnsRsLDevCtxToRtrCfgFromLogicalDeviceCon if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsLIfCtx_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsLIfCtx_service.go index e9351f8b8..496c29605 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsLIfCtx_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsLIfCtx_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationvnsRsLIfCtxToCustQosPolFromLogicalInterf if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -123,7 +124,7 @@ func (sm *ServiceManager) CreateRelationvnsRsLIfCtxToSvcEPgPolFromLogicalInterfa if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -173,7 +174,7 @@ func (sm *ServiceManager) CreateRelationvnsRsLIfCtxToSvcRedirectPolFromLogicalIn if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -223,7 +224,7 @@ func (sm *ServiceManager) CreateRelationvnsRsLIfCtxToLIfFromLogicalInterfaceCont if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -273,7 +274,7 @@ func (sm *ServiceManager) CreateRelationvnsRsLIfCtxToOutDefFromLogicalInterfaceC if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -318,7 +319,7 @@ func (sm *ServiceManager) CreateRelationvnsRsLIfCtxToInstPFromLogicalInterfaceCo if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -368,7 +369,7 @@ func (sm *ServiceManager) CreateRelationvnsRsLIfCtxToBDFromLogicalInterfaceConte if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } @@ -418,7 +419,7 @@ func (sm *ServiceManager) CreateRelationvnsRsLIfCtxToOutFromLogicalInterfaceCont if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsRedirectDest_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsRedirectDest_service.go index c42588489..77b894ad5 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsRedirectDest_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsRedirectDest_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationvnsRsRedirectHealthGroupFromDestinationo if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsSvcRedirectPol_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsSvcRedirectPol_service.go index cfb625586..e58c62941 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsSvcRedirectPol_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/vnsSvcRedirectPol_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationvnsRsIPSLAMonitoringPolFromServiceRedire if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/github.com/ciscoecosystem/aci-go-client/client/vzCPIf_service.go b/vendor/github.com/ciscoecosystem/aci-go-client/client/vzCPIf_service.go index b54793b65..cc3ff87b2 100644 --- a/vendor/github.com/ciscoecosystem/aci-go-client/client/vzCPIf_service.go +++ b/vendor/github.com/ciscoecosystem/aci-go-client/client/vzCPIf_service.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "log" "github.com/ciscoecosystem/aci-go-client/container" "github.com/ciscoecosystem/aci-go-client/models" @@ -78,7 +79,7 @@ func (sm *ServiceManager) CreateRelationvzRsIfFromImportedContract(parentDn, tnV if err != nil { return err } - fmt.Printf("%+v", cont) + log.Printf("%+v", cont) return nil } diff --git a/vendor/modules.txt b/vendor/modules.txt index d7d288b16..f2eeda631 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -56,7 +56,7 @@ github.com/aws/aws-sdk-go/service/sts github.com/aws/aws-sdk-go/service/sts/stsiface # github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d github.com/bgentry/go-netrc/netrc -# github.com/ciscoecosystem/aci-go-client v1.20.1 +# github.com/ciscoecosystem/aci-go-client v1.20.2 github.com/ciscoecosystem/aci-go-client/client github.com/ciscoecosystem/aci-go-client/container github.com/ciscoecosystem/aci-go-client/models diff --git a/website/docs/d/epg_to_contract.html.markdown b/website/docs/d/epg_to_contract.html.markdown index a53473f01..81330b67b 100644 --- a/website/docs/d/epg_to_contract.html.markdown +++ b/website/docs/d/epg_to_contract.html.markdown @@ -16,7 +16,7 @@ Data source for ACI EPG to contract relationship. ```hcl data "aci_epg_to_contract" "example" { application_epg_dn = aci_application_epg.demo.id - contract_name = "example" + contract_dn = aci_contract.demo.id contract_type = "consumer" } ``` @@ -31,6 +31,5 @@ data "aci_epg_to_contract" "example" { - `id` - Attribute id set to the Dn of the provider/consumer contract. - `annotation` - (Optional) annotation for EPg to contract relationship. -- `description` - (Optional) annotation for EPg to contract relationship. - `match_t` - (Optional) Provider matching criteria. - `prio` - (Optional) Priority of relation object. diff --git a/website/docs/d/epg_to_static_path.html.markdown b/website/docs/d/epg_to_static_path.html.markdown index 868d5d68b..feb87dbc9 100644 --- a/website/docs/d/epg_to_static_path.html.markdown +++ b/website/docs/d/epg_to_static_path.html.markdown @@ -32,3 +32,4 @@ data "aci_epg_to_static_path" "example" { * `instr_imedcy` - (Optional) Immediacy of the Static Path. * `mode` - (Optional) Mode of the static association with the path. * `primary_encap` - (Optional) Primary encap for object Static Path. +* `description` - (Optional) Description for object Static Path. diff --git a/website/docs/d/external_network_instance_profile.html.markdown b/website/docs/d/external_network_instance_profile.html.markdown index 6da84e0e1..256841a27 100644 --- a/website/docs/d/external_network_instance_profile.html.markdown +++ b/website/docs/d/external_network_instance_profile.html.markdown @@ -29,6 +29,7 @@ data "aci_external_network_instance_profile" "dev_ext_net_prof" { - `id` - Attribute id set to the Dn of the External Network Instance Profile. - `annotation` - (Optional) Annotation for object external network instance profile. +- `description` - (Optional) Specifies the description of the external network instance profile. - `exception_tag` - (Optional) Exception tag for object external network instance profile. - `flood_on_encap` - (Optional) Control at EPG level if the traffic L2 Multicast/Broadcast and Link Local Layer should be flooded only on ENCAP or based on bridg-domain settings. - `match_t` - (Optional) The provider label match criteria. diff --git a/website/docs/d/l3out_hsrp_secondary_vip.html.markdown b/website/docs/d/l3out_hsrp_secondary_vip.html.markdown index 2196616c5..a6c59dfb1 100644 --- a/website/docs/d/l3out_hsrp_secondary_vip.html.markdown +++ b/website/docs/d/l3out_hsrp_secondary_vip.html.markdown @@ -31,5 +31,4 @@ data "aci_l3out_hsrp_secondary_vip" "example" { - `annotation` - (Optional) Annotation for object L3out HSRP Secondary VIP. - `description` - (Optional) Description for object L3out HSRP Secondary VIP. - `config_issues` - (Optional) Configuration Issues. -- `ip` - (Optional) IP address. - `name_alias` - (Optional) Name alias for object L3out HSRP Secondary VIP. diff --git a/website/docs/r/contract.html.markdown b/website/docs/r/contract.html.markdown index 8359eade0..6fb12c3be 100644 --- a/website/docs/r/contract.html.markdown +++ b/website/docs/r/contract.html.markdown @@ -63,7 +63,7 @@ Allowed values: "unspecified", "ftpData", "smtp", "dns", "http","pop3", "https", Allowed values: "unspecified", "ftpData", "smtp", "dns", "http","pop3", "https", "rtsp" * `filter.filter_entry.stateful` - (Optional) Determines if entry is stateful or not. Allowed values are "yes" and "no". Default is "no". * `filter.filter_entry.tcp_rules` - (Optional) TCP Session Rules. Allowed values are "unspecified", "est", "syn", "ack", "fin" and "rst". Default is "unspecified". -* `relation_vz_rs_graph_att` - (Optional) Relation to class vzRsGraphAtt. Cardinality - N_TO_ONE. Type - String. +* `relation_vz_rs_graph_att` - (Optional) Relation to class vnsAbsGraph. Cardinality - N_TO_ONE. Type - String. ## Attribute Reference diff --git a/website/docs/r/epg_to_contract.html.markdown b/website/docs/r/epg_to_contract.html.markdown index 3c30468e0..ecadce54d 100644 --- a/website/docs/r/epg_to_contract.html.markdown +++ b/website/docs/r/epg_to_contract.html.markdown @@ -30,8 +30,7 @@ resource "aci_epg_to_contract" "example" { - `contract_dn` - (Required) Distinguished name of contract to attach. - `contract_type` - (Required) Type of relationship. Allowed values are "consumer" and "provider". - `annotation` - (Optional) Annotation for EPg to contract relationship. -- `description` - (Optional) Description for EPg to contract relationship. -- `match_t` - (Optional) Provider matching criteria. Allowed values: "All", "AtleastOne", "AtmostOne", "None". Default value: "AtleastOne". +- `match_t` - (Optional) Provider matching criteria. Allowed values: "All", "AtleastOne", "AtmostOne", "None". Default value: "AtleastOne". This attribute is supported only for resources with "contract_type" with value "provider" - `prio` - (Optional) Priority of relation object. Allowed values: "unspecified", "level1", "level2", "level3", "level4", "level5", "level6". Default value: "unspecified". ## Attribute Reference diff --git a/website/docs/r/epg_to_domain.html.markdown b/website/docs/r/epg_to_domain.html.markdown index 216b350fc..44b132d62 100644 --- a/website/docs/r/epg_to_domain.html.markdown +++ b/website/docs/r/epg_to_domain.html.markdown @@ -76,9 +76,9 @@ Allowed values: "immediate", "lazy", "pre-provision". Default value: "lazy" * `switching_mode` - (Optional) Switching mode for object domain. Allowed values: "native", "AVE". Default value: "native" -* `vmm_allow_promiscuous` - (Optional) Allow promiscuous for object Vmm security policy. -* `vmm_forged_transmits` - (Optional) Forged transmits for object Vmm security policy. -* `vmm_mac_changes` - (Optional) Mac changes for object Vmm security policy. +* `vmm_allow_promiscuous` - (Optional) Allow promiscuous for object Vmm security policy. Allowed values: "reject" and "accept". Default value is "reject". +* `vmm_forged_transmits` - (Optional) Forged transmits for object Vmm security policy.Allowed values: "reject" and "accept". Default value is "reject". +* `vmm_mac_changes` - (Optional) Mac changes for object Vmm security policy. Allowed values: "reject" and "accept". Default value is "reject". ## Attribute Reference @@ -93,5 +93,5 @@ An existing Domain can be [imported][docs-import] into this resource via its Dn, [docs-import]: https://www.terraform.io/docs/import/index.html ``` -terraform import aci_domain.example +terraform import aci_epg_to_domain.example ``` diff --git a/website/docs/r/epg_to_static_path.html.markdown b/website/docs/r/epg_to_static_path.html.markdown index a70196c5c..f20665a6a 100644 --- a/website/docs/r/epg_to_static_path.html.markdown +++ b/website/docs/r/epg_to_static_path.html.markdown @@ -36,6 +36,7 @@ Allowed values: "immediate", "lazy". Default value: "lazy" * `mode` - (Optional) Mode of the static association with the path. Allowed values: "regular", "native", "untagged". Default value: "regular" * `primary_encap` - (Optional) Primary encap for object Static Path. +* `description` - (Optional) Description for object Static Path. ## Attribute Reference diff --git a/website/docs/r/external_network_instance_profile.html.markdown b/website/docs/r/external_network_instance_profile.html.markdown index 93d1bdb82..ecb428b24 100644 --- a/website/docs/r/external_network_instance_profile.html.markdown +++ b/website/docs/r/external_network_instance_profile.html.markdown @@ -34,7 +34,8 @@ Manages ACI External Network Instance Profile - `l3_outside_dn` - (Required) Distinguished name of parent L3Outside object. - `name` - (Required) Name of Object external network instance profile. - `annotation` - (Optional) Annotation for object external network instance profile. -- `exception_tag` - (Optional) Exception tag for object external network instance profile. Allowed value range is "0" - "512". +- `description` - (Optional) Specifies the description of the external network instance profile. +- `exception_tag` - (Optional) Exception tag for object external network instance profile. - `flood_on_encap` - (Optional) Control at EPG level if the traffic L2 Multicast/Broadcast and Link Local Layer should be flooded only on ENCAP or based on bridg-domain settings. Allowed values are "disabled" and "enabled". Default value is "disabled". - `match_t` - (Optional) The provider label match criteria. Allowed values are "All", "AtleastOne", "AtmostOne" and "None". Default is "AtleastOne". - `name_alias` - (Optional) Name alias for object external network instance profile. diff --git a/website/docs/r/l3_ext_subnet.html.markdown b/website/docs/r/l3_ext_subnet.html.markdown index b4ef2f190..e9172d3ee 100644 --- a/website/docs/r/l3_ext_subnet.html.markdown +++ b/website/docs/r/l3_ext_subnet.html.markdown @@ -40,8 +40,6 @@ Manages ACI l3 extension subnet ``` -## Argument Reference - ## Argument Reference ## * `external_network_instance_profile_dn` - (Required) Distinguished name of parent ExternalNetworkInstanceProfile object. * `ip` - (Required) ip of Object l3 extension subnet. diff --git a/website/docs/r/l3out_floating_svi.html.markdown b/website/docs/r/l3out_floating_svi.html.markdown index 0601cc323..e2ee716a6 100644 --- a/website/docs/r/l3out_floating_svi.html.markdown +++ b/website/docs/r/l3out_floating_svi.html.markdown @@ -43,7 +43,7 @@ resource "aci_l3out_floating_svi" "example" { - `description` - (Optional) Description for L3out floating SVI object. - `autostate` - (Optional) Autostate for L3out floating SVI object. Allowed values are "disabled" and "enabled". Default value is "disabled". - `encap_scope` - (Optional) Encap scope for L3out floating SVI object. Allowed values are "ctx" and "local". Default value is "local". -- `if_inst_t` - (Optional) Interface type for L3out floating SVI object. Allowed values are "ext-svi", "l3-port", "sub-interface" and "unspecified". Default value is "unspecified". +- `if_inst_t` - (Optional) Interface type for L3out floating SVI object. Allowed values are "ext-svi", "l3-port", "sub-interface". - `ipv6_dad` - (Optional) IPv6 dad for L3out floating SVI object. Allowed values are "disabled" and "enabled". Default value is "enabled". - `ll_addr` - (Optional) Link local address for L3out floating SVI object. Default value: "::". - `mac` - (Optional) MAC address for L3out floating SVI object. diff --git a/website/docs/r/l3out_hsrp_interface_group.html.markdown b/website/docs/r/l3out_hsrp_interface_group.html.markdown index e58b93159..dc16b2a08 100644 --- a/website/docs/r/l3out_hsrp_interface_group.html.markdown +++ b/website/docs/r/l3out_hsrp_interface_group.html.markdown @@ -37,11 +37,11 @@ resource "aci_l3out_hsrp_interface_group" "example" { - `description` - (Optional) Description for L3out HSRP interface group object. - `config_issues` - (Optional) Configuration issues for L3out HSRP interface group object. Allowed values are "GroupMac-Conflicts-Other-Group", "GroupName-Conflicts-Other-Group", "GroupVIP-Conflicts-Other-Group", "Multiple-Version-On-Interface", "Secondary-vip-conflicts-if-ip", "Secondary-vip-subnet-mismatch", "group-vip-conflicts-if-ip", "group-vip-subnet-mismatch" and "none". Default value is "none". - `group_af` - (Optional) Group type for L3out HSRP interface group object. Allowed values are "ipv4" and "ipv6". Default value is "ipv4". -- `group_id` - (Optional) Group id for L3out HSRP interface group object. +- `group_id` - (Optional) Group id for L3out HSRP interface group object. Allowed range for HSRP v1 "0" - "255" and for HSRP v2 "0" - "4095". Default value is "0". - `group_name` - (Optional) Group name for L3out HSRP interface group object. - `ip` - (Optional) IP address for L3out HSRP interface group object. - `ip_obtain_mode` - (Optional) IP obtain mode for L3out HSRP interface group object. Allowed values are "admin", "auto" and "learn". Default value is "admin". -- `mac` - (Optional) MAC address for L3out HSRP interface group object. +- `mac` - (Optional) MAC address for L3out HSRP interface group object. Default value is "00:00:00:00:00:00". - `name_alias` - (Optional) Name alias for L3out HSRP interface group object. - `relation_hsrp_rs_group_pol` - (Optional) Relation to class hsrpGroupPol. Cardinality - N_TO_ONE. Type - String. diff --git a/website/docs/r/l3out_hsrp_secondary_vip.html.markdown b/website/docs/r/l3out_hsrp_secondary_vip.html.markdown index 70f957e65..cd65a6429 100644 --- a/website/docs/r/l3out_hsrp_secondary_vip.html.markdown +++ b/website/docs/r/l3out_hsrp_secondary_vip.html.markdown @@ -34,7 +34,6 @@ resource "aci_l3out_hsrp_secondary_vip" "example" { - `description` - (Optional) Description for object L3out HSRP Secondary VIP. - `config_issues` - (Optional) Configuration Issues. Allowed values: "GroupMac-Conflicts-Other-Group", "GroupName-Conflicts-Other-Group", "GroupVIP-Conflicts-Other-Group", "Multiple-Version-On-Interface", "Secondary-vip-conflicts-if-ip", "Secondary-vip-subnet-mismatch", "group-vip-conflicts-if-ip", "group-vip-subnet-mismatch", "none". Default value: "none". -- `ip` - (Optional) IP address. - `name_alias` - (Optional) Name alias for object L3out HSRP Secondary VIP. ## Attribute Reference diff --git a/website/docs/r/vrf.html.markdown b/website/docs/r/vrf.html.markdown index 53e99ea8c..602d63ccd 100644 --- a/website/docs/r/vrf.html.markdown +++ b/website/docs/r/vrf.html.markdown @@ -58,12 +58,18 @@ resource "aci_vrf" "foovrf" { - `relation_fv_rs_vrf_validation_pol` - (Optional) Relation to class l3extVrfValidationPol. Cardinality - N_TO_ONE. Type - String. - `relation_fv_rs_ctx_mcast_to` - (Optional) Relation to class vzFilter. Cardinality - N_TO_M. Type - [Set of String]. - `relation_fv_rs_ctx_to_eigrp_ctx_af_pol` - (Optional) Relation to class eigrpCtxAfPol. Cardinality - N_TO_M. Type - [Set of Map]. +- `relation_fv_rs_ctx_to_eigrp_ctx_af_pol.tn_eigrp_ctx_af_pol_name` - (Required) Dn of class eigrpCtxAfPol. +- `relation_fv_rs_ctx_to_eigrp_ctx_af_pol.af` - (Required) Address family. Allowed values are "ipv4-ucast" and "ipv6-ucast". - `relation_fv_rs_ctx_to_ospf_ctx_pol` - (Optional) Relation to class ospfCtxPol. Cardinality - N_TO_M. Type - [Set of Map]. +- `relation_fv_rs_ctx_to_ospf_ctx_pol.tn_ospf_ctx_pol_name` - (Required) Dn of class ospfCtxPol. +- `relation_fv_rs_ctx_to_ospf_ctx_pol.af` - (Required) Address family. Allowed values are "ipv4-ucast" and "ipv6-ucast". - `relation_fv_rs_ctx_to_ep_ret` - (Optional) Relation to class fvEpRetPol. Cardinality - N_TO_ONE. Type - String. - `relation_fv_rs_bgp_ctx_pol` - (Optional) Relation to class bgpCtxPol. Cardinality - N_TO_ONE. Type - String. - `relation_fv_rs_ctx_mon_pol` - (Optional) Relation to class monEPGPol. Cardinality - N_TO_ONE. Type - String. - `relation_fv_rs_ctx_to_ext_route_tag_pol` - (Optional) Relation to class l3extRouteTagPol. Cardinality - N_TO_ONE. Type - String. - `relation_fv_rs_ctx_to_bgp_ctx_af_pol` - (Optional) Relation to class bgpCtxAfPol. Cardinality - N_TO_M. Type - [Set of Map]. +- `relation_fv_rs_ctx_to_bgp_ctx_af_pol.tn_bgp_ctx_af_pol_name` - (Required) Dn of class bgpCtxAfPol. +- `relation_fv_rs_ctx_to_bgp_ctx_af_pol.af` - (Required) Address family. Allowed values are "ipv4-ucast" and "ipv6-ucast". Note: In the APIC GUI,a VRF (fvCtx) was called a "Context"or "PrivateNetwork."