0
0

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 1 year has passed since last update.

【Terraform AWS】既存IAMユーザーにIAMポリシーを付与する

Last updated at Posted at 2022-05-24

はじめに

Terraformで既存のIAMユーザーにIAMポリシーを付与する方法です。

説明

IAMポリシーはAWS管理ポリシーのAmazonEC2FullAccessをデータリソースとして取得しました。
IAMユーザーもタイトルにあるように既存のIAMユーザーを取得しました。
aws_iam_user内のxxxxxxはポリシーを付与したいIAMユーザー名を指定します。

コード

# IAMポリシー取得
data "aws_iam_policy" "policy_01" {
  arn = "arn:aws:iam::aws:policy/AmazonEC2FullAccess"
}

# IAMユーザー取得
data "aws_iam_user" "user_01" {
  user_name = "xxxxxxxx"
}

# IAMユーザーにIAMポリシーを付与
resource "aws_iam_user_policy_attachment" "attach" {
  user = data.aws_iam_user.user_01.user_name
  policy_arn = data.aws_iam_policy.policy_01.arn
}

参考サイト

Terraformの公式ドキュメントは読みやすく分かりやすい

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?