Skip to content

Instantly share code, notes, and snippets.

@thattommyhall
Last active October 1, 2015 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thattommyhall/92ce3cce00065e871bdf to your computer and use it in GitHub Desktop.
Save thattommyhall/92ce3cce00065e871bdf to your computer and use it in GitHub Desktop.
azs = [:a, :b, :c]
cidr_block_lookup = {
public: { a: '172.20.0.0/24',
b: '172.20.1.0/24',
c: '172.20.2.0/24' },
private: { a: '172.20.8.0/24',
b: '172.20.9.0/24',
c: '172.20.10.0/24' }
}
provider :aws do
region 'eu-west-1'
access_key ''
secret_key ''
end
resource :aws_vpc, :production do
# tags do
# Name 'production'
# end
cidr_block '172.20.0.0/20'
end
resource :aws_internet_gateway, :production do
vpc_id id_of('aws_vpc', 'production')
end
azs.each do |az|
[:private, :public].each do |type|
subnet_name = "#{type}-#{az}"
resource :aws_subnet, subnet_name do
vpc_id id_of('aws_vpc', :production)
cidr_block cidr_block_lookup[type][az]
availability_zone "eu-west-1#{az}"
end
resource :aws_route_table, subnet_name do
vpc_id id_of('aws_vpc', :production)
route({ cidr_block:"0.0.0.0/0",
gateway_id: id_of('aws_internet_gateway', 'production')})
end
resource :aws_route_table_association, subnet_name do
route_table_id id_of('aws_route_table', subnet_name)
subnet_id id_of('aws_subnet', subnet_name)
end
end
resource :aws_security_group, "nat-#{az}" do
name "nat-#{az}"
ingress(from_port: 0,
to_port: 65535,
protocol: 'tcp',
cidr_blocks: [output_of('aws_subnet',
"private-#{az}",
:cidr_block)])
end
end
{
"provider": {
"aws": {
"region": "eu-west-1",
"access_key": "",
"secret_key": ""
}
},
"variable": {
},
"resource": {
"aws_vpc": {
"production": {
"tags": {
"Name": "production"
},
"cidr_block": "172.20.0.0/20"
}
},
"aws_internet_gateway": {
"production": {
"vpc_id": "${aws_vpc.production.id}"
}
},
"aws_subnet": {
"private-a": {
"tags": {
"Name": "private-a"
},
"vpc_id": "${aws_vpc.production.id}",
"cidr_block": "172.20.8.0/24",
"availability_zone": "eu-west-1a"
},
"public-a": {
"tags": {
"Name": "public-a"
},
"vpc_id": "${aws_vpc.production.id}",
"cidr_block": "172.20.0.0/24",
"availability_zone": "eu-west-1a"
},
"private-b": {
"tags": {
"Name": "private-b"
},
"vpc_id": "${aws_vpc.production.id}",
"cidr_block": "172.20.9.0/24",
"availability_zone": "eu-west-1b"
},
"public-b": {
"tags": {
"Name": "public-b"
},
"vpc_id": "${aws_vpc.production.id}",
"cidr_block": "172.20.1.0/24",
"availability_zone": "eu-west-1b"
},
"private-c": {
"tags": {
"Name": "private-c"
},
"vpc_id": "${aws_vpc.production.id}",
"cidr_block": "172.20.10.0/24",
"availability_zone": "eu-west-1c"
},
"public-c": {
"tags": {
"Name": "public-c"
},
"vpc_id": "${aws_vpc.production.id}",
"cidr_block": "172.20.2.0/24",
"availability_zone": "eu-west-1c"
}
},
"aws_route_table": {
"private-a": {
"tags": {
"Name": "private-a"
},
"vpc_id": "${aws_vpc.production.id}",
"route": {
"cidr_block": "0.0.0.0/0",
"gateway_id": "${aws_internet_gateway.production.id}"
}
},
"public-a": {
"tags": {
"Name": "public-a"
},
"vpc_id": "${aws_vpc.production.id}",
"route": {
"cidr_block": "0.0.0.0/0",
"gateway_id": "${aws_internet_gateway.production.id}"
}
},
"private-b": {
"tags": {
"Name": "private-b"
},
"vpc_id": "${aws_vpc.production.id}",
"route": {
"cidr_block": "0.0.0.0/0",
"gateway_id": "${aws_internet_gateway.production.id}"
}
},
"public-b": {
"tags": {
"Name": "public-b"
},
"vpc_id": "${aws_vpc.production.id}",
"route": {
"cidr_block": "0.0.0.0/0",
"gateway_id": "${aws_internet_gateway.production.id}"
}
},
"private-c": {
"tags": {
"Name": "private-c"
},
"vpc_id": "${aws_vpc.production.id}",
"route": {
"cidr_block": "0.0.0.0/0",
"gateway_id": "${aws_internet_gateway.production.id}"
}
},
"public-c": {
"tags": {
"Name": "public-c"
},
"vpc_id": "${aws_vpc.production.id}",
"route": {
"cidr_block": "0.0.0.0/0",
"gateway_id": "${aws_internet_gateway.production.id}"
}
}
},
"aws_route_table_association": {
"private-a": {
"route_table_id": "${aws_route_table.private-a.id}",
"subnet_id": "${aws_subnet.private-a.id}"
},
"public-a": {
"route_table_id": "${aws_route_table.public-a.id}",
"subnet_id": "${aws_subnet.public-a.id}"
},
"private-b": {
"route_table_id": "${aws_route_table.private-b.id}",
"subnet_id": "${aws_subnet.private-b.id}"
},
"public-b": {
"route_table_id": "${aws_route_table.public-b.id}",
"subnet_id": "${aws_subnet.public-b.id}"
},
"private-c": {
"route_table_id": "${aws_route_table.private-c.id}",
"subnet_id": "${aws_subnet.private-c.id}"
},
"public-c": {
"route_table_id": "${aws_route_table.public-c.id}",
"subnet_id": "${aws_subnet.public-c.id}"
}
},
"aws_security_group": {
"nat-a": {
"name": "nat-a",
"ingress": {
"from_port": 0,
"to_port": 65535,
"protocol": "tcp",
"cidr_blocks": [
"${aws_subnet.private-a.cidr_block}"
]
}
},
"nat-b": {
"name": "nat-b",
"ingress": {
"from_port": 0,
"to_port": 65535,
"protocol": "tcp",
"cidr_blocks": [
"${aws_subnet.private-b.cidr_block}"
]
}
},
"nat-c": {
"name": "nat-c",
"ingress": {
"from_port": 0,
"to_port": 65535,
"protocol": "tcp",
"cidr_blocks": [
"${aws_subnet.private-c.cidr_block}"
]
}
}
}
}
}
@redroot
Copy link

redroot commented Oct 1, 2015

whats this? Looks a bit like capistrano but slightly different, Chef?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment