name: Terraform Provision

on:
  push:
    branches:
      - main
    paths:
      - opdracht-3/**/*.tf
      - opdracht-3/**/*.tfvars
      - opdracht-3/**/*.tftpl

jobs:
  terraform:
    name: Terraform Apply
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./opdracht-3

    env:
      TF_VAR_esxi_hostname: ${{ secrets.ESXI_HOSTNAME }}
      TF_VAR_esxi_username: ${{ secrets.ESXI_USERNAME }}
      TF_VAR_esxi_password: ${{ secrets.ESXI_PASSWORD }}

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up Terraform
        uses: hashicorp/setup-terraform@v3

      - name: Terraform Init
        run: terraform init

      - name: Terraform Format
        run: terraform fmt -check

      - name: Terraform Validate
        run: terraform validate

      - name: Terraform Plan
        run: terraform plan

      - name: Terraform Apply
        run: terraform apply -auto-approve
