Skip to content

Commit

Permalink
add explicit_proxy for firewall_policy_resource
Browse files Browse the repository at this point in the history
  • Loading branch information
wuxu92 committed Aug 2, 2022
1 parent ee184ed commit f374b46
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 9 deletions.
44 changes: 41 additions & 3 deletions internal/services/firewall/firewall_policy_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ func resourceFirewallPolicyCreateUpdate(d *pluginsdk.ResourceData, meta interfac
}
}

if v, ok := d.GetOk("allow_sql_redirect"); ok {
props.FirewallPolicyPropertiesFormat.SQL = &network.FirewallPolicySQL{
AllowSQLRedirect: utils.Bool(v.(bool)),
}
}

if v, ok := d.GetOk("private_ip_ranges"); ok {
privateIPRanges := utils.ExpandStringSlice(v.([]interface{}))
props.FirewallPolicyPropertiesFormat.Snat = &network.FirewallPolicySNAT{
Expand Down Expand Up @@ -198,6 +204,12 @@ func resourceFirewallPolicyRead(d *pluginsdk.ResourceData, meta interface{}) err
if err := d.Set("insights", flattenFirewallPolicyInsights(prop.Insights)); err != nil {
return fmt.Errorf(`setting "insights": %+v`, err)
}

if prop.SQL != nil && prop.SQL.AllowSQLRedirect != nil {
if err := d.Set("allow_sql_redirect", prop.SQL.AllowSQLRedirect); err != nil {
return fmt.Errorf("setting `allow_sql_redirect`: %+v", err)
}
}
}

flattenedIdentity, err := flattenFirewallPolicyIdentity(resp.Identity)
Expand Down Expand Up @@ -297,10 +309,16 @@ func expandFirewallPolicyIntrusionDetection(input []interface{}) *network.Firewa
})
}

var privateRanges []string
for _, v := range raw["private_ranges"].([]interface{}) {
privateRanges = append(privateRanges, v.(string))
}

return &network.FirewallPolicyIntrusionDetection{
Mode: network.FirewallPolicyIntrusionDetectionStateType(raw["mode"].(string)),
Configuration: &network.FirewallPolicyIntrusionDetectionConfiguration{
SignatureOverrides: &signatureOverrides,
PrivateRanges: &privateRanges,
BypassTrafficSettings: &trafficBypass,
},
}
Expand Down Expand Up @@ -460,12 +478,12 @@ func flattenFirewallPolicyIntrusionDetection(input *network.FirewallPolicyIntrus
description = *bypass.Description
}

sourceAddresses := make([]string, 0)
var sourceAddresses []string
if bypass.SourceAddresses != nil {
sourceAddresses = *bypass.SourceAddresses
}

destinationAddresses := make([]string, 0)
var destinationAddresses []string
if bypass.DestinationAddresses != nil {
destinationAddresses = *bypass.DestinationAddresses
}
Expand Down Expand Up @@ -497,12 +515,17 @@ func flattenFirewallPolicyIntrusionDetection(input *network.FirewallPolicyIntrus
})
}
}
var privateRanges []string
if privates := input.Configuration.PrivateRanges; privates != nil {
privateRanges = *privates
}

return []interface{}{
map[string]interface{}{
"mode": string(input.Mode),
"signature_overrides": signatureOverrides,
"traffic_bypass": trafficBypass,
"private_ranges": privateRanges,
},
}
}
Expand Down Expand Up @@ -727,6 +750,15 @@ func resourceFirewallPolicySchema() map[string]*pluginsdk.Schema {
},
},
},

"private_ranges": {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
},

