Fix Terraform Error: CloudWatch Log Group Already Exists
Fix terraform CloudWatch Log Group ResourceAlreadyExistsException. Import orphaned log groups, prevent Lambda auto-creation
DevOps
Fix InvalidStructure errors when creating AWS CodePipeline in Terraform. Handle action configuration, stage ordering, artifact naming, and IAM permission...
The CodePipeline definition has structural errors — missing required fields, invalid action configurations, wrong artifact names, or incorrect stage ordering. Source must be the first stage, and every action's input/output artifacts must chain correctly.
Error: error creating CodePipeline: InvalidStructureException:
Pipeline has only 1 stage(s). There should be a minimum of 2 stages.Error: error creating CodePipeline: InvalidStructureException:
Invalid action configuration: No Branch specifiedresource "aws_codepipeline" "main" {
name = "${var.project}-pipeline"
role_arn = aws_iam_role.codepipeline.arn
artifact_store {
location = aws_s3_bucket.artifacts.id
type = "S3"
}
# Stage 1: Source (REQUIRED)
stage {
name = "Source"
action {
name = "Source"
category = "Source"
owner = "AWS"
provider = "CodeStarSourceConnection"
version = "1"
output_artifacts = ["source_output"]
configuration = {
ConnectionArn = aws_codestarconnections_connection.github.arn
FullRepositoryId = "myorg/myrepo"
BranchName = "main" # Required!
}
}
}
# Stage 2: Build
stage {
name = "Build"
action {
name = "Build"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
version = "1"
input_artifacts = ["source_output"] # Must match Source output
output_artifacts = ["build_output"]
configuration = {
ProjectName = aws_codebuild_project.main.name
}
}
}
# Stage 3: Deploy (optional but common)
stage {
name = "Deploy"
action {
name = "Deploy"
category = "Deploy"
owner = "AWS"
provider = "ECS"
version = "1"
input_artifacts = ["build_output"] # Must match Build output
configuration = {
ClusterName = aws_ecs_cluster.main.name
ServiceName = aws_ecs_service.app.name
}
}
}
}# ❌ Broken — artifact names don't match
stage {
name = "Source"
action {
output_artifacts = ["src"] # Named "src"
}
}
stage {
name = "Build"
action {
input_artifacts = ["source_output"] # Looking for "source_output" — MISMATCH!
}
}
# ✅ Fixed — names match
stage {
name = "Source"
action {
output_artifacts = ["source_output"]
}
}
stage {
name = "Build"
action {
input_artifacts = ["source_output"] # Matches!
}
}| Error Detail | Fix |
|---|---|
| "Only 1 stage" | Add at least Source + Build/Deploy |
| "No Branch specified" | Add BranchName to Source config |
| "Invalid action configuration" | Check required fields for your action provider |
| Artifact not found | Match output_artifacts → input_artifacts names |
| Wrong category | Source actions must be category = "Source" |
InvalidStructureException means your pipeline definition has structural errors. Ensure minimum 2 stages, Source first, all required configuration fields present, and artifact names chaining correctly between stages. Validate the pipeline structure with terraform plan before applying.
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.