From 9615fa69c109e1a54f8d24ba32f03e6bc6f888ee Mon Sep 17 00:00:00 2001 From: Niklas van Schrick Date: Thu, 11 Jul 2024 21:27:34 +0200 Subject: [PATCH] Update pipeline to support separated environments --- .gitlab-ci.yml | 30 ++++++++++++++++---------- main.tf => envs/main/main.tf | 4 ++-- variables.tf => envs/main/variables.tf | 0 3 files changed, 21 insertions(+), 13 deletions(-) rename main.tf => envs/main/main.tf (92%) rename variables.tf => envs/main/variables.tf (100%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 077ebd2..24a14a0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,11 +11,11 @@ default: before_script: - cd $TF_ROOT -tf-plan:main: +.tf-plan: extends: - .tf stage: terraform-plan - resource_group: tf/main + resource_group: tf/$TF_STATE_NAME script: - gitlab-terraform plan | tee output - gitlab-terraform plan-json @@ -29,17 +29,12 @@ tf-plan:main: - $TF_ROOT/plan.cache reports: terraform: $TF_ROOT/plan.json - variables: - TF_STATE_NAME: main - TF_ROOT: '.' -tf-apply:main: +.tf-apply: extends: - .tf stage: terraform-apply - resource_group: tf/main - needs: - - tf-plan:main + resource_group: tf/$TF_STATE_NAME script: - gitlab-terraform apply | tee output - | @@ -47,10 +42,23 @@ tf-apply:main: grep "Apply complete!" output | sed -r "s/[[:cntrl:]]\[[0-9]{1,3}m//g" echo -e "\e[0Ksection_end:`date +%s`:glpa_summary\r\e[0K" environment: - name: main + name: $TF_STATE_NAME deployment_tier: production - variables: !reference ["tf-plan:main", variables] rules: - if: $C0_GH_REF == "refs/heads/main" when: delayed start_in: 2 min + +tf-plan:main: + extends: + - .tf-plan + variables: + TF_STATE_NAME: main + TF_ROOT: 'envs/main' + +tf-apply:main: + extends: + - .tf-apply + needs: + - tf-plan:main + variables: !reference ["tf-plan:main", variables] diff --git a/main.tf b/envs/main/main.tf similarity index 92% rename from main.tf rename to envs/main/main.tf index fccaeed..a9ed67d 100644 --- a/main.tf +++ b/envs/main/main.tf @@ -36,11 +36,11 @@ provider "github" { } module "domain" { - source = "./system/domain" + source = "../../system/domain" cloudflare_account_id = var.cloudflare_account_id cloudflare_api_token = var.cloudflare_api_token } module "github" { - source = "./system/github" + source = "../../system/github" } diff --git a/variables.tf b/envs/main/variables.tf similarity index 100% rename from variables.tf rename to envs/main/variables.tf