|
7 | 7 |
|
8 | 8 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" |
9 | 9 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
10 | | - "github.com/hashicorp/terraform-plugin-testing/terraform" |
11 | 10 | ) |
12 | 11 |
|
13 | 12 | func TestAccAciRestManaged_tenant(t *testing.T) { |
@@ -981,67 +980,34 @@ func TestAccAciRestManaged_onDestroyCreate(t *testing.T) { |
981 | 980 | } |
982 | 981 |
|
983 | 982 | func TestAccAciRestManaged_onDestroyImport(t *testing.T) { |
984 | | - |
985 | 983 | resource.Test(t, resource.TestCase{ |
986 | 984 | PreCheck: func() { testAccPreCheck(t, "both", "5.2(1g)-") }, |
987 | 985 | ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, |
988 | 986 | Steps: []resource.TestStep{ |
989 | 987 | { |
990 | | - Config: testAccAciRestManagedConfig_onDestroyMinimal(), |
991 | | - ImportState: true, |
992 | | - ImportStateId: fmt.Sprintf("uni/tn-%s:ap-web,ctx-vrf1", onDestroyTestName), |
993 | | - ResourceName: "aci_rest_managed.tenant_with_destroy", |
994 | | - ImportStateCheck: func(states []*terraform.InstanceState) error { |
995 | | - if len(states) != 1 { |
996 | | - return fmt.Errorf("expected 1 resource state, got %d", len(states)) |
997 | | - } |
998 | | - |
999 | | - state := states[0] |
1000 | | - |
1001 | | - // Validate parent |
1002 | | - if state.Attributes["dn"] != "uni/tn-"+onDestroyTestName { |
1003 | | - return fmt.Errorf("dn mismatch") |
1004 | | - } |
1005 | | - |
1006 | | - if state.Attributes["class_name"] != "fvTenant" { |
1007 | | - return fmt.Errorf("class_name mismatch") |
1008 | | - } |
1009 | | - |
1010 | | - if state.Attributes["content.descr"] != "Decommissioned Tenant" { |
1011 | | - return fmt.Errorf("content.descr mismatch: expected 'Decommissioned Tenant', got '%s'", state.Attributes["content.descr"]) |
1012 | | - } |
1013 | | - |
1014 | | - // Check children count |
1015 | | - childCount := 2 |
1016 | | - if state.Attributes["child.#"] != "2" { |
1017 | | - return fmt.Errorf("expected 2 children, got %s", state.Attributes["child.#"]) |
1018 | | - } |
1019 | | - |
1020 | | - // Validate each child using helper |
1021 | | - if err := findAndValidateChildForRestManaged(state, childCount, "ap-web", "fvAp", map[string]string{ |
1022 | | - "name": "web", |
1023 | | - "descr": "Archived Web App", |
1024 | | - }); err != nil { |
1025 | | - return err |
1026 | | - } |
1027 | | - |
1028 | | - if err := findAndValidateChildForRestManaged(state, childCount, "ctx-vrf1", "fvCtx", map[string]string{ |
1029 | | - "name": "vrf1", |
1030 | | - "descr": "Archived VRF", |
1031 | | - }); err != nil { |
1032 | | - return err |
1033 | | - } |
1034 | | - |
1035 | | - return nil |
1036 | | - }, |
| 988 | + Config: testAccDataSourceAciRestManagedConfig_onDestroy(), |
| 989 | + Check: resource.ComposeTestCheckFunc( |
| 990 | + resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "class_name", "fvTenant"), |
| 991 | + resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "id", "uni/tn-"+onDestroyTestName), |
| 992 | + resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "dn", "uni/tn-"+onDestroyTestName), |
| 993 | + resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "content.name", onDestroyTestName), |
| 994 | + resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "content.descr", "Decommissioned Tenant"), |
| 995 | + resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "child.0.class_name", "fvAp"), |
| 996 | + resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "child.0.rn", "ap-web"), |
| 997 | + resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "child.0.content.name", "web"), |
| 998 | + resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "child.0.content.descr", "Archived Web App"), |
| 999 | + resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "child.1.class_name", "fvCtx"), |
| 1000 | + resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "child.1.rn", "ctx-vrf1"), |
| 1001 | + resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "child.1.content.name", "vrf1"), |
| 1002 | + resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "child.1.content.descr", "Archived VRF"), |
| 1003 | + ), |
1037 | 1004 | }, |
1038 | 1005 | { |
1039 | 1006 | Config: testAccAciRestManagedConfig_onDestroyMinimal(), |
1040 | 1007 | ImportState: true, |
1041 | 1008 | ImportStateId: fmt.Sprintf("uni/tn-%s:ap-database", onDestroyTestName), |
1042 | 1009 | ResourceName: "aci_rest_managed.tenant_with_destroy", |
1043 | 1010 | ExpectError: regexp.MustCompile("Unable to find specified child 'ap-database'"), |
1044 | | - Destroy: true, |
1045 | 1011 | }, |
1046 | 1012 | }, |
1047 | 1013 | }) |
@@ -1670,6 +1636,14 @@ func testAccAciRestManagedConfig_onDestroy() string { |
1670 | 1636 | `, onDestroyTestName) |
1671 | 1637 | } |
1672 | 1638 |
|
| 1639 | +func testAccDataSourceAciRestManagedConfig_onDestroy() string { |
| 1640 | + return fmt.Sprintf(` |
| 1641 | + data "aci_rest_managed" "tenant_with_destroy" { |
| 1642 | + dn = "uni/tn-%[1]s" |
| 1643 | + } |
| 1644 | + `, onDestroyTestName) |
| 1645 | +} |
| 1646 | + |
1673 | 1647 | func testAccAciRestManagedConfig_onDestroyMinimal() string { |
1674 | 1648 | return fmt.Sprintf(` |
1675 | 1649 | resource "aci_rest_managed" "tenant_with_destroy" { |
|
0 commit comments