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

feat: add option to pin service to task def revision #331

Merged
merged 5 commits into from
Nov 22, 2024
Merged
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
2 changes: 1 addition & 1 deletion service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ No modules.
| <a name="input_ephemeral_storage_size_in_gib"></a> [ephemeral\_storage\_size\_in\_gib](#input\_ephemeral\_storage\_size\_in\_gib) | The size of the ephemeral storage to use for the task definition | `number` | `30` | no |
| <a name="input_force_new_deployment"></a> [force\_new\_deployment](#input\_force\_new\_deployment) | Whether to force a new deployment of the service | `bool` | `false` | no |
| <a name="input_health_check_grace_period_seconds"></a> [health\_check\_grace\_period\_seconds](#input\_health\_check\_grace\_period\_seconds) | The grace period to allow for healthy instances to warm up before checking them | `number` | `0` | no |
| <a name="input_ignore_changes"></a> [ignore\_changes](#input\_ignore\_changes) | Whether to ignore changes to the service, task definition, container definition | `bool` | n/a | yes |
| <a name="input_name"></a> [name](#input\_name) | The name of the ECS service | `string` | n/a | yes |
| <a name="input_pin_task_definition_revision"></a> [pin\_task\_definition\_revision](#input\_pin\_task\_definition\_revision) | The revision of the task definition to use | `number` | `0` | no |
| <a name="input_security_groups"></a> [security\_groups](#input\_security\_groups) | A list of security group IDs to associate with the service | `list(string)` | n/a | yes |
| <a name="input_service_load_balancers"></a> [service\_load\_balancers](#input\_service\_load\_balancers) | A list of load balancers to associate with the service | <pre>list(object({<br/> container_name = string<br/> container_port = number<br/> elb_name = optional(string)<br/> target_group_arn = string<br/> }))</pre> | n/a | yes |
| <a name="input_service_role_arn"></a> [service\_role\_arn](#input\_service\_role\_arn) | The ARN of the IAM role to use for the service | `string` | n/a | yes |
Expand Down
6 changes: 3 additions & 3 deletions service/service.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resource "aws_ecs_service" "default" {

cluster = var.cluster_arn

task_definition = aws_ecs_task_definition.default.arn
task_definition = var.pin_task_definition_revision != 0 ? "${aws_ecs_task_definition.default.arn_without_revision}:${var.pin_task_definition_revision}" : aws_ecs_task_definition.default.arn

launch_type = "FARGATE"
network_configuration {
Expand All @@ -20,8 +20,8 @@ resource "aws_ecs_service" "default" {

force_new_deployment = var.force_new_deployment
triggers = var.force_new_deployment ? {
update = plantimestamp() # force update in-place every apply that has force_new_deployment set to true
} : null
redeployment = plantimestamp() # force update in-place every apply that has force_new_deployment set to true
} : {}

dynamic "load_balancer" {
for_each = var.service_load_balancers
Expand Down
11 changes: 6 additions & 5 deletions service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ variable "container_definitions" {
sensitive = false
}

variable "ignore_changes" {
type = bool
description = "Whether to ignore changes to the service, task definition, container definition"
}

variable "efs_volumes" {
type = list(object({
host_path = string
Expand Down Expand Up @@ -151,3 +146,9 @@ variable "deployment_circuit_breaker" {
rollback = false
}
}

variable "pin_task_definition_revision" {
type = number
description = "The revision of the task definition to use"
default = 0
}