Skip to content

Commit 35525ef

Browse files
hugoalmeida264boldlinksig
andauthored
chore: add the tags propagation and var.tags to additional resources (#41)
* chore: add the tags propagation and var.tags to additional resources that support it * [Boldlinksig]: Pre-commit auto updated files on 28-05-2024 10:20:21. --------- Co-authored-by: boldlinksig <boldlinksig@boldlink.io>
1 parent ca2c5b4 commit 35525ef

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2828
- feat: expand volume block of the task definition as it has more configuration
2929
- feat: Add example for service security group using a security group id for `service_ingress_sg`
3030

31+
## [1.12.0] - 2024-05-28
32+
### Changes
33+
- feat: Add progate tags to the ecs service
34+
- feat: Add tags to additional resources that support it
35+
3136
## [1.11.0] - 2024-05-28
3237
### Changes
3338
- feat: Add Step Scaling Policy to ECS Service

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ No modules.
277277
| <a name="input_network_configuration"></a> [network\_configuration](#input\_network\_configuration) | (Optional) Network configuration for the service. This parameter is required for task definitions that use the awsvpc network mode to receive their own Elastic Network Interface, and it is not supported for other network modes. | `any` | `{}` | no |
278278
| <a name="input_network_mode"></a> [network\_mode](#input\_network\_mode) | Docker networking mode to use for the containers in the task. Valid values are none, bridge, awsvpc, and host. | `string` | `"none"` | no |
279279
| <a name="input_path"></a> [path](#input\_path) | (May be required) Destination for the health check request. Required for HTTP/HTTPS ALB and HTTP NLB. Only applies to HTTP/HTTPS. | `string` | `"/"` | no |
280+
| <a name="input_propagate_tags"></a> [propagate\_tags](#input\_propagate\_tags) | (Optional) 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 |
280281
| <a name="input_requires_compatibilities"></a> [requires\_compatibilities](#input\_requires\_compatibilities) | Set of launch types required by the task. The valid values are EC2 and FARGATE. | `list(string)` | `[]` | no |
281282
| <a name="input_retention_in_days"></a> [retention\_in\_days](#input\_retention\_in\_days) | Specifies the number of days you want to retain log events in the specified log group. Possible values are: 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653, and 0. If you select 0, the events in the log group are always retained and never expire. | `number` | `3653` | no |
282283
| <a name="input_scalable_dimension"></a> [scalable\_dimension](#input\_scalable\_dimension) | (Required) The scalable dimension of the scalable target. | `string` | `""` | no |

examples/complete/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module "ecs_service_alb" {
4040
path = var.path
4141
tasks_minimum_healthy_percent = 80
4242
tasks_maximum_percent = 150
43+
propagate_tags = "SERVICE"
4344
tags = local.tags
4445

4546
load_balancer = [{

main.tf

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ resource "aws_ecs_service" "service" {
1010
enable_execute_command = var.enable_execute_command
1111
force_new_deployment = var.force_new_deployment
1212
triggers = var.triggers
13+
propagate_tags = var.propagate_tags
1314
tags = var.tags
1415

1516
deployment_controller {
@@ -49,13 +50,15 @@ resource "aws_ecs_task_definition" "this" {
4950
name = var.volume_name
5051
}
5152
container_definitions = var.container_definitions
53+
tags = var.tags
5254
}
5355

5456
# IAM Roles
5557
resource "aws_iam_role" "task_role" {
5658
count = local.create_task_definition && var.task_assume_role_policy != "" ? 1 : 0
5759
name = "${var.name}-ecs-task-role"
5860
assume_role_policy = var.task_assume_role_policy
61+
tags = var.tags
5962
}
6063

6164
resource "aws_iam_role_policy" "task_role_policy" {
@@ -70,6 +73,7 @@ resource "aws_iam_role" "task_execution_role" {
7073
description = "${var.name} task execution role"
7174
name = "${var.name}-task-execution-role"
7275
assume_role_policy = var.task_execution_assume_role_policy
76+
tags = var.tags
7377
}
7478

7579
resource "aws_iam_role_policy" "task_execution_role_policy" {
@@ -86,6 +90,7 @@ resource "aws_kms_key" "cloudwatch_log_group" {
8690
enable_key_rotation = var.enable_key_rotation
8791
policy = local.kms_policy
8892
deletion_window_in_days = var.key_deletion_window_in_days
93+
tags = var.tags
8994
}
9095

9196
resource "aws_cloudwatch_log_group" "main" {
@@ -148,6 +153,7 @@ resource "aws_lb_target_group" "main_alb" {
148153
}
149154

150155
depends_on = [aws_lb.main]
156+
tags = var.tags
151157
}
152158

153159
resource "aws_lb_target_group" "main_nlb" {
@@ -162,7 +168,7 @@ resource "aws_lb_target_group" "main_nlb" {
162168
healthy_threshold = var.healthy_threshold
163169
interval = var.interval
164170
}
165-
171+
tags = var.tags
166172
depends_on = [aws_lb.main]
167173
}
168174

@@ -182,6 +188,7 @@ resource "aws_lb_listener" "http_redirect" {
182188
status_code = "HTTP_301"
183189
}
184190
}
191+
tags = var.tags
185192
lifecycle {
186193
create_before_destroy = true
187194
}
@@ -200,6 +207,7 @@ resource "aws_lb_listener" "https" {
200207
type = var.default_type
201208
target_group_arn = aws_lb_target_group.main_alb[0].arn
202209
}
210+
tags = var.tags
203211
lifecycle {
204212
create_before_destroy = true
205213
}
@@ -216,6 +224,7 @@ resource "aws_lb_listener" "nlb" {
216224
type = var.default_type
217225
target_group_arn = aws_lb_target_group.main_nlb[0].arn
218226
}
227+
tags = var.tags
219228
lifecycle {
220229
create_before_destroy = true
221230
}
@@ -255,6 +264,7 @@ resource "aws_acm_certificate" "main" {
255264
lifecycle {
256265
create_before_destroy = true
257266
}
267+
tags = var.tags
258268
}
259269

260270
# Alb Security group
@@ -366,6 +376,7 @@ resource "aws_appautoscaling_target" "this" {
366376
depends_on = [
367377
aws_ecs_service.service
368378
]
379+
tags = var.tags
369380
}
370381

371382
resource "aws_appautoscaling_policy" "stepscaling" {
@@ -393,7 +404,6 @@ resource "aws_appautoscaling_policy" "stepscaling" {
393404
}
394405
}
395406
}
396-
397407
depends_on = [
398408
aws_appautoscaling_target.this
399409
]

variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,3 +514,10 @@ variable "service_ingress_rules_sg" {
514514
type = list(any)
515515
default = []
516516
}
517+
518+
variable "propagate_tags" {
519+
description = "(Optional) Whether to propagate the tags from the task definition or the service to the tasks. The valid values are SERVICE and TASK_DEFINITION"
520+
type = string
521+
default = "TASK_DEFINITION"
522+
523+
}

0 commit comments

Comments
 (0)