79 lines
2.9 KiB
YAML
79 lines
2.9 KiB
YAML
name: terraform-proxmox
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
target:
|
|
description: 'Целевой узел Proxmox'
|
|
required: true
|
|
type: choice
|
|
options:
|
|
- netcore
|
|
- pve
|
|
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 }}
|
|
TF_VAR_proxmox_endpoint: ${{ inputs.target == 'netcore' && (secrets.NETCORE_ENDPOINT || 'https://192.168.1.100:8006/') || (secrets.PVE_ENDPOINT || 'https://192.168.1.2:8006/') }}
|
|
TF_VAR_proxmox_api_token: ${{ secrets.PVE_API_TOKEN }}
|
|
RUNNER_SSH_KEY: ${{ secrets.RUNNER_SSH_KEY }}
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN || github.token }}
|
|
run: |
|
|
set -eu
|
|
|
|
# Гарантированный резолв локальной Gitea внутри Docker-раннера
|
|
if ! grep -q "gitea.gunihome.ru" /etc/hosts; then
|
|
echo "192.168.1.201 gitea.gunihome.ru" >> /etc/hosts
|
|
fi
|
|
|
|
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/${TARGET}"
|
|
|
|
terraform init \
|
|
-backend-config="address=https://gitea.gunihome.ru/api/v1/packages/karpenok/terraform/state/${TARGET}" \
|
|
-backend-config="lock_address=https://gitea.gunihome.ru/api/v1/packages/karpenok/terraform/state/${TARGET}/lock" \
|
|
-backend-config="unlock_address=https://gitea.gunihome.ru/api/v1/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
|