AWS Builder Center
From “Access Denied” to Understanding AWS IAM

From “Access Denied” to Understanding AWS IAM

What Terraform Taught Me About Permissions

Community Builder | AWS
The first time I encountered an AWS  AccessDenied  error while working with Terraform, my first instinct was simple: something must be wrong with my Terraform code.
I checked the syntax. I checked the resource configuration. I checked the credentials. I ran the command again.
The error was still there.
What made it more confusing was that I was able to interact with AWS normally in other situations. So why was Terraform being denied?
That experience made me realize something I had previously treated as a theoretical AWS concept: having AWS credentials does not mean you automatically have permission to perform every action.
The problem eventually led me deep into IAM, policies, roles, instance profiles, and one permission in particular that I had seen before but never really understood:  iam:PassRole .
This is the story of how an “Access Denied” error helped me understand AWS IAM much better.

The problem wasn't Terraform syntax

When you're learning Terraform, it's easy to assume that if a configuration looks correct, Terraform should be able to create the resources described in it.
Terraform, however, doesn't get special permission just because it is Terraform.
Terraform makes API calls to AWS using credentials. AWS then evaluates whether the identity making each request is actually allowed to perform that action.
The simplified flow looks something like this:
Terraform
|
| AWS API request
v
AWS credentials
|
v
IAM principal
|
v
IAM policy evaluation
|
v
AWS service/resource
So when Terraform reports something like:
AccessDenied
User is not authorized to perform:
some-aws-action
the important question isn't necessarily:
“What's wrong with my Terraform?”
It can instead be:
“What AWS API operation is Terraform trying to perform, and does my identity have permission to perform it?”
That distinction changed how I approached the problem.

IAM started becoming more than policies to memorize

Before working through this issue, I understood IAM mostly through the usual concepts:
  • Users
  • Groups
  • Roles
  • Policies
  • Permissions
I knew what each term meant individually.
The difficult part was understanding how they interacted during an actual AWS operation.
An IAM policy can allow or deny an action. But the identity making the request is what AWS evaluates when deciding whether that action can happen.
For example, a policy might contain:
{
"Effect": "Allow",
"Action": "ec2:RunInstances",
"Resource": "*"
}
At first glance, it can be tempting to think:
“I have permission to launch EC2, so I can launch EC2.”
But real AWS operations can involve several related API calls and resources.
The operation might require permissions for things such as:
  • launching the instance
  • using a particular AMI
  • working with networking resources
  • creating or using security groups
  • attaching an IAM role
That last part was where I got stuck.

The permission I misunderstood:  iam:PassRole 

I had come across  iam:PassRole  while studying IAM, but I hadn't fully understood why it existed.
The name actually gives a useful clue.
 iam:PassRole  is about allowing one AWS identity to pass an IAM role to an AWS service.
This is different from simply allowing someone to use the permissions contained inside that role.
Consider this simplified situation:
You
|
| create/use AWS resource
v
AWS Service
|
| assumes
v
IAM Role
There are two different identities involved.
The identity making the request needs permission to pass the role.
The service that receives the role can then assume it and use the permissions associated with that role.
These are separate permission decisions.
That's the part that initially confused me.

Why “I have the role” isn't enough

Suppose an IAM role has a policy that allows an EC2 instance to perform certain actions.
That doesn't automatically mean that every user or Terraform execution identity is allowed to attach that role to an EC2 instance.
The identity making the request may need something like:
{
"Effect": "Allow",
"Action": "iam:PassRole",
"Resource": "arn:aws:iam::123456789012:role/example-role"
}
The important part is the distinction between:
Role permissions
and
Permission to pass the role
The role defines what the service can do after assuming it.
 iam:PassRole  determines whether the requesting identity is allowed to give that role to the service in the first place.
Once I understood that distinction, the error made much more sense.

Debugging the error instead of randomly changing policies

