Skip to content

Commit

Permalink
feat(refactor): major refactor of ad hoc environment modules
Browse files Browse the repository at this point in the history
  • Loading branch information
briancaffey committed Jan 2, 2023
1 parent 617b264 commit 2d95d0b
Show file tree
Hide file tree
Showing 53 changed files with 373 additions and 510 deletions.
71 changes: 40 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,56 +1,65 @@
examples-simple-init:
terraform -chdir=examples/simple init
# commands used for local development

examples-simple-plan:
terraform -chdir=examples/simple plan
tf-fmt:
terraform fmt -recursive

tf-validate:
terraform validate

# ad hoc environment stacks

# ad hoc base
ad-hoc-base-init:
terraform -chdir=examples/ad-hoc/base init

ad-hoc-base-plan:
terraform -chdir=examples/ad-hoc/base plan

examples-simple-apply:
terraform -chdir=examples/simple apply
ad-hoc-base-apply:
terraform -chdir=examples/ad-hoc/base apply

examples-simple: examples-simple-init examples-simple-plan examples-simple-apply
ad-hoc-base-destroy:
terraform -chdir=examples/ad-hoc/base destroy

examples-simple-destroy:
terraform -chdir=examples/simple destroy
# ad hoc app
ad-hoc-app-init:
terraform -chdir=examples/ad-hoc/app init

examples-ad-hoc-init:
terraform -chdir=examples/ad-hoc init -backend-config=backend.config
ad-hoc-app-plan:
terraform -chdir=examples/ad-hoc/app plan

examples-ad-hoc-plan:
terraform -chdir=examples/ad-hoc plan
ad-hoc-app-apply:
terraform -chdir=examples/ad-hoc/app apply

examples-ad-hoc-apply:
terraform -chdir=examples/ad-hoc apply
ad-hoc-app-destroy:
terraform -chdir=examples/ad-hoc/app destroy

# PROD base
# prod environment stacks

examples-prod-base-init:
# prod base

prod-base-init:
terraform -chdir=examples/prod/base init

examples-prod-base-plan:
prod-base-plan:
terraform -chdir=examples/prod/base plan

examples-prod-base-apply:
prod-base-apply:
terraform -chdir=examples/prod/base apply

examples-prod-base-destroy:
prod-base-destroy:
terraform -chdir=examples/prod/base destroy

# PROD app
# prod app

examples-prod-app-init:
prod-app-init:
TF_LOG=ERROR terraform -chdir=examples/prod/app init 2> logs.txt

examples-prod-app-plan:
prod-app-plan:
terraform -chdir=examples/prod/app plan

examples-prod-app-apply:
prod-app-apply:
terraform -chdir=examples/prod/app apply

examples-prod-app-destroy:
prod-app-destroy:
terraform -chdir=examples/prod/app destroy

tf-fmt:
terraform fmt -recursive

tf-validate:
terraform validate
File renamed without changes.
41 changes: 41 additions & 0 deletions examples/ad-hoc/app/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
terraform {
required_version = ">=1.3.6"

required_providers {
aws = {
source = "hashicorp/aws"
version = "4.48.0"
}
}

backend "local" {}
}

provider "aws" {
region = var.region
}

data "terraform_remote_state" "this" {
backend = "local"

config = {
path = "../base/terraform.tfstate"
}
}

module "main" {
source = "../../../modules/ad-hoc/app"

vpc_id = data.terraform_remote_state.this.outputs.vpc_id
assets_bucket_name = data.terraform_remote_state.this.outputs.assets_bucket_name
private_subnet_ids = data.terraform_remote_state.this.outputs.private_subnet_ids
app_sg_id = data.terraform_remote_state.this.outputs.app_sg_id
alb_sg_id = data.terraform_remote_state.this.outputs.alb_sg_id
listener_arn = data.terraform_remote_state.this.outputs.listener_arn
alb_dns_name = data.terraform_remote_state.this.outputs.alb_dns_name
service_discovery_namespace_id = data.terraform_remote_state.this.outputs.service_discovery_namespace_id
rds_address = data.terraform_remote_state.this.outputs.rds_address
domain_name = data.terraform_remote_state.this.outputs.domain_name
base_stack_name = data.terraform_remote_state.this.outputs.base_stack_name
region = var.region
}
3 changes: 3 additions & 0 deletions examples/ad-hoc/app/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "backend_update_script" {
value = module.main.backend_update_command
}
14 changes: 14 additions & 0 deletions examples/ad-hoc/app/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
variable "region" {
default = "us-east-1"
}


