1
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?

managed_policy_arns is deprecatedの解決方法

Last updated at Posted at 2025-06-10

概要

スクリーンショット 2025-06-10 11.12.23.png

上記のようなIAMロールのリソース内でエラーが出ていたがうざいなと思いつつ
時間がなかったので放置していたが我慢の限界が来たので調べて見た

解決方法

単純にIAMロールの中にIAMポリシーを記述することが非推奨になったみたいです

一つのリソースに複数のリソースの定義を含むのがダメになった感じですね

一つ一つリソースごとに定義して書くとコードが分離されて可読性が上がるから変わったのでしょう

まぁでも個人的に非推奨の方が見やすい...

非推奨

resource "aws_iam_role" "hoge_role" {
  name               = "hoge-dev-role"
  assume_role_policy = jsonencode({
    Version   = "2012-10-17"
    Statement = [
      {
        Action = "sts:AssumeRole"
        Effect = "Allow"
        Sid    = ""
        Principal = {
          Service = "ec2.amazonaws.com"
        }
      },
    ]
  })
  managed_policy_arns = [
    "arn:aws:iam::aws:policy/CloudWatchFullAccess"
  ]
}

推奨

resource "aws_iam_role" "hoge_role" {
  name               = "hoge-dev-role"
  assume_role_policy = jsonencode({
    Version   = "2012-10-17"
    Statement = [
      {
        Action = "sts:AssumeRole"
        Effect = "Allow"
        Sid    = ""
        Principal = {
          Service = "ec2.amazonaws.com"
        }
      },
    ]
  })
-  managed_policy_arns = [
-    "arn:aws:iam::aws:policy/CloudWatchFullAccess"
-  ]
}

+resource "aws_iam_role_policy_attachment"  "cloudwatch_full_access" { 
+  role = aws_iam_role.hoge_role.name 
+  policy_arn = "arn:aws:iam::aws:policy/CloudWatchFullAccess"
+ }
1
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
1
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?