Skip to content

Commit

Permalink
Merge pull request #145 from kloia/adjust-waf-ip-set-to-create-generi…
Browse files Browse the repository at this point in the history
…c-groups

adjust dynamic waf ip set creation
  • Loading branch information
ugurcancaykara authored Mar 18, 2024
2 parents 9424aee + e8fa1b5 commit d4eff64
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 27 deletions.
16 changes: 13 additions & 3 deletions aws-waf-ip-set/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
resource "aws_wafv2_ip_set" "blacklist_ip_set" {

ip_address_version = "IPV4"
scope = "${var.blacklist_scope}"
scope = var.blacklist_scope
description = var.blacklist_ip_set_description
name = var.blacklist_ip_set_name
addresses = var.blacklist_ip_addresses
Expand All @@ -11,9 +11,19 @@ resource "aws_wafv2_ip_set" "blacklist_ip_set" {

resource "aws_wafv2_ip_set" "whitelist_ip_set" {
ip_address_version = "IPV4"
scope = "${var.whitelist_scope}"
scope = var.whitelist_scope
description = var.ip_set_description
name = var.ip_set_name
addresses = var.ip_set_addresses

}
}


resource "aws_wafv2_ip_set" "ip_addresses" {
for_each = var.ip_address_groups
ip_address_version = each.value.ip_address_version
scope = each.value.whitelist_scope
description = each.value.ip_set_description
name = each.value.ip_set_name
addresses = each.value.ip_set_addresses
}
16 changes: 11 additions & 5 deletions aws-waf-ip-set/output.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
output "blacklist_ip_set_arn" {
value = aws_wafv2_ip_set.blacklist_ip_set.arn
description = "arn of blacklist ip set"
value = aws_wafv2_ip_set.blacklist_ip_set.arn
description = "arn of blacklist ip set"
}

output "whitelist_ip_set_arn" {
value = aws_wafv2_ip_set.whitelist_ip_set.arn
description = "arn of whitelist ip set"
}
value = aws_wafv2_ip_set.whitelist_ip_set.arn
description = "arn of whitelist ip set"
}

output "dynamic_waf_ip_set_arns" {
value = { for key, ip_set in aws_wafv2_ip_set.ip_addresses : key => ip_set.arn }
description = "Map of ARNs for dynamically created IP address groups"
}

53 changes: 34 additions & 19 deletions aws-waf-ip-set/variables.tf
Original file line number Diff line number Diff line change
@@ -1,43 +1,58 @@
variable "ip_set_addresses" {
description = "IP addresses"
type = list(string)
default = []
description = "IP addresses"
type = list(string)
default = []
}

variable "ip_set_name" {
description = "IP Set Name"
default = ""
description = "IP Set Name"
default = ""
}

variable "ip_set_description" {
description = "Description of the IP set"
default = ""
description = "Description of the IP set"
default = ""

}

variable "whitelist_scope" {
description = ""
default = "REGIONAL"
default = "REGIONAL"
}

variable "blacklist_ip_addresses" {
description = "Blacklist IP addresses"
type = list(string)
default = []
description = "Blacklist IP addresses"
type = list(string)
default = []
}

variable "blacklist_ip_set_name" {
description = "IP Set Name"
default = ""
description = "IP Set Name"
default = ""
}

variable "blacklist_ip_set_description" {
description = "Description of the IP set"
default = ""
description = "Description of the IP set"
default = ""

}

variable "blacklist_scope" {
description = ""
default = "REGIONAL"
}
default = "REGIONAL"
}




variable "ip_address_groups" {
description = "Map of IP address groups for creating multiple AWS WAFv2 IP Sets"
type = map(object({
ip_address_version = string
whitelist_scope = string
ip_set_description = string
ip_set_name = string
ip_set_addresses = list(string)
}))
default = {}
}

0 comments on commit d4eff64

Please sign in to comment.