and*_*o2L 6 amazon-web-services terraform
我在 AWS 中启动并运行了一个完全可用的 Fargate 应用程序。我回去为我的所有资源添加标签,以更好地监控微服务架构中的成本。向我的 aws_ecs_service 资源添加标签后,运行时出现以下异常terraform apply
:
aws_ecs_service.main: error tagging ECS Cluster (arn:aws:ecs:*region*:*account_number*:service/*service_name*): InvalidParameterException: Long arn format must be used for tagging operations
Run Code Online (Sandbox Code Playgroud)
经过一番研究,发现11月15日AWS引入了新的ARN和ID格式:https : //aws.amazon.com/ecs/faqs/#Transition_to_new_ARN_and_ID_format
我知道我需要将设置应用到我分配给我的服务的 IAM 角色,但我不知道如何。以下是账户设置的 AWS 文档链接:https : //docs.aws.amazon.com/AmazonECS/latest/APIReference/API_Setting.html
以下是 ecs 服务资源以及任务定义的片段:
resource "aws_ecs_task_definition" "app" {
family = "${var.app_name}"
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
cpu = "${var.app_cpu}"
memory = "${var.app_memory}"
execution_role_arn = "${var.execution_role_arn}"
task_role_arn = "${var.task_role_arn}"
tags {
Name = "${var.app_name}-ecs-task-definition-${var.environment}"
Service = "${var.app_name}"
Environment = "${var.environment}"
Cost_Center = "${var.tag_cost_center}"
Cost_Code = "${var.tag_cost_code}"
}
container_definitions = <<DEFINITION
[
{
"cpu": ${var.app_cpu},
"image": "${var.app_image}",
"memory": ${var.app_memory},
"name": "${var.app_name}",
"networkMode": "awsvpc",
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "stash-${var.app_name}",
"awslogs-region": "${var.aws_region}",
"awslogs-stream-prefix": "${var.app_name}"
}
},
"portMappings": [
{
"containerPort": ${var.app_port},
"hostPort": ${var.app_port}
}
]
}
]
DEFINITION
}
resource "aws_ecs_service" "main" {
name = "${var.app_name}-service"
cluster = "${var.cluster_id}"
task_definition = "${aws_ecs_task_definition.app.arn}"
desired_count = "1"
launch_type = "FARGATE"
network_configuration {
security_groups = ["${var.security_groups}"]
subnets = ["${var.subnets}"]
}
load_balancer {
target_group_arn = "${var.target_group_arn}"
container_name = "${var.app_name}"
container_port = "${var.app_port}"
}
lifecycle {
ignore_changes = ["desired_count"]
}
tags {
Name = "${var.app_name}-ecs-service-${var.environment}"
Service = "${var.app_name}"
Environment = "${var.environment}"
Cost_Center = "${var.tag_cost_center}"
Cost_Code = "${var.tag_cost_code}"
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我的安全资源:
resource "aws_iam_role" "task_role" {
name = "${var.app_name}-task-${var.environment}"
assume_role_policy = <<END
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "ecs-tasks.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
END
}
Run Code Online (Sandbox Code Playgroud)
我正在使用 terraform 版本 0.11.8。
既然你提到了terraform
,让我添加这个(我也在使用 terraform 并遇到了一个非常相似的问题)。您可以使用AWS CLI,用ECS子命令put-account-setting
来设置三个LongArnFormat
的
aws ecs put-account-setting --name containerInstanceLongArnFormat --value enabled --region _yourRegion_
aws ecs put-account-setting --name serviceLongArnFormat --value enabled --region _yourRegion_
aws ecs put-account-setting --name taskLongArnFormat --value enabled --region _yourRegion_
Run Code Online (Sandbox Code Playgroud)
参考:AWS 文档
归档时间: |
|
查看次数: |
3676 次 |
最近记录: |