95 lines
3.8 KiB
YAML
95 lines
3.8 KiB
YAML
name: Reusable OpenTofu Deploy Template
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
proxmox_endpoint:
|
|
description: "The URL endpoint for the Proxmox API"
|
|
type: string
|
|
default: "https://212.3.125.242:8006/"
|
|
infisical_api_url:
|
|
description: "Infisical API URL (for self-hosted instances)"
|
|
type: string
|
|
required: false
|
|
default: "https://secrets.itlab-ffeks.dnu.edu.ua"
|
|
secrets:
|
|
infisical_cicd_token:
|
|
description: "Infisical Service Token for CI/CD secrets"
|
|
required: true
|
|
|
|
jobs:
|
|
deploy-to-proxmox:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
# Proxmox Auth (Endpoint from inputs)
|
|
PROXMOX_VE_ENDPOINT: ${{ inputs.proxmox_endpoint }}
|
|
PROXMOX_VE_INSECURE: "true"
|
|
|
|
# Gitea Remote State Backend (Dynamic per-repository package/workspace)
|
|
TF_HTTP_ADDRESS: "https://git.itlab-ffeks.dnu.edu.ua/api/packages/${{ gitea.repository_owner }}/terraform/state/${{ gitea.event.repository.name }}-${{ gitea.ref_name }}"
|
|
TF_HTTP_LOCK_ADDRESS: "https://git.itlab-ffeks.dnu.edu.ua/api/packages/${{ gitea.repository_owner }}/terraform/state/${{ gitea.event.repository.name }}-${{ gitea.ref_name }}/lock"
|
|
TF_HTTP_UNLOCK_ADDRESS: "https://git.itlab-ffeks.dnu.edu.ua/api/packages/${{ gitea.repository_owner }}/terraform/state/${{ gitea.event.repository.name }}-${{ gitea.ref_name }}/lock"
|
|
TF_HTTP_LOCK_METHOD: "POST"
|
|
TF_HTTP_UNLOCK_METHOD: "DELETE"
|
|
TF_HTTP_USERNAME: ${{ gitea.actor }}
|
|
TF_VAR_environment: ${{ gitea.ref_name }}
|
|
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install Infisical CLI
|
|
run: |
|
|
curl -1sLf 'https://dl.cloudsmith.io/public/infisical/infisical-cli/setup.deb.sh' | sudo -E bash
|
|
sudo apt-get update && sudo apt-get install -y infisical
|
|
|
|
- name: Fetch secrets from Infisical
|
|
run: |
|
|
export INFISICAL_TOKEN="${{ secrets.infisical_cicd_token }}"
|
|
export INFISICAL_API_URL="${{ inputs.infisical_api_url || 'https://app.infisical.com' }}"
|
|
export INFISICAL_DOMAIN="$INFISICAL_API_URL"
|
|
export INFISICAL_DISABLE_UPDATE_CHECK=true
|
|
|
|
# Fetch secrets (assuming CLI is pre-installed)
|
|
echo "Fetching secrets from Infisical..."
|
|
PROXMOX_VE_API_TOKEN=$(infisical secrets get PROXMOX_VE_API_TOKEN --plain)
|
|
INFRASTRUCTURE_TOKEN=$(infisical secrets get INFRASTRUCTURE_TOKEN --plain)
|
|
|
|
# Mask values in logs immediately
|
|
echo "::add-mask::$PROXMOX_VE_API_TOKEN"
|
|
echo "::add-mask::$INFRASTRUCTURE_TOKEN"
|
|
|
|
# Export to GITHUB_ENV for subsequent steps/env context
|
|
echo "PROXMOX_VE_API_TOKEN=$PROXMOX_VE_API_TOKEN" >> $GITHUB_ENV
|
|
echo "INFRASTRUCTURE_TOKEN=$INFRASTRUCTURE_TOKEN" >> $GITHUB_ENV
|
|
echo "TF_HTTP_PASSWORD=$INFRASTRUCTURE_TOKEN" >> $GITHUB_ENV
|
|
|
|
- name: Verify Secrets
|
|
run: |
|
|
if [ -z "$PROXMOX_VE_API_TOKEN" ]; then
|
|
echo "Error: PROXMOX_VE_API_TOKEN is not set or is empty." >&2
|
|
exit 1
|
|
fi
|
|
if [ -z "$INFRASTRUCTURE_TOKEN" ]; then
|
|
echo "Error: INFRASTRUCTURE_TOKEN is not set or is empty." >&2
|
|
exit 1
|
|
fi
|
|
echo "Verification successful: both tokens are present."
|
|
|
|
- name: Configure Git for private modules
|
|
run: git config --global url."https://oauth2:$INFRASTRUCTURE_TOKEN@git.itlab-ffeks.dnu.edu.ua".insteadOf "https://git.itlab-ffeks.dnu.edu.ua"
|
|
|
|
- name: Setup OpenTofu
|
|
uses: opentofu/setup-opentofu@v1
|
|
|
|
- name: OpenTofu Init
|
|
run: tofu init
|
|
|
|
- name: OpenTofu Validate
|
|
run: tofu validate
|
|
|
|
# For debugging.
|
|
- name: OpenTofu Plan
|
|
run: tofu plan
|
|
|
|
- name: OpenTofu Apply
|
|
run: tofu apply -auto-approve |