Skip to content

Terraform-Deploy

Terraform-Deploy #1

Workflow file for this run

name: 'Terraform-Deploy'
on:
workflow_dispatch:
inputes:
tfvars_file:
description: 'Path to the .tfvars file'
required: true
default: 'dev.tfvars'
action:
type: choice
description: 'Apply or Destroy'
options:
- plan
- apply
- destroy
required: true
default: 'apply'
env:
AWS_REGION: eu-west-1
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: {{ secrets.AWS_SECRET_ACCESS_KEY }}

Check failure on line 23 in .github/workflows/terraform.yaml

View workflow run for this annotation

GitHub Actions / Terraform-Deploy

Invalid workflow file

The workflow is not valid. .github/workflows/terraform.yaml (Line: 23, Col: 26): A mapping was not expected .github/workflows/terraform.yaml (Line: 45, Col: 5): Unexpected value 'default'
permissions:
contents: read
jobs:
# name: 'Terraform'
# uses: actions/checkout@v4
# runs-on: ubuntu-latest
# environment: production
# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
# defaults:
# run:
# shell: bash
# working-directory: eks
CheckOut-Repo:
runs-on: ubuntu-latest
environment: production
default:
run:
shell: bash
working-directory: eks
env:
AWS_REGION: eu-west-1
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# needs: terraform
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v4
Setting-Up-Terraform:
runs-on: ubuntu-latest
needs: CheckOut-Repo
steps:
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.9.3
Terraform-Initializing:
runs-on: ubuntu-latest
needs: Setting-Up-Terraform
steps:
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.9.3
- name: Checkout repository
uses: actions/checkout@v4
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
working-directory: eks
run: terraform init
Terraform-Formatting-Validating:
runs-on: ubuntu-latest
needs: Terraform-Initializing
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.9.3
- name: Terraform Init
working-directory: eks
run: terraform init
# Checks that all Terraform configuration files adhere to a canonical format
- name: Terraform Format
working-directory: eks
run: terraform fmt
- name: Terraform Validate
working-directory: eks
run: terraform validate
Terraform-Action:
runs-on: ubuntu-latest
needs: Terraform-Formatting-Validating
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.9.3
- name: Terraform Init
working-directory: eks
run: terraform init
- name: Terraform Plan
if: ${{ github.event.inputs.action == 'plan'}}
working-directory: eks
run: terraform init
# Generates an execution plan for Terraform
run:
terraform plan -var-file=${{ github.event.inputs.tfvars_file }} -input=false
# Apply the Terraform Configuration according to the parameter
- name: Terraform Action
if: ${{ github.event.inputs.action == 'apply' }}
run: terraform ${{ github.event.inputs.action }} -auto-approve -var-file=${{ github.event.inputs.tfvars_file }} -input=false
- name: Terraform Destroy
if: ${{ github.event.inputs.action == 'destroy' }}
working-directory: eks
run: terraform ${{ github.event.inputs.action }} -auto-approve -var-file=${{ github.event.inputs.tfvars_file }} -input=false