diff --git a/README.md b/README.md index 3ddb8c4..35d0fd5 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ No resources. | [link\_ecs\_to\_asg\_capacity\_provider](#input\_link\_ecs\_to\_asg\_capacity\_provider) | Specify whether to link ECS to autoscaling group capacity provider | `bool` | `false` | no | | [name](#input\_name) | Name of the product/project/application | `string` | `""` | no | | [platform\_version](#input\_platform\_version) | Platform version (applicable for FARGATE launch type) | `string` | `"LATEST"` | no | +| [service\_connect\_defaults](#input\_service\_connect\_defaults) | Configures a Service Connect Namespace | `map(string)` | `{}` | no | | [service\_deployment\_maximum\_percent](#input\_service\_deployment\_maximum\_percent) | Upper limit (as a percentage of the service's desiredCount) of the number of running tasks that can be running in a service during a deployment. Not valid when using the DAEMON scheduling strategy. | `number` | `200` | no | | [service\_deployment\_minimum\_healthy\_percent](#input\_service\_deployment\_minimum\_healthy\_percent) | Lower limit (as a percentage of the service's desiredCount) of the number of running tasks that must remain running and healthy in a service during a deployment. | `number` | `100` | no | | [service\_map](#input\_service\_map) | A map of services to deploy | `map(any)` | `{}` | no | diff --git a/main.tf b/main.tf index 039c500..eb696ba 100644 --- a/main.tf +++ b/main.tf @@ -42,6 +42,7 @@ module "cluster" { default_capacity_provider_strategy = var.default_capacity_provider_strategy capacity_providers = var.capacity_providers + service_connect_defaults = var.service_connect_defaults tags = var.cluster_tags } @@ -78,7 +79,8 @@ module "service" { task_placement_constraints = var.task_placement_constraints capacity_provider_strategy = var.default_capacity_provider_strategy - tags = var.service_tags + + service_connect_configuration = length(var.service_connect_defaults) > 0 ? try(each.value.service_connect_configuration, {}) : {} } module "service_cpu_autoscaling_policy" { diff --git a/modules/cluster/README.md b/modules/cluster/README.md index ffb7116..09ff0eb 100644 --- a/modules/cluster/README.md +++ b/modules/cluster/README.md @@ -51,6 +51,7 @@ No modules. | [scaling\_max\_step\_size](#input\_scaling\_max\_step\_size) | Sets managed scaling max step size | `number` | `10` | no | | [scaling\_min\_step\_size](#input\_scaling\_min\_step\_size) | Sets managed scaling min step size | `number` | `1` | no | | [scaling\_target\_capacity](#input\_scaling\_target\_capacity) | Sets managed scaling target capacity | `number` | `80` | no | +| [service\_connect\_defaults](#input\_service\_connect\_defaults) | Configures a Service Connect Namespace | `map(string)` | `{}` | no | | [tags](#input\_tags) | AWS tags to be applied to resources | `map(string)` | `{}` | no | | [termination\_protection](#input\_termination\_protection) | Enables or disables container-aware termination of instances in the auto scaling group when scale-in happens. | `bool` | `true` | no | diff --git a/modules/cluster/main.tf b/modules/cluster/main.tf index 4c85bef..b27a043 100644 --- a/modules/cluster/main.tf +++ b/modules/cluster/main.tf @@ -79,5 +79,14 @@ resource "aws_ecs_cluster" "this" { } } } + + dynamic "service_connect_defaults" { + for_each = length(var.service_connect_defaults) > 0 ? [var.service_connect_defaults] : [] + + content { + namespace = service_connect_defaults.value.namespace + } + } + tags = merge(var.tags, { "Name" : var.ecs_cluster_name }) } diff --git a/modules/cluster/variables.tf b/modules/cluster/variables.tf index c411ea6..87b7c39 100644 --- a/modules/cluster/variables.tf +++ b/modules/cluster/variables.tf @@ -10,6 +10,12 @@ variable "ecs_cluster_name" { default = null } +variable "service_connect_defaults" { + description = "Configures a Service Connect Namespace" + type = map(string) + default = {} +} + ################################################################################ # Cloudwatch ################################################################################ diff --git a/modules/service/README.md b/modules/service/README.md index 8a7b32d..f72c753 100644 --- a/modules/service/README.md +++ b/modules/service/README.md @@ -10,7 +10,7 @@ | Name | Version | |------|---------| -| [aws](#provider\_aws) | 5.38.0 | +| [aws](#provider\_aws) | 5.18.1 | ## Modules @@ -51,6 +51,7 @@ No modules. | [platform\_version](#input\_platform\_version) | Platform version (applicable for FARGATE launch type) | `string` | `"LATEST"` | no | | [propagate\_tags](#input\_propagate\_tags) | Specifies whether to propagate the tags from the task definition or the service to the tasks. The valid values are SERVICE and TASK\_DEFINITION | `string` | `"TASK_DEFINITION"` | no | | [security\_groups](#input\_security\_groups) | Security group IDs to attach to your ECS Service | `list(string)` | `null` | no | +| [service\_connect\_configuration](#input\_service\_connect\_configuration) | The ECS Service Connect configuration to discover and connect to services | `any` | `{}` | no | | [service\_placement\_constraints](#input\_service\_placement\_constraints) | The rules that are taken into consideration during task placement. Maximum number of placement\_constraints is 10. |
list(object({
type = string
expression = string
}))
| `[]` | no | | [service\_registries](#input\_service\_registries) | Service discovery registries for the service. The maximum number of service\_registries blocks is 1 | `list(any)` | `[]` | no | | [subnets](#input\_subnets) | Private subnets for ECS | `list(string)` | `null` | no | diff --git a/modules/service/main.tf b/modules/service/main.tf index bfb5332..c06781a 100644 --- a/modules/service/main.tf +++ b/modules/service/main.tf @@ -119,6 +119,53 @@ resource "aws_ecs_service" "this" { } } + dynamic "service_connect_configuration" { + for_each = length(var.service_connect_configuration) > 0 ? [var.service_connect_configuration] : [] + + content { + enabled = try(service_connect_configuration.value.enabled, true) + + dynamic "log_configuration" { + for_each = try([service_connect_configuration.value.log_configuration], []) + + content { + log_driver = try(log_configuration.value.log_driver, null) + options = try(log_configuration.value.options, null) + + dynamic "secret_option" { + for_each = try(log_configuration.value.secret_option, []) + + content { + name = secret_option.value.name + value_from = secret_option.value.value_from + } + } + } + } + + namespace = lookup(service_connect_configuration.value, "namespace", null) + + dynamic "service" { + for_each = try([service_connect_configuration.value.service], []) + + content { + + dynamic "client_alias" { + for_each = try([service.value.client_alias], []) + + content { + dns_name = try(client_alias.value.dns_name, null) + port = client_alias.value.port + } + } + + discovery_name = try(service.value.discovery_name, null) + ingress_port_override = try(service.value.ingress_port_override, null) + port_name = service.value.port_name + } + } + } + } dynamic "ordered_placement_strategy" { for_each = var.ordered_placement_strategy diff --git a/modules/service/variables.tf b/modules/service/variables.tf index 88b38f6..a819a7b 100644 --- a/modules/service/variables.tf +++ b/modules/service/variables.tf @@ -137,6 +137,12 @@ variable "capacity_provider_strategy" { default = [] } +variable "service_connect_configuration" { + description = "The ECS Service Connect configuration to discover and connect to services" + type = any + default = {} +} + ################################################################################ # ECS Task Definition ################################################################################ diff --git a/variables.tf b/variables.tf index d37eaf9..0e0a3ff 100644 --- a/variables.tf +++ b/variables.tf @@ -4,6 +4,12 @@ variable "name" { default = "" } +variable "service_connect_defaults" { + description = "Configures a Service Connect Namespace" + type = map(string) + default = {} +} + ############################## # ECS ##############################