name: terraform-proxmox on: workflow_dispatch: inputs: action: description: 'Действие Terraform (plan / apply)' required: true type: choice options: - plan - apply default: plan jobs: terraform: runs-on: homelab container: image: homelab-ansible:latest timeout-minutes: 15 steps: - name: Выполнить Terraform для Proxmox (netcore) env: TF_VAR_proxmox_endpoint: ${{ secrets.PVE_ENDPOINT || 'https://192.168.1.100:8006/' }} TF_VAR_proxmox_api_token: ${{ secrets.PVE_API_TOKEN }} RUNNER_SSH_KEY: ${{ secrets.RUNNER_SSH_KEY }} GITEA_TOKEN: ${{ secrets.GITEA_TOKEN || github.token }} ACTION: ${{ inputs.action }} run: | set -eu rm -rf "${HOME}/homelab-infra" git clone https://gitea.gunihome.ru/karpenok/homelab-infra.git "${HOME}/homelab-infra" sha="${GITHUB_SHA:-${GITEA_SHA:-}}" if [ -n "${sha}" ]; then git -C "${HOME}/homelab-infra" checkout "${sha}" fi if [ -n "${RUNNER_SSH_KEY:-}" ]; then install -d -m 700 "${HOME}/.ssh" printf '%s\n' "${RUNNER_SSH_KEY}" > "${HOME}/.ssh/id_ed25519" chmod 600 "${HOME}/.ssh/id_ed25519" eval "$(ssh-agent -s)" >/dev/null ssh-add "${HOME}/.ssh/id_ed25519" 2>/dev/null trap 'rm -f "${HOME}/.ssh/id_ed25519"' EXIT fi cd "${HOME}/homelab-infra/terraform" terraform init \ -backend-config="address=https://gitea.gunihome.ru/api/v1/packages/karpenok/terraform/state/netcore" \ -backend-config="lock_address=https://gitea.gunihome.ru/api/v1/packages/karpenok/terraform/state/netcore/lock" \ -backend-config="unlock_address=https://gitea.gunihome.ru/api/v1/packages/karpenok/terraform/state/netcore/lock" \ -backend-config="username=karpenok" \ -backend-config="password=${GITEA_TOKEN}" \ -backend-config="lock_method=POST" \ -backend-config="unlock_method=DELETE" \ -backend-config="retry_wait_min=5" if [ "${ACTION}" = "plan" ]; then terraform plan elif [ "${ACTION}" = "apply" ]; then terraform apply -auto-approve fi