2024-04-26 06:06:01 -04:00
|
|
|
name: Update TFState
|
|
|
|
description: "Update the terraform state artifact."
|
|
|
|
|
|
|
|
inputs:
|
2024-05-03 02:17:40 -04:00
|
|
|
name:
|
2024-04-26 06:06:01 -04:00
|
|
|
description: "The name of the artifact that contains the tfstate."
|
|
|
|
required: true
|
|
|
|
runID:
|
|
|
|
description: "The ID of your current run (github.run_id)."
|
|
|
|
required: true
|
|
|
|
encryptionSecret:
|
|
|
|
description: "The encryption secret for the artifacts."
|
|
|
|
required: true
|
|
|
|
skipDeletion:
|
|
|
|
description: "Don't try to delete the artifact before updating. You should only use this if you know that no artifact exists."
|
|
|
|
default: "false"
|
|
|
|
required: false
|
|
|
|
|
|
|
|
runs:
|
|
|
|
using: "composite"
|
|
|
|
steps:
|
|
|
|
- name: Check if tfstate should be deleted
|
2024-05-03 02:17:40 -04:00
|
|
|
if: always() && inputs.skipDeletion == 'false'
|
2024-04-26 06:06:01 -04:00
|
|
|
shell: bash
|
|
|
|
run: |
|
2024-05-07 02:48:38 -04:00
|
|
|
if [[ -d constellation-terraform ]] || [[ -d constellation-iam-terraform ]]; then
|
2024-05-03 02:17:40 -04:00
|
|
|
echo "DELETE_TF_STATE=true" >> "$GITHUB_ENV"
|
2024-04-26 06:06:01 -04:00
|
|
|
else
|
2024-05-03 02:17:40 -04:00
|
|
|
echo "DELETE_TF_STATE=false" >> "$GITHUB_ENV"
|
2024-04-26 06:06:01 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
- name: Delete tfstate artifact if necessary
|
2024-05-03 02:17:40 -04:00
|
|
|
if: always() && env.DELETE_TF_STATE == 'true' && inputs.skipDeletion == 'false'
|
2024-04-26 06:06:01 -04:00
|
|
|
uses: ./.github/actions/artifact_delete
|
|
|
|
with:
|
|
|
|
name: ${{ inputs.name }}
|
|
|
|
workflowID: ${{ inputs.runID }}
|
|
|
|
|
|
|
|
- name: Prepare terraform state folders
|
|
|
|
if: always()
|
|
|
|
shell: bash
|
|
|
|
run: |
|
|
|
|
rm -rf to-zip/*
|
2024-05-03 02:17:40 -04:00
|
|
|
mkdir -p to-zip
|
|
|
|
|
2024-04-26 06:06:01 -04:00
|
|
|
to_upload=""
|
2024-05-03 02:17:40 -04:00
|
|
|
if [[ -d constellation-terraform ]]; then
|
|
|
|
cp -r constellation-terraform to-zip
|
|
|
|
rm -f to-zip/constellation-terraform/plan.zip
|
|
|
|
rm -rf to-zip/constellation-terraform/.terraform
|
|
|
|
to_upload+="to-zip/constellation-terraform"
|
2024-04-26 06:06:01 -04:00
|
|
|
fi
|
2024-05-03 02:17:40 -04:00
|
|
|
if [[ -d constellation-iam-terraform ]]; then
|
|
|
|
cp -r constellation-iam-terraform to-zip
|
|
|
|
rm -rf to-zip/constellation-iam-terraform/.terraform
|
|
|
|
to_upload+=" to-zip/constellation-iam-terraform"
|
2024-04-26 06:06:01 -04:00
|
|
|
fi
|
|
|
|
echo "TO_UPLOAD=$to_upload" >> "$GITHUB_ENV"
|
|
|
|
|
|
|
|
- name: Update tfstate
|
2024-05-03 02:17:40 -04:00
|
|
|
if: always() && env.TO_UPLOAD != ''
|
2024-04-26 06:06:01 -04:00
|
|
|
uses: ./.github/actions/artifact_upload
|
|
|
|
with:
|
|
|
|
name: ${{ inputs.name }}
|
|
|
|
path: >
|
|
|
|
${{ env.TO_UPLOAD }}
|
|
|
|
encryptionSecret: ${{ inputs.encryptionSecret }}
|
|
|
|
overwrite: true
|