diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9cff6907b3691fabae7cd8d308ad9cc4b1507576..9305237e1573f7df6bfd5ed9eeaf258acb7f9952 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 diff --git a/manifests/psc/destroy-psc.sh b/manifests/psc/destroy-psc.sh new file mode 100644 index 0000000000000000000000000000000000000000..aa22192a8950a587b2afe68299dfa285d9f5e7a1 --- /dev/null +++ b/manifests/psc/destroy-psc.sh @@ -0,0 +1,3 @@ +#!/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