Skip to content

Instantly share code, notes, and snippets.

@hervekhg
Created September 18, 2019 14:26
Show Gist options
  • Save hervekhg/21c701778690c7decc2b96549ce71ff1 to your computer and use it in GitHub Desktop.
Save hervekhg/21c701778690c7decc2b96549ce71ff1 to your computer and use it in GitHub Desktop.
# --------------------------------------------------------------
#### Step 1: Create VPC
# --------------------------------------------------------------
resource "aws_vpc" "hg_vpc" {
cidr_block = "10.20.0.0/16"
enable_dns_hostnames = true
enable_dns_support = true
tags = {
BillingBusinessApp = "hg-devops"
Name = "hg-devops-vpc"
}
}
# --------------------------------------------------------------
#### Step 2: Create Subnets
# --------------------------------------------------------------
resource "aws_subnet" "hg_subnet_01" {
cidr_block = "10.20.10.0/24"
vpc_id = "${aws_vpc.hg_vpc.id}"
availability_zone = "eu-west-1a"
tags = {
BillingBusinessApp = "hg-devops"
Name = "hg-devops-subnet01"
}
}
resource "aws_subnet" "hg_subnet_02" {
cidr_block = "10.20.20.0/24"
vpc_id = "${aws_vpc.hg_vpc.id}"
availability_zone = "eu-west-1b"
tags = {
BillingBusinessApp = "hg-devops"
Name = "hg-devops-subnet02"
}
}
# --------------------------------------------------------------
#### Step 3: Create Internet Gateway
# --------------------------------------------------------------
resource "aws_internet_gateway" "hg-igw" {
vpc_id = "${aws_vpc.hg_vpc.id}"
tags = {
BillingBusinessApp = "hg-devops"
Name = "hg-devops-igw"
}
}
# --------------------------------------------------------------
#### Step 4: Create Route table
# --------------------------------------------------------------
resource "aws_route_table" "hg-route-table" {
vpc_id = "${aws_vpc.hg_vpc.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.hg-igw.id}"
}
tags = {
BillingBusinessApp = "hg-devops"
Name = "hg-devops-routetable"
}
}
# --------------------------------------------------------------
#### Step 5: Associate route table with subnets
# --------------------------------------------------------------
resource "aws_route_table_association" "hg-route-association1" {
route_table_id = "${aws_route_table.hg-route-table.id}"
subnet_id = "${aws_subnet.hg_subnet_01.id}"
}
resource "aws_route_table_association" "hg-route-association2" {
route_table_id = "${aws_route_table.hg-route-table.id}"
subnet_id = "${aws_subnet.hg_subnet_02.id}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment