diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..baa355b --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate* + +# plan files +*.tfplan \ No newline at end of file diff --git a/terraform/dev/.terraform.lock.hcl b/terraform/dev/.terraform.lock.hcl new file mode 100644 index 0000000..7c7c2df --- /dev/null +++ b/terraform/dev/.terraform.lock.hcl @@ -0,0 +1,25 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "5.64.0" + constraints = "~> 5.49" + hashes = [ + "h1:YH4I78rsS9t+YoGMPNzrM53aWi0Rb9Nud16iusrSXMg=", + "zh:1d361f8062c68c9d5ac14b0aa8390709542129b8a9b258e61bbbabc706078b44", + "zh:39dcbf53e3896bdd77071384c8fad4a5862c222c73f3bcf356aca488101f22fd", + "zh:3fad63505f0c5b6f01cc9a6ef02b2226983b79424126a9caf6eb724f654299f4", + "zh:53a8b90d00829cc27e3171a13a8ff1404ee0ea018e73f31d3f916d246cc39613", + "zh:5734c25ef5a04b40f3c1ac5f817f11e42ee3328f74dbc141c0e64afbb0acc834", + "zh:66ea14dbd87f291ce4a877123363933d3ca4022f209f885807a6689c22c24e80", + "zh:68e79654ad0894a3d93134c3377748ace3058d5fad5ec09d1e9a8f8f9b8a47ea", + "zh:7b74259d0ceef0c49cea6bcd171df997b6bad141085bbadded15b440faeb0eee", + "zh:988ebfb5d115dc57070b5abf2e4200ad49cde535f27fd2ba5e34cf9ab336a57f", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:a0a2d4efe2835f0101a0a5024e044a3f28c00e10a8d87fce89c707ef6db75cea", + "zh:aecb3e4b9121771dee9cac7975bf5d0657b5f3e8b57788c455beaeb0f3c48d93", + "zh:d2d3393170b8ef761d3146f39f6788c4a3e876e6c5d4cedca4870c2680688ae6", + "zh:daba5a005c1baa4a5eefbfb86d43ccf880eb5b42e8136f0d932f55886d72bda0", + "zh:de16a6ff3baacdaf9609a0a89aa1913fc19cccaf5ee0fc1c49c5a075baa47c02", + ] +} diff --git a/terraform/dev/igw.tf b/terraform/dev/igw.tf new file mode 100644 index 0000000..f714060 --- /dev/null +++ b/terraform/dev/igw.tf @@ -0,0 +1,19 @@ +resource "aws_internet_gateway" "igw" { + vpc_id = aws_vpc.main.id + + tags = { + Name = "${local.environment}-igw" + environment = "${local.environment}" + } +} + +resource "aws_nat_gateway" "aws_nat_gateway" { + allocation_id = aws_eip.nat.id + subnet_id = aws_subnet.public_zone1.id + + tags = { + "Name" = "${local.environment}-nat" + } + + depends_on = [aws_internet_gateway.igw] +} diff --git a/terraform/dev/locals.tf b/terraform/dev/locals.tf new file mode 100644 index 0000000..773ce4a --- /dev/null +++ b/terraform/dev/locals.tf @@ -0,0 +1,8 @@ +locals { + environment = "dev" + region = "us-east-1" + zone1 = "us-east-1a" + zone2 = "us-east-1b" + eks_name = "dieubernetes" + eks_version = "1.30" +} diff --git a/terraform/dev/nat.tf b/terraform/dev/nat.tf new file mode 100644 index 0000000..0054e15 --- /dev/null +++ b/terraform/dev/nat.tf @@ -0,0 +1,8 @@ +# translates private machine IP addresses into public ones +resource "aws_eip" "nat" { + domain = "vpc" + + tags = { + "Name" = "${local.environment}-nat" + } +} diff --git a/terraform/dev/providers.tf b/terraform/dev/providers.tf new file mode 100644 index 0000000..5a2946e --- /dev/null +++ b/terraform/dev/providers.tf @@ -0,0 +1,14 @@ +provider "aws" { + region = local.region +} + +terraform { + required_version = ">= 1.0" + + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5.64" + } + } +} diff --git a/terraform/dev/routes.tf b/terraform/dev/routes.tf new file mode 100644 index 0000000..be0b8b3 --- /dev/null +++ b/terraform/dev/routes.tf @@ -0,0 +1,45 @@ +resource "aws_route_table" "private" { + vpc_id = aws_vpc.main.id + + route { + cidr_block = "0.0.0.0/0" + nat_gateway_id = aws_nat_gateway.aws_nat_gateway.id + } + + tags = { + "Name" = "${local.environment}-private" + } +} + +resource "aws_route_table" "public" { + vpc_id = aws_vpc.main.id + + route { + cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.igw.id + } + + tags = { + "Name" = "${local.environment}-public" + } +} + +resource "aws_route_table_association" "private_zone1" { + route_table_id = aws_route_table.private.id + subnet_id = aws_subnet.private_zone1.id +} + +resource "aws_route_table_association" "private_zone2" { + route_table_id = aws_route_table.private.id + subnet_id = aws_subnet.private_zone2.id +} + +resource "aws_route_table_association" "public_zone1" { + route_table_id = aws_route_table.public.id + subnet_id = aws_subnet.public_zone1.id +} + +resource "aws_route_table_association" "public_zone2" { + route_table_id = aws_route_table.public.id + subnet_id = aws_subnet.public_zone2.id +} diff --git a/terraform/dev/subnets.tf b/terraform/dev/subnets.tf new file mode 100644 index 0000000..ba240b8 --- /dev/null +++ b/terraform/dev/subnets.tf @@ -0,0 +1,48 @@ +resource "aws_subnet" "private_zone1" { + vpc_id = aws_vpc.main.id + cidr_block = "10.0.0.0/19" + availability_zone = local.zone1 + + tags = { + Name = "${local.environment}-private-${local.zone1}" + "kubernetes.io/role/internal-elb" = "1" # allows us to expose services internally within the vpc + "kubernetes.io/cluster/${local.environment}-${local.eks_name}" = "owned" + } +} + +resource "aws_subnet" "private_zone2" { + vpc_id = aws_vpc.main.id + cidr_block = "10.0.32.0/19" + availability_zone = local.zone2 + tags = { + Name = "${local.environment}-private-${local.zone1}" + "kubernetes.io/role/internal-elb" = "1" # allows us to expose services internally within the vpc + "kubernetes.io/cluster/${local.environment}-${local.eks_name}" = "owned" + } +} + +resource "aws_subnet" "public_zone1" { + vpc_id = aws_vpc.main.id + cidr_block = "10.0.64.0/19" + availability_zone = local.zone1 + map_public_ip_on_launch = true + + tags = { + "Name" = "${local.environment}-public-${local.zone1}" + "kubernetes.io/role/elb" = "1" + "kubernetes.io/cluster/${local.environment}-${local.eks_name}" = "owned" + } +} + +resource "aws_subnet" "public_zone2" { + vpc_id = aws_vpc.main.id + cidr_block = "10.0.96.0/19" + availability_zone = local.zone2 + map_public_ip_on_launch = true + + tags = { + "Name" = "${local.environment}-public-${local.zone2}" + "kubernetes.io/role/elb" = "1" + "kubernetes.io/cluster/${local.environment}-${local.eks_name}" = "owned" + } +} diff --git a/terraform/dev/vpc.tf b/terraform/dev/vpc.tf new file mode 100644 index 0000000..ce65bbf --- /dev/null +++ b/terraform/dev/vpc.tf @@ -0,0 +1,15 @@ +resource "aws_vpc" "main" { + cidr_block = "10.0.0.0/16" + + # requirement for EFS, CSI driver, client VPNs + enable_dns_support = true + enable_dns_hostnames = true + + tags = { + Name = "${local.environment}-main" + environment = "${local.environment}" + } +} + +data "aws_availability_zones" "available" {} +