Terraform 1.3 how to to Attach IAM Policies to EC2 Instance Role During Apply
I'm trying to configure I'm sure I'm missing something obvious here, but I've been researching this but I'm updating my dependencies and I'm currently working with an scenario where Terraform 1.3 fails to attach IAM policies to an EC2 instance role during the `terraform apply`. Despite defining everything correctly in my configuration, I'm getting the following behavior message: ``` behavior: behavior attaching IAM policies to role: MalformedPolicyDocument: Invalid JSON ``` I've double-checked my policy document for syntax errors, and it appears valid. Here's the relevant part of my Terraform code: ```hcl resource "aws_iam_role" "ec2_instance_role" { name = "my-ec2-role" assume_role_policy = jsonencode({ Version = "2012-10-17" Statement = [{ Effect = "Allow" Principal = { Service = "ec2.amazonaws.com" } Action = "sts:AssumeRole" }] }) } resource "aws_iam_policy" "ec2_policy" { name = "my-ec2-policy" description = "A policy to allow EC2 actions" policy = jsonencode({ Version = "2012-10-17" Statement = [{ Effect = "Allow" Action = ["ec2:DescribeInstances", "ec2:StartInstances"], Resource = "*" }] }) } resource "aws_iam_role_policy_attachment" "attach_policy" { role = aws_iam_role.ec2_instance_role.name policy_arn = aws_iam_policy.ec2_policy.arn } ``` I’ve made sure that the role exists before applying the policy attachment, but I'm still working with this behavior. I've also attempted to use the `aws_iam_role_policy` resource as an alternative, but I run into the same scenario. Has anyone else experienced this question, or can anyone offer some insights into what might be wrong? Any help would be greatly appreciated! What's the best practice here? This is for a desktop app running on macOS. What are your experiences with this? I'm coming from a different tech stack and learning Hcl. What are your experiences with this? This is my first time working with Hcl 3.11.