Skip to content

Refactor Terraform workflow to use GitHub Actions setup and cache #22

Merged
merged 22 commits into from
Oct 9, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 15 additions & 23 deletions .github/workflows/terraform_plan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -48,25 +38,27 @@ 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
run: |
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
Loading