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

azurerm_private_dns_zone_virtual_network_link - explicit test for cross-tenant usage #23420

Merged
merged 4 commits into from
Nov 24, 2023
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
2 changes: 1 addition & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureContextFunc {
}

if len(auxTenants) > 3 {
return nil, diag.Errorf("the provider only supports 3 auxiliary tenant IDs")
return nil, diag.Errorf("the provider only supports up to 3 auxiliary tenant IDs")
}

var clientCertificateData []byte
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package privatedns_test
import (
"context"
"fmt"
"os"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/privatedns/2020-06-01/virtualnetworklinks"
Expand Down Expand Up @@ -46,6 +47,28 @@ func TestAccPrivateDnsZoneVirtualNetworkLink_complete(t *testing.T) {
})
}

func TestAccPrivateDnsZoneVirtualNetworkLink_crossTenant(t *testing.T) {
// Multiple tenants are needed for this test
altTenantId := os.Getenv("ARM_TENANT_ID_ALT")
subscriptionIdAltTenant := os.Getenv("ARM_SUBSCRIPTION_ID_ALT_TENANT")

if altTenantId == "" || subscriptionIdAltTenant == "" {
t.Skip("One of ARM_TENANT_ID_ALT, ARM_SUBSCRIPTION_ID_ALT_TENANT are not specified")
}

data := acceptance.BuildTestData(t, "azurerm_private_dns_zone_virtual_network_link", "test")
r := PrivateDnsZoneVirtualNetworkLinkResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.crossTenant(data, altTenantId, subscriptionIdAltTenant),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccPrivateDnsZoneVirtualNetworkLink_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_private_dns_zone_virtual_network_link", "test")
r := PrivateDnsZoneVirtualNetworkLinkResource{}
Expand Down Expand Up @@ -171,6 +194,61 @@ resource "azurerm_private_dns_zone_virtual_network_link" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (PrivateDnsZoneVirtualNetworkLinkResource) crossTenant(data acceptance.TestData, altTenantId, subscriptionIdAltTenant string) string {
return fmt.Sprintf(`
provider "azurerm" {
auxiliary_tenant_ids = ["%[1]s"]

features {}
}

provider "azurerm-alt" {
tenant_id = "%[1]s"
subscription_id = "%[2]s"

features {}
}

resource "azurerm_resource_group" "test_alt" {
provider = azurerm-alt

name = "acctestRG-%[3]d"
location = "%[4]s"
}

resource "azurerm_virtual_network" "test_alt" {
provider = azurerm-alt

name = "vnet%[3]d"
location = azurerm_resource_group.test_alt.location
resource_group_name = azurerm_resource_group.test_alt.name
address_space = ["10.0.0.0/16"]

subnet {
name = "subnet1"
address_prefix = "10.0.1.0/24"
}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%[3]d"
location = "%[4]s"
}

resource "azurerm_private_dns_zone" "test" {
name = "acctestzone%[3]d.com"
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_private_dns_zone_virtual_network_link" "test" {
name = "acctestVnetZone%[3]d.com"
resource_group_name = azurerm_resource_group.test.name
private_dns_zone_name = azurerm_private_dns_zone.test.name
virtual_network_id = azurerm_virtual_network.test_alt.id
}
`, altTenantId, subscriptionIdAltTenant, data.RandomInteger, data.Locations.Primary)
}

func (r PrivateDnsZoneVirtualNetworkLinkResource) requiresImport(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down
Loading