gpt4 book ai didi

amazon-web-services - 如何将 IAM 角色附加到 EC2 实例,以便它们可以从 Terraform 中的 ECR 中提取特定图像

转载 作者:行者123 更新时间:2023-12-04 14:24:04 25 4
gpt4 key购买 nike

我正在尝试将 IAM 角色附加到 EC2 实例(而非 ECS),以便它们可以从 ECR 中提取图像。

最佳答案

做这样的事情。请注意,您可能希望限制可访问的 ECR 存储库。

resource "aws_instance" "test" {
...
}

resource "aws_launch_configuration" "ecs_cluster" {
...
iam_instance_profile = "${aws_iam_instance_profile.test.id}"
}

resource "aws_iam_role" "test" {
name = "test_role"
assume_role_policy = "..."
}

resource "aws_iam_instance_profile" "test" {
name = "ec2-instance-profile"
role = "${aws_iam_role.test.name}"
}

resource "aws_iam_role_policy_attachment" "test" {
role = "${aws_iam_role.test.name}"
policy_arn = "${aws_iam_policy.test.arn}"
}

resource "aws_iam_policy" "test" {
name = "ec2-instance-pulls-from-ecr"
description = "EC2 instance can pull from ECR"

policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage"
],
"Resource": "*"
}
]
}
EOF
}

关于amazon-web-services - 如何将 IAM 角色附加到 EC2 实例,以便它们可以从 Terraform 中的 ECR 中提取特定图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49562015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com