Skip to content
Error: creating: Conflict with ...

Error: creating: Conflict with ...

DodaTech 3 min read

Terraform’s “Conflict with” error means your cloud provider rejected a resource creation because the same ID already exists outside Terraform state.

What It Means

The API call from Terraform to the cloud provider returned a conflict error. For example, creating an AWS S3 bucket with a name that already exists globally, or creating a Kubernetes namespace that another process already created. The resource exists in the cloud but not in Terraform’s state.

Why It Happens

  • A resource similar to what Terraform is creating already exists in the cloud account.
  • The resource was created manually through the cloud console or CLI.
  • Another Terraform workspace or configuration manages the same resource.
  • A previous terraform destroy was interrupted, leaving the resource alive.
  • The resource has a globally unique name constraint (like S3 buckets or IAM roles).
  • The import step was skipped when adopting existing infrastructure.

How to Fix It

Step 1: Identify the conflicting resource

The error message includes the resource details. For example:

Error: creating S3 Bucket: BucketAlreadyExists: The requested bucket name is not available.

Note the resource type and name from the error output.

Step 2: Import the existing resource into Terraform state

If the resource already exists and you want Terraform to manage it:

terraform import <resource_type>.<name> <resource_id>

Example for an AWS S3 bucket:

terraform import aws_s3_bucket.my_bucket my-existing-bucket

Step 3: Remove the resource from configuration and state

If you don’t want Terraform to manage this resource, remove it from your .tf files and remove it from state:

terraform state rm <resource_type>.<name>

Step 4: Use a unique name or generate one

For resources with global name constraints, use a random or prefixed name:

resource "aws_s3_bucket" "example" {
  bucket = "my-app-${random_id.suffix.hex}"
}

resource "random_id" "suffix" {
  byte_length = 4
}

Step 5: Use lifecycle prevent_destroy for protection

To prevent accidental deletion of critical resources:

resource "aws_s3_bucket" "critical" {
  bucket = "my-critical-bucket"

  lifecycle {
    prevent_destroy = true
  }
}
What if the resource name must be fixed and can't be random?
If the name is fixed (like a production DNS name), check whether the current name is in use by another account or team. Use terraform state list to verify no other configuration tracks it. If it exists elsewhere, coordinate ownership or use a qualifier like prod- in the name.
Can I ignore changes to an existing resource without importing it?
No — if you define a resource in configuration that already exists outside Terraform, you must import it first. Without import, Terraform will try to create it and get a conflict. You can use lifecycle { ignore_changes = all } only after the resource is imported.
How do I find what resources already exist in my cloud account?
Use the cloud provider’s CLI or console to list resources. For AWS, run aws s3 ls or aws ec2 describe-instances. Cross-reference these with terraform state list. Any resource that exists in the cloud but not in state needs to be imported before Terraform can manage it.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro