From 3fe7a8ba9fb99d710cb230bbb27555d8e6626f3b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nicolas=20B=C3=A9jean?= <nicolas@bejean.fr>
Date: Sun, 12 Dec 2021 16:18:13 +0100
Subject: [PATCH] Add jobs

---
 .gitlab-ci.yml | 56 +++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 46 insertions(+), 10 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1cc6933..ae29409 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,8 +1,9 @@
+# docs: https://docs.gitlab.com/ee/user/infrastructure/iac/terraform_state.html#get-started-using-gitlab-ci
+
 image: busybox:latest
 
-# docs: https://docs.gitlab.com/ee/user/infrastructure/iac/terraform_state.html#get-started-using-gitlab-ci
-terraform-elastic:
-  stage: deploy
+check-elastic:
+  stage: test
   tags:
     - docker
   image:
@@ -18,10 +19,8 @@ terraform-elastic:
     gitlab-terraform validate
     gitlab-terraform fmt -check
     gitlab-terraform plan
-#    gitlab-terraform apply -auto-approve
-#    gitlab-terraform destroy -auto-approve
 
-terraform-magento:
+check-magento:
   stage: deploy
   tags:
     - docker
@@ -41,14 +40,51 @@ terraform-magento:
     gitlab-terraform validate
     gitlab-terraform fmt -check
     gitlab-terraform plan
-#    gitlab-terraform apply -auto-approve
-#    gitlab-terraform destroy -auto-approve
+
+apply-elastic:
+  stage: deploy
+  needs:
+    - check-elastic
+  tags:
+    - docker
+  image:
+    name: registry.gitlab.com/gitlab-org/terraform-images/stable:latest
+    entrypoint: [""]
+  variables:
+    TF_ROOT: ${CI_PROJECT_DIR}/manifests/elastic
+    TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/elastic
+    TF_VAR_ec_apikey: $EC_API_KEY
+  script: |-
+    cd $TF_ROOT
+    gitlab-terraform init 
+    gitlab-terraform apply -auto-approve
+
+apply-magento:
+  stage: deploy
+  needs:
+    - check-magento
+  tags:
+    - docker
+  image:
+    name: registry.gitlab.com/gitlab-org/terraform-images/stable:latest
+    entrypoint: [""]
+  variables:
+    TF_ROOT: ${CI_PROJECT_DIR}/manifests/magento
+    TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/magento
+    TF_VAR_ec_apikey: $EC_API_KEY
+    TF_VAR_project_id: $GCP_PROJECT_ID
+    GCP_SA_GITLAB: $GCP_SA_GITLAB
+  script: |-
+    cd $TF_ROOT
+    echo $GCP_SA_GITLAB > gcp-sa.json
+    gitlab-terraform init 
+    gitlab-terraform apply -auto-approve
 
 gcloud-psc:
   stage: deploy
   needs:
-    - terraform-elastic
-    - terraform-magento
+    - apply-elastic
+    - apply-magento
   tags:
     - docker
   image:
-- 
GitLab