##############################################################################
# Frontend
##############################################################################

variable "extra_env_vars" {
description = "User-defined environment variables to pass to the backend service and task containers (api, worker, migrate, etc.)"
type = list(object({ name = string, value = string }))
default = []
}
6 changes: 6 additions & 0 deletions examples/ad-hoc/base/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
terraform.state
terraform.tfstate
terraform.tfvars
.terraform
terraform.tfstate.backup
backend.config
22 changes: 22 additions & 0 deletions examples/ad-hoc/base/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
terraform {
required_version = ">=1.3.6"

required_providers {
aws = {
source = "hashicorp/aws"
version = "4.48.0"
}
}

backend "local" {}
}

provider "aws" {
region = var.region
}

module "main" {
source = "../../../modules/ad-hoc/base"
certificate_arn = var.certificate_arn
domain_name = var.domain_name
}
46 changes: 46 additions & 0 deletions examples/ad-hoc/base/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
output "vpc_id" {
value = module.main.vpc_id
}

output "assets_bucket_name" {
value = module.main.assets_bucket_name
description = "Bucket name used for S3 assets"
}

output "private_subnet_ids" {
value = module.main.private_subnet_ids
}

output "app_sg_id" {
value = module.main.app_sg_id
}

output "alb_sg_id" {
value = module.main.alb_sg_id
}

output "listener_arn" {
value = module.main.listener_arn
}

output "alb_dns_name" {
value = module.main.alb_dns_name
}

output "service_discovery_namespace_id" {
value = module.main.service_discovery_namespace_id
description = "service discovery namespace id"
}

output "rds_address" {
value = module.main.rds_address
description = "address of the RDS instance"
}

output "domain_name" {
value = module.main.domain_name
}

output "base_stack_name" {
value = module.main.base_stack_name
}
13 changes: 13 additions & 0 deletions examples/ad-hoc/base/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
variable "region" {
type = string
default = "us-east-1"
}

variable "certificate_arn" {
type = string
}

variable "domain_name" {
description = "Route53 domain name (e.g. example.com)"
type = string
}
57 changes: 0 additions & 57 deletions examples/ad-hoc/main.tf

This file was deleted.

48 changes: 0 additions & 48 deletions examples/ad-hoc/variables.tf

This file was deleted.

3 changes: 1 addition & 2 deletions examples/prod/app/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ module "main" {
execution_role_arn = data.terraform_remote_state.shared.outputs.execution_role_arn
listener_arn = data.terraform_remote_state.shared.outputs.listener_arn
alb_dns_name = data.terraform_remote_state.shared.outputs.alb_dns_name
ecs_sg_id = data.terraform_remote_state.shared.outputs.ecs_sg_id
alb_default_tg_arn = data.terraform_remote_state.shared.outputs.alb_default_tg_arn
app_sg_id = data.terraform_remote_state.shared.outputs.app_sg_id
private_subnets = data.terraform_remote_state.shared.outputs.private_subnets
public_subnets = data.terraform_remote_state.shared.outputs.public_subnets

Expand Down
10 changes: 3 additions & 7 deletions examples/prod/base/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@ output "alb_dns_name" {
value = module.main.alb_dns_name
}

output "ecs_sg_id" {
value = module.main.ecs_sg_id
output "app_sg_id" {
value = module.main.app_sg_id
}

output "alb_default_tg_arn" {
value = module.main.alb_default_tg_arn
}

output "private_subnets" {
output "private_subnet_ids" {
value = module.main.private_subnets
}

Expand Down
Loading

0 comments on commit 2d95d0b

Please sign in to comment.