constellation/.github/actions/update_tfstate/action.yml
Daniel Weiße 259e85d9c1
ci: reduce noise from warnings (#3055)
* Fix whitespace errors
* Remove usage of external action to URI encode component
* Upgrade Azure login action to v2.1
* Remove GitHub actions warning when running e2e test with NOP payload
* Only try to upload updated tf state if it exists
* Upgrade out of date aws credential actions

---------

Signed-off-by: Daniel Weiße <dw@edgeless.systems>
2024-05-03 08:17:40 +02:00

69 lines
2.2 KiB
YAML

name: Update TFState
description: "Update the terraform state artifact."
inputs:
name:
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
if: always() && inputs.skipDeletion == 'false'
shell: bash
run: |
if [[ ! -d constellation-terraform ]] && [[ ! -d constellation-iam-terraform ]]; then
echo "DELETE_TF_STATE=true" >> "$GITHUB_ENV"
else
echo "DELETE_TF_STATE=false" >> "$GITHUB_ENV"
fi
- name: Delete tfstate artifact if necessary
if: always() && env.DELETE_TF_STATE == 'true' && inputs.skipDeletion == 'false'
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/*
mkdir -p to-zip
to_upload=""
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"
fi
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"
fi
echo "TO_UPLOAD=$to_upload" >> "$GITHUB_ENV"
- name: Update tfstate
if: always() && env.TO_UPLOAD != ''
uses: ./.github/actions/artifact_upload
with:
name: ${{ inputs.name }}
path: >
${{ env.TO_UPLOAD }}
encryptionSecret: ${{ inputs.encryptionSecret }}
overwrite: true