IAM Role Mapping on EKS

0

I am working on IaC EKS using terraform. https://www.ahead.com/resources/automate-iam-role-mapping-on-amazon-eks I receive below error. Error: creating IAM Role (eks_admin): MalformedPolicyDocument: Invalid principal in policy: "AWS":"arn:aws:iam::xxxxxxxxxxx:user/eks-test-usr" status code: 400

resource "aws_iam_role" "eks_admin" {
  name = "eks_admin"

  assume_role_policy = jsonencode({
    Version = "2012-10-17"
    Statement = [
      {
        Action = "sts:AssumeRole"
        Effect = "Allow"
        Sid    = ""
        Principal: { "AWS" : "${var.assume_role}" }
      },
    ]
  })

  inline_policy {
    name = "eks_admin_policy"

    policy = jsonencode({
      Version = "2012-10-17"
      Statement = [
        {
          Action   = ["eks:DescribeCluster"]
          Effect   = "Allow"
          Resource = "*"
        },
      ]
    })
  }
}

I pass the variable as 
assum_role=["eks-test-dev","eks-test-admin"]
1 réponse
2

Hello rePost-User-9219791,

You are facing this issue because your terraform variable assume_role is a list of role names.

The Principal property of the IAM policy only allows role ARNs as valid principals. Therefore, pass the list of role ARNs instead of role names as shown below.

assume_role=["arn:aws:iam::<account_id>:role/eks-test-dev","arn:aws:iam::<account_id>:role/eks-test-admin"]

Also make sure that the above roles exist in your AWS account before creating the IAM role resource using terraform.

I hope this helps!

profile pictureAWS
INGÉNIEUR EN ASSISTANCE TECHNIQUE
répondu il y a un an
  • Thanks. I did the same, but the list I passed didn't exist in my AWS account.

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions