6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【AWS】TerraformでAWS管理ポリシーを使用する

Posted at

状況

Terraformでデプロイ用のユーザを作成している。自分の参考書はjson形式で、許可するactionを細かく設定していたが、今回は簡単のためにAWS管理ポリシーを使用したい。すぐに解決したが備忘録として。

解決策

必要なAWS管理ポリシーをAWSコンソールで探す

# AWS管理ポリシー取得
data "aws_iam_policy" "AmazonEC2ContainerRegistryFullAccess" {
  arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryFullAccess"
}

# IAMユーザー作成
resource "aws_iam_user" "user" {
  name = "test-user"
}

# IAMユーザーにAWS管理ポリシーをアタッチ
resource "aws_iam_user_policy_attachment" "test-attach" {
  user       = aws_iam_user.user.name
  policy_arn = data.aws_iam_policy.AmazonEC2ContainerRegistryFullAccess.arn
}

スクリーンショット 2020-07-15 21.16.26.png

Terraform公式リファレンス
resource "aws_iam_user_policy_attachment"
data "aws_iam_policy"

参考

[Terraform: correct way to attach AWS managed policies to a role?](Terraform: correct way to attach AWS managed policies to a role?)

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?