Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multitenancy tests to pass with tenant user #1098

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions nsxt/data_source_nsxt_policy_segment_realization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
27 changes: 21 additions & 6 deletions nsxt/resource_nsxt_policy_dhcp_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package nsxt

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand Down Expand Up @@ -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"]

Expand All @@ -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"]

Expand All @@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions nsxt/resource_nsxt_policy_dhcp_v4_static_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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" {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion nsxt/resource_nsxt_policy_dns_forwarder_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestAccResourceNsxtPolicyDNSForwarderZone_importBasic_multitenancy(t *testi
},
Steps: []resource.TestStep{
{
Config: testAccNsxtPolicyDNSForwarderZoneMinimalistic(false),
Config: testAccNsxtPolicyDNSForwarderZoneMinimalistic(true),
},
{
ResourceName: testResourceName,
Expand Down
5 changes: 4 additions & 1 deletion nsxt/resource_nsxt_policy_fixed_segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion nsxt/resource_nsxt_policy_ip_pool_block_subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestAccResourceNsxtPolicyIPPoolBlockSubnet_importBasic_multitenancy(t *test
ImportStateIdFunc: testAccResourceNsxtPolicyImportIDRetriever(testResourceName),
},
{
Config: testAccNSXPolicyIPPoolBlockSubnetIPBlockTemplate(false),
Config: testAccNSXPolicyIPPoolBlockSubnetIPBlockTemplate(true),
},
},
})
Expand Down
10 changes: 7 additions & 3 deletions nsxt/resource_nsxt_policy_tier0_gateway_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 8 additions & 2 deletions nsxt/resource_nsxt_policy_tier1_gateway_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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" {
Expand All @@ -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()
}

Expand Down
20 changes: 14 additions & 6 deletions nsxt/resource_nsxt_policy_vlan_segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand All @@ -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"]

Expand All @@ -394,7 +402,7 @@ resource "nsxt_policy_vlan_segment" "test" {
tag = "orange"
}
}
`, context, name)
`, context, name, tzSpec)
}

func testAccNsxtPolicyVlanSegmentBasicAdvConfigTemplate(name string) string {
Expand Down
Loading