From 4a2ed7bf4fd2dd5d6a1060aa9531c79e7530ee10 Mon Sep 17 00:00:00 2001 From: Patrick de Ruiter Date: Sun, 2 Nov 2025 00:32:28 +0100 Subject: [PATCH] Refactor Terraform init to use backend-config flags - Updated backend.tf to use partial configuration - Modified workflow to pass backend settings via -backend-config flags - Follows Azure-style pattern with environment variables - Improves flexibility and keeps configuration out of version control - Required secrets: MINIO_ENDPOINT, MINIO_BUCKET, MINIO_STATE_KEY --- .gitea/workflows/sonarqube.yaml | 16 +++++++++++++++- backend.tf | 15 ++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.gitea/workflows/sonarqube.yaml b/.gitea/workflows/sonarqube.yaml index e481aa0..57014db 100644 --- a/.gitea/workflows/sonarqube.yaml +++ b/.gitea/workflows/sonarqube.yaml @@ -96,4 +96,18 @@ jobs: env: AWS_ACCESS_KEY_ID: ${{ secrets.MINIO_ACCESS_KEY }} AWS_SECRET_ACCESS_KEY: ${{ secrets.MINIO_SECRET_KEY }} - run: terraform init + TF_BACKEND_ENDPOINT: ${{ secrets.MINIO_ENDPOINT }} + TF_BACKEND_BUCKET: ${{ secrets.MINIO_BUCKET }} + TF_BACKEND_KEY: ${{ secrets.MINIO_STATE_KEY }} + TF_BACKEND_REGION: "main" + run: | + terraform init \ + -backend-config="endpoints={s3=\"${TF_BACKEND_ENDPOINT}\"}" \ + -backend-config="bucket=${TF_BACKEND_BUCKET}" \ + -backend-config="key=${TF_BACKEND_KEY}" \ + -backend-config="region=${TF_BACKEND_REGION}" \ + -backend-config="skip_credentials_validation=true" \ + -backend-config="skip_metadata_api_check=true" \ + -backend-config="skip_requesting_account_id=true" \ + -backend-config="skip_region_validation=true" \ + -backend-config="use_path_style=true" diff --git a/backend.tf b/backend.tf index 7a16643..356c3c5 100644 --- a/backend.tf +++ b/backend.tf @@ -1,17 +1,6 @@ terraform { backend "s3" { - endpoints = { - s3 = "https://minio.bsdserver.nl:443" - } - - bucket = "home-terraform" - key = "home/vsphere/network/vsphere-resourcegroup-config.tfstate" - - region = "main" - skip_credentials_validation = true - skip_metadata_api_check = true - skip_requesting_account_id = true - skip_region_validation = true - use_path_style = true + # Backend configuration provided via -backend-config flags during terraform init + # This allows for environment-specific and CI/CD-friendly configuration } }