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

r/storage_account: handling when network_rules is empty #5210

Merged
merged 1 commit into from
Dec 18, 2019
Merged
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
36 changes: 23 additions & 13 deletions azurerm/resource_arm_storage_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -1177,10 +1177,8 @@ func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) err
d.Set("secondary_blob_connection_string", secondaryBlobConnectStr)
}

if networkRules := props.NetworkRuleSet; networkRules != nil {
if err := d.Set("network_rules", flattenStorageAccountNetworkRules(networkRules)); err != nil {
return fmt.Errorf("Error setting `network_rules`: %+v", err)
}
if err := d.Set("network_rules", flattenStorageAccountNetworkRules(props.NetworkRuleSet)); err != nil {
return fmt.Errorf("Error setting `network_rules`: %+v", err)
}
}

Expand Down Expand Up @@ -1547,9 +1545,10 @@ func expandQueuePropertiesCors(input []interface{}) *queues.Cors {
}

func flattenStorageAccountNetworkRules(input *storage.NetworkRuleSet) []interface{} {
if len(*input.IPRules) == 0 && len(*input.VirtualNetworkRules) == 0 {
if input == nil {
return []interface{}{}
}

networkRules := make(map[string]interface{})

networkRules["ip_rules"] = schema.NewSet(schema.HashString, flattenStorageAccountIPRules(input.IPRules))
Expand All @@ -1561,23 +1560,34 @@ func flattenStorageAccountNetworkRules(input *storage.NetworkRuleSet) []interfac
}

func flattenStorageAccountIPRules(input *[]storage.IPRule) []interface{} {
ipRules := make([]interface{}, len(*input))
if input != nil {
for i, ipRule := range *input {
ipRules[i] = *ipRule.IPAddressOrRange
if input == nil {
return []interface{}{}
}

ipRules := make([]interface{}, 0)
for _, ipRule := range *input {
if ipRule.IPAddressOrRange == nil {
continue
}

ipRules = append(ipRules, *ipRule.IPAddressOrRange)
}

return ipRules
}

func flattenStorageAccountVirtualNetworks(input *[]storage.VirtualNetworkRule) []interface{} {
virtualNetworks := make([]interface{}, len(*input))
if input == nil {
return []interface{}{}
}

if input != nil {
for i, virtualNetwork := range *input {
virtualNetworks[i] = *virtualNetwork.VirtualNetworkResourceID
virtualNetworks := make([]interface{}, 0)
for _, virtualNetwork := range *input {
if virtualNetwork.VirtualNetworkResourceID == nil {
continue
}

virtualNetworks = append(virtualNetworks, *virtualNetwork.VirtualNetworkResourceID)
}

return virtualNetworks
Expand Down