Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 9f493193 authored by Nicolas's avatar Nicolas
Browse files

feat: Add destroy job

parent ec69da8b
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ stages:
- gke
- psc
- elastic
- destroy
variables:
TF_ROOT_ELASTIC: ${CI_PROJECT_DIR}/manifests/elastic
......@@ -20,72 +21,159 @@ cache:
paths:
- ${TF_ROOT_GKE}/.terraform
check-gke:
stage: gke
tags:
- docker
- amd64
image:
name: registry.gitlab.com/gitlab-org/terraform-images/stable:latest
entrypoint: [""]
variables:
TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/gke
TF_VAR_ec_apikey: $EC_API_KEY
TF_VAR_project_id: $GCP_PROJECT_ID
TF_VAR_region: $GCP_REGION
TF_VAR_vpc_network_name: $GCP_NETWORK_NAME
TF_VAR_vpc_subnetwork_name: $GCP_SUBNETWORK_NAME
GCP_SA: $GCP_SA
before_script:
- |
cd $TF_ROOT_GKE
echo $GCP_SA > gcp-sa.json
script:
- |
gitlab-terraform init
gitlab-terraform validate
gitlab-terraform fmt -check
gitlab-terraform plan
gitlab-terraform plan-json
artifacts:
name: plan
paths:
- ${TF_ROOT_GKE}/plan.cache
reports:
terraform: ${TF_ROOT_GKE}/plan.json
apply-gke:
stage: gke
needs:
- check-gke
tags:
- docker
- amd64
image:
name: registry.gitlab.com/gitlab-org/terraform-images/stable:latest
entrypoint: [""]
variables:
TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/gke
TF_VAR_ec_apikey: $EC_API_KEY
TF_VAR_project_id: $GCP_PROJECT_ID
TF_VAR_region: $GCP_REGION
TF_VAR_vpc_network_name: $GCP_NETWORK_NAME
TF_VAR_vpc_subnetwork_name: $GCP_SUBNETWORK_NAME
GCP_SA: $GCP_SA
before_script:
- |
cd $TF_ROOT_GKE
echo $GCP_SA > gcp-sa.json
script:
- |
gitlab-terraform init
gitlab-terraform apply -auto-approve
#check-gke:
# stage: gke
# tags:
# - docker
# - amd64
# image:
# name: registry.gitlab.com/gitlab-org/terraform-images/stable:latest
# entrypoint: [""]
# variables:
# TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/gke
# TF_VAR_ec_apikey: $EC_API_KEY
# TF_VAR_project_id: $GCP_PROJECT_ID
# TF_VAR_region: $GCP_REGION
# TF_VAR_vpc_network_name: $GCP_NETWORK_NAME
# TF_VAR_vpc_subnetwork_name: $GCP_SUBNETWORK_NAME
# GCP_SA: $GCP_SA
# before_script:
# - |
# cd $TF_ROOT_GKE
# echo $GCP_SA > gcp-sa.json
# script:
# - |
# gitlab-terraform init
# gitlab-terraform validate
# gitlab-terraform fmt -check
# gitlab-terraform plan
# gitlab-terraform plan-json
# artifacts:
# name: plan
# paths:
# - ${TF_ROOT_GKE}/plan.cache
# reports:
# terraform: ${TF_ROOT_GKE}/plan.json
#
#apply-gke:
# stage: gke
# needs:
# - check-gke
# tags:
# - docker
# - amd64
# image:
# name: registry.gitlab.com/gitlab-org/terraform-images/stable:latest
# entrypoint: [""]
# variables:
# TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/gke
# TF_VAR_ec_apikey: $EC_API_KEY
# TF_VAR_project_id: $GCP_PROJECT_ID
# TF_VAR_region: $GCP_REGION
# TF_VAR_vpc_network_name: $GCP_NETWORK_NAME
# TF_VAR_vpc_subnetwork_name: $GCP_SUBNETWORK_NAME
# GCP_SA: $GCP_SA
# before_script:
# - |
# cd $TF_ROOT_GKE
# echo $GCP_SA > gcp-sa.json
# script:
# - |
# gitlab-terraform init
# gitlab-terraform apply -auto-approve
#
#
#gcloud-psc:
# stage: psc
# needs:
# - apply-gke
# tags:
# - docker
# image:
# name: google/cloud-sdk:slim
# entrypoint: [""]
# variables:
# GCP_PROJECT_ID: $GCP_PROJECT_ID
# GCP_SA: $GCP_SA
# GCP_REGION: $GCP_REGION
# GCP_NETWORK_NAME: $GCP_NETWORK_NAME
# GCP_SUBNETWORK_NAME: $GCP_SUBNETWORK_NAME
# GCP_INTERNAL_IP_NAME: $GCP_INTERNAL_IP_NAME
# GCP_PSC_NAME: $GCP_PSC_NAME
# GCP_DNS_ZONE_GKE_ELASTIC: $GCP_DNS_ZONE_GKE_ELASTIC
# EC_SERVICE_ATTACHMENT_URI: $EC_SERVICE_ATTACHMENT_URI
# EC_DNS_ZONE: $EC_DNS_ZONE
# before_script:
# - |
# echo $GCP_SA > gcp-sa.json
# gcloud auth activate-service-account --key-file gcp-sa.json
# echo "Activate Service Account: OK"
# gcloud config set project $GCP_PROJECT_ID
# echo "Set Project: OK"
# cd $GCLOUD_ROOT_PSC
# script:
# - |
# chmod +x ./setting-psc.sh
# ./setting-psc.sh
# artifacts:
# paths:
# - ${CI_PROJECT_DIR}/pscConnectionId.env
#
#check-elastic:
# stage: elastic
# tags:
# - docker
# - amd64
# needs:
# - gcloud-psc
# image:
# name: registry.gitlab.com/gitlab-org/terraform-images/stable:latest
# entrypoint: [""]
# variables:
# TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/elastic
# TF_VAR_ec_apikey: $EC_API_KEY
# before_script:
# - |
# export TF_VAR_psc_connection_id=$(cat ${CI_PROJECT_DIR}/pscConnectionId.env | grep GCP_PSC_CONNECTION_ID | cut -d = -f2)
# cd $TF_ROOT_ELASTIC
# script:
# - |
# gitlab-terraform init
# gitlab-terraform validate
# gitlab-terraform fmt -check
# gitlab-terraform plan
# gitlab-terraform plan-json
# artifacts:
# name: plan
# paths:
# - ${TF_ROOT_ELASTIC}/plan.cache
# reports:
# terraform: ${TF_ROOT_ELASTIC}/plan.json
#
#apply-elastic:
# stage: elastic
# needs:
# - check-elastic
# tags:
# - docker
# - amd64
# image:
# name: registry.gitlab.com/gitlab-org/terraform-images/stable:latest
# entrypoint: [""]
# variables:
# TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/elastic
# TF_VAR_ec_apikey: $EC_API_KEY
# before_script:
# - |
# export TF_VAR_psc_connection_id=$(cat ${CI_PROJECT_DIR}/pscConnectionId.env | grep GCP_PSC_CONNECTION_ID | cut -d = -f2)
# cd $TF_ROOT_ELASTIC
# script:
# - |
# gitlab-terraform init
# gitlab-terraform apply -auto-approve
gcloud-psc:
stage: psc
needs:
- apply-gke
destroy-psc:
stage: destroy
tags:
- docker
image:
......@@ -112,47 +200,16 @@ gcloud-psc:
cd $GCLOUD_ROOT_PSC
script:
- |
chmod +x ./setting-psc.sh
./setting-psc.sh
chmod +x ./destroy-psc.sh
./destroy-psc.sh
artifacts:
paths:
- ${CI_PROJECT_DIR}/pscConnectionId.env
check-elastic:
stage: elastic
tags:
- docker
- amd64
destroy-elastic:
stage: destroy
needs:
- gcloud-psc
image:
name: registry.gitlab.com/gitlab-org/terraform-images/stable:latest
entrypoint: [""]
variables:
TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/elastic
TF_VAR_ec_apikey: $EC_API_KEY
before_script:
- |
export TF_VAR_psc_connection_id=$(cat ${CI_PROJECT_DIR}/pscConnectionId.env | grep GCP_PSC_CONNECTION_ID | cut -d = -f2)
cd $TF_ROOT_ELASTIC
script:
- |
gitlab-terraform init
gitlab-terraform validate
gitlab-terraform fmt -check
gitlab-terraform plan
gitlab-terraform plan-json
artifacts:
name: plan
paths:
- ${TF_ROOT_ELASTIC}/plan.cache
reports:
terraform: ${TF_ROOT_ELASTIC}/plan.json
apply-elastic:
stage: elastic
needs:
- check-elastic
- destroy-psc
tags:
- docker
- amd64
......@@ -168,5 +225,32 @@ apply-elastic:
cd $TF_ROOT_ELASTIC
script:
- |
gitlab-terraform init
gitlab-terraform apply -auto-approve
gitlab-terraform init
gitlab-terraform destroy -auto-approve
#destroy-gke:
# stage: destroy
# needs:
# - destroy-psc
# tags:
# - docker
# - amd64
# image:
# name: registry.gitlab.com/gitlab-org/terraform-images/stable:latest
# entrypoint: [""]
# variables:
# TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/gke
# TF_VAR_ec_apikey: $EC_API_KEY
# TF_VAR_project_id: $GCP_PROJECT_ID
# TF_VAR_region: $GCP_REGION
# TF_VAR_vpc_network_name: $GCP_NETWORK_NAME
# TF_VAR_vpc_subnetwork_name: $GCP_SUBNETWORK_NAME
# GCP_SA: $GCP_SA
# before_script:
# - |
# cd $TF_ROOT_GKE
# echo $GCP_SA > gcp-sa.json
# script:
# - |
# gitlab-terraform init
# gitlab-terraform destroy -auto-approve
\ No newline at end of file
#!/bin/bash
echo "GCP_PSC_CONNECTION_ID=$(gcloud compute forwarding-rules describe $GCP_PSC_NAME --region=$GCP_REGION --format="get(pscConnectionId)")" > ${CI_PROJECT_DIR}/pscConnectionId.env
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment