on:
  push:
  workflow_dispatch:

jobs:
  apply:
    name: OpenTofu
    # Ensure 'nixos-latest' runner has Docker, SSH client, and basic Nix tools installed.
    # It seems it already does.
    runs-on: nixos-latest
    env:
      PROXMOX_API_URL: https://192.168.1.205:8006/api2/json
      # PROXMOX_API_TOKEN_ID: nixos-builder.lab
      # PROXMOX_API_TOKEN_SECRET: nixos-builder.lab

    steps:
      - name: Install dependencies
        run: |
          nix-env -iA nixpkgs.nodejs
          nix-env -iA nixpkgs.openssh
          nix-env -iA nixpkgs.opentofu

      - uses: actions/checkout@v3

      - name: OpenTofu fmt
        id: fmt
        run: tofu fmt -check
        working-directory: ${{ forge.workspace }}/infrastructure/proxmox
        continue-on-error: true

      - name: OpenTofu Init
        id: init
        run: tofu init
        working-directory: ${{ forge.workspace }}/infrastructure/proxmox

      - name: OpenTofu Validate
        id: validate
        run: tofu validate -no-color
        working-directory: ${{ forge.workspace }}/infrastructure/proxmox

      - name: OpenTofu Plan
        id: plan
        run: tofu plan -no-color
        working-directory: ${{ forge.workspace }}/infrastructure/proxmox
        continue-on-error: true
