Skip to content

Instantly share code, notes, and snippets.

@gsdevme
Created January 25, 2018 22:37
Show Gist options
  • Save gsdevme/80b58b1df0ccda7387fcb51ccd1b04ac to your computer and use it in GitHub Desktop.
Save gsdevme/80b58b1df0ccda7387fcb51ccd1b04ac to your computer and use it in GitHub Desktop.
variable "name" {}
variable "region" {
default = "eu-west-1"
}
variable "vpc_network" {
"default" = "10.0.0.0/16"
}
variable "public_subnets" {
type = "map"
default = {
# (254 hosts each)
"a" = "10.0.0.0/24"
"b" = "10.0.1.0/24"
"c" = "10.0.2.0/24"
"d" = "10.0.3.0/24"
}
}
variable "private_subnets" {
type = "map"
default = {
# (4094 hosts each)
"a" = "10.16.0.0/20"
"b" = "10.16.16.0/20"
"c" = "10.16.32.0/20"
"d" = "10.16.48.0/20"
}
}
data "aws_availability_zones" "available" {}
resource "aws_vpc" "default" {
# 10.0.0.1 - 10.15.255.254 (1,048,574 hosts)
cidr_block = "10.0.0.0/16"
enable_dns_support = true
enable_dns_hostnames = true
enable_classiclink_dns_support = false
enable_classiclink = false
assign_generated_ipv6_cidr_block = false
tags {
Name = "${var.name}-vpc"
}
}
resource "aws_subnet" "public" {
count = "${length(data.aws_availability_zones.available.names)}"
availability_zone = "${var.region}${element(keys(var.public_subnets), count.index)}"
vpc_id = "${aws_vpc.default.id}"
cidr_block = "${element(values(var.public_subnets), count.index)}"
tags {
Name = "${var.name}-public-${var.region}-${element(keys(var.public_subnets), count.index)}"
}
}
resource "aws_subnet" "private" {
count = "${length(data.aws_availability_zones.available.names)}"
availability_zone = "${var.region}${element(keys(var.private_subnets), count.index)}"
vpc_id = "${aws_vpc.default.id}"
cidr_block = "${element(values(var.private_subnets), count.index)}"
tags {
Name = "${var.name}-private-${var.region}-${element(keys(var.private_subnets), count.index)}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment