Terraform AWS:ECS DOSN' t部署最新的任务定义
我在Terraform部署方面面临一个小问题。
在部署期间创建了一个新的任务定义。然后,我也在Web控制台中看到了这一点。 ECS现在实际上应该使用此新任务定义并进行更新。相反,最新的修订再次部署。
我的期望是,如果我创建一个新的任务定义并将其传递给ECS,那将被部署。
不幸的是,我不知道该从这里去哪里。
我创建了一个具有以下配置的ECS服务:
resource "aws_ecs_service" "service" {
name = "${var.appPrefix}-api-service-${var.envPrefix}"
cluster = var.ecsClusterId
task_definition = aws_ecs_task_definition.ecsTaskDefinition.arn
platform_version = "1.3.0"
desired_count = 1
deployment_minimum_healthy_percent = 50
deployment_maximum_percent = 200
launch_type = "FARGATE"
scheduling_strategy = "REPLICA"
wait_for_steady_state = true
force_new_deployment = true
network_configuration {
security_groups = [var.ecsSecurityGroupId]
subnets = [var.privateSubnet1Id, var.privateSubnet2Id]
assign_public_ip = false
}
load_balancer {
target_group_arn = var.targetGroupId
container_name = var.containerName
container_port = var.httpPort
}
lifecycle {
ignore_changes = [task_definition, desired_count]
}
}
我的任务定义如下:
resource "aws_ecs_task_definition" "ecsTaskDefinition" {
family = "${var.appPrefix}-api-ECSTaskDefinition"
task_role_arn = var.ecsTaskRoleArn
execution_role_arn = var.ecsTaskExecutionRoleArn
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
cpu = "512"
memory = "1024"
container_definitions = <<DEFINITION
[...]
DEFINITION
}
〜编辑: 这是Terraform日志:
# module.ecs_api_module.aws_ecs_task_definition.ecsTaskDefinition must be replaced
-/+ resource "aws_ecs_task_definition" "ecsTaskDefinition" {
~ arn = "arn:aws:ecs:*****:********:task-definition/project-name-api-ECSTaskDefinition:507" -> (known after apply)
~ container_definitions = (sensitive) # forces replacement
~ id = "project-name-api-ECSTaskDefinition" -> (known after apply)
- ipc_mode = "" -> null
- pid_mode = "" -> null
~ revision = 507 -> (known after apply)
- tags = {} -> null
~ tags_all = {} -> (known after apply)
# (8 unchanged attributes hidden)
}
I'm facing a little problem with my terraform deployment.
A new task definition is created during deployment. I then also see this in the web console.
ecs should now actually use this new task definition and update it. Instead, the most recent revision is deployed again.
My expectation would be that if I create a new task definition and pass the arn from that to ecs, that it will be deployed.
Unfortunately, I have no idea where to go from here.
I have created an ecs service with the following config:
resource "aws_ecs_service" "service" {
name = "${var.appPrefix}-api-service-${var.envPrefix}"
cluster = var.ecsClusterId
task_definition = aws_ecs_task_definition.ecsTaskDefinition.arn
platform_version = "1.3.0"
desired_count = 1
deployment_minimum_healthy_percent = 50
deployment_maximum_percent = 200
launch_type = "FARGATE"
scheduling_strategy = "REPLICA"
wait_for_steady_state = true
force_new_deployment = true
network_configuration {
security_groups = [var.ecsSecurityGroupId]
subnets = [var.privateSubnet1Id, var.privateSubnet2Id]
assign_public_ip = false
}
load_balancer {
target_group_arn = var.targetGroupId
container_name = var.containerName
container_port = var.httpPort
}
lifecycle {
ignore_changes = [task_definition, desired_count]
}
}
My task definition looks like this:
resource "aws_ecs_task_definition" "ecsTaskDefinition" {
family = "${var.appPrefix}-api-ECSTaskDefinition"
task_role_arn = var.ecsTaskRoleArn
execution_role_arn = var.ecsTaskExecutionRoleArn
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
cpu = "512"
memory = "1024"
container_definitions = <<DEFINITION
[...]
DEFINITION
}
~edit:
this is the terraform log:
# module.ecs_api_module.aws_ecs_task_definition.ecsTaskDefinition must be replaced
-/+ resource "aws_ecs_task_definition" "ecsTaskDefinition" {
~ arn = "arn:aws:ecs:*****:********:task-definition/project-name-api-ECSTaskDefinition:507" -> (known after apply)
~ container_definitions = (sensitive) # forces replacement
~ id = "project-name-api-ECSTaskDefinition" -> (known after apply)
- ipc_mode = "" -> null
- pid_mode = "" -> null
~ revision = 507 -> (known after apply)
- tags = {} -> null
~ tags_all = {} -> (known after apply)
# (8 unchanged attributes hidden)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从
ecs_service
资源或最少删除task_definition
中删除ignore_changes
属性。Remove the
ignore_changes
attribute from theecs_service
resource or least remove thetask_definition
.