Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Options to Enable ECS Service Connect #27

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ No resources.
| <a name="input_link_ecs_to_asg_capacity_provider"></a> [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 |
| <a name="input_name"></a> [name](#input\_name) | Name of the product/project/application | `string` | `""` | no |
| <a name="input_platform_version"></a> [platform\_version](#input\_platform\_version) | Platform version (applicable for FARGATE launch type) | `string` | `"LATEST"` | no |
| <a name="input_service_connect_defaults"></a> [service\_connect\_defaults](#input\_service\_connect\_defaults) | Configures a Service Connect Namespace | `map(string)` | `{}` | no |
| <a name="input_service_deployment_maximum_percent"></a> [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 |
| <a name="input_service_deployment_minimum_healthy_percent"></a> [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 |
| <a name="input_service_map"></a> [service\_map](#input\_service\_map) | A map of services to deploy | `map(any)` | `{}` | no |
Expand Down
4 changes: 3 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions modules/cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ No modules.
| <a name="input_scaling_max_step_size"></a> [scaling\_max\_step\_size](#input\_scaling\_max\_step\_size) | Sets managed scaling max step size | `number` | `10` | no |
| <a name="input_scaling_min_step_size"></a> [scaling\_min\_step\_size](#input\_scaling\_min\_step\_size) | Sets managed scaling min step size | `number` | `1` | no |
| <a name="input_scaling_target_capacity"></a> [scaling\_target\_capacity](#input\_scaling\_target\_capacity) | Sets managed scaling target capacity | `number` | `80` | no |
| <a name="input_service_connect_defaults"></a> [service\_connect\_defaults](#input\_service\_connect\_defaults) | Configures a Service Connect Namespace | `map(string)` | `{}` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | AWS tags to be applied to resources | `map(string)` | `{}` | no |
| <a name="input_termination_protection"></a> [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 |

Expand Down
9 changes: 9 additions & 0 deletions modules/cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
6 changes: 6 additions & 0 deletions modules/cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
################################################################################
Expand Down
3 changes: 2 additions & 1 deletion modules/service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.38.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.18.1 |

## Modules

Expand Down Expand Up @@ -51,6 +51,7 @@ No modules.
| <a name="input_platform_version"></a> [platform\_version](#input\_platform\_version) | Platform version (applicable for FARGATE launch type) | `string` | `"LATEST"` | no |
| <a name="input_propagate_tags"></a> [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 |
| <a name="input_security_groups"></a> [security\_groups](#input\_security\_groups) | Security group IDs to attach to your ECS Service | `list(string)` | `null` | no |
| <a name="input_service_connect_configuration"></a> [service\_connect\_configuration](#input\_service\_connect\_configuration) | The ECS Service Connect configuration to discover and connect to services | `any` | `{}` | no |
| <a name="input_service_placement_constraints"></a> [service\_placement\_constraints](#input\_service\_placement\_constraints) | The rules that are taken into consideration during task placement. Maximum number of placement\_constraints is 10. | <pre>list(object({<br> type = string<br> expression = string<br> }))</pre> | `[]` | no |
| <a name="input_service_registries"></a> [service\_registries](#input\_service\_registries) | Service discovery registries for the service. The maximum number of service\_registries blocks is 1 | `list(any)` | `[]` | no |
| <a name="input_subnets"></a> [subnets](#input\_subnets) | Private subnets for ECS | `list(string)` | `null` | no |
Expand Down
47 changes: 47 additions & 0 deletions modules/service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions modules/service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
################################################################################
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ variable "name" {
default = ""
}

variable "service_connect_defaults" {
description = "Configures a Service Connect Namespace"
type = map(string)
default = {}
}

##############################
# ECS
##############################
Expand Down
Loading