Skip to main content
Fix Terraform Error - Error Creating Cognito User Pool - UsernameExistsException

Fix Terraform Error - Error Creating Cognito User Pool - UsernameExistsException

Key Takeaway

Fix AWS Cognito user pool errors in Terraform. Covers duplicate pool names, schema attribute conflicts, and lambda trigger configuration.

Table of Contents

Introduction

The Error Creating Cognito User Pool - UsernameExistsException error in Terraform stops your deployment workflow. This guide explains the root causes and provides tested solutions.

Error Message

Error: Error Creating Cognito User Pool - UsernameExistsException

Common Causes

  1. Resource conflicts - Duplicate names or existing resources
  2. Permission issues - Missing IAM or RBAC permissions
  3. Configuration errors - Invalid parameter values or types
  4. State drift - State file doesn’t match real infrastructure
  5. Provider bugs - Outdated provider version

Solution 1 - Verify Resource State

terraform state list | grep <resource>
terraform state show <resource_address>

If the resource exists outside Terraform:

terraform import <resource_address> <resource_id>

Solution 2 - Fix Configuration

Review and correct your resource configuration:

resource "<type>" "example" {
  name = "${var.project}-${var.env}-<name>"
  
  lifecycle {
    create_before_destroy = true
  }
}

Solution 3 - Update Provider

terraform init -upgrade
terraform providers

Solution 4 - Refresh and Retry

terraform refresh
terraform plan
terraform apply

Solution 5 - State Surgery

If the resource was deleted outside Terraform:

terraform state rm <resource_address>
terraform apply

Prevention Tips

  • Pin provider versions in required_providers
  • Use unique resource naming with environment prefixes
  • Enable state locking (DynamoDB for S3 backend)
  • Run terraform plan before every apply
  • Use lifecycle blocks for critical resources

Hands-On Courses

Conclusion

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

The Error Creating Cognito User Pool - UsernameExistsException error is resolved by checking resource state, fixing configuration, and keeping providers updated. Follow the prevention tips to avoid this error in the future.

🚀

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.