How to delete all resources for the product¶
This page provides instructions on how to delete resources for a product. Resources related to the product are stored across several Git repositories with Terraform code in our GitLab:
- Product infrastructure repositories
- GitLab GKE CI Runner Infrastructure
- Gitlab Project Factory
- Google Cloud Product Factory
As our cloud platform deployment comprises multiple stages, it must be deleted in a strict order. The following information illustrates the right order.
Info
Not every stage in this guide is required. For example, a product can have no related GitLab CI runner infrastructure.
Stage 1 - Delete Resources in Infrastructure Project¶
First, it is needed to delete the top-level infrastructure, i.e. resources that are used by the product's deployment (Cloud SQL instances, Cloud Run instances, so on).
Almost all infrastructure projects were created from the template. However, the set of resources may vary from product to product (e.g. some products use the MySQL database and others use the PostgreSQL database), so there is no universal solution. The general steps are as follows:
- Clone the Git project.
-
Get a list of the workspaces for the infrastructure project by running
logan terraform workspace list
inside the infrastructure project directory. The output will be similar to the one shown below:default * development production staging test
Info
Alternatively, workspaces can be found in product's
.tfvars
file in Google Cloud Product Factory. -
Check your project for resources protected from deletion (Storage buckets, SQL instances, etc). For example, if the infrastructure project was created from Boilerplate Google Cloud Deployment project and it uses SQL, then most probably the
deletion_protection
option for the SQL instance is set totrue
. Set it tofalse
and apply the configuration before the next step, otherwiseterraform destroy
command will fail. If the infrastructure project has storage bucket(s), ensure that it can be actually deleted. This can be achieved by addingforce_destroy = true
to the bucket resource(s) and applying the Terraform configuration. -
Destroy resources in every workspace. The example below shows how to do it for a
development
workspace:logan --workspace=development terraform destroy
During this process, Terraform will display all resources that it will destroy. Carefully
review and type yes
.
Stage 2 - Delete GitLab GKE CI Runner¶
Next, if your product uses the GKE based CI runner, delete it from the Terraform code in GitLab GKE CI Runner Infrastructure. To do so, perform the following:
-
Clone the GitLab GKE CI Runner Infrastructure repository.
git clone git@gitlab.developers.cam.ac.uk:uis/devops/devhub/gitlab-runner-infrastructure.git cd gitlab-runner-infrastructure
-
Create a new branch with a relevant name, for example
delete-ci-runner-for-my-product-name
.git checkout -b delete-ci-runner-for-my-product-name
-
Find the information about the product in locals.tf
- Remove the corresponding item from
product_runners.production
map. -
Commit changes, push, and submit new merge request for review:
git add locals.tf git commit -m "Delete CI runner for my-product-name" git push --set-upstream origin delete-ci-runner-for-my-product-name
-
After merging it, apply the production configuration from the
master
branch by running the following:git checkout master git pull logan --workspace=production terraform apply
Stage 3 - Delete Resources in Gitlab Project Factory¶
Next, when the top-level infrastructure and CI runner are destroyed, it is possible to delete projects/groups in GitLab. Here's a simple steps to do so:
-
Clone the Gitlab Project Factory repository:
git clone git@gitlab.developers.cam.ac.uk:uis/devops/infra/gitlab-project-factory.git cd gitlab-project-factory
-
Create a new branch with a relevant name, for example
delete-gitlab-resources-for-my-product-name
:git checkout -b delete-gitlab-resources-for-my-product-name
-
Identify the product's directory under the product-vars directory.
-
Destroy resources:
./run-project-factory.sh -p ./product-vars/my-product-name destroy
Make sure
my-product-name
is replaced by actual product name.Warning
This is irreversible operation! On this step all GitLab resources, described in related directroy under
./product-vars/
will be deleted! -
Delete folder
./product-vars/my-product-name
. -
Commit changes, push and submit a new merge request for post factum review:
git add ./product-vars/my-product-name git commit -m "Delete GitLab resources for my-product-name" git push --set-upstream origin delete-gitlab-resources-for-my-product-name
Stage 4 - Delete Resources in GCP Product Factory¶
Finally, destroy the low-level GCP resources (projects, IAM, DNS, so on).
-
Clone the Google Cloud Product Factory repository:
git clone git@gitlab.developers.cam.ac.uk:uis/devops/infra/gcp-product-factory.git cd gcp-product-factory
-
Create a new branch with a relevant name, for example
delete-gcp-resources-for-my-product-name
:git checkout -b delete-gcp-resources-for-my-product-name
-
Identify the product's directory in the product-vars directory.
-
Destroy resources:
./run-product-factory.sh -p ./product-vars/my-product-name destroy
Make sure
my-product-name
is replaced by actual product name.Warning
This is irreversible operation! On this step all GCP resources, described in related directroy under
./product-vars/
(including IAM, DNS, and projects) will be deleted! -
Delete folder
./product-vars/my-product-name
. -
Commit changes, push and submit a new merge request for post factum review:
git add ./product-vars/my-product-name git commit -m "Delete GCP resources for my-product-name" git push --set-upstream origin elete-gitlab-resources-for-my-product-name