Skip to content

feat: Add Conditional Support for policy_variables in Policy Module #8

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

Closed
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
3 changes: 3 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ module "policy" {
stateless_fragment_default_actions = var.policy_stateless_fragment_default_actions
stateless_rule_group_reference = var.policy_stateless_rule_group_reference
name = try(coalesce(var.policy_name, var.name), "")
policy_variable_enabled = var.policy_variable_enabled
rule_variable_key = var.policy_rule_variable_key
rule_variable_definition = var.policy_rule_variable_definition

# Resource policy
create_resource_policy = var.create_policy_resource_policy
Expand Down
14 changes: 14 additions & 0 deletions modules/policy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ resource "aws_networkfirewall_firewall_policy" "this" {
}

firewall_policy {

# Create the policy_variables
dynamic "policy_variables" {
for_each = var.policy_variable_enabled ? [1] : []
content {
rule_variables {
key = var.rule_variable_key
ip_set {
definition = var.rule_variable_definition
}
}
}
}

# Stateful
stateful_default_actions = var.stateful_default_actions

Expand Down
19 changes: 19 additions & 0 deletions modules/policy/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,25 @@ variable "name" {
default = ""
}

variable "policy_variable_enabled" {
description = "Toggle to enable or disable the policy_variables block"
type = bool
default = false
}

variable "rule_variable_key" {
description = "Key for the rule_variables block (e.g., HOME_NET)"
type = string
default = null
}

variable "rule_variable_definition" {
description = "List of IP ranges to include in the rule"
type = list(string)
default = []
}


################################################################################
# Resource Policies
################################################################################
Expand Down
18 changes: 18 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,24 @@ variable "policy_tags" {
default = {}
}

variable "policy_variable_enabled" {
description = "Toggle to enable or disable the policy_variables block"
type = bool
default = false
}

variable "policy_rule_variable_key" {
description = "Key for the rule_variables block (e.g., HOME_NET)"
type = string
default = null
}

variable "policy_rule_variable_definition" {
description = "List of IP ranges to include in the rule"
type = list(string)
default = []
}

# Resource Policy
variable "create_policy_resource_policy" {
description = "Controls if a resource policy should be created"
Expand Down
Loading