From c6ea55ae4e9415cab7f858516b9a30b6c76da67f Mon Sep 17 00:00:00 2001 From: gomez385 Date: Mon, 7 Oct 2024 19:45:37 -0400 Subject: [PATCH] Refactor Terraform workflow to use GitHub Actions setup and cache This commit refactors the Terraform workflow to use the GitHub Actions setup and cache. It removes the unnecessary steps for checking out the repository and blowing up the .terraform directory. It also adds the setup for AWS and GitHub credentials. The Terraform init and plan steps are now using the CSVD/terraform-init and CSVD/terraform-plan actions, respectively, with specific versions and workspace configurations. --- .github/workflows/terraform_plan.yaml | 38 +++++++++++---------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index d57aa70..bcbb3d1 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -28,16 +28,6 @@ jobs: # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v3 - - - uses: CSVD/gh-actions-setup-node@v3 - with: - node-version: 16 - - - name: blow up .terraform - run: rm -rf ${{ github.workspace }}/.terraform || echo "nope" - - name: Setup AWS Credentials id: aws_credentials run: | @@ -48,6 +38,7 @@ jobs: echo AWS_SECRET_ACCESS_KEY=`jq -r '.SecretAccessKey' aws_credentials.json` >> $GITHUB_ENV aws configure set aws_session_token `jq -r '.Token' aws_credentials.json` echo AWS_SESSION_TOKEN=`jq -r '.Token' aws_credentials.json` >> $GITHUB_ENV + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: Setup GITHUB Credentials id: github_credentials @@ -55,18 +46,19 @@ jobs: echo GITHUB_TOKEN=$(python encode_jwt.py "$GITHUB_APP_PEM_FILE" "$GITHUB_APP_INSTALLATION_ID" "$GITHUB_BASE_URL") >> $GITHUB_ENV - name: Terraform Init - id: init - run: /opt/tfenv/bin/terraform init -upgrade - - - name: Terraform Validate - id: validate - run: /opt/tfenv/bin/terraform validate + uses: CSVD/terraform-init@main + id: terraform_init + with: + terraform_version: "1.9.1" + workspace: ${{ vars.terraform_workspace }} + setup_terraform: true + terraform_init: true - name: Terraform Plan - id: plan - run: /opt/tfenv/bin/terraform plan -var-file=varfiles/${{ vars.terraform_workspace }}.tfvars - -# - name: Terraform Apply -# id: plan -# run: /opt/tfenv/bin/terraform apply -auto-approve -var-file=varfiles/${{ vars.terraform_workspace }}.tfvars -# continue-on-error: true + uses: CSVD/terraform-plan@main + with: + terraform_version: "1.9.1" + workspace: ${{ vars.terraform_workspace }} + commit_sha: ${{ steps.terraform_init.outputs.commit_sha }} + varfile: varfiles/${{ vars.terraform_workspace }}.tfvars + download_cache: true