【发布时间】:2019-01-07 19:14:03
【问题描述】:
我正在使用 Terraform 在 AWS 中创建一些服务。其中一项服务是 ECS 任务定义。我按照文档进行操作,但不断收到以下错误:
aws_ecs_task_definition.github-backup: ClientException: Fargate requires task definition to have execution role ARN to support ECR images.
status code: 400, request id: 84df70ec-94b4-11e8-b116-97f92c6f483f
首先task_role_arn 是可选的,我可以看到创建了一个新角色。我还尝试自己创建一个具有任务定义所需权限的角色。
这是我所拥有的:
任务定义:
resource "aws_ecs_task_definition" "github-backup" {
family = "${var.task_name}"
requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"
cpu = "${var.fargate_cpu}"
memory = "${var.fargate_memory}"
task_role_arn = "${aws_iam_role.github-role.arn}"
container_definitions = <<DEFINITION
[
{
"cpu": ${var.fargate_cpu},
"image": "${var.image}",
"memory": ${var.fargate_memory},
"name": "github-backup",
"networkMode": "awsvpc"
}
]
DEFINITION
}
IAM 政策:
resource "aws_iam_policy" "access_policy" {
name = "github_policy"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1532966429082",
"Action": [
"s3:PutObject",
"s3:PutObjectTagging",
"s3:PutObjectVersionTagging"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::zego-github-backup11"
},
{
"Sid": "Stmt1532967608746",
"Action": "lambda:*",
"Effect": "Allow",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "*"
}
]
}
EOF
}
IAM 角色:
resource "aws_iam_role" "github-role" {
name = "github-backup"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": [
"s3.amazonaws.com",
"lambda.amazonaws.com",
"ecs.amazonaws.com"
]
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
IAM 政策附件:
resource "aws_iam_role_policy_attachment" "test-attach" {
role = "${aws_iam_role.github-role.name}"
policy_arn = "${aws_iam_policy.access_policy.arn}"
}
Terraform 计划没有显示任何错误。只有在运行 Terraform apply 时,我才会收到此错误。我正在提供一个具有任务定义所需权限的角色,但我仍然得到这个。这有什么问题?
【问题讨论】:
标签: amazon-web-services terraform amazon-ecs