From dae529d8be6a9e8315186b84683f5585d8491681 Mon Sep 17 00:00:00 2001 From: Abdul Wahid Date: Mon, 24 Jul 2023 16:05:48 +0100 Subject: [PATCH] Upgrade to 5.x + Fixes (#74) * chore: upgrade to 5.x compatibility * fix: setting container_name is now mandatory to utilise multiple container names set externally to module * fix: protocol set to HTTP by default * chore: changelog + add versions files for examples * chore: set examples to 5 to demonstrate compatability --- .pre-commit-config.yaml | 2 +- CHANGELOG.md | 28 ++++++++++++------- README.md | 4 +-- examples/core/main.tf | 13 +-------- examples/core/versions.tf | 14 ++++++++++ .../external-container-definitions/main.tf | 18 ++---------- .../versions.tf | 14 ++++++++++ examples/fargate-efs/main.tf | 15 ++-------- examples/fargate-efs/versions.tf | 14 ++++++++++ examples/fargate-spot/main.tf | 12 -------- examples/fargate-spot/versions.tf | 14 ++++++++++ examples/multiple-target-groups/main.tf | 14 ++-------- examples/multiple-target-groups/versions.tf | 14 ++++++++++ main.tf | 4 +-- versions.tf | 5 +++- 15 files changed, 105 insertions(+), 80 deletions(-) create mode 100644 examples/core/versions.tf create mode 100644 examples/external-container-definitions/versions.tf create mode 100644 examples/fargate-efs/versions.tf create mode 100644 examples/fargate-spot/versions.tf create mode 100644 examples/multiple-target-groups/versions.tf diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index af2d7ae..8a512ab 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: args: ['--allow-missing-credentials'] - id: trailing-whitespace - repo: https://github.com/antonbabenko/pre-commit-terraform - rev: v1.77.2 + rev: v1.81.0 hooks: - id: terraform_fmt - id: terraform_docs diff --git a/CHANGELOG.md b/CHANGELOG.md index db48098..4775f09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,15 +5,21 @@ All notable changes to this project will be documented in this file. ## [Unreleased] -- Comment about 'target_type' for Fargate -- Revert container name to original -- Remove square brackets as input is a list -- Lint fixes -- Turn cloudwatch logging optional - fix -- Turn cloudwatch logging optional -- chore: Update documentation -- Turn cloudwatch logging optional -- Refactored container definitions out of module +- fix: protocol set to HTTP by default +- fix: setting container_name is now mandatory to utilise multiple container names set externally to module +- chore: upgrade to 5.x compatibility + + + +## [7.0.0] - 2023-04-12 + +- Refactored container definitions out of module ([#69](https://github.com/umotif-public/terraform-aws-ecs-fargate/issues/69)) + + + +## [6.7.1] - 2023-03-28 + +- Make egress rule configurable ([#71](https://github.com/umotif-public/terraform-aws-ecs-fargate/issues/71)) @@ -272,7 +278,9 @@ All notable changes to this project will be documented in this file. - Initial commit -[Unreleased]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.7.0...HEAD +[Unreleased]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/7.0.0...HEAD +[7.0.0]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.7.1...7.0.0 +[6.7.1]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.7.0...6.7.1 [6.7.0]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.6.0...6.7.0 [6.6.0]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.5.2...6.6.0 [6.5.2]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.5.1...6.5.2 diff --git a/README.md b/README.md index 06143f9..5987e2a 100644 --- a/README.md +++ b/README.md @@ -85,13 +85,13 @@ Module managed by [uMotif](https://github.com/umotif-public/). | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 1.0.11 | -| [aws](#requirement\_aws) | >= 4.6.0, < 5.0.0 | +| [aws](#requirement\_aws) | >= 4.6.0 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 4.6.0, < 5.0.0 | +| [aws](#provider\_aws) | >= 4.6.0 | ## Modules diff --git a/examples/core/main.tf b/examples/core/main.tf index 9a548a3..80bbebb 100644 --- a/examples/core/main.tf +++ b/examples/core/main.tf @@ -1,15 +1,3 @@ -terraform { - required_version = ">= 1.0.11" - - required_providers { - aws = ">= 4.6.0" - } -} - -provider "aws" { - region = "eu-west-1" -} - ##### # VPC and subnets ##### @@ -116,6 +104,7 @@ module "fargate" { { target_group_name = "tg-example" container_port = 80 + container_name = "ecs-fargate-example" # should be equal to container_name in container definition } ] diff --git a/examples/core/versions.tf b/examples/core/versions.tf new file mode 100644 index 0000000..ec7cbd1 --- /dev/null +++ b/examples/core/versions.tf @@ -0,0 +1,14 @@ +terraform { + required_version = "1.0.11" + + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5" + } + } +} + +provider "aws" { + region = "eu-west-1" +} diff --git a/examples/external-container-definitions/main.tf b/examples/external-container-definitions/main.tf index 4b06de5..794d9c0 100644 --- a/examples/external-container-definitions/main.tf +++ b/examples/external-container-definitions/main.tf @@ -1,15 +1,3 @@ -terraform { - required_version = ">= 1.0.11" - - required_providers { - aws = ">= 4.8.0" - } -} - -provider "aws" { - region = "eu-west-1" -} - ##### # VPC and subnets ##### @@ -48,7 +36,7 @@ resource "aws_ecs_cluster_capacity_providers" "cluster" { module "container_1" { source = "cloudposse/ecs-container-definition/aws" - version = "0.58.2" + version = "0.60.0" container_name = "example" container_image = "hello-world:latest" @@ -65,7 +53,7 @@ module "container_1" { module "container_2" { source = "cloudposse/ecs-container-definition/aws" - version = "0.58.2" + version = "0.60.0" container_name = "example-2" container_image = "hello-world:latest" @@ -164,7 +152,7 @@ module "fargate" { target_groups = [ { - container_name = "example" + container_name = "example" # should be equal to container_name in container definition target_group_name = "tg-example" container_port = 80 } diff --git a/examples/external-container-definitions/versions.tf b/examples/external-container-definitions/versions.tf new file mode 100644 index 0000000..b486525 --- /dev/null +++ b/examples/external-container-definitions/versions.tf @@ -0,0 +1,14 @@ +terraform { + required_version = ">= 1.3.0" + + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5" + } + } +} + +provider "aws" { + region = "eu-west-1" +} diff --git a/examples/fargate-efs/main.tf b/examples/fargate-efs/main.tf index 0578dff..5fc1313 100644 --- a/examples/fargate-efs/main.tf +++ b/examples/fargate-efs/main.tf @@ -1,15 +1,3 @@ -terraform { - required_version = ">= 1.0.11" - - required_providers { - aws = ">= 4.8.0" - } -} - -provider "aws" { - region = "eu-west-1" -} - ##### # VPC and subnets ##### @@ -86,7 +74,7 @@ resource "aws_efs_file_system" "efs" { # ECS cluster and fargate ##### resource "aws_ecs_cluster" "cluster" { - name = "ecs-spot-test" + name = "ecs-efs-test" setting { name = "containerInsights" value = "disabled" @@ -124,6 +112,7 @@ module "fargate" { { target_group_name = "efs-example" container_port = 80 + container_name = "ecs-fargate-example" } ] diff --git a/examples/fargate-efs/versions.tf b/examples/fargate-efs/versions.tf new file mode 100644 index 0000000..4b6f4ac --- /dev/null +++ b/examples/fargate-efs/versions.tf @@ -0,0 +1,14 @@ +terraform { + required_version = ">= 1.0.11" + + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5" + } + } +} + +provider "aws" { + region = "eu-west-1" +} diff --git a/examples/fargate-spot/main.tf b/examples/fargate-spot/main.tf index 4deee31..575a187 100644 --- a/examples/fargate-spot/main.tf +++ b/examples/fargate-spot/main.tf @@ -1,15 +1,3 @@ -terraform { - required_version = ">= 1.0.11" - - required_providers { - aws = ">= 4.6.0" - } -} - -provider "aws" { - region = "eu-west-1" -} - ##### # VPC and subnets ##### diff --git a/examples/fargate-spot/versions.tf b/examples/fargate-spot/versions.tf new file mode 100644 index 0000000..4b6f4ac --- /dev/null +++ b/examples/fargate-spot/versions.tf @@ -0,0 +1,14 @@ +terraform { + required_version = ">= 1.0.11" + + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5" + } + } +} + +provider "aws" { + region = "eu-west-1" +} diff --git a/examples/multiple-target-groups/main.tf b/examples/multiple-target-groups/main.tf index f100e19..e5e20f4 100644 --- a/examples/multiple-target-groups/main.tf +++ b/examples/multiple-target-groups/main.tf @@ -1,15 +1,3 @@ -terraform { - required_version = ">= 1.0.11" - - required_providers { - aws = ">= 4.6.0" - } -} - -provider "aws" { - region = "eu-west-1" -} - ##### # VPC and subnets ##### @@ -145,10 +133,12 @@ module "fargate" { { target_group_name = "external-alb" container_port = 443 + container_name = "ecs-fargate-example" }, { target_group_name = "internal-alb" container_port = 80 + container_name = "ecs-fargate-example" } ] diff --git a/examples/multiple-target-groups/versions.tf b/examples/multiple-target-groups/versions.tf new file mode 100644 index 0000000..4b6f4ac --- /dev/null +++ b/examples/multiple-target-groups/versions.tf @@ -0,0 +1,14 @@ +terraform { + required_version = ">= 1.0.11" + + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5" + } + } +} + +provider "aws" { + region = "eu-west-1" +} diff --git a/main.tf b/main.tf index a5aff39..c03adf7 100644 --- a/main.tf +++ b/main.tf @@ -122,7 +122,7 @@ resource "aws_lb_target_group" "task" { interval = lookup(health_check.value, "interval", 30) path = lookup(health_check.value, "path", "/") port = lookup(health_check.value, "port", "traffic-port") - protocol = lookup(health_check.value, "protocol", "TCP") + protocol = lookup(health_check.value, "protocol", "HTTP") timeout = lookup(health_check.value, "timeout", 5) healthy_threshold = lookup(health_check.value, "healthy_threshold", 5) unhealthy_threshold = lookup(health_check.value, "unhealthy_threshold", 2) @@ -292,7 +292,7 @@ resource "aws_ecs_service" "service" { dynamic "load_balancer" { for_each = var.load_balanced ? var.target_groups : [] content { - container_name = var.container_name != "" ? var.container_name : var.name_prefix + container_name = try(load_balancer.value, "container_name") != "" ? lookup(load_balancer.value, "container_name") : var.name_prefix container_port = lookup(load_balancer.value, "container_port", var.task_container_port) target_group_arn = aws_lb_target_group.task[lookup(load_balancer.value, "target_group_name")].arn } diff --git a/versions.tf b/versions.tf index 978475c..71fad67 100644 --- a/versions.tf +++ b/versions.tf @@ -2,6 +2,9 @@ terraform { required_version = ">= 1.0.11" required_providers { - aws = ">= 4.6.0, < 5.0.0" + aws = { + source = "hashicorp/aws" + version = ">= 4.6.0" + } } }