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_web_application_firewall_policy - fix the value of rule_group_name does not exist for Application Gateway Firewall #24194

Merged
merged 3 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -782,7 +782,7 @@ func expandWebApplicationFirewallPolicyExclusionManagedRuleGroup(input []interfa
for _, item := range input {
v := item.(map[string]interface{})

ruleGroupName := v["rule_group_name"].(string)
ruleGroupName := convertRuleGroupNameToBeAcceptedByAPI(v["rule_group_name"].(string))

result := webapplicationfirewallpolicies.ExclusionManagedRuleGroup{
RuleGroupName: ruleGroupName,
Expand Down Expand Up @@ -874,7 +874,7 @@ func expandWebApplicationFirewallPolicyRuleGroupOverrides(input []interface{}, d
for i, item := range input {
v := item.(map[string]interface{})

ruleGroupName := v["rule_group_name"].(string)
ruleGroupName := convertRuleGroupNameToBeAcceptedByAPI(v["rule_group_name"].(string))

result := webapplicationfirewallpolicies.ManagedRuleGroupOverride{
RuleGroupName: ruleGroupName,
Expand Down Expand Up @@ -1108,7 +1108,7 @@ func flattenWebApplicationFirewallPolicyExclusionManagedRuleGroups(input *[]weba
for _, item := range *input {
v := make(map[string]interface{})

v["rule_group_name"] = item.RuleGroupName
v["rule_group_name"] = convertRuleGroupNameFromAPI(item.RuleGroupName)
v["excluded_rules"] = flattenWebApplicationFirewallPolicyExclusionManagedRules(item.Rules)

results = append(results, v)
Expand Down Expand Up @@ -1183,7 +1183,7 @@ func flattenWebApplicationFirewallPolicyRuleGroupOverrides(input *[]webapplicati
for _, item := range *input {
v := make(map[string]interface{})

v["rule_group_name"] = item.RuleGroupName
v["rule_group_name"] = convertRuleGroupNameFromAPI(item.RuleGroupName)

if !features.FourPointOhBeta() {
v["disabled_rules"] = flattenWebApplicationFirewallPolicyRules(item.Rules)
Expand Down Expand Up @@ -1296,3 +1296,57 @@ func flattenWebApplicationFirewallPoliciesSubResourcesToIDs(input *[]webapplicat

return ids
}

func convertRuleGroupNameToBeAcceptedByAPI(name string) string {
var ruleGroupName string
switch name {
case "APPLICATION-ATTACK-LFI":
ruleGroupName = "LFI"
case "APPLICATION-ATTACK-RFI":
ruleGroupName = "RFI"
case "APPLICATION-ATTACK-RCE":
ruleGroupName = "RCE"
case "APPLICATION-ATTACK-PHP":
ruleGroupName = "PHP"
case "APPLICATION-ATTACK-NodeJS":
ruleGroupName = "NODEJS"
case "APPLICATION-ATTACK-XSS":
ruleGroupName = "XSS"
case "APPLICATION-ATTACK-SQLI":
ruleGroupName = "SQLI"
case "APPLICATION-ATTACK-SESSION-FIXATION":
ruleGroupName = "FIX"
case "APPLICATION-ATTACK-SESSION-JAVA":
ruleGroupName = "JAVA"
default:
ruleGroupName = name
}
return ruleGroupName
}
Copy link
Member

Choose a reason for hiding this comment

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

If the API doesn't accept any of these values then we can probably just remove these from the validation function instead of adding a conversion function here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.


func convertRuleGroupNameFromAPI(name string) string {
var ruleGroupName string
switch name {
case "LFI":
ruleGroupName = "APPLICATION-ATTACK-LFI"
case "RFI":
ruleGroupName = "APPLICATION-ATTACK-RFI"
case "RCE":
ruleGroupName = "APPLICATION-ATTACK-RCE"
case "PHP":
ruleGroupName = "APPLICATION-ATTACK-PHP"
case "NODEJS":
ruleGroupName = "APPLICATION-ATTACK-NodeJS"
case "XSS":
ruleGroupName = "APPLICATION-ATTACK-XSS"
case "SQLI":
ruleGroupName = "APPLICATION-ATTACK-SQLI"
case "FIX":
ruleGroupName = "APPLICATION-ATTACK-SESSION-FIXATION"
case "JAVA":
ruleGroupName = "APPLICATION-ATTACK-SESSION-JAVA"
default:
ruleGroupName = name
}
return ruleGroupName
}
Copy link
Member

Choose a reason for hiding this comment

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

Then we can also remove this unnecessary conversion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,87 @@ resource "azurerm_web_application_firewall_policy" "test" {
action = "Log"
}
}

rule_group_override {
rule_group_name = "APPLICATION-ATTACK-LFI"
rule {
id = "930100"
enabled = false
action = "Log"
}
}

rule_group_override {
rule_group_name = "APPLICATION-ATTACK-RFI"
rule {
id = "931100"
enabled = false
action = "Log"
}
}

rule_group_override {
rule_group_name = "APPLICATION-ATTACK-RCE"
rule {
id = "932100"
enabled = false
action = "Log"
}
}

rule_group_override {
rule_group_name = "APPLICATION-ATTACK-PHP"
rule {
id = "933100"
enabled = false
action = "Log"
}
}

rule_group_override {
rule_group_name = "APPLICATION-ATTACK-NodeJS"
rule {
id = "934100"
enabled = false
action = "Log"
}
}

rule_group_override {
rule_group_name = "APPLICATION-ATTACK-XSS"
rule {
id = "941100"
enabled = false
action = "Log"
}
}

rule_group_override {
rule_group_name = "APPLICATION-ATTACK-SQLI"
rule {
id = "942100"
enabled = false
action = "Log"
}
}

rule_group_override {
rule_group_name = "APPLICATION-ATTACK-SESSION-FIXATION"
rule {
id = "943100"
enabled = false
action = "Log"
}
}

rule_group_override {
rule_group_name = "APPLICATION-ATTACK-SESSION-JAVA"
rule {
id = "944100"
enabled = false
action = "Log"
}
}
}
}
}
Expand Down
Loading