Skip to main content

Fix Terraform Error - IAM EntityAlreadyExists

Key Takeaway

Fix the Terraform error when an IAM role or user already exists Learn step-by-step solutions with code examples and best practices for your Terraform projects.

Table of Contents

The Error

When working with Terraform, you may encounter this error:

Error: creating IAM Role: EntityAlreadyExists

This error can block your entire workflow. Let’s understand why it happens and how to fix it.

What Causes This Error

An IAM entity with the same name already exists, created manually or by another Terraform workspace.

How to Fix It

Solution 1

Import the existing IAM role: terraform import aws_iam_role.example role-name

Solution 2

Use a unique name with a prefix/suffix for each environment.

Solution 3

Check existing roles using the AWS CLI.

Solution 4

If from another workspace, coordinate naming conventions across teams.

Prevention Tips

  • Always run terraform validate before terraform plan
  • Use terraform fmt to keep configuration clean and readable
  • Pin provider versions to avoid unexpected schema changes
  • Review plan output carefully before applying

Learn More

Conclusion

Related: How to install Terraform on macOS — our most popular installation guide.

This error is common but straightforward to fix. The key is understanding the root cause and applying the correct solution for your specific situation. Following the prevention tips above will help you avoid this error in future projects.

🚀

Level Up Your Terraform Skills

Hands-on courses, books, and resources from Luca Berton

Luca Berton
Written by

Luca Berton

DevOps Engineer, AWS Partner, Terraform expert, and author. Creator of Ansible Pilot, Terraform Pilot, and CopyPasteLearn.