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

AccTest: storage account (network rules) modify the test for private_link property #23383

Merged
merged 4 commits into from
Oct 31, 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
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ func TestAccStorageAccountNetworkRules_privateLinkAccess(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_account_network_rules", "test")
r := StorageAccountNetworkRulesResource{}

// Not all regions support setting the private endpoint resource as the endpoint resource in network_rules.private_link_access in the storage account
data.Locations.Primary = "westeurope"

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.disablePrivateLinkAccess(data),
Expand Down Expand Up @@ -426,13 +423,20 @@ resource "azurerm_storage_account_network_rules" "test" {
ip_rules = []
virtual_network_subnet_ids = []
}
`, StorageAccountResource{}.networkRulesPrivateEndpointTemplate(data), data.RandomString)
`, StorageAccountResource{}.networkRulesTemplate(data), data.RandomString)
}

func (r StorageAccountNetworkRulesResource) privateLinkAccess(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_search_service" "test" {
name = "acctestsearchservice%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
sku = "basic"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sanity checking: does the standard sku of search support private link? else this'd break in the future

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tombuildsstuff Yes, I've tried the standard sku, which works fine. I believe the sku doesn't matter as otherwise it should be mentioned in https://learn.microsoft.com/en-us/azure/storage/common/storage-network-security?tabs=azure-portal#trusted-access-based-on-a-managed-identity?

}

resource "azurerm_storage_account" "test" {
name = "unlikely23exst2acct%s"
resource_group_name = azurerm_resource_group.test.name
Expand All @@ -446,19 +450,15 @@ resource "azurerm_storage_account" "test" {
}

resource "azurerm_storage_account_network_rules" "test" {
storage_account_id = azurerm_storage_account.test.id

storage_account_id = azurerm_storage_account.test.id
default_action = "Deny"
ip_rules = ["127.0.0.1"]
virtual_network_subnet_ids = [azurerm_subnet.test.id]
private_link_access {
endpoint_resource_id = azurerm_private_endpoint.blob.id
}
private_link_access {
endpoint_resource_id = azurerm_private_endpoint.table.id
endpoint_resource_id = azurerm_search_service.test.id
}
}
`, StorageAccountResource{}.networkRulesPrivateEndpointTemplate(data), data.RandomString)
`, StorageAccountResource{}.networkRulesTemplate(data), data.RandomInteger, data.RandomString)
}

func (r StorageAccountNetworkRulesResource) synapseAccess(data acceptance.TestData) string {
Expand Down Expand Up @@ -514,7 +514,7 @@ resource "azurerm_storage_account_network_rules" "test" {
endpoint_resource_id = azurerm_synapse_workspace.test.id
}
}
`, StorageAccountResource{}.networkRulesPrivateEndpointTemplate(data), data.RandomString, data.RandomInteger)
`, StorageAccountResource{}.networkRulesTemplate(data), data.RandomString, data.RandomInteger)
}

func (r StorageAccountNetworkRulesResource) deploy(data acceptance.TestData) string {
Expand Down
95 changes: 9 additions & 86 deletions internal/services/storage/storage_account_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,6 @@ func TestAccStorageAccount_privateLinkAccess(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_account", "test")
r := StorageAccountResource{}

// Not all regions support setting the private endpoint resource as the endpoint resource in network_rules.private_link_access in the storage account
data.Locations.Primary = "westeurope"

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.networkRules(data),
Expand Down Expand Up @@ -2273,84 +2270,6 @@ resource "azurerm_subnet" "test" {
`, data.RandomInteger, data.Locations.Primary)
}

func (r StorageAccountResource) networkRulesPrivateEndpointTemplate(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s

resource "azurerm_subnet" "blob_endpoint" {
name = "acctestsnetblobendpoint-%[2]d"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefixes = ["10.0.5.0/24"]

enforce_private_link_endpoint_network_policies = true
}

resource "azurerm_subnet" "table_endpoint" {
name = "acctestsnettableendpoint-%[2]d"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefixes = ["10.0.6.0/24"]

enforce_private_link_endpoint_network_policies = true
}

resource "azurerm_storage_account" "blob_connection" {
name = "accblobconnacct%[3]s"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
account_tier = "Standard"
account_replication_type = "LRS"
}

resource "azurerm_storage_account" "table_connection" {
name = "acctableconnacct%[3]s"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
account_tier = "Standard"
account_replication_type = "LRS"
}

resource "azurerm_private_dns_zone" "blob" {
name = "privatelink.blob.core.windows.net"
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_private_dns_zone" "table" {
name = "privatelink.table.core.windows.net"
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_private_endpoint" "blob" {
name = "acctest-privatelink-blob-%[2]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
subnet_id = azurerm_subnet.blob_endpoint.id

private_service_connection {
name = "acctest-privatelink-mssc-%[2]d"
private_connection_resource_id = azurerm_storage_account.blob_connection.id
subresource_names = ["blob"]
is_manual_connection = false
}
}

resource "azurerm_private_endpoint" "table" {
name = "acctest-privatelink-table-%[2]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
subnet_id = azurerm_subnet.table_endpoint.id

private_service_connection {
name = "acctest-privatelink-mssc-%[2]d"
private_connection_resource_id = azurerm_storage_account.table_connection.id
subresource_names = ["table"]
is_manual_connection = false
}
}
`, r.networkRulesTemplate(data), data.RandomInteger, data.RandomString)
}

func (r StorageAccountResource) networkRules(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down Expand Up @@ -2427,6 +2346,13 @@ func (r StorageAccountResource) networkRulesPrivateLinkAccess(data acceptance.Te
return fmt.Sprintf(`
%s

resource "azurerm_search_service" "test" {
name = "acctestsearchservice%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
sku = "basic"
}

resource "azurerm_storage_account" "test" {
name = "unlikely23exst2acct%s"
resource_group_name = azurerm_resource_group.test.name
Expand All @@ -2439,18 +2365,15 @@ resource "azurerm_storage_account" "test" {
ip_rules = ["127.0.0.1"]
virtual_network_subnet_ids = [azurerm_subnet.test.id]
private_link_access {
endpoint_resource_id = azurerm_private_endpoint.blob.id
}
private_link_access {
endpoint_resource_id = azurerm_private_endpoint.table.id
endpoint_resource_id = azurerm_search_service.test.id
}
}

tags = {
environment = "production"
}
}
`, r.networkRulesPrivateEndpointTemplate(data), data.RandomString)
`, r.networkRulesTemplate(data), data.RandomInteger, data.RandomString)
}

func (r StorageAccountResource) networkRulesSynapseAccess(data acceptance.TestData) string {
Expand Down
Loading