Skip to content

Commit edb36d8

Browse files
Patch application deployment workflow
- Should use bucket name output not hardcoded value - Digest was in tfvars file which overwrote command-line argument - Remove from tfvars and restructure order to avoid overwrite in the future - Script to exit on failed grep
1 parent 1bfdc0e commit edb36d8

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

.github/workflows/deploy-application.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ jobs:
6868
working-directory: ${{ env.terraform-working-directory }}
6969
run: |
7070
terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
71-
terraform plan -var="image_digest=$DIGEST" -target=aws_ecs_task_definition.task_definition \
71+
terraform plan -target=aws_ecs_task_definition.task_definition \
7272
-target=aws_s3_object.appspec_object -var-file="env/${{ inputs.environment }}.tfvars" \
73-
-out=${{ runner.temp }}/tfplan | tee ${{ runner.temp }}/tf_stdout
73+
-var="image_digest=$DIGEST" -out=${{ runner.temp }}/tfplan | tee ${{ runner.temp }}/tf_stdout
7474
- name: Validate the changes
7575
run: |
7676
./terraform/scripts/check_task_definition.sh ${{ runner.temp }}/tf_stdout
@@ -143,9 +143,8 @@ jobs:
143143
run: |
144144
source ${{ runner.temp }}/artifact/CODEDEPLOY_ENV
145145
deployment_id=$(aws deploy create-deployment \
146-
--application-name $application --deployment-group-name $application_group \
147-
--s3-location bucket=appspec-bucket-${{ inputs.environment }},key=appspec.yaml,bundleType=yaml \
148-
| jq -r .deploymentId)
146+
--application-name "$application" --deployment-group-name "$application_group" \
147+
--s3-location bucket="$s3_bucket",key="$s3_key",bundleType=yaml | jq -r .deploymentId)
149148
echo "Deployment started: $deployment_id"
150149
echo "deployment_id=$deployment_id" >> $GITHUB_ENV
151150
- name: Wait up to 30 minutes for deployment to complete

terraform/app/env/qa.tfvars

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@ http_hosts = {
2323
}
2424
minimum_replicas = 3
2525
appspec_bucket = "nhse-mavis-appspec-bucket-qa"
26-
image_digest="sha256:b35aa00cd4e61cc796f9c852291fb5ea188e33a08ce84a9ca1519b57c77d9a31"

terraform/scripts/check_task_definition.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ else
2323
echo "S3 bucket object is not being replaced, aborting."
2424
exit 1
2525
fi
26-
MODIFICATIONS=$(grep -E "[0-9]+ to add, [0-9]+ to change, [0-9]+ to destroy." test_less)
27-
ADDITIONS=$(echo "$MODIFICATIONS" | sed -E 's/.*([0-9]+) to add.*/\1/')
28-
CHANGES=$(echo "$MODIFICATIONS" | sed -E 's/.*([0-9]+) to change.*/\1/')
29-
DELETIONS=$(echo "$MODIFICATIONS" | sed -E 's/.*([0-9]+) to destroy.*/\1/')
26+
MODIFICATIONS=$(grep -E "[0-9]+ to add, [0-9]+ to change, [0-9]+ to destroy." "$tf_stdout") || exit 1
27+
ADDITIONS=$(echo "$MODIFICATIONS" | sed -E 's/.*([0-9]+) to add.*/\1/') || exit 1
28+
CHANGES=$(echo "$MODIFICATIONS" | sed -E 's/.*([0-9]+) to change.*/\1/') || exit 1
29+
DELETIONS=$(echo "$MODIFICATIONS" | sed -E 's/.*([0-9]+) to destroy.*/\1/') || exit 1
3030
if [[ $DELETIONS -gt $ADDITIONS ]]; then
3131
echo "More resources are being destroyed than created."
3232
echo "Other resources than task definition and s3 bucket object are being deleted, aborting."

0 commit comments

Comments
 (0)