Skip to content

Instantly share code, notes, and snippets.

@Gunisalvo
Created July 4, 2018 15:52
Show Gist options
  • Save Gunisalvo/2ddf17238090263e0017ccc38e0d6c29 to your computer and use it in GitHub Desktop.
Save Gunisalvo/2ddf17238090263e0017ccc38e0d6c29 to your computer and use it in GitHub Desktop.
UoL: Cloud Computing Networking
variable "student_name" {
default = "<STUDENT_NAME>" #fixme!
}
variable "region" {
default = "us-east-2"
}
provider "aws" {
region = "${var.region}"
}
resource "aws_vpc" "uol_vpc" {
cidr_block = "192.168.0.0/16"
instance_tenancy = "default"
enable_dns_support = true
enable_dns_hostnames = true
tags {
Name = "VPC_CIT523_${var.student_name}"
}
}
resource "aws_subnet" "uol_subnet" {
vpc_id = "${aws_vpc.uol_vpc.id}"
cidr_block = "192.168.171.0/24"
tags {
Name = "SBNET_CIT523_${var.student_name}"
}
}
resource "aws_eip" "uol_eip" {
vpc = true
depends_on = ["aws_internet_gateway.uol_gateway"]
tags {
Name = "GW_IP_CIT523_${var.student_name}"
}
}
resource "aws_internet_gateway" "uol_gateway" {
vpc_id = "${aws_vpc.uol_vpc.id}"
tags {
Name = "IGW_CIT523_${var.student_name}"
}
}
resource "aws_nat_gateway" "uol_nat" {
allocation_id = "${aws_eip.uol_eip.id}"
subnet_id = "${aws_subnet.uol_subnet.id}"
depends_on = ["aws_internet_gateway.uol_gateway"]
tags {
Name = "NAT_CIT523_${var.student_name}"
}
}
resource "aws_route" "internet_access" {
route_table_id = "${aws_vpc.uol_vpc.main_route_table_id}"
destination_cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.uol_gateway.id}"
}
resource "aws_route_table" "uol_route_table" {
vpc_id = "${aws_vpc.uol_vpc.id}"
route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = "${aws_nat_gateway.uol_nat.id}"
}
tags {
Name = "RT1_CIT523_${var.student_name}"
}
}
resource "aws_route_table_association" "uol_route_table_association" {
subnet_id = "${aws_subnet.uol_subnet.id}"
route_table_id = "${aws_route_table.uol_route_table.id}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment