title: Terraform error creating user pool domain
body: <p>Following this <a href="https://github.com/bholzer/AutoBlenderRender" rel="nofollow noreferrer">Github repo</a>, the user pool domain <code>farm_users</code> is created yet <code>terraform apply</code>returns this error. Tried <code>destroy</code>. Tried deleting the user pool domain in the aws console and repeating <code>apply</code>.</p>
  <pre><code>╷
  │ Error: Error creating Cognito User Pool Domain: InvalidParameterException: Domain already associated with another user pool.
  │ 
  │   with module.api.aws_cognito_user_pool_domain.farm_users_pool_domain,
  │   on modules/api/main.tf line 55, in resource &quot;aws_cognito_user_pool_domain&quot; &quot;farm_users_pool_domain&quot;:
  │   55: resource &quot;aws_cognito_user_pool_domain&quot; &quot;farm_users_pool_domain&quot; {
  │ 
  </code></pre>
  <p>After running <code>apply</code>:</p>
  <p><code>$ aws cognito-idp describe-user-pool-domain --domain &quot;fupdomain&quot;</code></p>
  <pre><code>An error occurred (ResourceNotFoundException) when calling the DescribeUserPoolDomain operation: User pool domain fupdomain does not exist in this account.
  </code></pre>
  <p><img src="https://i.imgur.com/22pT3rT.png" alt="screenshot after running apply" /></p>
  <p><code>main.tf</code></p>
  <pre><code>provider &quot;aws&quot; {
    version = &quot;~&gt; 2.31&quot;
    region = var.region
  }
  
  data &quot;aws_caller_identity&quot; &quot;current&quot; {}
  
  resource &quot;random_string&quot; &quot;build_id&quot; {
    length = 16
    special = false
    upper = false
    number = false
  }
  
  module &quot;network&quot; {
    source = &quot;./modules/network&quot;
  
    availability_zone = var.availability_zone
    vpc_cidr = var.vpc_cidr
  }
  
  module &quot;node_iam_role&quot; {
    source = &quot;./modules/node_iam_role&quot;
  }
  
  resource &quot;aws_s3_bucket&quot; &quot;render_bucket&quot; {
    bucket = &quot;${random_string.build_id.result}-render-data&quot;
    acl    = &quot;private&quot;
  }
  
  # Stores server-side code bundles. i.e. Worker node and lambda layer
  resource &quot;aws_s3_bucket&quot; &quot;code_bundles_bucket&quot; {
    bucket = &quot;${random_string.build_id.result}-code-bundles&quot;
    acl    = &quot;private&quot;
  }
  
  # Stores and serves javascript client
  resource &quot;aws_s3_bucket&quot; &quot;client_bucket&quot; {
    bucket = &quot;${random_string.build_id.result}-client-bucket&quot;
    acl    = &quot;public-read&quot;
  
    website {
      index_document = &quot;index.html&quot;
      error_document = &quot;error.html&quot;
    }
  }
  
  # Code bundles
  
  data &quot;archive_file&quot; &quot;worker_node_code&quot; {
    type = &quot;zip&quot;
    source_dir = &quot;${path.root}/src/farm_worker&quot;
    output_path = &quot;${path.root}/src/bundles/farm_worker.zip&quot;
  }
  
  resource &quot;aws_s3_bucket_object&quot; &quot;worker_code_bundle&quot; {
    bucket = aws_s3_bucket.code_bundles_bucket.id
    key = &quot;farm_worker.zip&quot;
    source = &quot;${path.root}/src/bundles/farm_worker.zip&quot;
  
    depends_on = [data.archive_file.worker_node_code]
  }
  
  # Security groups for the worker nodes
  
  resource &quot;aws_security_group&quot; &quot;ssh&quot; {
    name = &quot;allow_ssh&quot;
    vpc_id = module.network.vpc_id
  
    ingress {
      from_port = 22
      to_port = 22
      protocol = &quot;tcp&quot;
      cidr_blocks = [&quot;0.0.0.0/0&quot;]
    }
  
    egress {
      from_port = 0
      to_port = 0
      protocol = &quot;-1&quot;
      cidr_blocks = [&quot;0.0.0.0/0&quot;]
    }
  }
  
  resource &quot;aws_security_group&quot; &quot;nfs&quot; {
    name = &quot;NFS&quot;
    vpc_id = module.network.vpc_id
  
    ingress {
      from_port = 2049
      to_port = 2049
      protocol = &quot;tcp&quot;
      cidr_blocks = [&quot;0.0.0.0/0&quot;]
    }
  
    egress {
      from_port = 0
      to_port = 0
      protocol = &quot;-1&quot;
      cidr_blocks = [&quot;0.0.0.0/0&quot;]
    }
  }
  
  # Build queues for project init and frame rendering
  
  resource &quot;aws_sqs_queue&quot; &quot;frame_render_deadletter&quot; {
    name = &quot;frame_render_deadletter_queue&quot;
  }
  
  resource &quot;aws_sqs_queue&quot; &quot;frame_render_queue&quot; {
    name                       = &quot;frame_render_queue&quot;
    visibility_timeout_seconds = 7000
    redrive_policy             = &quot;{\&quot;deadLetterTargetArn\&quot;:\&quot;${aws_sqs_queue.frame_render_deadletter.arn}\&quot;,\&quot;maxReceiveCount\&quot;:5}&quot;
  }
  
  resource &quot;aws_sqs_queue&quot; &quot;project_init_queue&quot; {
    name                       = &quot;project_init_queue&quot;
    visibility_timeout_seconds = 7000
  }
  
  # EFS for shared storage during baking and rendering
  
  resource &quot;aws_efs_file_system&quot; &quot;shared_render_vol&quot; {
  
    tags = {
      Name = &quot;SharedRenderEFS&quot;
    }
  }
  
  resource &quot;aws_efs_mount_target&quot; &quot;shared_mount&quot; {
    file_system_id = aws_efs_file_system.shared_render_vol.id
    subnet_id      = module.network.subnet_id
  
    security_groups = [aws_security_group.nfs.id]
  }
  
  module &quot;worker_node&quot; {
    source = &quot;./modules/worker_node&quot;
  
    key_name = var.node_key_name
    image_id = var.blender_node_image_id
    vpc_security_group_ids = [aws_security_group.ssh.id, aws_security_group.nfs.id]
    iam_instance_profile = module.node_iam_role.worker_iam_profile_name
  
    build_id = random_string.build_id.result
    region = var.region
    render_bucket = aws_s3_bucket.render_bucket.id
    code_bucket = aws_s3_bucket.code_bundles_bucket.id
    frame_queue_url = aws_sqs_queue.frame_render_queue.id
    project_init_queue_url = aws_sqs_queue.project_init_queue.id
    shared_file_system_id = aws_efs_file_system.shared_render_vol.id
  
    instance_types = var.instance_types
    asg_name = var.worker_asg_name
    asg_subnets = [module.network.subnet_id]
    asg_max_workers = var.worker_node_max_count
    asg_min_workers = 0
    cloudwatch_namespace = var.cloudwatch_namespace
  }
  
  module &quot;bpi_emitter&quot; {
    source = &quot;./modules/bpi_emitter&quot;
  
    cloudwatch_namespace = var.cloudwatch_namespace
    asg_name = module.worker_node.asg_name
    frame_queue = aws_sqs_queue.frame_render_queue.id
    project_init_queue = aws_sqs_queue.project_init_queue.id
    frame_queue_bpi = var.frame_queue_bpi
    project_init_queue_bpi = var.project_init_queue_bpi
  }
  
  # module &quot;bucket_upload_listener&quot; {
  #   source = &quot;./modules/bucket_upload_listener&quot;
  
  #   bucket_name = aws_s3_bucket.render_bucket.id
  #   bucket_arn = aws_s3_bucket.render_bucket.arn
  #   project_init_queue = aws_sqs_queue.project_init_queue.id
  # }
  
  resource &quot;aws_dynamodb_table&quot; &quot;projects_table&quot; {
    name = &quot;FarmProjects&quot;
    billing_mode = &quot;PAY_PER_REQUEST&quot;
    hash_key = &quot;ProjectId&quot;
  
    attribute {
      name = &quot;ProjectId&quot;
      type = &quot;S&quot;
    }
  }
  
  resource &quot;aws_dynamodb_table&quot; &quot;application_settings&quot; {
    name = &quot;FarmApplicationSettings&quot;
    billing_mode = &quot;PAY_PER_REQUEST&quot;
    hash_key = &quot;SettingName&quot;
  
    attribute {
      name = &quot;SettingName&quot;
      type = &quot;S&quot;
    }
  }
  
  module &quot;api&quot; {
    source = &quot;./modules/api&quot;
  
    region = var.region
    bucket = aws_s3_bucket.render_bucket.id
    frame_queue = aws_sqs_queue.frame_render_queue.id
    project_init_queue = aws_sqs_queue.project_init_queue.id
    client_endpoint = &quot;https://${aws_s3_bucket.client_bucket.website_endpoint}&quot;
  
    dynamo_tables = {
      projects = aws_dynamodb_table.projects_table.name,
      application_settings = aws_dynamodb_table.application_settings.name
    }
  }
  
  
  </code></pre>