Skip to content

Commit

Permalink
Fix Keyvault network ACL with multiple subnet ids (#2324)
Browse files Browse the repository at this point in the history
* Added a failing test

* Fixed tests

* Add vnet to lock list only if it it's not already there

* Removed golang modules files

* Fixed fmt in key_vault test
  • Loading branch information
leonfs authored and tombuildsstuff committed Nov 19, 2018
1 parent 9918cfa commit 5e178d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
10 changes: 7 additions & 3 deletions azurerm/resource_arm_key_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ func resourceArmKeyVaultCreateUpdate(d *schema.ResourceData, meta interface{}) e
}

virtualNetworkName := id.Path["virtualNetworks"]
virtualNetworkNames = append(virtualNetworkNames, virtualNetworkName)
if !sliceContainsValue(virtualNetworkNames, virtualNetworkName) {
virtualNetworkNames = append(virtualNetworkNames, virtualNetworkName)
}
}

azureRMLockMultipleByName(&virtualNetworkNames, virtualNetworkResourceName)
Expand Down Expand Up @@ -350,8 +352,10 @@ func resourceArmKeyVaultDelete(d *schema.ResourceData, meta interface{}) error {
return err2
}

networkName := id.Path["virtualNetworks"]
virtualNetworkNames = append(virtualNetworkNames, networkName)
virtualNetworkName := id.Path["virtualNetworks"]
if !sliceContainsValue(virtualNetworkNames, virtualNetworkName) {
virtualNetworkNames = append(virtualNetworkNames, virtualNetworkName)
}
}
}
}
Expand Down
22 changes: 15 additions & 7 deletions azurerm/resource_arm_key_vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestAccAzureRMKeyVault_networkAcls(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "network_acls.0.bypass", "None"),
resource.TestCheckResourceAttr(resourceName, "network_acls.0.default_action", "Deny"),
resource.TestCheckResourceAttr(resourceName, "network_acls.0.ip_rules.#", "0"),
resource.TestCheckResourceAttr(resourceName, "network_acls.0.virtual_network_subnet_ids.#", "1"),
resource.TestCheckResourceAttr(resourceName, "network_acls.0.virtual_network_subnet_ids.#", "2"),
),
},
{
Expand Down Expand Up @@ -351,14 +351,22 @@ resource "azurerm_virtual_network" "test" {
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_subnet" "test" {
name = "acctestsubnet%d"
resource "azurerm_subnet" "test_a" {
name = "acctestsubneta%d"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.2.0/24"
service_endpoints = ["Microsoft.KeyVault"]
service_endpoints = ["Microsoft.KeyVault",]
}
resource "azurerm_subnet" "test_b" {
name = "acctestsubnetb%d"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.4.0/24"
service_endpoints = ["Microsoft.KeyVault",]
}
`, rInt, location, rInt, rInt)
`, rInt, location, rInt, rInt, rInt)
}

func testAccAzureRMKeyVault_networkAcls(rInt int, location string) string {
Expand Down Expand Up @@ -392,7 +400,7 @@ resource "azurerm_key_vault" "test" {
network_acls {
default_action = "Deny"
bypass = "None"
virtual_network_subnet_ids = ["${azurerm_subnet.test.id}"]
virtual_network_subnet_ids = ["${azurerm_subnet.test_a.id}", "${azurerm_subnet.test_b.id}"]
}
}
`, template, rInt)
Expand Down Expand Up @@ -430,7 +438,7 @@ resource "azurerm_key_vault" "test" {
default_action = "Allow"
bypass = "AzureServices"
ip_rules = ["10.0.0.102/32"]
virtual_network_subnet_ids = ["${azurerm_subnet.test.id}"]
virtual_network_subnet_ids = ["${azurerm_subnet.test_a.id}"]
}
}
`, template, rInt)
Expand Down

0 comments on commit 5e178d7

Please sign in to comment.