Facing IAM assume role issue

Hi, I am trying to run terraform code from my local machine which is Linux Ubuntu. When I fire the terraform plan command I am facing this error that my IAM role cannot be assumed. I have the role for that and have admin permissions with the role.

Error: error configuring Terraform AWS Provider: IAM Role (arn:aws:iam::501446***:role/ec2-*-iam-profile) cannot be assumed.

There are a number of possible causes of this - the most common are:

  • The credentials used in order to assume the role are invalid
  • The credentials do not have appropriate permission to assume the role
  • The role ARN is not valid

Error: NoCredentialProviders: no valid providers in chain. Deprecated.
For verbose messaging see aws.Config.CredentialsChainVerboseErrors

with provider[“Terraform Registry”],
on main.tf line 1, in provider “aws”:
1: provider “aws” {
Error:
IAM user or role ARN experiencing the issue: Error: error configuring Terraform AWS Provider: IAM Role ( arn:aws:iam::501446****:role/ec2-*-iam-profile) cannot be assumed.

Please help me out.

When you say “I have the role for that and have admin permissions with the role.” what do you mean? What AWS_ environment variables do you have set, if any, while trying to run a terraform plan?