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_firewall_polcy - Added new property private_ip_ranges #12696

Merged
merged 3 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
27 changes: 27 additions & 0 deletions azurerm/internal/services/firewall/firewall_policy_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,19 @@ func resourceFirewallPolicy() *pluginsdk.Resource {
},
},

"private_ip_ranges": {
Type: pluginsdk.TypeList,
Optional: true,
MinItems: 1,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validation.Any(
validation.IsCIDR,
validation.IsIPv4Address,
),
},
},

"tags": tags.SchemaEnforceLowerCaseKeys(),
},
}
Expand Down Expand Up @@ -211,6 +224,12 @@ func resourceFirewallPolicyCreateUpdate(d *pluginsdk.ResourceData, meta interfac
}
}

if v, ok := d.GetOk("private_ip_ranges"); ok {
privateIpRanges := utils.ExpandStringSlice(v.([]interface{}))
props.FirewallPolicyPropertiesFormat.Snat = &network.FirewallPolicySNAT{
PrivateRanges: privateIpRanges}
Copy link
Contributor

Choose a reason for hiding this comment

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

minor can we clean this up:

Suggested change
PrivateRanges: privateIpRanges}
PrivateRanges: privateIpRanges,
}

}

locks.ByName(name, azureFirewallPolicyResourceName)
defer locks.UnlockByName(name, azureFirewallPolicyResourceName)

Expand Down Expand Up @@ -287,6 +306,14 @@ func resourceFirewallPolicyRead(d *pluginsdk.ResourceData, meta interface{}) err
if err := d.Set("rule_collection_groups", flattenNetworkSubResourceID(prop.RuleCollectionGroups)); err != nil {
return fmt.Errorf(`setting "rule_collection_groups": %+v`, err)
}

var privateIpRanges []interface{}
if prop.Snat != nil {
privateIpRanges = utils.FlattenStringSlice(prop.Snat.PrivateRanges)
}
if err := d.Set("private_ip_ranges", privateIpRanges); err != nil {
return fmt.Errorf("Error setting `private_ip_ranges`: %+v", err)
}
}

return tags.FlattenAndSet(d, resp.Tags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ resource "azurerm_firewall_policy" "test" {
servers = ["1.1.1.1", "2.2.2.2"]
proxy_enabled = true
}
private_ip_ranges = ["172.16.0.0/12", "192.168.0.0/16"]
tags = {
env = "Test"
}
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/firewall_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ In addition to the Arguments listed above - the following Attributes are exporte

* `rule_collection_groups` - A list of references to Firewall Policy Rule Collection Groups that belongs to this Firewall Policy.

* `private_ip_ranges` - A list of private IP ranges to which traffic will not be SNAT.

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:
Expand Down