Skip to content

Commit b227504

Browse files
committed
Add debug outputs
1 parent 1becb6d commit b227504

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

.github/workflows/data-replication-pipeline.yml

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,38 @@ jobs:
159159
run: |
160160
set -e
161161
terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
162-
PLAN_CMD="terraform plan -var=image_digest=${{ env.DOCKER_DIGEST }} \
163-
-var=db_secret_arn=${{ env.DB_SECRET_ARN }} \
164-
-var=imported_snapshot=${{ env.SNAPSHOT_ARN }} \
165-
-var-file=env/${{ inputs.environment }}.tfvars \
166-
-var=allowed_egress_cidr_blocks='${{ inputs.egress_cidr }}'"
162+
163+
# Build terraform plan arguments as an array
164+
PLAN_ARGS=(
165+
"plan"
166+
"-var=image_digest=${{ env.DOCKER_DIGEST }}"
167+
"-var=db_secret_arn=${{ env.DB_SECRET_ARN }}"
168+
"-var=imported_snapshot=${{ env.SNAPSHOT_ARN }}"
169+
"-var-file=env/${{ inputs.environment }}.tfvars"
170+
"-var=allowed_egress_cidr_blocks='${{ inputs.egress_cidr }}'"
171+
)
167172
168173
if [ "${{ env.REPLACE_DB_CLUSTER }}" = "true" ]; then
169-
PLAN_CMD="$PLAN_CMD -replace aws_rds_cluster.core"
174+
PLAN_ARGS+=("-replace" "aws_rds_cluster.core")
170175
fi
171176
172-
PLAN_CMD="$PLAN_CMD -out ${{ runner.temp }}/tfplan"
173-
eval "$PLAN_CMD" | tee ${{ runner.temp }}/tf_stdout
177+
# Add output file argument
178+
PLAN_ARGS+=("-out" "${{ runner.temp }}/tfplan")
179+
180+
terraform "${PLAN_ARGS[@]}" | tee ${{ runner.temp }}/tf_stdout
181+
182+
# Capture the exit code of the terraform command
183+
EXIT_CODE=${PIPESTATUS[0]}
184+
# Check if the command was successful
185+
if [ $EXIT_CODE -ne 0 ]; then
186+
echo "Terraform plan failed with exit code $EXIT_CODE"
187+
echo "Plan output:"
188+
cat ${{ runner.temp }}/tf_stdout
189+
exit $EXIT_CODE
190+
fi
174191
175-
echo "$PLAN_CMD"
192+
echo "Plan cmd: $PLAN_CMD"
193+
echo "Cidr input: ${{ inputs.egress_cidr }}"
176194
177195
- name: Upload artifact
178196
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)