Terraform 1.4.1 AWS IAM Policy Attachment optimization guide with 'InvalidPrincipal' scenarios
I've been researching this but I'm updating my dependencies and Quick question that's been bugging me - I'm working with an scenario while trying to attach an IAM policy to an existing role in AWS using Terraform 1.4.1. After applying my configuration, I receive an 'InvalidPrincipal' behavior message, which is confusing because I've verified that the principal exists and the ARN is correctly formatted. Here’s the snippet of my Terraform code: ```hcl resource "aws_iam_role" "my_role" { name = "my-role" } resource "aws_iam_policy" "my_policy" { name = "my-policy" description = "A policy for testing" policy = jsonencode({ Version = "2012-10-17" Statement = [ { Effect = "Allow" Action = "s3:ListBucket" Resource = "*" } ] }) } resource "aws_iam_policy_attachment" "my_policy_attachment" { name = "my-policy-attachment" roles = [aws_iam_role.my_role.name] policy_arn = aws_iam_policy.my_policy.arn } ``` I’ve tried both referencing the role by its name and using the IAM role data source, but the behavior continues. Here’s the full behavior message I receive: ``` behavior: behavior attaching policy my-policy to role my-role: Invalid principal: my-role ``` I’ve double-checked that the role and policy are created in the same region and account, and I’ve confirmed that there are no typos in the role name. Additionally, I ensured that the AWS user I’m using has sufficient permissions to attach policies to roles. Does anyone have insights into why this might be happening or potential fixes? Any help would be greatly appreciated. My development environment is macOS. The project is a microservice built with Hcl. Any suggestions would be helpful.