Founding prices until 15 December: 30% off Pro, locked for life. See pricing

$ … Error: creating ...: already exists

Terraform 'already exists': adopt the resource instead of recreating it

The real resource exists but isn't in the state, so Terraform tries to create it again.

Terraform

What it means

Terraform only manages what's in its state. A resource created by hand, by another configuration, or lost from state looks new, and the cloud rejects the duplicate name.

Causes and fixes

Most likely first. Run the check, and if it matches, apply the fix.

1. Created outside Terraform

Check:

terraform state list | grep <name>

Fix: Add an import block (or terraform import) and plan until there are no changes.

2. Renamed in code without moving it in state

Check:

terraform plan   # one destroy, one create

Fix: Add a moved block from the old address to the new.

Fix it yourself

A live machine in your browser with this problem already on it. The grader checks the result.

Open the lab

No account needed for your first tries.

Related errors