Skip to content

Commit

Permalink
make ip_rules, virtual_network_subnet_ids could become zero - `az…
Browse files Browse the repository at this point in the history
…urerm_storage_account_network_rules` (#7385)

fix #7357

"getOk" will ignore the zero value, and the rules will always contain last value
we could directly get the vaules and pass them
  • Loading branch information
njuCZ authored Jun 23, 2020
1 parent fde4418 commit a21bd9d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
Expand Down Expand Up @@ -116,7 +115,7 @@ func resourceArmStorageAccountNetworkRulesCreateUpdate(d *schema.ResourceData, m
return fmt.Errorf("Error retrieving Storage Account %q (Resource Group %q): %+v", storageAccountName, resourceGroup, err)
}

if features.ShouldResourcesBeImported() && d.IsNewResource() {
if d.IsNewResource() {
if storageAccount.AccountProperties == nil {
return fmt.Errorf("Error retrieving Storage Account %q (Resource Group %q): `properties` was nil", storageAccountName, resourceGroup)
}
Expand All @@ -132,18 +131,9 @@ func resourceArmStorageAccountNetworkRulesCreateUpdate(d *schema.ResourceData, m
}

rules.DefaultAction = storage.DefaultAction(d.Get("default_action").(string))

if v, ok := d.GetOk("bypass"); ok {
rules.Bypass = expandStorageAccountNetworkRuleBypass(v.(*schema.Set).List())
}

if v, ok := d.GetOk("ip_rules"); ok {
rules.IPRules = expandStorageAccountNetworkRuleIpRules(v.(*schema.Set).List())
}

if v, ok := d.GetOk("virtual_network_subnet_ids"); ok {
rules.VirtualNetworkRules = expandStorageAccountNetworkRuleVirtualRules(v.(*schema.Set).List())
}
rules.Bypass = expandStorageAccountNetworkRuleBypass(d.Get("bypass").(*schema.Set).List())
rules.IPRules = expandStorageAccountNetworkRuleIpRules(d.Get("ip_rules").(*schema.Set).List())
rules.VirtualNetworkRules = expandStorageAccountNetworkRuleVirtualRules(d.Get("virtual_network_subnet_ids").(*schema.Set).List())

opts := storage.AccountUpdateParameters{
AccountPropertiesUpdateParameters: &storage.AccountPropertiesUpdateParameters{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ func TestAccAzureRMStorageAccountNetworkRules_update(t *testing.T) {
),
},
data.ImportStep(),
{
Config: testAccAzureRMStorageAccountNetworkRules_empty(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists("azurerm_storage_account.test"),
),
},
data.ImportStep(),
{
Config: testAccAzureRMStorageAccountNetworkRules_basic(data),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -213,8 +220,10 @@ resource "azurerm_storage_account_network_rules" "test" {
resource_group_name = azurerm_resource_group.test.name
storage_account_name = azurerm_storage_account.test.name
default_action = "Deny"
bypass = ["Metrics"]
default_action = "Deny"
bypass = ["None"]
ip_rules = []
virtual_network_subnet_ids = []
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}

0 comments on commit a21bd9d

Please sign in to comment.