CodexBloom - Programming Q&A Platform

Terraform how to to set up EKS cluster with 'InvalidArgumentException' due to unexpected IAM role configuration

👀 Views: 96 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-01
terraform aws eks iam HCL

I'm testing a new approach and This might be a silly question, but I'm dealing with Hey everyone, I'm running into an issue that's driving me crazy....... I'm trying to set up an Amazon EKS cluster using Terraform, but I'm working with an `InvalidArgumentException` when applying the configuration. The behavior message indicates that there's an scenario with the IAM role configuration, but I'm fairly certain that my roles and policies are set up correctly. Here's the relevant part of my Terraform configuration: ```hcl resource "aws_eks_cluster" "my_cluster" { name = "my-cluster" role_arn = aws_iam_role.eks_role.arn vpc_config { subnet_ids = aws_subnet.my_subnet.*.id } } resource "aws_iam_role" "eks_role" { name = "eks-cluster-role" assume_role_policy = jsonencode({ Version = "2012-10-17" Statement = [ { Action = "sts:AssumeRole" Principal = { Service = "eks.amazonaws.com" } Effect = "Allow" Sid = "" } ] }) } resource "aws_iam_role_policy_attachment" "eks_policy_attachment" { role = aws_iam_role.eks_role.name policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy" } ``` I verified that the IAM role has the correct permissions attached, including `AmazonEKSClusterPolicy` and `AmazonEKSServicePolicy`. However, when I run `terraform apply`, I get this behavior: ``` behavior: invalid EKS cluster configuration with aws_eks_cluster.my_cluster, on main.tf line 1, in resource "aws_eks_cluster" "my_cluster": 1: resource "aws_eks_cluster" "my_cluster" { The IAM role is missing the required policies or the configuration is invalid. ``` I've also checked the EKS console, and it seems like the IAM role is correctly set up and shows the necessary permissions. I've tried recreating the role and reattaching the policies but nothing has worked. Is there something I'm missing in the configuration? Am I overlooking any specific IAM requirements for the EKS cluster? Any help would be appreciated! I'm developing on Ubuntu 22.04 with Hcl. What am I doing wrong? I'd be grateful for any help. I recently upgraded to Hcl 3.10.