OpenTofu Iac
Kompletny pipeline CI/CD dla projektów OpenTofu Infrastructure as Code. Obsługuje formatowanie, linting, walidację konfiguracji, generowanie planu i deployment przez tofu apply na środowiska GitLab.
Użycie
Section titled “Użycie”W projekcie dodaj do .gitlab-ci.yml:
Joby i stagi
Section titled “Joby i stagi”Przepływ CI (branch != main)
Section titled “Przepływ CI (branch != main)”Przepływ CD (źródło: api/push/web)
Section titled “Przepływ CD (źródło: api/push/web)”Tabela jobów
Section titled “Tabela jobów”| Job | Nazwa emoji | Stage | CI | CD |
|---|---|---|---|---|
| versioning (Set Version) | 🕵 Set Version | .pre | ✅ | ✅ |
| environment-deployment-prepare | 🔧 Prepare Dynamic Deployment | .pre | ❌ | ✅ |
| conventional-commits | 🔍 Analyze Conventional Commits | validate | ✅ | ❌ |
| yamllint | 🕵 yamllint | validate | ✅* | ❌ |
| shellcheck | 🐚 shellcheck | validate | ✅* | ❌ |
| opentofu-fmt | 🕵 opentofu fmt | validate | ✅ | ❌ |
| tflint | 🔍 tflint | validate | ✅ | ❌ |
| opentofu-validate | ✅ opentofu validate | validate | ✅ | ❌ |
| dependency | 📦 dependency | dependency | ❌ | ❌ |
| build | 🚀 build | build | ❌ | ❌ |
| trigger-deployment | 🚀 Trigger Deployment | deployment | ❌ | ✅ |
| opentofu-plan | 🧪 opentofu-plan | tests | ✅ | ❌ |
| unit-test | 🧪 unit-test | tests | ❌ | ❌ |
| deployment | 💥 deployment | deployment | ❌ | ✅** |
| publish | 🌐 publish | publish | ❌ | ❌ |
| versioning (Publish Version) | 📍 Publish Version | publish | ✅ | ❌ |
* tylko gdy zmienił się odpowiedni typ pliku względem main
** uruchamia się w child pipeline (CI_PIPELINE_SOURCE == "parent_pipeline")
OpenTofu-specyficzne joby
Section titled “OpenTofu-specyficzne joby”Helper tofu_init (before_script)
Section titled “Helper tofu_init (before_script)”Joby opentofu-validate, opentofu-plan i deployment uruchamiają tofu_init w before_script, który inicjalizuje backend GitLab Terraform State:
✅ opentofu validate (validate)
Section titled “✅ opentofu validate (validate)”Weryfikuje poprawność konfiguracji bez łączenia z zewnętrznym backendem.
🧪 opentofu-plan (tests)
Section titled “🧪 opentofu-plan (tests)”Generuje plan zmian. Zależy od: Set Version + opentofu fmt + tflint + opentofu validate.
💥 deployment (deployment — child pipeline)
Section titled “💥 deployment (deployment — child pipeline)”Uruchamia pełny deployment dla każdego środowiska GitLab. Wprowadza rzeczywiste zmiany infrastruktury.
Zmienne konfiguracyjne
Section titled “Zmienne konfiguracyjne”| Zmienna | Domyślna | Opis |
|---|---|---|
TOFU_VALIDATE_AUTOFIX | "true" | Autofix formatowania HCL: amend + push |
TF_STATE_NAME | production | Nazwa stanu Terraform (validate, plan, deployment) |
GITLAB_TOKEN | — (CI secret) | Wymagany przez opentofu-fmt i joby OpenTofu |
Zależności 📍 Publish Version
Section titled “Zależności 📍 Publish Version”| Job | Wymagany |
|---|---|
🧪 opentofu-plan | ✅ (required) |
Obraz Docker
Section titled “Obraz Docker”Joby OpenTofu (opentofu-fmt, tflint, opentofu-validate, opentofu-plan, deployment):
registry.gitlab.com/pl.rachuna-net/artifacts/containers/opentofu:v1.1.2
Pozostałe joby: dziedziczą z common (python:v1.1.1 lub semantic-release).
Runner
Section titled “Runner”Wszystkie joby uruchamiane na runnerze z tagiem gitlab-rnp.
Prefiks YAML
Section titled “Prefiks YAML”.pipelines.opentofu-iac.*
Różnice względem pipelines/opentofu-module
Section titled “Różnice względem pipelines/opentofu-module”| Aspekt | opentofu-iac | opentofu-module |
|---|---|---|
| Deployment (CD) | ✅ tofu apply -auto-approve | ❌ brak |
opentofu-validate | ✅ CI | ❌ brak |
opentofu-plan | ✅ CI (tests stage) | ❌ brak |
terraform-docs | ❌ brak | ✅ CI |
| Backend Terraform State | ✅ GitLab HTTP | ❌ nie dotyczy |
| Przeznaczenie | Infrastruktura (IaC) | Moduł wielokrotnego użytku |