Skip to content

Instantly share code, notes, and snippets.

@J00MZ
Last active May 12, 2019 16:17
Show Gist options
  • Save J00MZ/74ea90621e380376bc4cda8112d1fb12 to your computer and use it in GitHub Desktop.
Save J00MZ/74ea90621e380376bc4cda8112d1fb12 to your computer and use it in GitHub Desktop.
Resolve terraform list items by key
resource "aws_vpc" "vpc" {
cidr_block = "10.0.0.0/16"
}
resource "aws_vpn_gateway" "vpn_gateway" {
vpc_id = "${aws_vpc.vpc.id}"
}
resource "aws_customer_gateway" "customer_gateway" {
count = "${length(var.vpn_resources)}"
bgp_asn = 65000
type = "ipsec.1"
ip_address = "${lookup(var.vpn_resources[count.index], "ip")}"
tags = {
Name = "${lookup(var.vpn_resources[count.index], "name")}"
}
}
resource "aws_vpn_connection" "main" {
count = "${length(var.vpn_resources)}"
vpn_gateway_id = "${aws_vpn_gateway.vpn_gateway.id}"
customer_gateway_id = "${aws_customer_gateway.customer_gateway.*.id}"
type = "ipsec.1"
static_routes_only = true
}
variable "vpn_resources" {
type = "list"
default = [
{
name = "VPN1_NAME"
ip = "VPN1_IP"
},
{
name = "VPN2_NAME"
ip = "VPN2_IP"
},
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment