Skip to content

Commit

Permalink
Move code generation to modules (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
soerenmartius authored Apr 24, 2024
2 parents d8d6967 + a143421 commit 0a41d52
Show file tree
Hide file tree
Showing 19 changed files with 117 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
terraform 1.7.5
terramate 0.6.2
terramate 0.6.3
pre-commit 3.6.2
5 changes: 1 addition & 4 deletions imports.tm.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import {
source = "./imports/backend.tm.hcl"
}
import {
source = "./imports/terraform.tm.hcl"
source = "./imports/mixins/*.tm.hcl"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
generate_hcl "main.tf" {
generate_hcl "ecs-fargate-cluster.tf" {
inherit = false

content {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
generate_hcl "main.tf" {
generate_hcl "ecs_fargate_service.tf" {
inherit = false

lets {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
generate_hcl "main.tf" {
generate_hcl "vpc.tf" {
inherit = false

content {
Expand Down
6 changes: 6 additions & 0 deletions stacks/config.tm.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
globals "terraform" "module" "version" {
alb = "9.9.0"
vpc = "5.7.1"
ecs_cluster = "5.11.1"
ecs_service = "5.11.1"
}
4 changes: 4 additions & 0 deletions stacks/prod/config.tm.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ globals "ecs" {
cluster_name = "prd-ecs-cluster"
}

globals "alb" {
name = "production-alb"
}

globals {
tags = {
Environment = "prd"
Expand Down
90 changes: 90 additions & 0 deletions stacks/prod/us-east-1/alb/alb.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

resource "null_resource" "initial_deployment_trigger" {
}
data "aws_vpc" "vpc" {
depends_on = [
null_resource.initial_deployment_trigger,
]
tags = {
Environment = "prd"
Terraform = "true"
}
}
data "aws_subnets" "subnets" {
tags = {
Tier = "public"
}
filter {
name = "vpc-id"
values = [
data.aws_vpc.vpc.id,
]
}
}
module "alb" {
enable_deletion_protection = false
listeners = {
ex_http = {
port = 80
protocol = "HTTP"
forward = {
target_group_key = "ex_ecs"
}
}
}
load_balancer_type = "application"
name = "production-alb"
security_group_egress_rules = {
all = {
ip_protocol = "-1"
cidr_ipv4 = "10.0.0.0/16"
}
}
security_group_ingress_rules = {
all_http = {
from_port = 80
to_port = 80
ip_protocol = "tcp"
cidr_ipv4 = "0.0.0.0/0"
}
}
source = "terraform-aws-modules/alb/aws"
subnets = data.aws_subnets.subnets.ids
tags = {
Environment = "prd"
Terraform = "true"
}
target_groups = {
ex_ecs = {
backend_protocol = "HTTP"
backend_port = 80
target_type = "ip"
deregistration_delay = 5
load_balancing_cross_zone_enabled = true
health_check = {
enabled = true
healthy_threshold = 5
interval = 30
matcher = "200"
path = "/"
port = "traffic-port"
protocol = "HTTP"
timeout = 5
unhealthy_threshold = 2
}
create_attachment = false
}
}
version = "9.9.0"
vpc_id = data.aws_vpc.vpc.id
}
output "security_group_arn" {
value = module.alb.security_group_arn
}
output "security_group_id" {
value = module.alb.security_group_id
}
output "target_group" {
value = module.alb.target_groups.ex_ecs
}
9 changes: 0 additions & 9 deletions stacks/prod/us-east-1/alb/config.tm.hcl

This file was deleted.

3 changes: 3 additions & 0 deletions stacks/prod/us-east-1/alb/import.tm.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {
source = "/imports/modules/alb.tm.hcl"
}
3 changes: 3 additions & 0 deletions stacks/prod/us-east-1/ecs-fargate-cluster/import.tm.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {
source = "/imports/modules/ecs-fargate-cluster.tm.hcl"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {
source = "/imports/modules/ecs-fargate-service.tm.hcl"
}
3 changes: 3 additions & 0 deletions stacks/prod/us-east-1/vpc/import.tm.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {
source = "/imports/modules/vpc.tm.hcl"
}
File renamed without changes.

0 comments on commit 0a41d52

Please sign in to comment.