From 895ecbd3612db4f72786c07cd368c487e71c7edb Mon Sep 17 00:00:00 2001 From: Soren Martius Date: Mon, 22 Apr 2024 23:36:46 +0200 Subject: [PATCH] feat: add ecs fargate cluster --- stacks/prod/config.tm.hcl | 7 ++++- .../us-east-1/ecs-fargate-cluster/backend.tf | 11 +++++++ .../us-east-1/ecs-fargate-cluster/main.tf | 24 +++++++++++++++ .../us-east-1/ecs-fargate-cluster/main.tm.hcl | 29 +++++++++++++++++++ .../ecs-fargate-cluster/stack.tm.hcl | 5 ++++ .../ecs-fargate-cluster/terraform.tf | 16 ++++++++++ 6 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 stacks/prod/us-east-1/ecs-fargate-cluster/backend.tf create mode 100644 stacks/prod/us-east-1/ecs-fargate-cluster/main.tf create mode 100644 stacks/prod/us-east-1/ecs-fargate-cluster/main.tm.hcl create mode 100644 stacks/prod/us-east-1/ecs-fargate-cluster/stack.tm.hcl create mode 100644 stacks/prod/us-east-1/ecs-fargate-cluster/terraform.tf diff --git a/stacks/prod/config.tm.hcl b/stacks/prod/config.tm.hcl index 66497ee..b86e2d2 100644 --- a/stacks/prod/config.tm.hcl +++ b/stacks/prod/config.tm.hcl @@ -1,5 +1,6 @@ globals "terraform" "module" "version" { - vpc = "5.7.1" + vpc = "5.7.1" + ecs_cluster = "5.11.1" } globals "vpc" { @@ -8,6 +9,10 @@ globals "vpc" { azs = ["us-east-1a", "us-east-1b", "us-east-1c"] } +globals "ecs" { + cluster_name = "prd-ecs-cluster" +} + globals { tags = { Environment = "prd" diff --git a/stacks/prod/us-east-1/ecs-fargate-cluster/backend.tf b/stacks/prod/us-east-1/ecs-fargate-cluster/backend.tf new file mode 100644 index 0000000..14cd05a --- /dev/null +++ b/stacks/prod/us-east-1/ecs-fargate-cluster/backend.tf @@ -0,0 +1,11 @@ +// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT + +terraform { + backend "s3" { + bucket = "terramate-example-terraform-state-backend" + dynamodb_table = "terraform-lock" + encrypt = true + key = "terraform/stacks/by-id/ac1cbc21-a7d8-451e-a12e-f390bbcc1a51/terraform.tfstate" + region = "us-east-1" + } +} diff --git a/stacks/prod/us-east-1/ecs-fargate-cluster/main.tf b/stacks/prod/us-east-1/ecs-fargate-cluster/main.tf new file mode 100644 index 0000000..185408a --- /dev/null +++ b/stacks/prod/us-east-1/ecs-fargate-cluster/main.tf @@ -0,0 +1,24 @@ +// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT + +module "ecs_cluster" { + cluster_name = "prd-ecs-cluster" + fargate_capacity_providers = { + FARGATE = { + default_capacity_provider_strategy = { + base = 20 + weight = 50 + } + } + FARGATE_SPOT = { + default_capacity_provider_strategy = { + weight = 50 + } + } + } + source = "terraform-aws-modules/ecs/aws//modules/cluster" + tags = { + Environment = "prd" + Terraform = "true" + } + version = "5.11.1" +} diff --git a/stacks/prod/us-east-1/ecs-fargate-cluster/main.tm.hcl b/stacks/prod/us-east-1/ecs-fargate-cluster/main.tm.hcl new file mode 100644 index 0000000..62931ba --- /dev/null +++ b/stacks/prod/us-east-1/ecs-fargate-cluster/main.tm.hcl @@ -0,0 +1,29 @@ +generate_hcl "main.tf" { + inherit = false + + content { + module "ecs_cluster" { + source = "terraform-aws-modules/ecs/aws//modules/cluster" + version = global.terraform.module.version.ecs_cluster + + cluster_name = global.ecs.cluster_name + + # Capacity provider + fargate_capacity_providers = tm_try(global.ecs_fargate.fargate_capacity_providers, { + FARGATE = { + default_capacity_provider_strategy = { + weight = 50 + base = 20 + } + } + FARGATE_SPOT = { + default_capacity_provider_strategy = { + weight = 50 + } + } + }) + + tags = tm_try(global.tags, {}) + } + } +} diff --git a/stacks/prod/us-east-1/ecs-fargate-cluster/stack.tm.hcl b/stacks/prod/us-east-1/ecs-fargate-cluster/stack.tm.hcl new file mode 100644 index 0000000..8829697 --- /dev/null +++ b/stacks/prod/us-east-1/ecs-fargate-cluster/stack.tm.hcl @@ -0,0 +1,5 @@ +stack { + name = "ECS Fargate Cluster Production" + description = "Production ECS Fargate Cluster deployed in us-east-1" + id = "ac1cbc21-a7d8-451e-a12e-f390bbcc1a51" +} diff --git a/stacks/prod/us-east-1/ecs-fargate-cluster/terraform.tf b/stacks/prod/us-east-1/ecs-fargate-cluster/terraform.tf new file mode 100644 index 0000000..c939ef7 --- /dev/null +++ b/stacks/prod/us-east-1/ecs-fargate-cluster/terraform.tf @@ -0,0 +1,16 @@ +// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT + +terraform { + required_version = "1.7.5" +} +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5.31" + } + } +} +provider "aws" { + region = "us-east-1" +}