"traffic_bypass": {
Type: pluginsdk.TypeList,
Optional: true,
Expand All @@ -743,12 +775,13 @@ func resourceFirewallPolicySchema() map[string]*pluginsdk.Schema {
"protocol": {
Type: pluginsdk.TypeString,
Required: true,
// protocol to be one of [ICMP ANY TCP UDP] but response may be "Any"
ValidateFunc: validation.StringInSlice([]string{
string(network.FirewallPolicyIntrusionDetectionProtocolICMP),
string(network.FirewallPolicyIntrusionDetectionProtocolANY),
string(network.FirewallPolicyIntrusionDetectionProtocolTCP),
string(network.FirewallPolicyIntrusionDetectionProtocolUDP),
}, false),
}, true),
},
"source_addresses": {
Type: pluginsdk.TypeSet,
Expand Down Expand Up @@ -851,6 +884,11 @@ func resourceFirewallPolicySchema() map[string]*pluginsdk.Schema {
},
},

"allow_sql_redirect": {
Type: pluginsdk.TypeBool,
Optional: true,
},

"child_policies": {
Type: pluginsdk.TypeList,
Computed: true,
Expand Down
25 changes: 19 additions & 6 deletions internal/services/firewall/firewall_policy_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,15 @@ resource "azurerm_firewall_policy" "test" {
tags = {
env = "Test"
}
intrusion_detection {
mode = "Alert"
signature_overrides {
state = "Alert"
id = "1"
}
private_ranges = ["172.111.111.111"]
}
allow_sql_redirect = true
}
`, template, data.RandomInteger)
}
Expand Down Expand Up @@ -287,11 +296,14 @@ resource "azurerm_firewall_policy" "test" {
state = "Alert"
id = "1"
}
private_ranges = ["172.111.111.111"]
traffic_bypass {
name = "Name bypass traffic settings"
description = "Description bypass traffic settings"
protocol = "ANY"
destination_ports = ["*"]
name = "Name bypass traffic settings"
description = "Description bypass traffic settings"
destination_addresses = []
source_addresses = []
protocol = "Any"
destination_ports = ["*"]
source_ip_groups = [
azurerm_ip_group.test_source.id,
]
Expand All @@ -300,6 +312,7 @@ resource "azurerm_firewall_policy" "test" {
]
}
}
allow_sql_redirect = true
identity {
type = "UserAssigned"
identity_ids = [
Expand Down Expand Up @@ -510,7 +523,7 @@ resource "azurerm_key_vault_certificate" "test" {
`, data.RandomInteger, "westeurope", data.RandomInteger, data.RandomInteger)
}

func (FirewallPolicyResource) defaultWorkspaceOnly(data acceptance.TestData) string {
func (f FirewallPolicyResource) defaultWorkspaceOnly(data acceptance.TestData) string {
r := FirewallPolicyResource{}
template := r.template(data)
return fmt.Sprintf(`
Expand All @@ -537,7 +550,7 @@ resource "azurerm_firewall_policy" "test" {
`, template, data.RandomInteger, data.RandomInteger)
}

func (FirewallPolicyResource) regionalWorkspace(data acceptance.TestData) string {
func (f FirewallPolicyResource) regionalWorkspace(data acceptance.TestData) string {
r := FirewallPolicyResource{}
template := r.template(data)
return fmt.Sprintf(`
Expand Down
5 changes: 5 additions & 0 deletions website/docs/r/firewall_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ The following arguments are supported:

* `tls_certificate` - (Optional) A `tls_certificate` block as defined below.

* `allow_sql_redirect` - (Optional) Whether SQL Redirect traffic filtering is enabled. Turning on the flag requires no rule using port 11000-11999.

---

A `dns` block supports the following:
Expand Down Expand Up @@ -97,6 +99,8 @@ A `intrusion_detection` block supports the following:

* `traffic_bypass` - (Optional) One or more `traffic_bypass` blocks as defined below.

* `private_ranges` - (Optional) A list of Private IP address ranges to identify traffic direction. By default, only ranges defined by IANA RFC 1918 are considered private IP addresses.

---

A `log_analytics_workspace` block supports the following:
Expand Down Expand Up @@ -149,6 +153,7 @@ A `traffic_bypass` block supports the following:

* `source_ip_groups` - (Optional) Specifies a list of source IP groups that shall be bypassed by intrusion detection.


## Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:
Expand Down

0 comments on commit f374b46

Please sign in to comment.