Skip to content

Commit

Permalink
Reusable Terraform Action (#445)
Browse files Browse the repository at this point in the history
* update cache action to v4

* use setup-terraform action
  • Loading branch information
ethangardner authored Jan 15, 2025
1 parent faa676c commit 7b27866
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 65 deletions.
26 changes: 4 additions & 22 deletions .github/workflows/_terraform-apply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ on:
deploy-env:
type: string
required: true
terraform_version:
description: Terraform version
required: false
default: "1.10.4"
type: string

env:
DEPLOY_ENV: ${{ inputs.deploy-env }}
Expand Down Expand Up @@ -44,7 +39,7 @@ jobs:
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
Expand All @@ -55,23 +50,10 @@ jobs:
- name: Install dependencies
run: pnpm install

- uses: actions/cache@v3
name: Check Cache for Terraform CLI
id: terraform-cache
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
path: /usr/local/bin/terraform
key: terraform-${{ inputs.terraform_version }}

- name: Install Terraform CLI
if: steps.terraform-cache.outputs.cache-hit != 'true'
run: |
sudo apt-get update && sudo apt-get install -y wget unzip
wget https://releases.hashicorp.com/terraform/${{ inputs.terraform_version }}/terraform_${{ inputs.terraform_version }}_linux_amd64.zip
unzip terraform_${{ inputs.terraform_version }}_linux_amd64.zip
sudo mv terraform /usr/local/bin/
- name: Verify Terraform Installation
run: terraform --version
terraform_version: "1.10.4"

- name: Initialize Terraform CDK configuration
shell: bash
Expand Down
26 changes: 4 additions & 22 deletions .github/workflows/_terraform-plan-pr-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ on:
deploy-env:
required: true
type: string
terraform_version:
description: Terraform version
required: false
default: "1.10.4"
type: string

jobs:
terraform:
Expand Down Expand Up @@ -46,7 +41,7 @@ jobs:
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
Expand All @@ -57,23 +52,10 @@ jobs:
- name: Install dependencies
run: pnpm install

- uses: actions/cache@v3
name: Check Cache for Terraform CLI
id: terraform-cache
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
path: /usr/local/bin/terraform
key: terraform-${{ inputs.terraform_version }}

- name: Install Terraform CLI
if: steps.terraform-cache.outputs.cache-hit != 'true'
run: |
sudo apt-get update && sudo apt-get install -y wget unzip
wget https://releases.hashicorp.com/terraform/${{ inputs.terraform_version }}/terraform_${{ inputs.terraform_version }}_linux_amd64.zip
unzip terraform_${{ inputs.terraform_version }}_linux_amd64.zip
sudo mv terraform /usr/local/bin/
- name: Verify Terraform Installation
run: terraform --version
terraform_version: "1.10.4"

- name: Initialize Terraform CDK configuration
shell: bash
Expand Down
24 changes: 3 additions & 21 deletions .github/workflows/_validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ on:
required: false
default: "1.48.1"
type: string
terraform_version:
description: Terraform version
required: false
default: "1.10.4"
type: string

jobs:
run-tests:
Expand Down Expand Up @@ -97,23 +92,10 @@ jobs:
shell: bash
run: AUTH_SECRET=not-super-secret pnpm test:ci

- uses: actions/cache@v3
name: Check Cache for Terraform CLI
id: terraform-cache
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
path: /usr/local/bin/terraform
key: terraform-${{ inputs.terraform_version }}

- name: Install Terraform CLI
if: steps.terraform-cache.outputs.cache-hit != 'true'
run: |
sudo apt-get update && sudo apt-get install -y wget unzip
wget https://releases.hashicorp.com/terraform/${{ inputs.terraform_version }}/terraform_${{ inputs.terraform_version }}_linux_amd64.zip
unzip terraform_${{ inputs.terraform_version }}_linux_amd64.zip
sudo mv terraform /usr/local/bin/
- name: Verify Terraform Installation
run: terraform --version
terraform_version: "1.10.4"

- name: Initialize Terraform CDK configuration
shell: bash
Expand Down

0 comments on commit 7b27866

Please sign in to comment.