CodexBloom - Programming Q&A Platform

Terraform not creating AWS IAM roles with AssumeRolePolicyDocument - 'MalformedPolicyDocument'

πŸ‘€ Views: 88 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-06
terraform aws iam HCL

Hey everyone, I'm running into an issue that's driving me crazy. I'm having a hard time understanding I'm working on a project and hit a roadblock. I'm trying to create an IAM role in AWS using Terraform, but I keep running into an scenario where the creation fails with the behavior 'MalformedPolicyDocument'. I'm using Terraform v1.3.6 and the AWS provider version 4.4.0. My goal is to create a role that allows a specific Lambda function to assume it. Here’s the relevant part of my Terraform configuration: ```hcl resource "aws_iam_role" "lambda_role" { name = "my_lambda_role" assume_role_policy = jsonencode({ Version = "2012-10-17" Statement = [ { Effect = "Allow" Principal = { Service = "lambda.amazonaws.com" } Action = "sts:AssumeRole" } ] }) } ``` I've double-checked the JSON structure, and it seems correct to me. However, I still get the same behavior every time I try to apply this configuration. I also attempted to hard-code the assume role policy as a string instead of using `jsonencode`, but that didn't help either. Additionally, I verified that my AWS user has the necessary permissions to create IAM roles. Could there be something wrong with how I'm defining the policy, or is there another scenario I'm overlooking? Any insights would be greatly appreciated! I'm working on a application that needs to handle this. What am I doing wrong? My team is using Hcl for this web app. Thanks for any help you can provide! My development environment is CentOS. I'm open to any suggestions. This is for a mobile app running on CentOS. Any help would be greatly appreciated!