petersumma is testing GitHub Actions π #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Terraform Github Actions | |
run-name: ${{ github.actor }} is testing GitHub Actions π | |
on: [push] | |
defaults: | |
run: | |
working-directory: ./terraform | |
env: | |
NSXT_MANAGER_HOST: ${{ secrets.NSXT_MANAGER_HOST }} | |
NSXT_USERNAME: ${{ secrets.NSXT_USERNAME }} | |
NSXT_PASSWORD: ${{ secrets.NSXT_PASSWORD }} | |
S3_ACCESS_KEY: ${{ secrets.S3_ACCESS_KEY }} | |
S3_SECRET_KEY: ${{ secrets.S3_SECRET_KEY }} | |
jobs: | |
Validate: | |
runs-on: [self-hosted] | |
container: | |
image: hashicorp/terraform | |
steps: | |
- name: clone repository | |
uses: actions/checkout@v2 | |
- name: terraform init | |
id: init | |
run: terraform init -backend-config="access_key=${S3_ACCESS_KEY}" -backend-config="secret_key=${S3_SECRET_KEY}" | |
continue-on-error: false | |
- name: terraform fmt | |
id: fmt | |
run: terraform fmt -check -recursive -diff | |
continue-on-error: false | |
- name: terraform validate | |
id: validate | |
run: terraform validate | |
continue-on-error: false | |
Plan: | |
needs: [Validate] | |
runs-on: [self-hosted] | |
container: | |
image: hashicorp/terraform | |
steps: | |
- name: terraform init | |
id: init | |
run: terraform init -backend-config="access_key=${S3_ACCESS_KEY}" -backend-config="secret_key=${S3_SECRET_KEY}" | |
- name: terraform plan | |
id: plan | |
run: terraform plan -out=planfile | |
Apply: | |
needs: [Validate, Plan] | |
runs-on: [self-hosted] | |
if: ${{ github.ref == 'refs/heads/main' }} | |
container: | |
image: hashicorp/terraform | |
steps: | |
- name: terraform apply | |
id: apply | |
run: terraform apply -input=false "planfile" |