Skip to content

Instantly share code, notes, and snippets.

@silveraid
Created October 26, 2017 01:46
Show Gist options
  • Save silveraid/6ba46a3801b235bf1992d9b72dbbd8fb to your computer and use it in GitHub Desktop.
Save silveraid/6ba46a3801b235bf1992d9b72dbbd8fb to your computer and use it in GitHub Desktop.
# List of maps
listener = [{
instance_port = "${var.backend_port}"
instance_protocol = "${var.backend_protocol}"
lb_port = 80
lb_protocol = "http"
},{
instance_port = "${var.backend2_port}"
instance_protocol = "${var.backend2_protocol}"
lb_port = 8080
lb_protocol = "http"
}]
# Reference a list
listener = ["${var.elb_listeners}"]
# Map processing example I.
variable "rules" {
default = {
"a" = "200,false,tcp,allow,0.0.0.0/0,23,23"
"b" = "100,true,tcp,allow,0.0.0.0/0,1024,65535"
}
}
resource "aws_network_acl_rule" "bar" {
count = "${length(var.rules)}"
network_acl_id = "${aws_network_acl.bar.id}"
rule_number = "${element(split(",",element(values(var.rules),count.index)),0)}"
egress = "${element(split(",",element(values(var.rules),count.index)),1)}"
protocol = "${element(split(",",element(values(var.rules),count.index)),2)}"
rule_action = "${element(split(",",element(values(var.rules),count.index)),3)}"
cidr_block = "${element(split(",",element(values(var.rules),count.index)),4)}"
from_port = "${element(split(",",element(values(var.rules),count.index)),5)}"
to_port = "${element(split(",",element(values(var.rules),count.index)),6)}"
}
# Map processing example II
variable "rules" {
default = [
{
rule_number = 200
egress = false
protocol = "tcp"
rule_action = "allow"
cidr_block = "0.0.0.0/0"
from_port= 23
to_port = 23
},
{
rule_number = 100
egress = true
procotol = "tcp"
rule_action = "allow"
cidr_block = "0.0.0.0/0"
from_port = 1024
to_port = 65535
},
]
}
resource "aws_network_acl_rule" "bar" {
count = "${length(var.rules)}"
network_acl_id = "<id>"
rule_number = "${lookup(var.rules[count.index], "rule_number")}"
egress = "${lookup(var.rules[count.index], "egress")}"
protocol = "${lookup(var.rules[count.index], "protocol")}"
rule_action = "${lookup(var.rules[count.index], "rule_action")}"
cidr_block = "${lookup(var.rules[count.index], "cidr_block")}"
from_port = "${lookup(var.rules[count.index], "from_port")}"
to_port = "${lookup(var.rules[count.index], "to_port")}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment