Skip to content

Commit

Permalink
prod environment + optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
mfar committed May 20, 2024
1 parent b617b46 commit 32ef08e
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 2 deletions.
1 change: 1 addition & 0 deletions terraform/environments/development/account.hcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
locals {
aws_profile_name = "dev"
aws_region = "us-east-1"
}
4 changes: 4 additions & 0 deletions terraform/environments/production/account.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
locals {
aws_profile_name = "prod"
aws_region = "us-east-1"
}
23 changes: 23 additions & 0 deletions terraform/environments/production/aurora/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Include the root `terragrunt.hcl` configuration. The root configuration contains settings that are common across all
# components and environments, such as how to configure remote state.
include "root" {
path = find_in_parent_folders()
}

terraform {
source = "../../../modules/postgresql-aurora"
}

locals {
environment_vars = read_terragrunt_config(find_in_parent_folders("env.hcl"))
}

inputs = {
identifier = local.environment_vars.locals.identifier
engine_version = local.environment_vars.locals.engine_version
vpc_id = local.environment_vars.locals.vpc_id
vpc_cidr = local.environment_vars.locals.vpc_cidr
subnet_ids = local.environment_vars.locals.private_subnet_ids
instances = local.environment_vars.locals.instances
database_name = local.environment_vars.locals.database_name
}
55 changes: 55 additions & 0 deletions terraform/environments/production/env.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Set common variables for the environment. This is automatically pulled in in the root terragrunt.hcl configuration to
# feed forward to the child modules.
locals {

//////////////////
//// Shared
//////////////////

environment = "production"
project_name = "identity"
region = "us-east-1"
vpc_id = "vpc-0fc38067c89106d19"
vpc_cidr = "10.1.0.0/16"
private_subnet_ids = ["subnet-0188da42ca87de29f", "subnet-0067bd76934a5a123", "subnet-085eaa7aa58476f7d", "subnet-0b9e4cad47b46a298"]
public_subnet_ids = ["subnet-0e6b30abd06c12017", "subnet-0c98f159030773c7e", "subnet-0ac2b8a4a1d8b58b3", "subnet-0da03025f0d5221d5", ]

//////////////////
//// Aurora
//////////////////

identifier = "${local.environment}-${local.project_name}"
engine_version = "16.2"
database_name = "identitydb" //DatabaseName `identity` cannot be used. It is a reserved word for this engine.
instances = {
1 = {
instance_class = "db.r7g.xlarge"
publicly_accessible = false
db_parameter_group_name = "default.aurora-postgresql16"
}
}

//////////////////
//// ECS
//////////////////

ecs_prefix = "${local.environment}-${local.project_name}"
ssl_certificate_arn = "arn:aws:acm:us-east-1:884078395586:certificate/62f6f766-c92e-4792-a26c-2edfff49194e"
cloudflare_zone_id = "43c53e4c8555e49c1a70efd4c949fb02" #treasure.lol
cloudflare_proxy_enabled = true
desired_count = 3
autoscaling_min_capacity = 3
autoscaling_max_capacity = 9
fargate_cpu = "2048"
fargate_memory = "4096"
task_cpu = "2048"
task_memory = "4096"
dns_name = "tdk-api1"

//////////////////
//// Github OIDC
//////////////////

iam_role_prefix = "${local.environment}-${local.project_name}"
github_project = "TreasureProject/tdk-js" # gitHubOrg/gitHubRepo
}
41 changes: 41 additions & 0 deletions terraform/environments/production/fargate/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Include the root `terragrunt.hcl` configuration. The root configuration contains settings that are common across all
# components and environments, such as how to configure remote state.
include "root" {
path = find_in_parent_folders()
}

terraform {
source = "../../../modules/ecs-fargate"
}

locals {
environment_vars = read_terragrunt_config(find_in_parent_folders("env.hcl"))
}

inputs = {
vpc_id = local.environment_vars.locals.vpc_id
public_subnets = local.environment_vars.locals.public_subnet_ids
private_subnets = local.environment_vars.locals.private_subnet_ids
ecs_prefix = local.environment_vars.locals.ecs_prefix
region = local.environment_vars.locals.region
aurora_secret_name = dependency.aurora.outputs.aurora_secret_name
ssl_certificate_arn = local.environment_vars.locals.ssl_certificate_arn
cloudflare_zone_id = local.environment_vars.locals.cloudflare_zone_id
desired_count = local.environment_vars.locals.desired_count
autoscaling_min_capacity = local.environment_vars.locals.autoscaling_min_capacity
autoscaling_max_capacity = local.environment_vars.locals.autoscaling_max_capacity
dns_name = local.environment_vars.locals.dns_name
cloudflare_proxy_enabled = local.environment_vars.locals.cloudflare_proxy_enabled
fargate_cpu = local.environment_vars.locals.fargate_cpu
fargate_memory = local.environment_vars.locals.fargate_memory
task_cpu = local.environment_vars.locals.task_cpu
task_memory = local.environment_vars.locals.task_memory

}

dependency "aurora" {
config_path = "../aurora"
mock_outputs = {
aurora_secret_name = "${local.environment_vars.locals.identifier}-db"
}
}
19 changes: 19 additions & 0 deletions terraform/environments/production/github-oidc/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Include the root `terragrunt.hcl` configuration. The root configuration contains settings that are common across all
# components and environments, such as how to configure remote state.
include "root" {
path = find_in_parent_folders()
}

terraform {
source = "../../../modules/github-oidc"
}

locals {
environment_vars = read_terragrunt_config(find_in_parent_folders("env.hcl"))
}

inputs = {
prefix = local.environment_vars.locals.iam_role_prefix
github_project = local.environment_vars.locals.github_project
}

2 changes: 2 additions & 0 deletions terraform/environments/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ locals {
account_vars = read_terragrunt_config(find_in_parent_folders("account.hcl"))

aws_profile = local.account_vars.locals.aws_profile_name
region = local.account_vars.locals.aws_region
}

terraform {
Expand Down Expand Up @@ -60,6 +61,7 @@ generate "provider" {
}
provider "aws" {
profile = "${local.aws_profile}"
region = "${local.region}"
}
EOF
Expand Down
4 changes: 2 additions & 2 deletions terraform/modules/ecs-fargate/dns.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ resource "cloudflare_record" "identity" {
name = var.dns_name #"dns_name.treasure.lol"
value = module.alb.dns_name # alb dns address
type = "CNAME"
ttl = 300
proxied = false
ttl = var.dns_ttl
proxied = var.cloudflare_proxy_enabled
}
12 changes: 12 additions & 0 deletions terraform/modules/ecs-fargate/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,16 @@ variable "autoscaling_max_capacity" {
type = number
default = 1
description = "auto scaling max"
}

variable "cloudflare_proxy_enabled" {
type = bool
default = false
description = "enabled cloudflare proxy"
}

variable "dns_ttl" {
type = number
default = 1 # auto
description = "dns record ttl"
}

0 comments on commit 32ef08e

Please sign in to comment.