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

feat: add override_action to aws_networkfirewall_firewall_policy #25135

Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 3 additions & 0 deletions .changelog/25135.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_networkfirewall_firewall_policy: Add `override` configuration block and `action` argument inside of it for `stateful_rule_group_reference`
```
52 changes: 52 additions & 0 deletions internal/service/networkfirewall/firewall_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ func ResourceFirewallPolicy() *schema.Resource {
Required: true,
ValidateFunc: verify.ValidARN,
},
"override": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"action": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(networkfirewall.OverrideAction_Values(), false),
},
},
},
},
},
},
},
Expand Down Expand Up @@ -310,6 +324,21 @@ func expandStatefulEngineOptions(l []interface{}) *networkfirewall.StatefulEngin
return options
}

func expandStatefulRuleGroupOverride(l []interface{}) *networkfirewall.StatefulRuleGroupOverride {
if len(l) == 0 || l[0] == nil {
return nil
}

lRaw := l[0].(map[string]interface{})
override := &networkfirewall.StatefulRuleGroupOverride{}

if v, ok := lRaw["action"].(string); ok && v != "" {
override.SetAction(v)
}

return override
}

func expandStatefulRuleGroupReferences(l []interface{}) []*networkfirewall.StatefulRuleGroupReference {
if len(l) == 0 || l[0] == nil {
return nil
Expand All @@ -320,15 +349,22 @@ func expandStatefulRuleGroupReferences(l []interface{}) []*networkfirewall.State
if !ok {
continue
}

reference := &networkfirewall.StatefulRuleGroupReference{}
if v, ok := tfMap["priority"].(int); ok && v > 0 {
reference.Priority = aws.Int64(int64(v))
}
if v, ok := tfMap["resource_arn"].(string); ok && v != "" {
reference.ResourceArn = aws.String(v)
}

if v, ok := tfMap["override"].([]interface{}); ok && len(v) > 0 {
reference.Override = expandStatefulRuleGroupOverride(v)
}

references = append(references, reference)
}

return references
}

Expand Down Expand Up @@ -429,6 +465,18 @@ func flattenStatefulEngineOptions(options *networkfirewall.StatefulEngineOptions
return []interface{}{m}
}

func flattenStatefulRuleGroupOverride(override *networkfirewall.StatefulRuleGroupOverride) []interface{} {
if override == nil {
return []interface{}{}
}

m := map[string]interface{}{
"action": aws.StringValue(override.Action),
}

return []interface{}{m}
}

func flattenPolicyStatefulRuleGroupReference(l []*networkfirewall.StatefulRuleGroupReference) []interface{} {
references := make([]interface{}, 0, len(l))
for _, ref := range l {
Expand All @@ -438,6 +486,10 @@ func flattenPolicyStatefulRuleGroupReference(l []*networkfirewall.StatefulRuleGr
if ref.Priority != nil {
reference["priority"] = int(aws.Int64Value(ref.Priority))
}
if ref.Override != nil {
reference["override"] = flattenStatefulRuleGroupOverride(ref.Override)
}

references = append(references, reference)
}

Expand Down
53 changes: 53 additions & 0 deletions internal/service/networkfirewall/firewall_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,34 @@ func TestAccNetworkFirewallFirewallPolicy_statefulRuleGroupPriorityReference(t *
})
}

func TestAccNetworkFirewallFirewallPolicy_statefulRuleGroupOverrideActionReference(t *testing.T) {
var firewallPolicy networkfirewall.DescribeFirewallPolicyOutput
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_networkfirewall_firewall_policy.test"
override_action := networkfirewall.OverrideActionDropToAlert

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t); testAccPreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, networkfirewall.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckFirewallPolicyDestroy,
Steps: []resource.TestStep{
{
Config: testAccFirewallPolicyConfig_statefulRuleGroupReferenceManagedOverrideAction(rName, override_action),
Check: resource.ComposeTestCheckFunc(
testAccCheckFirewallPolicyExists(resourceName, &firewallPolicy),
resource.TestCheckResourceAttr(resourceName, "firewall_policy.0.stateful_rule_group_reference.0.override.0.action", override_action),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccNetworkFirewallFirewallPolicy_updateStatefulRuleGroupPriorityReference(t *testing.T) {
var firewallPolicy1, firewallPolicy2 networkfirewall.DescribeFirewallPolicyOutput
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
Expand Down Expand Up @@ -1088,6 +1116,31 @@ resource "aws_networkfirewall_firewall_policy" "test" {
`, rName, priority))
}

func testAccFirewallPolicyConfig_statefulRuleGroupReferenceManagedOverrideAction(rName, override_action string) string {
return acctest.ConfigCompose(
testAccFirewallPolicyStatefulRuleGroupDependencies(rName, 1),
fmt.Sprintf(`
data "aws_region" "current" {}

data "aws_partition" "current" {}

resource "aws_networkfirewall_firewall_policy" "test" {
name = %[1]q

firewall_policy {
stateless_fragment_default_actions = ["aws:drop"]
stateless_default_actions = ["aws:pass"]
stateful_rule_group_reference {
resource_arn = "arn:${data.aws_partition.current.partition}:network-firewall:${data.aws_region.current.name}:aws-managed:stateful-rulegroup/MalwareDomainsActionOrder"
override {
action = %[2]q
}
}
}
}
`, rName, override_action))
}

func testAccFirewallPolicyConfig_singleStatefulRuleGroupReference(rName string) string {
return acctest.ConfigCompose(
testAccFirewallPolicyStatefulRuleGroupDependencies(rName, 2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ The `stateful_rule_group_reference` block supports the following arguments:

* `resource_arn` - (Required) The Amazon Resource Name (ARN) of the stateful rule group.

* `override` - (Optional) Configuration block for override values

#### Override

* `action` - (Optional) The action that changes the rule group from DROP to ALERT . This only applies to managed rule groups.

### Stateless Custom Action

The `stateless_custom_action` block supports the following arguments:
Expand Down