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: support snat private ip ranges #7535

Closed
wants to merge 1 commit into from
Closed
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
38 changes: 37 additions & 1 deletion azurerm/internal/services/network/firewall_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"regexp"
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-03-01/network"
Expand Down Expand Up @@ -79,6 +80,20 @@ func resourceArmFirewall() *schema.Resource {
},
},

"private_ip_ranges": {
Type: schema.TypeSet,
Optional: true,
Computed: true, // By default, service will set it as "IANAPrivateRanges"
MinItems: 1,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.Any(
validation.IsCIDR,
validation.StringInSlice([]string{"IANAPrivateRanges"}, false),
),
},
},

"zones": azure.SchemaMultipleZones(),

"tags": tags.Schema(),
Expand Down Expand Up @@ -134,11 +149,21 @@ func resourceArmFirewallCreateUpdate(d *schema.ResourceData, meta interface{}) e
Location: &location,
Tags: tags.Expand(t),
AzureFirewallPropertiesFormat: &network.AzureFirewallPropertiesFormat{
IPConfigurations: ipConfigs,
IPConfigurations: ipConfigs,
AdditionalProperties: make(map[string]*string),
},
Zones: zones,
}

privateIpRanges := "IANAPrivateRanges"
if v, ok := d.GetOk("private_ip_ranges"); ok {
rangeSlice := utils.ExpandStringSlice(v.(*schema.Set).List())
if rangeSlice != nil {
privateIpRanges = strings.Join(*rangeSlice, ",")
parameters.AdditionalProperties["Network.SNAT.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.

is there a reason these fields aren't exposed in the Swagger? historically the Networking API's have introduced breaking schema changes - so this is less likely if these are typed, since they'll be caught via ARM review?

}
}

if !d.IsNewResource() {
exists, err2 := client.Get(ctx, resourceGroup, name)
if err2 != nil {
Expand Down Expand Up @@ -214,6 +239,17 @@ func resourceArmFirewallRead(d *schema.ResourceData, meta interface{}) error {
}
}

var privateIpRanges []interface{}
if props := read.AdditionalProperties; props != nil {
if v, ok := props["Network.SNAT.PrivateRanges"]; ok && v != nil {
ranges := strings.Split(*v, ",")
privateIpRanges = utils.FlattenStringSlice(&ranges)
}
}
if err := d.Set("private_ip_ranges", privateIpRanges); err != nil {
return fmt.Errorf("Error setting `private_ip_ranges`: %+v", err)
}

if err := d.Set("zones", azure.FlattenZones(read.Zones)); err != nil {
return fmt.Errorf("Error setting `zones`: %+v", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ resource "azurerm_firewall" "test" {
subnet_id = azurerm_subnet.test.id
public_ip_address_id = azurerm_public_ip.test.id
}

private_ip_ranges = ["IANAPrivateRanges", "10.0.0.0/16"]
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/firewall.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ The following arguments are supported:

* `ip_configuration` - (Required) A `ip_configuration` block as documented below.

* `private_ip_ranges` - (Optional) A list of SNAT private CIDR IP ranges, or the special string `IANAPrivateRanges`, which indicates Azure Firewall does not SNAT when the destination IP address is a private range per IANA RFC 1918. Defaults to a list contains only `IANAPrivateRanges`.

* `zones` - (Optional) Specifies the availability zones in which the Azure Firewall should be created.

-> **Please Note**: Availability Zones are [only supported in several regions at this time](https://docs.microsoft.com/en-us/azure/availability-zones/az-overview).
Expand Down