diff --git a/README.md b/README.md index 073cb94..10fc901 100644 --- a/README.md +++ b/README.md @@ -356,14 +356,14 @@ module "eventbridge" { | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.13.1 | -| [aws](#requirement\_aws) | >= 4.7 | +| [terraform](#requirement\_terraform) | >= 1.0 | +| [aws](#requirement\_aws) | >= 4.64 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 4.7 | +| [aws](#provider\_aws) | >= 4.64 | ## Modules diff --git a/examples/api-gateway-event-source/README.md b/examples/api-gateway-event-source/README.md index 2ae2a40..2672a52 100644 --- a/examples/api-gateway-event-source/README.md +++ b/examples/api-gateway-event-source/README.md @@ -19,15 +19,15 @@ Note that this example may create resources which cost money. Run `terraform des | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.13.1 | -| [aws](#requirement\_aws) | >= 4.7 | +| [terraform](#requirement\_terraform) | >= 1.0 | +| [aws](#requirement\_aws) | >= 4.64 | | [random](#requirement\_random) | >= 3.0 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 4.7 | +| [aws](#provider\_aws) | >= 4.64 | | [random](#provider\_random) | >= 3.0 | ## Modules diff --git a/examples/api-gateway-event-source/versions.tf b/examples/api-gateway-event-source/versions.tf index c06fd69..9bc2614 100644 --- a/examples/api-gateway-event-source/versions.tf +++ b/examples/api-gateway-event-source/versions.tf @@ -1,10 +1,10 @@ terraform { - required_version = ">= 0.13.1" + required_version = ">= 1.0" required_providers { aws = { source = "hashicorp/aws" - version = ">= 4.7" + version = ">= 4.64" } random = { source = "hashicorp/random" diff --git a/examples/complete/README.md b/examples/complete/README.md index 88629bc..9c9e34b 100644 --- a/examples/complete/README.md +++ b/examples/complete/README.md @@ -19,8 +19,8 @@ Note that this example may create resources which cost money. Run `terraform des | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.13.1 | -| [aws](#requirement\_aws) | >= 4.7 | +| [terraform](#requirement\_terraform) | >= 1.0 | +| [aws](#requirement\_aws) | >= 4.64 | | [null](#requirement\_null) | >= 2.0 | | [random](#requirement\_random) | >= 3.0 | @@ -28,7 +28,7 @@ Note that this example may create resources which cost money. Run `terraform des | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 4.7 | +| [aws](#provider\_aws) | >= 4.64 | | [null](#provider\_null) | >= 2.0 | | [random](#provider\_random) | >= 3.0 | diff --git a/examples/complete/versions.tf b/examples/complete/versions.tf index 576e5e2..cdf3d85 100644 --- a/examples/complete/versions.tf +++ b/examples/complete/versions.tf @@ -1,10 +1,10 @@ terraform { - required_version = ">= 0.13.1" + required_version = ">= 1.0" required_providers { aws = { source = "hashicorp/aws" - version = ">= 4.7" + version = ">= 4.64" } random = { source = "hashicorp/random" diff --git a/examples/default-bus/README.md b/examples/default-bus/README.md index 3325cb1..84046d2 100644 --- a/examples/default-bus/README.md +++ b/examples/default-bus/README.md @@ -19,15 +19,15 @@ Note that this example may create resources which cost money. Run `terraform des | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.13.1 | -| [aws](#requirement\_aws) | >= 4.7 | +| [terraform](#requirement\_terraform) | >= 1.0 | +| [aws](#requirement\_aws) | >= 4.64 | | [random](#requirement\_random) | >= 3.0 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 4.7 | +| [aws](#provider\_aws) | >= 4.64 | | [random](#provider\_random) | >= 3.0 | ## Modules diff --git a/examples/default-bus/versions.tf b/examples/default-bus/versions.tf index c06fd69..9bc2614 100644 --- a/examples/default-bus/versions.tf +++ b/examples/default-bus/versions.tf @@ -1,10 +1,10 @@ terraform { - required_version = ">= 0.13.1" + required_version = ">= 1.0" required_providers { aws = { source = "hashicorp/aws" - version = ">= 4.7" + version = ">= 4.64" } random = { source = "hashicorp/random" diff --git a/examples/with-api-destination/README.md b/examples/with-api-destination/README.md index dfa3e36..ad5289b 100644 --- a/examples/with-api-destination/README.md +++ b/examples/with-api-destination/README.md @@ -19,15 +19,15 @@ Note that this example may create resources which cost money. Run `terraform des | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.13.1 | -| [aws](#requirement\_aws) | >= 4.7 | +| [terraform](#requirement\_terraform) | >= 1.0 | +| [aws](#requirement\_aws) | >= 4.64 | | [random](#requirement\_random) | >= 3.0 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 4.7 | +| [aws](#provider\_aws) | >= 4.64 | | [random](#provider\_random) | >= 3.0 | ## Modules diff --git a/examples/with-api-destination/versions.tf b/examples/with-api-destination/versions.tf index c06fd69..9bc2614 100644 --- a/examples/with-api-destination/versions.tf +++ b/examples/with-api-destination/versions.tf @@ -1,10 +1,10 @@ terraform { - required_version = ">= 0.13.1" + required_version = ">= 1.0" required_providers { aws = { source = "hashicorp/aws" - version = ">= 4.7" + version = ">= 4.64" } random = { source = "hashicorp/random" diff --git a/examples/with-archive/README.md b/examples/with-archive/README.md index c1a1935..a866416 100644 --- a/examples/with-archive/README.md +++ b/examples/with-archive/README.md @@ -19,15 +19,15 @@ Note that this example may create resources which cost money. Run `terraform des | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.13.1 | -| [aws](#requirement\_aws) | >= 4.7 | +| [terraform](#requirement\_terraform) | >= 1.0 | +| [aws](#requirement\_aws) | >= 4.64 | | [random](#requirement\_random) | >= 3.0 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 4.7 | +| [aws](#provider\_aws) | >= 4.64 | | [random](#provider\_random) | >= 3.0 | ## Modules diff --git a/examples/with-archive/versions.tf b/examples/with-archive/versions.tf index c06fd69..9bc2614 100644 --- a/examples/with-archive/versions.tf +++ b/examples/with-archive/versions.tf @@ -1,10 +1,10 @@ terraform { - required_version = ">= 0.13.1" + required_version = ">= 1.0" required_providers { aws = { source = "hashicorp/aws" - version = ">= 4.7" + version = ">= 4.64" } random = { source = "hashicorp/random" diff --git a/examples/with-ecs-scheduling/README.md b/examples/with-ecs-scheduling/README.md index 04378e5..45366bb 100644 --- a/examples/with-ecs-scheduling/README.md +++ b/examples/with-ecs-scheduling/README.md @@ -19,33 +19,31 @@ Note that this example may create resources which cost money. Run `terraform des | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.13.1 | -| [aws](#requirement\_aws) | >= 4.7 | +| [terraform](#requirement\_terraform) | >= 1.0 | +| [aws](#requirement\_aws) | >= 4.64 | | [random](#requirement\_random) | >= 3.0 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 4.7 | +| [aws](#provider\_aws) | >= 4.64 | | [random](#provider\_random) | >= 3.0 | ## Modules | Name | Source | Version | |------|--------|---------| -| [ecs](#module\_ecs) | terraform-aws-modules/ecs/aws | ~> 3.0 | +| [ecs\_cluster](#module\_ecs\_cluster) | terraform-aws-modules/ecs/aws | ~> 5.0 | | [eventbridge](#module\_eventbridge) | ../../ | n/a | ## Resources | Name | Type | |------|------| -| [aws_ecs_service.hello_world](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_service) | resource | -| [aws_ecs_task_definition.hello_world](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition) | resource | | [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource | | [aws_security_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/security_group) | data source | -| [aws_subnet_ids.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet_ids) | data source | +| [aws_subnets.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnets) | data source | | [aws_vpc.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | data source | ## Inputs diff --git a/examples/with-ecs-scheduling/main.tf b/examples/with-ecs-scheduling/main.tf index 08bad27..bbae3ec 100644 --- a/examples/with-ecs-scheduling/main.tf +++ b/examples/with-ecs-scheduling/main.tf @@ -21,8 +21,11 @@ data "aws_security_group" "default" { vpc_id = data.aws_vpc.default.id } -data "aws_subnet_ids" "default" { - vpc_id = data.aws_vpc.default.id +data "aws_subnets" "default" { + filter { + name = "vpc-id" + values = [data.aws_vpc.default.id] + } } #################### @@ -37,7 +40,7 @@ module "eventbridge" { create_role = true role_name = "ecs-eventbridge-${random_pet.this.id}" attach_ecs_policy = true - ecs_target_arns = [aws_ecs_task_definition.hello_world.arn] + ecs_target_arns = [module.ecs_cluster.services["hello-world"].task_definition_arn] # Fire every five minutes rules = { @@ -53,19 +56,38 @@ module "eventbridge" { orders = [ { name = "orders" - arn = module.ecs.ecs_cluster_arn + arn = module.ecs_cluster.cluster_arn attach_role_arn = true ecs_target = { - launch_type = "FARGATE" - task_count = 1 - task_definition_arn = aws_ecs_task_definition.hello_world.arn + # If a capacity_provider_strategy specified, the launch_type parameter must be omitted. + # launch_type = "FARGATE" + task_count = 1 + task_definition_arn = module.ecs_cluster.services["hello-world"].task_definition_arn + enable_ecs_managed_tags = true + tags = { + production = true + } network_configuration = { assign_public_ip = true - subnets = data.aws_subnet_ids.default.ids - security_groups = [data.aws_security_group.default.arn] + subnets = data.aws_subnets.default.ids + security_groups = [data.aws_security_group.default.id] } + + # If a capacity_provider_strategy is specified, the launch_type parameter must be omitted. + # If no capacity_provider_strategy or launch_type is specified, the default capacity provider strategy for the cluster is used. + capacity_provider_strategy = [ + { + capacity_provider = "FARGATE" + base = 1 + weight = 100 + }, + { + capacity_provider = "FARGATE_SPOT" + weight = 100 + } + ] } } ] @@ -76,37 +98,41 @@ module "eventbridge" { # ECS ###### -module "ecs" { +module "ecs_cluster" { source = "terraform-aws-modules/ecs/aws" - version = "~> 3.0" - - name = random_pet.this.id - - capacity_providers = ["FARGATE", "FARGATE_SPOT"] -} - -resource "aws_ecs_service" "hello_world" { - name = "hello_world-${random_pet.this.id}" - cluster = module.ecs.ecs_cluster_id - task_definition = aws_ecs_task_definition.hello_world.arn - - desired_count = 1 + version = "~> 5.0" - deployment_maximum_percent = 100 - deployment_minimum_healthy_percent = 0 -} + cluster_name = random_pet.this.id -resource "aws_ecs_task_definition" "hello_world" { - family = "hello_world-${random_pet.this.id}" + fargate_capacity_providers = { + FARGATE = { + default_capacity_provider_strategy = { + weight = 100 + } + } + FARGATE_SPOT = { + default_capacity_provider_strategy = { + weight = 100 + } + } + } - container_definitions = jsonencode([ - { - name = "hello_world-${random_pet.this.id}", - image = "hello-world", - cpu = 0, - memory = 128 + services = { + hello-world = { + subnet_ids = data.aws_subnets.default.ids + desired_count = 1 + deployment_maximum_percent = 100 + deployment_minimum_healthy_percent = 0 + + container_definitions = { + hello-world = { + image = "hello-world", + cpu = 0, + memory = 128 + } + } } - ]) + } } ################## diff --git a/examples/with-ecs-scheduling/versions.tf b/examples/with-ecs-scheduling/versions.tf index c06fd69..9bc2614 100644 --- a/examples/with-ecs-scheduling/versions.tf +++ b/examples/with-ecs-scheduling/versions.tf @@ -1,10 +1,10 @@ terraform { - required_version = ">= 0.13.1" + required_version = ">= 1.0" required_providers { aws = { source = "hashicorp/aws" - version = ">= 4.7" + version = ">= 4.64" } random = { source = "hashicorp/random" diff --git a/examples/with-lambda-scheduling/README.md b/examples/with-lambda-scheduling/README.md index de5b024..91817df 100644 --- a/examples/with-lambda-scheduling/README.md +++ b/examples/with-lambda-scheduling/README.md @@ -19,8 +19,8 @@ Note that this example may create resources which cost money. Run `terraform des | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.13.1 | -| [aws](#requirement\_aws) | >= 4.7 | +| [terraform](#requirement\_terraform) | >= 1.0 | +| [aws](#requirement\_aws) | >= 4.64 | | [null](#requirement\_null) | >= 2.0 | | [random](#requirement\_random) | >= 3.0 | diff --git a/examples/with-lambda-scheduling/versions.tf b/examples/with-lambda-scheduling/versions.tf index 576e5e2..cdf3d85 100644 --- a/examples/with-lambda-scheduling/versions.tf +++ b/examples/with-lambda-scheduling/versions.tf @@ -1,10 +1,10 @@ terraform { - required_version = ">= 0.13.1" + required_version = ">= 1.0" required_providers { aws = { source = "hashicorp/aws" - version = ">= 4.7" + version = ">= 4.64" } random = { source = "hashicorp/random" diff --git a/examples/with-permissions/README.md b/examples/with-permissions/README.md index 7be537b..81a5cb5 100644 --- a/examples/with-permissions/README.md +++ b/examples/with-permissions/README.md @@ -19,15 +19,15 @@ Note that this example may create resources which cost money. Run `terraform des | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.13.1 | -| [aws](#requirement\_aws) | >= 4.7 | +| [terraform](#requirement\_terraform) | >= 1.0 | +| [aws](#requirement\_aws) | >= 4.64 | | [random](#requirement\_random) | >= 3.0 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 4.7 | +| [aws](#provider\_aws) | >= 4.64 | | [random](#provider\_random) | >= 3.0 | ## Modules diff --git a/examples/with-permissions/versions.tf b/examples/with-permissions/versions.tf index c06fd69..9bc2614 100644 --- a/examples/with-permissions/versions.tf +++ b/examples/with-permissions/versions.tf @@ -1,10 +1,10 @@ terraform { - required_version = ">= 0.13.1" + required_version = ">= 1.0" required_providers { aws = { source = "hashicorp/aws" - version = ">= 4.7" + version = ">= 4.64" } random = { source = "hashicorp/random" diff --git a/main.tf b/main.tf index 2956d1f..8b977cc 100644 --- a/main.tf +++ b/main.tf @@ -103,11 +103,15 @@ resource "aws_cloudwatch_event_target" "this" { ] : [] content { - group = lookup(ecs_target.value, "group", null) - launch_type = lookup(ecs_target.value, "launch_type", null) - platform_version = lookup(ecs_target.value, "platform_version", null) - task_count = lookup(ecs_target.value, "task_count", null) - task_definition_arn = lookup(ecs_target.value, "task_definition_arn", null) + group = lookup(ecs_target.value, "group", null) + launch_type = lookup(ecs_target.value, "launch_type", null) + platform_version = lookup(ecs_target.value, "platform_version", null) + task_count = lookup(ecs_target.value, "task_count", null) + task_definition_arn = ecs_target.value.task_definition_arn + enable_ecs_managed_tags = lookup(ecs_target.value, "enable_ecs_managed_tags", null) + enable_execute_command = lookup(ecs_target.value, "enable_execute_command", null) + propagate_tags = lookup(ecs_target.value, "propagate_tags", null) + tags = lookup(ecs_target.value, "tags", null) dynamic "network_configuration" { for_each = lookup(ecs_target.value, "network_configuration", null) != null ? [ @@ -120,6 +124,34 @@ resource "aws_cloudwatch_event_target" "this" { assign_public_ip = lookup(network_configuration.value, "assign_public_ip", null) } } + + dynamic "capacity_provider_strategy" { + for_each = try(ecs_target.value.capacity_provider_strategy, []) + + content { + capacity_provider = try(capacity_provider_strategy.value.capacity_provider, null) + weight = try(capacity_provider_strategy.value.weight, null) + base = try(capacity_provider_strategy.value.base, null) + } + } + + dynamic "ordered_placement_strategy" { + for_each = try(ecs_target.value.ordered_placement_strategy, []) + + content { + type = try(ordered_placement_strategy.value.type, null) + field = try(ordered_placement_strategy.value.field, null) + } + } + + dynamic "placement_constraint" { + for_each = try(ecs_target.value.placement_constraint, []) + + content { + type = try(placement_constraint.value.type, null) + expression = try(placement_constraint.value.expression, null) + } + } } } diff --git a/versions.tf b/versions.tf index 36060f7..726b2bb 100644 --- a/versions.tf +++ b/versions.tf @@ -1,10 +1,10 @@ terraform { - required_version = ">= 0.13.1" + required_version = ">= 1.0" required_providers { aws = { source = "hashicorp/aws" - version = ">= 4.7" + version = ">= 4.64" } } }