Skip to content

Commit 542e4b1

Browse files
Added Propagate tags and ecs managed tags (#6)
1 parent ca71368 commit 542e4b1

File tree

5 files changed

+35
-13
lines changed

5 files changed

+35
-13
lines changed

EXAMPLE.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ Below is an examples of calling this module.
66
module "ecs_service" {
77
source = "./ecs-service"
88
ecs_cluster_id = cluster_name
9-
container_port = 80
109
name = "demo-ecs-service"
1110
task_definition_arn = ecs_task_definition_arn
12-
target_groups_arn = [
13-
target_group_arn
14-
]
11+
load_balancer = {
12+
target_group_arn = target_group_arn
13+
container_port = 80
14+
container_name = "demo-ecs-service"
15+
}
1516
desired_task_count = 1
1617
autoscaling = true # Set it false, if you don't require autoscaling
1718
autoscaling_policy = [

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,30 @@ No modules.
3030

3131
| Name | Description | Type | Default | Required |
3232
|------|-------------|------|---------|:--------:|
33-
| <a name="input_autoscaling"></a> [autoscaling](#input\_autoscaling) | Autoscaling enabled | `bool` | n/a | yes |
33+
| <a name="input_autoscaling"></a> [autoscaling](#input\_autoscaling) | Autoscaling enabled | `bool` | `false` | no |
3434
| <a name="input_autoscaling_policy"></a> [autoscaling\_policy](#input\_autoscaling\_policy) | Autoscaling target value for CPU/Memory | <pre>list(object({<br> name = string<br> scale_in_cooldown = number<br> scale_out_cooldown = number<br> target_value = number<br> predefined_metric_type = string<br> }))</pre> | `[]` | no |
35-
| <a name="input_capacity_provider_strategy"></a> [capacity\_provider\_strategy](#input\_capacity\_provider\_strategy) | proper weights to associate to Fargate & Fargate spot | `map(number)` | n/a | yes |
36-
| <a name="input_container_port"></a> [container\_port](#input\_container\_port) | ECS container port | `number` | n/a | yes |
35+
| <a name="input_capacity_provider_strategy"></a> [capacity\_provider\_strategy](#input\_capacity\_provider\_strategy) | proper weights to associate to Fargate & Fargate spot | `map(number)` | `{}` | no |
3736
| <a name="input_desired_task_count"></a> [desired\_task\_count](#input\_desired\_task\_count) | ECS desired task count to be running | `number` | n/a | yes |
3837
| <a name="input_ecs_cluster_id"></a> [ecs\_cluster\_id](#input\_ecs\_cluster\_id) | ECS cluster id | `string` | n/a | yes |
38+
| <a name="input_enable_ecs_managed_tags"></a> [enable\_ecs\_managed\_tags](#input\_enable\_ecs\_managed\_tags) | Specifies whether to enable Amazon ECS managed tags for the tasks within the service. | `bool` | `false` | no |
3939
| <a name="input_health_check_grace_period_seconds"></a> [health\_check\_grace\_period\_seconds](#input\_health\_check\_grace\_period\_seconds) | Task warm up time before health checks in seconds | `number` | `0` | no |
40+
| <a name="input_load_balancer"></a> [load\_balancer](#input\_load\_balancer) | Load balancer config | `map(any)` | `{}` | no |
4041
| <a name="input_max_autoscaling_task_count"></a> [max\_autoscaling\_task\_count](#input\_max\_autoscaling\_task\_count) | Maximum task count in autoscaling | `number` | `5` | no |
41-
| <a name="input_min_autoscaling_task_count"></a> [min\_autoscaling\_task\_count](#input\_min\_autoscaling\_task\_count) | Minimum autoscaling task count | `number` | 1 | no |
42-
| <a name="input_service_connect_configuration"></a> [service\_connect\_configuration](#input\_service\_connect\_configuration) | Service Connect Configuration | `map(any)` | n/a | no |
42+
| <a name="input_min_autoscaling_task_count"></a> [min\_autoscaling\_task\_count](#input\_min\_autoscaling\_task\_count) | Minimum task count in autoscaling | `number` | `1` | no |
4343
| <a name="input_name"></a> [name](#input\_name) | ECS task definition name | `string` | n/a | yes |
44+
| <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` | n/a | yes |
4445
| <a name="input_security_group_ids"></a> [security\_group\_ids](#input\_security\_group\_ids) | ECS security group id | `list(any)` | n/a | yes |
46+
| <a name="input_service_connect_config"></a> [service\_connect\_config](#input\_service\_connect\_config) | Service connect configuration | `map(any)` | `{}` | no |
4547
| <a name="input_subnets"></a> [subnets](#input\_subnets) | VPC subnets id | `list(any)` | n/a | yes |
4648
| <a name="input_tags"></a> [tags](#input\_tags) | A mapping of tags to assign to all resources | `map(string)` | `{}` | no |
47-
| <a name="input_target_groups_arn"></a> [target\_groups\_arn](#input\_target\_groups\_arn) | Target groups arn | `list(any)` | `[]` | no |
4849
| <a name="input_task_definition_arn"></a> [task\_definition\_arn](#input\_task\_definition\_arn) | ECS task definition arn | `string` | n/a | yes |
4950

5051
## Outputs
5152

5253
| Name | Description |
5354
|------|-------------|
54-
| <a name="output_service_name"></a> [service\_name](#output\_service\_name) | n/a |
55+
| <a name="output_service_name"></a> [service\_name](#output\_service\_name) | n/a |
56+
57+
## License
58+
59+
Apache 2 Licensed. See [LICENSE](https://github.com/TechHoldingLLC/terraform-aws-ecs-service/blob/main/LICENSE) for full details.

autoscaling.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
resource "aws_appautoscaling_target" "autoscaling" {
66
count = var.autoscaling ? 1 : 0
77
max_capacity = var.max_autoscaling_task_count
8-
min_capacity = min(var.min_autoscaling_task_count,var.desired_task_count)
8+
min_capacity = min(var.min_autoscaling_task_count, var.desired_task_count)
99
resource_id = "service/${aws_ecs_service.service.cluster}/${aws_ecs_service.service.name}"
1010
role_arn = "arn:${local.aws_partition}:iam::${local.account_id}:role/aws-service-role/ecs.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_ECSService"
1111
scalable_dimension = "ecs:service:DesiredCount"

ecs.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ resource "aws_ecs_service" "service" {
6565
tags = merge(var.tags, {
6666
Name = var.name
6767
})
68+
# If propagate tags are set to NONE, the ECS task will not have any tags. With propagate tags, we can specify whether the task will inherit tags from the service or the task definition.
69+
propagate_tags = var.propagate_tags
70+
#If ECS managed tags are enabled, the ECS task will automatically be tagged with the ECS service and cluster names.
71+
enable_ecs_managed_tags = var.enable_ecs_managed_tags
6872

6973
lifecycle {
70-
ignore_changes = [desired_count]
74+
ignore_changes = [desired_count]
7175
}
7276
}

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,16 @@ variable "service_connect_config" {
9090
description = "Service connect configuration"
9191
type = map(any)
9292
default = {}
93+
}
94+
95+
variable "propagate_tags" {
96+
description = "Specifies whether to propagate the tags from the task definition or the service to the tasks. The valid values are SERVICE, TASK_DEFINITION and NONE"
97+
type = string
98+
default = "TASK_DEFINITION"
99+
}
100+
101+
variable "enable_ecs_managed_tags" {
102+
description = "Specifies whether to enable Amazon ECS managed tags for the tasks within the service."
103+
type = bool
104+
default = true
93105
}

0 commit comments

Comments
 (0)