Fix Terraform Error: CloudWatch Log Group Already Exists
Fix terraform CloudWatch Log Group ResourceAlreadyExistsException. Import orphaned log groups, prevent Lambda auto-creation
DevOps
Fix AlreadyExistsException when creating AWS Glue jobs in Terraform. Import existing jobs, handle name conflicts, and manage Glue job state.
A Glue job with that name already exists in AWS. Import it into Terraform state with terraform import aws_glue_job.my_job my-etl-job, or use a unique name.
Error: error creating Glue Job (my-etl-job): AlreadyExistsException:
Job already exists: my-etl-jobSomeone created the Glue job manually in the AWS Console or via CLI.
Terraform created the job in AWS but failed to write the state — so it tries to create again.
Two Terraform configs managing the same Glue job name.
# Import format: terraform import aws_glue_job.RESOURCE_NAME JOB_NAME
terraform import aws_glue_job.etl my-etl-jobThen verify:
terraform plan
# Adjust config to match the imported job's settingsresource "aws_glue_job" "etl" {
name = "${var.project}-${var.environment}-etl"
role_arn = aws_iam_role.glue.arn
command {
name = "glueetl"
script_location = "s3://${aws_s3_bucket.scripts.id}/etl.py"
python_version = "3"
}
default_arguments = {
"--job-language" = "python"
"--TempDir" = "s3://${aws_s3_bucket.temp.id}/tmp/"
"--enable-metrics" = "true"
"--enable-spark-ui" = "true"
"--spark-event-logs-path" = "s3://${aws_s3_bucket.logs.id}/spark-logs/"
}
max_retries = 1
timeout = 60
number_of_workers = 2
worker_type = "G.1X"
glue_version = "4.0"
}# If you don't need the existing job
aws glue delete-job --job-name my-etl-job
terraform applyterraform state list | grep glue
# If the job isn't in state but exists in AWS → import it
# If it's in state with wrong name → terraform state rm, then re-addterraform import before managing pre-existing Glue resourcesterraform state list before creating jobs that might already existAlreadyExistsException means a Glue job with that name exists in AWS. Import it with terraform import, use unique environment-prefixed names, or delete the orphaned job. Always check AWS Console and Terraform state to understand where the duplicate came from.
Fix terraform CloudWatch Log Group ResourceAlreadyExistsException. Import orphaned log groups, prevent Lambda auto-creation
Fix terraform import errors when a resource already exists in state. Covers state rm, state show, reimport workflow, import blocks
Fix terraform too many command line arguments errors. Correct -var syntax, quote values with spaces, and learn proper Terraform CLI argument format for plan
Fix terraform invalid escape sequence errors. Double backslashes for Windows paths, use heredocs for regex, and learn all valid HCL escape sequences.