One of the easiest mistakes when facing an AWS permission error is to keep adding permissions until the error disappears.
That may make the immediate problem go away, but it doesn't necessarily solve the underlying issue.
Worse, it can lead to unnecessarily broad permissions.
I started looking at the error differently.
Instead of asking:
“What permission should I add?”
I asked:
“What exact action is being denied?”
That meant looking at:
  1. The AWS service involved.
  1. The API action being attempted.
  1. The IAM identity making the request.
  1. The policies attached to that identity.
  1. The resource being accessed.
  1. Whether another permission, such as  iam:PassRole , was required.
This made troubleshooting much more systematic.

The difference between a role and an instance profile

Another thing that became clearer during this process was the relationship between an IAM role and an instance profile.
These terms are easy to mix up when you're starting with AWS.
An IAM role is an identity that defines a set of permissions.
An instance profile is a container that allows an EC2 instance to use an IAM role.
A simplified relationship is:
IAM Role
|
v
Instance Profile
|
v
EC2 Instance
This distinction becomes particularly important when working with infrastructure as code because Terraform may need to create or reference these different AWS resources separately.
Understanding what each resource represents helped me stop treating IAM-related errors as random configuration problems.

Why giving AdministratorAccess isn't really a solution

At some point, when permissions become frustrating, it can be tempting to give the user:
AdministratorAccess
and move on.
Technically, this can remove many permission-related obstacles.
But it also avoids the actual problem.
If an application, developer, or automation process only needs a small set of actions, giving it unrestricted access is unnecessary and potentially dangerous.
The better approach is least privilege:
Give an identity only the permissions it actually needs to perform its intended tasks.
For example, if the problem is specifically that an identity cannot pass one particular role, a much more precise permission might be:
{
"Effect": "Allow",
"Action": "iam:PassRole",
"Resource": "arn:aws:iam::123456789012:role/example-role"
}
rather than allowing unrestricted IAM actions.
The exact policy required will depend on the resources and workflow, but the principle remains the same.

What finally clicked for me

The biggest lesson wasn't actually about  iam:PassRole .
It was about changing the way I think about AWS permissions.
Earlier, I was thinking about permissions like this:
“I have AWS access.”
Then:
“I have an IAM policy.”
And finally:
“So I should be able to create the resource.”
Now I think about it more like this:
Who is making the request?
|
v
What API action are they trying to perform?
|
v
What resource are they trying to access?
|
v
What policies apply to that identity?
|
v
Is the action explicitly allowed?
|
v
Are there additional permissions involved?
That mental model is much more useful when debugging AWS.

What I would do differently now

If I encountered the same kind of problem again, I wouldn't immediately modify my Terraform configuration.
I'd first identify the failed AWS operation.
Then I'd trace the permission chain:
Terraform
↓
AWS credentials
↓
IAM identity
↓
Requested API action
↓
Target resource
↓
Applicable IAM policies
If an IAM role is involved, I'd separately ask:
What can the role do?

AND

Is my current identity allowed to pass that role?
That second question is the one I wasn't asking before.

A small error can teach a much bigger concept

What initially felt like a frustrating Terraform problem turned out to be an IAM learning experience.
I didn't learn IAM properly by memorizing the definition of  iam:PassRole .
I understood it when I had to figure out why something that looked correct was still being rejected.
That experience also changed how I approach AWS errors in general.
An  AccessDenied  message isn't simply AWS saying “no.”
It's a clue.
The useful information is in the identity, action, resource, and permission being evaluated.
Once you start breaking the request down that way, IAM becomes much less mysterious.

Final takeaway

Working with AWS through Terraform taught me that infrastructure as code doesn't remove the need to understand the cloud platform underneath it.
Terraform can describe what you want AWS to create, but AWS still decides whether you're allowed to create it.
And when IAM gets in the way, the solution isn't always to add more permissions.
Sometimes the better solution is to understand which identity is making the request, which action is being denied, why that action is required, and exactly where the missing permission belongs.
For me,  iam:PassRole  was one of those concepts that only really made sense after I encountered it in practice.
That was probably the most useful part of the whole debugging process.
Share your debugging experience of when you started working with AWS in the comments!
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article