diff --git a/infra/fargate/Makefile b/infra/fargate/Makefile new file mode 100644 index 0000000..cb42529 --- /dev/null +++ b/infra/fargate/Makefile @@ -0,0 +1,24 @@ +plan=out.plan + +SHELL := /bin/bash + +$(plan): *.tf + source ../secrets/set-env.sh && terraform plan -input=false -out $(plan) + +push: build + source ../secrets/set-env.sh && terraform apply $(plan) + +refresh: + source ../secrets/set-env.sh && terraform apply -refresh-only + +test: + terraform validate + + +rip: + source ../secrets/set-env.sh && terraform destroy + +clean: + rm -f $(plan) + +.PHONY: test build clean push rip diff --git a/infra/alpha.tf b/infra/fargate/alpha.tf similarity index 100% rename from infra/alpha.tf rename to infra/fargate/alpha.tf diff --git a/infra/fargate/backend.tf b/infra/fargate/backend.tf new file mode 100644 index 0000000..909172f --- /dev/null +++ b/infra/fargate/backend.tf @@ -0,0 +1,24 @@ +terraform { + required_version = ">= 0.13" + backend "s3" { + bucket = "project-athens" + key = "infra/fargate/state/build.tfstate" + region = "us-west-1" + encrypt = true + } + required_providers { + aws = { + source = "hashicorp/aws" + version = "4.13.0" + } + } +} + +# Base config for using AWS features w/ Terraform +provider "aws" { + access_key = var.aws_key + secret_key = var.aws_secret + region = var.aws_region + max_retries = 1 +} + diff --git a/infra/cluster-logging.tf b/infra/fargate/cluster-logging.tf similarity index 100% rename from infra/cluster-logging.tf rename to infra/fargate/cluster-logging.tf diff --git a/infra/fargate/data.tf b/infra/fargate/data.tf new file mode 100644 index 0000000..f655ae9 --- /dev/null +++ b/infra/fargate/data.tf @@ -0,0 +1,12 @@ +data "aws_vpc" "athens" { + id = var.vpc_id +} + +data "aws_subnet" "delphi" { + id = "subnet-0a1943f26e4338cf6" +} + +data "aws_subnet" "crete" { + id = "subnet-09302319a6678643f" +} + diff --git a/infra/ecr.tf b/infra/fargate/ecr.tf similarity index 100% rename from infra/ecr.tf rename to infra/fargate/ecr.tf diff --git a/infra/fargate/local.tf b/infra/fargate/local.tf new file mode 100644 index 0000000..2eb5d6c --- /dev/null +++ b/infra/fargate/local.tf @@ -0,0 +1,13 @@ +locals { + # ECR + repos = [ + "reverse-proxy", + ] + buckets = [ + "shockrah.xyz", + "resume.shockrah.xyz" + ] + nginx_name = "${var.athens_prefix}-nginx-static-content" + nginx_hp_check_interval = 300 +} + diff --git a/infra/nginx.tf b/infra/fargate/nginx.tf similarity index 93% rename from infra/nginx.tf rename to infra/fargate/nginx.tf index e33d872..a5e9be6 100644 --- a/infra/nginx.tf +++ b/infra/fargate/nginx.tf @@ -44,7 +44,7 @@ resource "aws_ecs_service" "beta_reverse_proxy" { desired_count = 1 launch_type = "FARGATE" load_balancer { - target_group_arn = aws_lb_target_group.nginx.arn + target_group_arn = var.lb_target_group container_name = local.nginx_name container_port = var.nginx_port } @@ -60,7 +60,4 @@ resource "aws_ecs_service" "beta_reverse_proxy" { var.sg.base_ecs, ] } - depends_on = [ - aws_lb_target_group.nginx - ] } diff --git a/infra/roles.tf b/infra/fargate/roles.tf similarity index 100% rename from infra/roles.tf rename to infra/fargate/roles.tf diff --git a/infra/fargate/variables.tf b/infra/fargate/variables.tf new file mode 100644 index 0000000..7482a0c --- /dev/null +++ b/infra/fargate/variables.tf @@ -0,0 +1,53 @@ +# All variables that are used in various places go here + +######################### General provider specific values + +variable "aws_key" { + description = "Access Key for AWS operations" + type = string + sensitive = true +} + +variable "aws_secret" { + description = "Secret Key for AWS operations" + type = string + sensitive = true +} + +variable "aws_region" { + description = "Region where the VPC is located" + type = string + sensitive = true +} + +variable "vpc_id" { + description = "Project Athens VPC ID" + type = string +} + +variable "athens_prefix" { + description = "Prefix for all things in alpha cluster" + type = string +} + +######################### Nginx reverse proxy vars + +variable "nginx_port" { + description = "Port for shockrah.xyz" + type = number +} + +######################### Nginx reverse proxy vars + +variable "sg" { + type = object({ + base_ecs = string + ecs_web_ingress = string + lb_health_check = string + }) +} + +variable "lb_target_group" { + type = string +} +