Files
homelab-infra/.gitea/workflows/terraform.yml
T
karpenokandCursor 9c692522fb
ansible-core-net / deploy (push) Failing after 39s
ansible-core-secrets / deploy (push) Successful in 30s
ansible-rus-central / deploy (push) Failing after 15s
refactor: split machine deploys from one-time secrets migration
Roles stay under the machine that runs them, CI applies only a known product, and the /opt/secrets move is a one-shot playbook instead of part of every core-secrets run.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-10 23:55:34 +07:00

92 lines
3.8 KiB
YAML

name: terraform-proxmox
on:
workflow_dispatch:
inputs:
target:
description: 'Целевой узел Proxmox'
required: true
type: choice
options:
- netcore
default: netcore
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
env:
TARGET: ${{ inputs.target }}
ACTION: ${{ inputs.action }}
INFISICAL_CLIENT_ID: ${{ secrets.INFISICAL_CLIENT_ID }}
INFISICAL_CLIENT_SECRET: ${{ secrets.INFISICAL_CLIENT_SECRET }}
run: |
set -eu
# Прямое подключение к Infisical (CT 901) без зависимости от Traefik
export INFISICAL_PROJECT_ID="806e7f09-5838-492a-946b-2d69b96876ab"
export INFISICAL_DOMAIN="http://192.168.1.102:8080/api"
TOKEN=$(infisical login \
--domain="${INFISICAL_DOMAIN}" \
--method=universal-auth \
--client-id="${INFISICAL_CLIENT_ID}" \
--client-secret="${INFISICAL_CLIENT_SECRET}" \
--plain)
# Подтягиваем SSH-ключ раннера и токен Gitea State Backend из /ci-cd
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/ci-cd" --format=dotenv-export --silent)"
# Подтягиваем эндпоинт и API-токен целевого гипервизора из /proxmox/<TARGET>
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/proxmox/${TARGET}" --format=dotenv-export --silent)"
export TF_VAR_proxmox_endpoint="${PROXMOX_ENDPOINT}"
export TF_VAR_proxmox_api_token="${PROXMOX_API_TOKEN}"
export GITEA_TOKEN="${TF_STATE_TOKEN}"
rm -rf "${HOME}/homelab-infra"
# Клонируем по прямому IP Gitea, чтобы не зависеть от внешних факторов
git clone http://192.168.1.217:3000/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/${TARGET}"
terraform init \
-backend-config="address=http://192.168.1.217:3000/api/packages/karpenok/terraform/state/${TARGET}" \
-backend-config="lock_address=http://192.168.1.217:3000/api/packages/karpenok/terraform/state/${TARGET}/lock" \
-backend-config="unlock_address=http://192.168.1.217:3000/api/packages/karpenok/terraform/state/${TARGET}/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