From 75cb3c20cc560d0dc6dff6b21c63951b207e48b6 Mon Sep 17 00:00:00 2001 From: miampf Date: Thu, 18 Apr 2024 16:31:44 +0200 Subject: [PATCH] refactor updating to new update_tfstate action use new action in manual e2e test add token to update tfstate refactored all e2e tests to use new action --- .github/actions/update_tfstate/action.yml | 64 +++++++++++++++++++++++ .github/workflows/e2e-test-daily.yml | 48 ++--------------- .github/workflows/e2e-test-release.yml | 48 ++--------------- .github/workflows/e2e-test-weekly.yml | 48 ++--------------- .github/workflows/e2e-test.yml | 48 ++--------------- .github/workflows/e2e-upgrade.yml | 48 ++--------------- 6 files changed, 89 insertions(+), 215 deletions(-) create mode 100644 .github/actions/update_tfstate/action.yml diff --git a/.github/actions/update_tfstate/action.yml b/.github/actions/update_tfstate/action.yml new file mode 100644 index 000000000..e135d1cb6 --- /dev/null +++ b/.github/actions/update_tfstate/action.yml @@ -0,0 +1,64 @@ +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 + +runs: + using: "composite" + steps: + - name: Check if tfstate should be deleted + if: always() + 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' + 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/* + to_upload="" + if [ -d constellation-terraform ]; then + cp -r constellation-terraform to-zip + rm 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() + uses: ./.github/actions/artifact_upload + with: + name: ${{ inputs.name }} + path: > + ${{ env.TO_UPLOAD }} + encryptionSecret: ${{ inputs.encryptionSecret }} + overwrite: true + + diff --git a/.github/workflows/e2e-test-daily.yml b/.github/workflows/e2e-test-daily.yml index 732b9517e..7618c8e73 100644 --- a/.github/workflows/e2e-test-daily.yml +++ b/.github/workflows/e2e-test-daily.yml @@ -123,53 +123,15 @@ jobs: azureCredentials: ${{ secrets.AZURE_E2E_IAM_CREDENTIALS }} gcpServiceAccount: "iam-e2e@constellation-e2e.iam.gserviceaccount.com" - - name: Check if tfstate should be deleted - if: always() - 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' - env: - GH_TOKEN: ${{ github.token }} - uses: ./.github/actions/artifact_delete - with: - name: terraform-state-${{ steps.e2e_test.outputs.namePrefix }} - workflowID: ${{ github.run_id }} - - - name: Prepare terraform state folders - if: always() - shell: bash - run: | - rm -rf to-zip/* - to_upload="" - if [ -d constellation-terraform ]; then - cp -r constellation-terraform to-zip - rm 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() - uses: ./.github/actions/artifact_upload + env: + GH_TOKEN: ${{ github.token }} + uses: ./.github/actions/update_tfstate with: - name: terraform-state-${{ steps.e2e_test.outputs.namePrefix }} - path: > - ${{ env.TO_UPLOAD }} + name: terraform-state-${{ steps.e2e_test.outputs.namePrefix }} + runID: ${{ github.run_id }} encryptionSecret: ${{ secrets.ARTIFACT_ENCRYPT_PASSWD }} - overwrite: true - name: Notify about failure if: | diff --git a/.github/workflows/e2e-test-release.yml b/.github/workflows/e2e-test-release.yml index e98972ec3..ba9b45947 100644 --- a/.github/workflows/e2e-test-release.yml +++ b/.github/workflows/e2e-test-release.yml @@ -379,53 +379,15 @@ jobs: azureCredentials: ${{ secrets.AZURE_E2E_IAM_CREDENTIALS }} gcpServiceAccount: "iam-e2e@constellation-e2e.iam.gserviceaccount.com" - - name: Check if tfstate should be deleted - if: always() - 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' - env: - GH_TOKEN: ${{ github.token }} - uses: ./.github/actions/artifact_delete - with: - name: terraform-state-${{ steps.e2e_test.outputs.namePrefix }} - workflowID: ${{ github.run_id }} - - - name: Prepare terraform state folders - if: always() - shell: bash - run: | - rm -rf to-zip/* - to_upload="" - if [ -d constellation-terraform ]; then - cp -r constellation-terraform to-zip - rm 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() - uses: ./.github/actions/artifact_upload + env: + GH_TOKEN: ${{ github.token }} + uses: ./.github/actions/update_tfstate with: - name: terraform-state-${{ steps.e2e_test.outputs.namePrefix }} - path: > - ${{ env.TO_UPLOAD }} + name: terraform-state-${{ steps.e2e_test.outputs.namePrefix }} + runID: ${{ github.run_id }} encryptionSecret: ${{ secrets.ARTIFACT_ENCRYPT_PASSWD }} - overwrite: true e2e-upgrade: strategy: diff --git a/.github/workflows/e2e-test-weekly.yml b/.github/workflows/e2e-test-weekly.yml index 0683ff7b2..bcb61fb07 100644 --- a/.github/workflows/e2e-test-weekly.yml +++ b/.github/workflows/e2e-test-weekly.yml @@ -379,53 +379,15 @@ jobs: azureCredentials: ${{ secrets.AZURE_E2E_IAM_CREDENTIALS }} gcpServiceAccount: "iam-e2e@constellation-e2e.iam.gserviceaccount.com" - - name: Check if tfstate should be deleted - if: always() - 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' - env: - GH_TOKEN: ${{ github.token }} - uses: ./.github/actions/artifact_delete - with: - name: terraform-state-${{ steps.e2e_test.outputs.namePrefix }} - workflowID: ${{ github.run_id }} - - - name: Prepare terraform state folders - if: always() - shell: bash - run: | - rm -rf to-zip/* - to_upload="" - if [ -d constellation-terraform ]; then - cp -r constellation-terraform to-zip - rm 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() - uses: ./.github/actions/artifact_upload + env: + GH_TOKEN: ${{ github.token }} + uses: ./.github/actions/update_tfstate with: - name: terraform-state-${{ steps.e2e_test.outputs.namePrefix }} - path: > - ${{ env.TO_UPLOAD }} + name: terraform-state-${{ steps.e2e_test.outputs.namePrefix }} + runID: ${{ github.run_id }} encryptionSecret: ${{ secrets.ARTIFACT_ENCRYPT_PASSWD }} - overwrite: true - name: Notify about failure if: | diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index 28297b00b..71eb9f53a 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -280,50 +280,12 @@ jobs: azureCredentials: ${{ secrets.AZURE_E2E_IAM_CREDENTIALS }} gcpServiceAccount: "iam-e2e@constellation-e2e.iam.gserviceaccount.com" - - name: Check if tfstate should be deleted - if: always() - 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' - env: - GH_TOKEN: ${{ github.token }} - uses: ./.github/actions/artifact_delete - with: - name: terraform-state-${{ steps.e2e_test.outputs.namePrefix }} - workflowID: ${{ github.run_id }} - - - name: Prepare terraform state folders - if: always() - shell: bash - run: | - rm -rf to-zip/* - to_upload="" - if [ -d constellation-terraform ]; then - cp -r constellation-terraform to-zip - rm 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() - uses: ./.github/actions/artifact_upload + env: + GH_TOKEN: ${{ github.token }} + uses: ./.github/actions/update_tfstate with: - name: terraform-state-${{ steps.e2e_test.outputs.namePrefix }} - path: > - ${{ env.TO_UPLOAD }} + name: terraform-state-${{ steps.e2e_test.outputs.namePrefix }} + runID: ${{ github.run_id }} encryptionSecret: ${{ secrets.ARTIFACT_ENCRYPT_PASSWD }} - overwrite: true diff --git a/.github/workflows/e2e-upgrade.yml b/.github/workflows/e2e-upgrade.yml index c9b8ee689..31ac0e1b8 100644 --- a/.github/workflows/e2e-upgrade.yml +++ b/.github/workflows/e2e-upgrade.yml @@ -536,53 +536,15 @@ jobs: azureCredentials: ${{ secrets.AZURE_E2E_IAM_CREDENTIALS }} gcpServiceAccount: "iam-e2e@constellation-e2e.iam.gserviceaccount.com" - - name: Check if tfstate should be deleted - if: always() - 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' - env: - GH_TOKEN: ${{ github.token }} - uses: ./.github/actions/artifact_delete - with: - name: terraform-state-${{ needs.create-cluster.outputs.e2e-name-prefix }} - workflowID: ${{ github.run_id }} - - - name: Prepare terraform state folders - if: always() - shell: bash - run: | - rm -rf to-zip/* - to_upload="" - if [ -d constellation-terraform ]; then - cp -r constellation-terraform to-zip - rm 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() - uses: ./.github/actions/artifact_upload + env: + GH_TOKEN: ${{ github.token }} + uses: ./.github/actions/update_tfstate with: - name: terraform-state-${{ needs.create-cluster.outputs.e2e-name-prefix }} - path: > - ${{ env.TO_UPLOAD }} + name: terraform-state-${{ needs.create-cluster.outputs.e2e-name-prefix }} + runID: ${{ github.run_id }} encryptionSecret: ${{ secrets.ARTIFACT_ENCRYPT_PASSWD }} - overwrite: true - name: Notify about failure if: |