-
-
Save jamestoyer/64d4984e409bb2beea22 to your computer and use it in GitHub Desktop.
File calling terraform module
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 "cidr_block" { | |
default = "10.0.0.0/16" | |
} | |
variable "environment" {} | |
variable "region" { | |
default = "us-east-1" | |
} | |
variable "subnet_addresses" { | |
default { | |
a = "10.0.0.0/20" | |
b = "10.0.16.0/20" | |
d = "10.0.48.0/20" | |
e = "10.0.64.0/20" | |
} | |
} | |
variable "vpc_name" {} | |
resource "aws_vpc" "environment_vpc" { | |
cidr_block = "${var.cidr_block}" | |
enable_dns_support = true | |
enable_dns_hostnames = true | |
tags { | |
Name = "${var.vpc_name}" | |
environment = "${var.environment}" | |
} | |
} | |
resource "aws_internet_gateway" "environment_gateway" { | |
vpc_id = "${aws_vpc.environment_vpc.id}" | |
} | |
resource "aws_route_table" "environment_route_table" { | |
vpc_id = "${aws_vpc.environment_vpc.id}" | |
route { | |
cidr_block = "0.0.0.0/0" | |
gateway_id = "${aws_internet_gateway.environment_gateway.id}" | |
} | |
tags = { | |
Name = "${var.vpc_name} Route Table" | |
environment = "${var.environment}" | |
} | |
} | |
resource "aws_main_route_table_association" "main_route_table_assoc" { | |
vpc_id = "${aws_vpc.environment_vpc.id}" | |
route_table_id = "${aws_route_table.environment_route_table.id}" | |
} | |
resource "aws_subnet" "environment_subnet_a" { | |
vpc_id = "${aws_vpc.environment_vpc.id}" | |
availability_zone = "${var.region}a" | |
cidr_block = "${lookup(var.subnet_addresses, \"a\")}" | |
map_public_ip_on_launch = true | |
tags { | |
Name = "${var.vpc_name} Subnet A" | |
environment = "${var.environment}" | |
} | |
} | |
resource "aws_subnet" "environment_subnet_b" { | |
vpc_id = "${aws_vpc.environment_vpc.id}" | |
availability_zone = "${var.region}b" | |
cidr_block = "${lookup(var.subnet_addresses, \"b\")}" | |
map_public_ip_on_launch = true | |
tags { | |
Name = "${var.vpc_name} Subnet B" | |
environment = "${var.environment}" | |
} | |
} | |
resource "aws_subnet" "environment_subnet_d" { | |
vpc_id = "${aws_vpc.environment_vpc.id}" | |
availability_zone = "${var.region}d" | |
cidr_block = "${lookup(var.subnet_addresses, \"d\")}" | |
map_public_ip_on_launch = true | |
tags { | |
Name = "${var.vpc_name} Subnet D" | |
environment = "${var.environment}" | |
} | |
} | |
resource "aws_subnet" "environment_subnet_e" { | |
vpc_id = "${aws_vpc.environment_vpc.id}" | |
availability_zone = "${var.region}e" | |
cidr_block = "${lookup(var.subnet_addresses, \"e\")}" | |
map_public_ip_on_launch = true | |
tags { | |
Name = "${var.vpc_name} Subnet E" | |
environment = "${var.environment}" | |
} | |
} | |
resource "aws_route_table_association" "environment_zone_a_assoc" { | |
subnet_id = "${aws_subnet.environment_subnet_a.id}" | |
route_table_id = "${aws_route_table.environment_route_table.id}" | |
} | |
resource "aws_route_table_association" "environment_zone_b_assoc" { | |
subnet_id = "${aws_subnet.environment_subnet_b.id}" | |
route_table_id = "${aws_route_table.environment_route_table.id}" | |
} | |
resource "aws_route_table_association" "environment_zone_d_assoc" { | |
subnet_id = "${aws_subnet.environment_subnet_d.id}" | |
route_table_id = "${aws_route_table.environment_route_table.id}" | |
} | |
resource "aws_route_table_association" "environment_zone_e_assoc" { | |
subnet_id = "${aws_subnet.environment_subnet_e.id}" | |
route_table_id = "${aws_route_table.environment_route_table.id}" | |
} | |
output "subnet_a_id" { | |
value = "${aws_subnet.environment_subnet_a.id}" | |
} | |
output "subnet_b_id" { | |
value = "${aws_subnet.environment_subnet_b.id}" | |
} | |
output "subnet_d_id" { | |
value = "${aws_subnet.environment_subnet_d.id}" | |
} | |
output "subnet_e_id" { | |
value = "${aws_subnet.environment_subnet_e.id}" | |
} | |
output "vpc_id" { | |
value = "${aws_vpc.environment_vpc.id}" | |
} |
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 "aws_access_key" {} | |
variable "aws_secret_key" {} | |
variable "aws_region" {} | |
variable "environment" {} | |
variable "vpc_cidr_block" { | |
default = "10.255.0.0/16" | |
} | |
variable "vpc_name" {} | |
variable "vpc_subnet_addresses" { | |
default = { | |
a = "10.255.0.0/20" | |
b = "10.255.16.0/20" | |
d = "10.255.48.0/20" | |
e = "10.255.64.0/20" | |
} | |
} | |
provider "aws" { | |
access_key = "${var.aws_access_key}" | |
secret_key = "${var.aws_secret_key}" | |
region = "${var.aws_region}" | |
} | |
module "new_vpc" { | |
source = "../modules/vpcs/us_east_1" | |
cidr_block = "${var.vpc_cidr_block}" | |
environment = "${var.environment}" | |
subnet_addresses = "${var.vpc_subnet_addresses}" | |
vpc_name = "${var.vpc_name}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment