UnauthorizedOperation: Not authorized to perform this operation"

I’m getting an “UnauthorizedOperation” error when launching an EC2 instance using Terraform. I have applied the AdministratorAccess policy to my IAM account and I’m using a STS token with MFA enabled, so I don’t think this is an IAM restriction issue. The Terraform code I’m using is below:

provider "aws"{
    region="us-east-1"
}
resource "aws_instance" "web" {
  ami           = "ami-00d4e9ff62bc40e03"
  instance_type = "t2.micro"
  tags = {
    Name = "HelloWorld"
  }
}

Can you please help me troubleshoot this issue?

Try adding the following block to the Terraform code to specify the AWS credentials explicitly:

provider "aws" {
  region     = "us-east-1"
  access_key = "YOUR_ACCESS_KEY"
  secret_key = "YOUR_SECRET_KEY"
  token      = "YOUR_SESSION_TOKEN"
}

Replace the placeholders with your own AWS access key, secret key, and session token. This should resolve the “UnauthorizedOperation” error you’re seeing.