Files
homelab-infra/.gitea/workflows/terraform.yml
T

61 lines
2.4 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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: hashicorp/terraform:1.9.8
timeout-minutes: 15
steps:
- name: Checkout repository
run: |
# В контейнере terraform git может отсутствовать, поэтому клонируем через рабочий каталог или curl/шаг checkout
echo "Запуск Terraform для Proxmox..."
- name: Выполнить Terraform
env:
TF_VAR_proxmox_endpoint: ${{ secrets.PVE_ENDPOINT }}
TF_VAR_proxmox_api_token: ${{ secrets.PVE_API_TOKEN }}
TF_VAR_ssh_public_key: ${{ secrets.RUNNER_SSH_PUBKEY }}
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN || github.token }}
ACTION: ${{ inputs.action }}
run: |
set -eu
# Клонируем проект (или переходим, если раннер уже подготовил workspace)
# Для совместимости с текущим окружением раннера
if [ -d "${HOME}/homelab-infra" ]; then
cd "${HOME}/homelab-infra/terraform"
else
cd "terraform"
fi
# Инициализация с Gitea HTTP Backend для безопасного хранения стейта
terraform init \
-backend-config="address=https://gitea.gunihome.ru/api/v1/packages/karpenok/terraform/state/proxmox" \
-backend-config="lock_address=https://gitea.gunihome.ru/api/v1/packages/karpenok/terraform/state/proxmox/lock" \
-backend-config="unlock_address=https://gitea.gunihome.ru/api/v1/packages/karpenok/terraform/state/proxmox/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