diff --git a/nsxt/data_source_nsxt_policy_segment_realization_test.go b/nsxt/data_source_nsxt_policy_segment_realization_test.go index ef0a4ae9f..a368eac96 100644 --- a/nsxt/data_source_nsxt_policy_segment_realization_test.go +++ b/nsxt/data_source_nsxt_policy_segment_realization_test.go @@ -66,14 +66,17 @@ func testAccNsxtPolicySegmentRealizationTemplate(vlan, withContext bool) string extra = "vlan_ids = [12]" } tzSpec := "" + tzDatasource := "" if !withContext { tzSpec = "transport_zone_path = data.nsxt_policy_transport_zone.test.path" - } - return fmt.Sprintf(` + tzDatasource = fmt.Sprintf(` data "nsxt_policy_transport_zone" "test" { display_name = "%s" } - +`, tz) + } + return fmt.Sprintf(` +%s resource "%s" "test" { %s display_name = "terra-test" @@ -84,5 +87,5 @@ resource "%s" "test" { data "nsxt_policy_segment_realization" "test" { %s path = %s.test.path -}`, tz, resource, context, tzSpec, extra, context, resource) +}`, tzDatasource, resource, context, tzSpec, extra, context, resource) } diff --git a/nsxt/resource_nsxt_policy_dhcp_server_test.go b/nsxt/resource_nsxt_policy_dhcp_server_test.go index db2a64179..734a5b89e 100644 --- a/nsxt/resource_nsxt_policy_dhcp_server_test.go +++ b/nsxt/resource_nsxt_policy_dhcp_server_test.go @@ -5,6 +5,7 @@ package nsxt import ( "fmt" + "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -196,17 +197,20 @@ func testAccNsxtPolicyDhcpServerCheckDestroy(state *terraform.State, displayName func testAccNsxtPolicyDhcpServerCreateTemplate(withContext bool) string { attrMap := accTestPolicyDhcpServerCreateAttributes context := "" + defsSpec := testAccNsxtPolicyGatewayFabricDeps(false) + edgeClusterSpec := "data.nsxt_policy_edge_cluster.EC.path" if withContext { context = testAccNsxtPolicyMultitenancyContext() + defsSpec, edgeClusterSpec = testAccNsxtPolicyProjectSpec() } - return testAccNsxtPolicyGatewayFabricDeps(false) + fmt.Sprintf(` + return defsSpec + fmt.Sprintf(` resource "nsxt_policy_dhcp_server" "test" { %s display_name = "%s" description = "%s" - edge_cluster_path = data.nsxt_policy_edge_cluster.EC.path + edge_cluster_path = %s lease_time = %s server_addresses = ["110.64.0.1/16"] @@ -215,22 +219,33 @@ resource "nsxt_policy_dhcp_server" "test" { tag = "tag1" } } -`, context, attrMap["display_name"], attrMap["description"], attrMap["lease_time"]) +`, context, attrMap["display_name"], attrMap["description"], edgeClusterSpec, attrMap["lease_time"]) +} + +func testAccNsxtPolicyProjectSpec() (string, string) { + return fmt.Sprintf(` +data "nsxt_policy_project" "test" { + id = "%s" +} +`, os.Getenv("NSXT_PROJECT_ID")), "data.nsxt_policy_project.test.site_info.0.edge_cluster_paths.0" } func testAccNsxtPolicyDhcpServerUpdateTemplate(withContext bool) string { attrMap := accTestPolicyDhcpServerUpdateAttributes + defsSpec := testAccNsxtPolicyGatewayFabricDeps(false) + edgeClusterSpec := "data.nsxt_policy_edge_cluster.EC.path" context := "" if withContext { context = testAccNsxtPolicyMultitenancyContext() + defsSpec, edgeClusterSpec = testAccNsxtPolicyProjectSpec() } - return testAccNsxtPolicyGatewayFabricDeps(false) + fmt.Sprintf(` + return defsSpec + fmt.Sprintf(` resource "nsxt_policy_dhcp_server" "test" { %s display_name = "%s" description = "%s" - edge_cluster_path = data.nsxt_policy_edge_cluster.EC.path + edge_cluster_path = %s lease_time = %s server_addresses = ["2001::1234:abcd:ffff:c0a8:101/64", "110.64.0.1/16"] @@ -239,7 +254,7 @@ resource "nsxt_policy_dhcp_server" "test" { tag = "tag1" } } -`, context, attrMap["display_name"], attrMap["description"], attrMap["lease_time"]) +`, context, attrMap["display_name"], attrMap["description"], edgeClusterSpec, attrMap["lease_time"]) } func testAccNsxtPolicyDhcpServerMinimalistic(withContext bool) string { diff --git a/nsxt/resource_nsxt_policy_dhcp_v4_static_binding_test.go b/nsxt/resource_nsxt_policy_dhcp_v4_static_binding_test.go index 28162945e..4dc4527d6 100644 --- a/nsxt/resource_nsxt_policy_dhcp_v4_static_binding_test.go +++ b/nsxt/resource_nsxt_policy_dhcp_v4_static_binding_test.go @@ -265,11 +265,14 @@ func testAccNsxtPolicyDhcpStaticBindingPrerequisites(isFixed, isIpv6, withContex } context := "" tzSpec := "transport_zone_path = data.nsxt_policy_transport_zone.test.path" + defsSpec := testAccNsxtPolicyGatewayFabricDeps(false) + edgeClusterSpec := "data.nsxt_policy_edge_cluster.EC.path" if withContext { context = testAccNsxtPolicyMultitenancyContext() tzSpec = "" + defsSpec, edgeClusterSpec = testAccNsxtPolicyProjectSpec() } - return testAccNsxtPolicyGatewayFabricDeps(false) + fmt.Sprintf(` + return defsSpec + fmt.Sprintf(` resource "nsxt_policy_tier1_gateway" "test" { %s display_name = "%s" @@ -278,7 +281,7 @@ resource "nsxt_policy_tier1_gateway" "test" { resource "nsxt_policy_dhcp_server" "test" { %s display_name = "%s" - edge_cluster_path = data.nsxt_policy_edge_cluster.EC.path + edge_cluster_path = %s } resource "%s" "test" { @@ -293,7 +296,7 @@ resource "%s" "test" { server_address = "%s" } } -}`, context, helperName, context, helperName, segmentResource, context, helperName, tzSpec, cidr, version, address) +}`, context, helperName, context, helperName, edgeClusterSpec, segmentResource, context, helperName, tzSpec, cidr, version, address) } func testAccNsxtPolicyGetSegmentResourceName(isFixed bool) string { diff --git a/nsxt/resource_nsxt_policy_dns_forwarder_zone_test.go b/nsxt/resource_nsxt_policy_dns_forwarder_zone_test.go index 397bc39eb..ef139d524 100644 --- a/nsxt/resource_nsxt_policy_dns_forwarder_zone_test.go +++ b/nsxt/resource_nsxt_policy_dns_forwarder_zone_test.go @@ -138,7 +138,7 @@ func TestAccResourceNsxtPolicyDNSForwarderZone_importBasic_multitenancy(t *testi }, Steps: []resource.TestStep{ { - Config: testAccNsxtPolicyDNSForwarderZoneMinimalistic(false), + Config: testAccNsxtPolicyDNSForwarderZoneMinimalistic(true), }, { ResourceName: testResourceName, diff --git a/nsxt/resource_nsxt_policy_fixed_segment_test.go b/nsxt/resource_nsxt_policy_fixed_segment_test.go index 051735548..dd0568997 100644 --- a/nsxt/resource_nsxt_policy_fixed_segment_test.go +++ b/nsxt/resource_nsxt_policy_fixed_segment_test.go @@ -74,7 +74,10 @@ func testAccResourceNsxtPolicyFixedSegmentBasicUpdate(t *testing.T, withContext name := getAccTestResourceName() updatedName := getAccTestResourceName() testResourceName := testAccPolicyFixedSegmentResourceName - tzName := getOverlayTransportZoneName() + tzName := "" + if !withContext { + tzName = getOverlayTransportZoneName() + } resource.ParallelTest(t, resource.TestCase{ PreCheck: preCheck, diff --git a/nsxt/resource_nsxt_policy_ip_pool_block_subnet_test.go b/nsxt/resource_nsxt_policy_ip_pool_block_subnet_test.go index e832b258a..4a22ce152 100644 --- a/nsxt/resource_nsxt_policy_ip_pool_block_subnet_test.go +++ b/nsxt/resource_nsxt_policy_ip_pool_block_subnet_test.go @@ -164,7 +164,7 @@ func TestAccResourceNsxtPolicyIPPoolBlockSubnet_importBasic_multitenancy(t *test ImportStateIdFunc: testAccResourceNsxtPolicyImportIDRetriever(testResourceName), }, { - Config: testAccNSXPolicyIPPoolBlockSubnetIPBlockTemplate(false), + Config: testAccNSXPolicyIPPoolBlockSubnetIPBlockTemplate(true), }, }, }) diff --git a/nsxt/resource_nsxt_policy_tier0_gateway_interface_test.go b/nsxt/resource_nsxt_policy_tier0_gateway_interface_test.go index ec2b7ec1d..b44320124 100644 --- a/nsxt/resource_nsxt_policy_tier0_gateway_interface_test.go +++ b/nsxt/resource_nsxt_policy_tier0_gateway_interface_test.go @@ -613,19 +613,23 @@ data "nsxt_policy_transport_zone" "test" { func testAccNsxtPolicyGatewayInterfaceDeps(vlans string, withContext bool) string { context := "" + tzSpec := "transport_zone_path = data.nsxt_policy_transport_zone.test.path" + defsSpec := testAccNsxtPolicyGatewayFabricDeps(true) if withContext { context = testAccNsxtPolicyMultitenancyContext() + tzSpec = "" + defsSpec, _ = testAccNsxtPolicyProjectSpec() } - return testAccNsxtPolicyGatewayFabricDeps(true) + fmt.Sprintf(` + return defsSpec + fmt.Sprintf(` resource "nsxt_policy_vlan_segment" "test" { %s - transport_zone_path = data.nsxt_policy_transport_zone.test.path + %s display_name = "interface_test" vlan_ids = [%s] subnet { cidr = "10.2.2.2/24" } -}`, context, vlans) +}`, context, tzSpec, vlans) } func testAccNsxtPolicyTier0EdgeClusterTemplate() string { diff --git a/nsxt/resource_nsxt_policy_tier1_gateway_interface_test.go b/nsxt/resource_nsxt_policy_tier1_gateway_interface_test.go index cfad4e518..7eaed2161 100644 --- a/nsxt/resource_nsxt_policy_tier1_gateway_interface_test.go +++ b/nsxt/resource_nsxt_policy_tier1_gateway_interface_test.go @@ -413,8 +413,11 @@ func testAccNsxtPolicyTier1InterfaceCheckDestroy(state *terraform.State, display func testAccNsxtPolicyTier1InterfaceTemplate(name string, subnet string, mtu string, withContext bool) string { context := "" + ecTemplate := testAccNsxtPolicyTier0EdgeClusterTemplate() if withContext { context = testAccNsxtPolicyMultitenancyContext() + _, ecSpec := testAccNsxtPolicyProjectSpec() + ecTemplate = fmt.Sprintf("edge_cluster_path = %s", ecSpec) } return testAccNsxtPolicyGatewayInterfaceDeps("11", withContext) + fmt.Sprintf(` resource "nsxt_policy_tier1_gateway" "test" { @@ -437,14 +440,17 @@ resource "nsxt_policy_tier1_gateway_interface" "test" { scope = "scope1" tag = "tag1" } -}`, context, nsxtPolicyTier1GatewayName, testAccNsxtPolicyTier0EdgeClusterTemplate(), context, name, mtu, subnet, testAccNsxtPolicyTier0InterfaceSiteTemplate()) + +}`, context, nsxtPolicyTier1GatewayName, ecTemplate, context, name, mtu, subnet, testAccNsxtPolicyTier0InterfaceSiteTemplate()) + testAccNextPolicyTier1InterfaceRealizationTemplate() } func testAccNsxtPolicyTier1InterfaceThinTemplate(name string, subnet string, withContext bool) string { context := "" + ecTemplate := testAccNsxtPolicyTier0EdgeClusterTemplate() if withContext { context = testAccNsxtPolicyMultitenancyContext() + _, ecSpec := testAccNsxtPolicyProjectSpec() + ecTemplate = fmt.Sprintf("edge_cluster_path = %s", ecSpec) } return testAccNsxtPolicyGatewayInterfaceDeps("11", withContext) + fmt.Sprintf(` resource "nsxt_policy_tier1_gateway" "test" { @@ -460,7 +466,7 @@ resource "nsxt_policy_tier1_gateway_interface" "test" { segment_path = nsxt_policy_vlan_segment.test.path subnets = ["%s"] %s -}`, context, nsxtPolicyTier1GatewayName, testAccNsxtPolicyTier0EdgeClusterTemplate(), context, name, subnet, testAccNsxtPolicyTier0InterfaceSiteTemplate()) + +}`, context, nsxtPolicyTier1GatewayName, ecTemplate, context, name, subnet, testAccNsxtPolicyTier0InterfaceSiteTemplate()) + testAccNextPolicyTier1InterfaceRealizationTemplate() } diff --git a/nsxt/resource_nsxt_policy_vlan_segment_test.go b/nsxt/resource_nsxt_policy_vlan_segment_test.go index c618bc7f8..bd8c67b11 100644 --- a/nsxt/resource_nsxt_policy_vlan_segment_test.go +++ b/nsxt/resource_nsxt_policy_vlan_segment_test.go @@ -349,16 +349,20 @@ resource "nsxt_policy_vlan_segment" "test" { func testAccNsxtPolicyVlanSegmentBasicTemplate(name string, withContext bool) string { context := "" + deps := testAccNsxtPolicyVlanSegmentDeps() + tzSpec := "transport_zone_path = data.nsxt_policy_transport_zone.test.path" if withContext { context = testAccNsxtPolicyMultitenancyContext() + deps = "" + tzSpec = "" } - return testAccNsxtPolicyVlanSegmentDeps() + fmt.Sprintf(` + return deps + fmt.Sprintf(` resource "nsxt_policy_vlan_segment" "test" { %s display_name = "%s" description = "Acceptance Test" - transport_zone_path = data.nsxt_policy_transport_zone.test.path + %s domain_name = "tftest.org" vlan_ids = ["101"] @@ -367,21 +371,25 @@ resource "nsxt_policy_vlan_segment" "test" { tag = "orange" } } -`, context, name) +`, context, name, tzSpec) } func testAccNsxtPolicyVlanSegmentBasicUpdateTemplate(name string, withContext bool) string { context := "" + deps := testAccNsxtPolicyVlanSegmentDeps() + tzSpec := "transport_zone_path = data.nsxt_policy_transport_zone.test.path" if withContext { context = testAccNsxtPolicyMultitenancyContext() + deps = "" + tzSpec = "" } - return testAccNsxtPolicyVlanSegmentDeps() + fmt.Sprintf(` + return deps + fmt.Sprintf(` resource "nsxt_policy_vlan_segment" "test" { %s display_name = "%s" description = "Acceptance Test2" - transport_zone_path = data.nsxt_policy_transport_zone.test.path + %s domain_name = "tftest2.org" vlan_ids = ["101", "104-110"] @@ -394,7 +402,7 @@ resource "nsxt_policy_vlan_segment" "test" { tag = "orange" } } -`, context, name) +`, context, name, tzSpec) } func testAccNsxtPolicyVlanSegmentBasicAdvConfigTemplate(name string) string {