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_policy_rule_collection_group: add support for http_headers #23641

Merged
merged 2 commits into from
Nov 7, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,24 @@ func resourceFirewallPolicyRuleCollectionGroup() *pluginsdk.Resource {
},
},
},
"http_headers": {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"value": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
},
},
},
"source_addresses": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -616,10 +634,21 @@ func expandFirewallPolicyRuleApplication(input []interface{}) *[]firewallpolicyr
Port: utils.Int64(int64(proto["port"].(int))),
})
}

var httpHeader []firewallpolicyrulecollectiongroups.FirewallPolicyHTTPHeaderToInsert
for _, h := range condition["http_headers"].([]interface{}) {
header := h.(map[string]interface{})
httpHeader = append(httpHeader, firewallpolicyrulecollectiongroups.FirewallPolicyHTTPHeaderToInsert{
HeaderName: pointer.To(header["name"].(string)),
HeaderValue: pointer.To(header["value"].(string)),
})
}

output := &firewallpolicyrulecollectiongroups.ApplicationRule{
Name: utils.String(condition["name"].(string)),
Description: utils.String(condition["description"].(string)),
Protocols: &protocols,
HTTPHeadersToInsert: &httpHeader,
SourceAddresses: utils.ExpandStringSlice(condition["source_addresses"].([]interface{})),
SourceIPGroups: utils.ExpandStringSlice(condition["source_ip_groups"].([]interface{})),
DestinationAddresses: utils.ExpandStringSlice(condition["destination_addresses"].([]interface{})),
Expand Down Expand Up @@ -839,10 +868,19 @@ func flattenFirewallPolicyRuleApplication(input *[]firewallpolicyrulecollectiong
}
}

httpHeaders := make([]interface{}, 0)
for _, header := range pointer.From(rule.HTTPHeadersToInsert) {
httpHeaders = append(httpHeaders, map[string]interface{}{
"name": pointer.From(header.HeaderName),
"value": pointer.From(header.HeaderValue),
})
}

output = append(output, map[string]interface{}{
"name": name,
"description": description,
"protocols": protocols,
"http_headers": httpHeaders,
"source_addresses": utils.FlattenStringSlice(rule.SourceAddresses),
"source_ip_groups": utils.FlattenStringSlice(rule.SourceIPGroups),
"destination_addresses": utils.FlattenStringSlice(rule.DestinationAddresses),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,14 @@ resource "azurerm_firewall_policy_rule_collection_group" "test" {
destination_urls = ["www.google.com/en"]
terminate_tls = true
web_categories = ["News"]
http_headers {
name = "head_foo"
value = "value_bar"
}
http_headers {
name = "head_bar"
value = "value2"
}
}
rule {
name = "app_rule_collection1_rule2"
Expand Down Expand Up @@ -794,6 +802,14 @@ resource "azurerm_firewall_policy_rule_collection_group" "test" {
destination_urls = ["www.google.com/en"]
terminate_tls = true
web_categories = ["News"]
http_headers {
name = "head_foo"
value = "value_bar2"
}
http_headers {
name = "head_bar2"
value = "value_bar2"
}
}
rule {
name = "app_rule_collection1_rule2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ A `application_rule` (application rule) block supports the following:

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

* `http_headers` - (Required) Specifies a list of HTTP/HTTPS headers to insert. One or more `http_headers` blocks as defined below.

* `source_addresses` - (Optional) Specifies a list of source IP addresses (including CIDR, IP range and `*`).

* `source_ip_groups` - (Optional) Specifies a list of source IP groups.
Expand Down Expand Up @@ -213,6 +215,14 @@ A `protocols` block supports the following:

* `port` - (Required) Port number of the protocol. Range is 0-64000.

---

A `http_headers` block supports the following:

* `name` - (Required) Specifies the name of the header.

* `value` - (Required) Specifies the value of the value.

## Attributes Reference

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