diff --git a/.gitea/workflows/terraform.yml b/.gitea/workflows/terraform.yml index 52f1a82..3c72d79 100644 --- a/.gitea/workflows/terraform.yml +++ b/.gitea/workflows/terraform.yml @@ -3,6 +3,14 @@ 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 @@ -19,16 +27,22 @@ jobs: image: homelab-ansible:latest timeout-minutes: 15 steps: - - name: Выполнить Terraform для Proxmox (netcore) + - name: Выполнить Terraform env: - TF_VAR_proxmox_endpoint: ${{ secrets.PVE_ENDPOINT || 'https://192.168.1.100:8006/' }} + 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 }} - ACTION: ${{ inputs.action }} 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:-}}" @@ -45,12 +59,12 @@ jobs: trap 'rm -f "${HOME}/.ssh/id_ed25519"' EXIT fi - cd "${HOME}/homelab-infra/terraform" + cd "${HOME}/homelab-infra/terraform/${TARGET}" 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="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" \ diff --git a/terraform/netcore/.terraform.lock.hcl b/terraform/netcore/.terraform.lock.hcl new file mode 100644 index 0000000..476f624 --- /dev/null +++ b/terraform/netcore/.terraform.lock.hcl @@ -0,0 +1,25 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/bpg/proxmox" { + version = "0.70.1" + constraints = "~> 0.70.0" + hashes = [ + "h1:vd6g2B0GKtx5Q6XsJ34QzUMZMN89+wo6Z92/+eO3rjE=", + "zh:1f3ca7b12fad410a3689e30f058ce210a8f4e5a13b25c5862acb62c9a6859cd5", + "zh:2669b0548f039e874a9f84362960fb5a479144a9c5bd3c1626b3aa9ec2b41e26", + "zh:313be32be4665f0d170b4065d57e530486b575081be1e27d793c6c9ac6bb1d42", + "zh:360ace6cffba80029a14a3b155a9ffe6c55419236e6b933c011edee1c2e5fc60", + "zh:3bc6e7617ba7ed1db1a3c89242714a1a4484ead154784a8fa62633124e8ebfaa", + "zh:3cc33cedb2bafff05ddf293525e1251ea82480e8298b3bfe51a75fc0ab2e53a7", + "zh:61fba29acaed2382f58af39c920207f8d2e62f1be79caa5ef9fa5b60bd90c740", + "zh:97d1495869da236220168c818496a4b49576fab29ff7a031e41baafc82e767b6", + "zh:9ef6047197682930c8144b1faeeeb42247bf1b07048a6ac37ff18e7965df40fd", + "zh:b30d58f33159028ab9e1d62353df9443efacd920497636c573d20beb3ad6aae0", + "zh:bf931b6de0ceae50a82183ca23a314f646068495514f27fb78a9ca66b2275ad3", + "zh:e071099e8ae796a1a57ac55b3340ede4b497c2666b12a84809c3df0c7a851a42", + "zh:e35790628fd80ff201292765e28db9cacc0db194df884d37bc5bac52ed86113c", + "zh:f26e0763dbe6a6b2195c94b44696f2110f7f55433dc142839be16b9697fa5597", + "zh:f2ae152820737ca4435c0a96c74dd84fea2e0fa90a53c52658d1d3c5598af2aa", + ] +} diff --git a/terraform/lxc.tf b/terraform/netcore/core_net.tf similarity index 100% rename from terraform/lxc.tf rename to terraform/netcore/core_net.tf diff --git a/terraform/main.tf b/terraform/netcore/main.tf similarity index 100% rename from terraform/main.tf rename to terraform/netcore/main.tf diff --git a/terraform/outputs.tf b/terraform/netcore/outputs.tf similarity index 100% rename from terraform/outputs.tf rename to terraform/netcore/outputs.tf diff --git a/terraform/terraform.tfvars.example b/terraform/netcore/terraform.tfvars.example similarity index 100% rename from terraform/terraform.tfvars.example rename to terraform/netcore/terraform.tfvars.example diff --git a/terraform/variables.tf b/terraform/netcore/variables.tf similarity index 100% rename from terraform/variables.tf rename to terraform/netcore/variables.tf diff --git a/terraform/pve/main.tf b/terraform/pve/main.tf new file mode 100644 index 0000000..98a41db --- /dev/null +++ b/terraform/pve/main.tf @@ -0,0 +1,22 @@ +terraform { + required_version = ">= 1.5.0" + + required_providers { + proxmox = { + source = "bpg/proxmox" + version = "~> 0.70.0" + } + } + + backend "http" {} +} + +provider "proxmox" { + endpoint = var.proxmox_endpoint + api_token = var.proxmox_api_token + insecure = var.proxmox_insecure + + ssh { + agent = true + } +} diff --git a/terraform/pve/outputs.tf b/terraform/pve/outputs.tf new file mode 100644 index 0000000..570ef7d --- /dev/null +++ b/terraform/pve/outputs.tf @@ -0,0 +1 @@ +# Выходные параметры для узла pve diff --git a/terraform/pve/terraform.tfvars.example b/terraform/pve/terraform.tfvars.example new file mode 100644 index 0000000..2172cad --- /dev/null +++ b/terraform/pve/terraform.tfvars.example @@ -0,0 +1,4 @@ +proxmox_endpoint = "https://192.168.1.2:8006/" +proxmox_api_token = "root@pam!automation-stack=00000000-0000-0000-0000-000000000000" +proxmox_insecure = true +proxmox_node = "pve" diff --git a/terraform/pve/variables.tf b/terraform/pve/variables.tf new file mode 100644 index 0000000..d1cb498 --- /dev/null +++ b/terraform/pve/variables.tf @@ -0,0 +1,32 @@ +variable "proxmox_endpoint" { + description = "URL Proxmox API для узла pve" + type = string + default = "https://192.168.1.2:8006/" +} + +variable "proxmox_api_token" { + description = "API Token Proxmox в формате USER@REALM!TOKENID=UUID_SECRET" + type = string + sensitive = true +} + +variable "proxmox_insecure" { + description = "Разрешить самоподписанные SSL-сертификаты Proxmox" + type = bool + default = true +} + +variable "proxmox_node" { + description = "Имя ноды Proxmox" + type = string + default = "pve" +} + +variable "ssh_public_keys" { + description = "Список публичных SSH-ключей для доступа к создаваемым контейнерам" + type = list(string) + default = [ + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIF/yxhAs022l/8FlPlhyi7NeF3CvVGsev3B1HtKICO7M root_from_windows", + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEpwqB40k8QQq3k8160gfMKDaCJCX9qzvmuijfe3mO4I gitea-runner" + ] +}