Terraform新手。我这里有一个ECS调度任务的代码。每当我对此进行更改并应用更改时,第一个版本的任务定义都会在ECS任务中设置。所以我尝试添加生命周期方法
resource "aws_cloudwatch_event_target" "sqs" {
rule = aws_cloudwatch_event_rule.sqs.name
target_id = local.namespace
arn = aws_ecs_cluster.app.arn
role_arn = aws_iam_role.ecsRole.arn
input = "{}"
ecs_target {
task_count = 1
task_definition_arn = aws_ecs_task_definition.sqs.arn
launch_type = "FARGATE"
platform_version = "LATEST"
network_configuration {
security_groups = [aws_security_group.nsg_task.id]
subnets = split(",", var.private_subnets)
}
}
}
尝试:
resource "aws_cloudwatch_event_target" "sqs" {
rule = aws_cloudwatch_event_rule.sqs.name
target_id = local.namespace
arn = aws_ecs_cluster.app.arn
role_arn = aws_iam_role.ecsRole.arn
input = "{}"
ecs_target {
task_count = 1
task_definition_arn = aws_ecs_task_definition.sqs.arn
launch_type = "FARGATE"
platform_version = "LATEST"
network_configuration {
security_groups = [aws_security_group.nsg_task.id]
subnets = split(",", var.private_subnets)
}
lifecycle {
ignore_changes = [task_definition_arn]
}
}
}
和
resource "aws_cloudwatch_event_target" "sqs" {
rule = aws_cloudwatch_event_rule.sqs.name
target_id = local.namespace
arn = aws_ecs_cluster.app.arn
role_arn = aws_iam_role.ecsRole.arn
input = "{}"
ecs_target {
task_count = 1
task_definition_arn = aws_ecs_task_definition.sqs.arn
launch_type = "FARGATE"
platform_version = "LATEST"
network_configuration {
security_groups = [aws_security_group.nsg_task.id]
subnets = split(",", var.private_subnets)
}
}
lifecycle {
ignore_changes = [ecs_target.task_definition_arn]
}
}
如何通过生命周期忽略嵌套字段?
找到了解决方案。这适用于
resource "aws_cloudwatch_event_target" "sqs" {
rule = aws_cloudwatch_event_rule.sqs.name
target_id = local.namespace
arn = aws_ecs_cluster.app.arn
role_arn = aws_iam_role.ecsRole.arn
input = "{}"
ecs_target {
task_count = 1
task_definition_arn = aws_ecs_task_definition.sqs.arn
launch_type = "FARGATE"
platform_version = "LATEST"
network_configuration {
security_groups = [aws_security_group.nsg_task.id]
subnets = split(",", var.private_subnets)
}
}
lifecycle {
ignore_changes = [ecs_target.0.task_definition_arn]
}
}
对我来说,不寻常的语法是这样的:(。