Skip to content

Commit

Permalink
fix: DBTP-1104 Ensure Terraform plan resources are available during a…
Browse files Browse the repository at this point in the history
…pply stage. (#174)
  • Loading branch information
antroy-madetech authored Jun 28, 2024
1 parent f57b122 commit 7d2b397
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 21 deletions.
4 changes: 1 addition & 3 deletions environment-pipelines/buildspec-apply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ phases:
commands:
- export PATH="${CODEBUILD_SRC_DIR}/build-tools/bin:$PATH"
- export PYTHONPATH="${CODEBUILD_SRC_DIR}/build-tools"
- eval export PLAN_TF_DIR=\$CODEBUILD_SRC_DIR_${ENVIRONMENT}_terraform_plan
build:
commands:
- set -e
- echo -e "\nTerraform Apply Phase"
- platform-helper notify add-comment "${SLACK_CHANNEL_ID}" "${SLACK_TOKEN}" "${SLACK_REF}" "Starting terraform apply phase for the ${ENVIRONMENT} environment."
- echo -e "\nWorking on environment ${ENVIRONMENT}"
- cd "terraform/environments/${ENVIRONMENT}"
- terraform init
- terraform apply "${PLAN_TF_DIR}/terraform/environments/${ENVIRONMENT}/plan.tfplan"
- terraform apply plan.tfplan
- echo -e "\nGenerating manifests and deploying AWS Copilot environment resources"
- cd "${CODEBUILD_SRC_DIR}"
- platform-helper environment generate --name "${ENVIRONMENT}"
Expand Down
3 changes: 1 addition & 2 deletions environment-pipelines/buildspec-plan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,4 @@ phases:
fi
artifacts:
files:
- terraform/environments/${ENVIRONMENT}/plan.tfplan
- copilot/environments/${ENVIRONMENT}/manifest.yml
- "**/*"
4 changes: 2 additions & 2 deletions environment-pipelines/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ locals {
env : env.name,
stage_name : "Apply-${env.name}",
accounts : env.accounts,
input_artifacts : ["build_output", "${env.name}_terraform_plan"],
input_artifacts : ["${env.name}_terraform_plan"],
output_artifacts : [],
configuration : {
ProjectName : "${var.application}-${var.pipeline_name}-environment-pipeline-apply"
PrimarySource : "build_output"
PrimarySource : "${env.name}_terraform_plan"
EnvironmentVariables : jsonencode([
{ name : "ENVIRONMENT", value : env.name },
{ name : "SLACK_CHANNEL_ID", value : var.slack_channel, type : "PARAMETER_STORE" },
Expand Down
20 changes: 6 additions & 14 deletions environment-pipelines/tests/unit.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -771,15 +771,11 @@ run "test_stages" {
error_message = "Action provider incorrect"
}
assert {
condition = length(aws_codepipeline.environment_pipeline.stage[3].action[0].input_artifacts) == 2
condition = length(aws_codepipeline.environment_pipeline.stage[3].action[0].input_artifacts) == 1
error_message = "Input artifacts incorrect"
}
assert {
condition = aws_codepipeline.environment_pipeline.stage[3].action[0].input_artifacts[0] == "build_output"
error_message = "Input artifacts incorrect"
}
assert {
condition = aws_codepipeline.environment_pipeline.stage[3].action[0].input_artifacts[1] == "dev_terraform_plan"
condition = aws_codepipeline.environment_pipeline.stage[3].action[0].input_artifacts[0] == "dev_terraform_plan"
error_message = "Input artifacts incorrect"
}
assert {
Expand All @@ -795,7 +791,7 @@ run "test_stages" {
error_message = "Configuration ProjectName incorrect"
}
assert {
condition = aws_codepipeline.environment_pipeline.stage[3].action[0].configuration.PrimarySource == "build_output"
condition = aws_codepipeline.environment_pipeline.stage[3].action[0].configuration.PrimarySource == "dev_terraform_plan"
error_message = "Configuration PrimarySource incorrect"
}
assert {
Expand Down Expand Up @@ -925,15 +921,11 @@ run "test_stages" {
error_message = "Action provider incorrect"
}
assert {
condition = length(aws_codepipeline.environment_pipeline.stage[6].action[0].input_artifacts) == 2
error_message = "Input artifacts incorrect"
}
assert {
condition = aws_codepipeline.environment_pipeline.stage[6].action[0].input_artifacts[0] == "build_output"
condition = length(aws_codepipeline.environment_pipeline.stage[6].action[0].input_artifacts) == 1
error_message = "Input artifacts incorrect"
}
assert {
condition = aws_codepipeline.environment_pipeline.stage[6].action[0].input_artifacts[1] == "prod_terraform_plan"
condition = aws_codepipeline.environment_pipeline.stage[6].action[0].input_artifacts[0] == "prod_terraform_plan"
error_message = "Input artifacts incorrect"
}
assert {
Expand All @@ -949,7 +941,7 @@ run "test_stages" {
error_message = "Configuration ProjectName incorrect"
}
assert {
condition = aws_codepipeline.environment_pipeline.stage[6].action[0].configuration.PrimarySource == "build_output"
condition = aws_codepipeline.environment_pipeline.stage[6].action[0].configuration.PrimarySource == "prod_terraform_plan"
error_message = "Configuration PrimarySource incorrect"
}
assert {
Expand Down

0 comments on commit 7d2b397

Please sign in to comment.