Created
March 23, 2020 10:54
-
-
Save aodj/f9903e2b00086527c1a39905ac463864 to your computer and use it in GitHub Desktop.
Using chunklist in TF11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "ips" { | |
default = [ | |
"1.1.1.1/32", | |
"2.2.2.2/32", | |
"3.3.3.3/32", | |
"4.4.4.4/32", | |
"5.5.5.5/32", | |
"6.6.6.6/32", | |
"7.7.7.7/32", | |
"8.8.8.8/29", | |
"9.9.9.9/32" | |
] | |
} | |
locals { | |
chunks = "${chunklist(var.ips, 5)}" | |
rules = [ | |
{ action = "allow", priority = "0", match = { versioned_expr = "SRC_IPS_V1", config = { src_ip_ranges = ["${local.chunks[0]}"] }}}, | |
{ action = "deny(403)", priority = "2147483647", match = { versioned_expr = "SRC_IPS_V1", config = { src_ip_ranges = ["*"] }}, description = "Default rule: deny all"} | |
] | |
} | |
output "rules" { | |
value = "${local.rules}" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ terraform apply | |
Apply complete! Resources: 0 added, 0 changed, 0 destroyed. | |
Outputs: | |
foo = [ | |
{ | |
"action" = "allow" | |
"match" = { | |
"config" = { | |
"src_ip_ranges" = [ | |
[ | |
"1.1.1.1/32", | |
"2.2.2.2/32", | |
"3.3.3.3/32", | |
"4.4.4.4/32", | |
"5.5.5.5/32", | |
], | |
] | |
} | |
"versioned_expr" = "SRC_IPS_V1" | |
} | |
"priority" = "0" | |
}, | |
{ | |
"action" = "deny(403)" | |
"description" = "Default rule: deny all" | |
"match" = { | |
"config" = { | |
"src_ip_ranges" = [ | |
"*", | |
] | |
} | |
"versioned_expr" = "SRC_IPS_V1" | |
} | |
"priority" = "2147483647" | |
}, | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment