Skip to content

Platform Teardown

This guide provides a structured process for decommissioning a Nexus SDV instance. Using the automated teardown-platform.sh script, you can securely remove infrastructure while having the option to preserve specific core components for future use. To go ahead, all you have to do is follow these steps:

  1. Verify Identity Ensure you are using the same Google Cloud project and GitHub repository that was used for the initial bootstrapping.

  2. Execute Teardown Run the decommissioning script from your terminal: bash ./iac/bootstrapping/teardown-platform.sh

  3. Verify Cleanup Confirm that the resources have been removed from the GCP Console and your environment is in the desired state.

The teardown process requires the same environment stability as the deployment.

Ensure these tools are installed and authenticated before starting:

ToolPurpose
Google Cloud CLI (gcloud)Removing GCP resources and Secret Manager entries.
Terraform CLI (terraform)Executing the terraform destroy command for infrastructure removal.
GitHub CLI (gh)Deleting environment variables and cleaning up repository states.
jq (jq)Processing JSON-based environment data from GitHub.

To initiate the decommissioning, execute the script from the project’s root directory:

Terminal window
$ bash iac/bootstrapping/teardown-platform.sh

In case a GitHub driven deployment was used, the script will prompt you for these inputs:

  1. GitHub Repository Notation (GITHUB_REPO): e.g., owner/repo.
  2. GitHub Environment (ENV): The name used during bootstrap (max. 15 chars).

During the process, the script will ask whether to delete or preserve specific resources. For PoC environments, we recommend a “soft” teardown:

The script asks if you want to preserve your Certificate Authority Pools.

  • Recommendation: Preserve them (Type ‘y’).
  • Why: GCP CA Pools have a 30-day recovery period. Keeping them prevents naming conflicts and makes redeploying the platform much faster and more resource-efficient.

At the end, you are asked whether to delete the local configuration file.

  • Recommendation: Do NOT delete (Type ‘n’).
  • Why: This file contains your project configuration. Keeping it allows you to restart the platform later without re-entering all IDs and regions.

Once started, the script performs a coordinated cleanup across three main layers:

Specific resources, such as GKE workloads, are terminated first to ensure a clean state and free up database connections.

The script executes terraform destroy. This removes the GKE cluster, BigTable instances, and networking components. Note that CA pools and APIs are often removed from the state instead of being deleted to avoid recovery locks.

In the final stage, the script:

  • Deletes the Cloud Storage bucket containing the Terraform state.
  • Clears non-essential GitHub Environment variables.
  • Wipes entries from the GCP Secret Manager.

A successful teardown is confirmed by the following message:

Terminal window
$ bash iac/bootstrapping/teardown-platform.sh
...
[INFO] ==================================================================
[INFO] 🎉 Nexus SDV platform teardown successfully completed! 🎉
[INFO] ==================================================================
[INFO] Your Google Cloud project environment is now empty again.
[INFO] Local files have been cleaned up.
ServiceExpected State
GKENo active clusters related to the environment.
Cloud StorageThe [gcp-project-name]-tfstate bucket has been removed.
Secret ManagerEnvironment-specific secrets are deleted.

A bootstrap or teardown stops with:

Error: Error acquiring the state lock
Lock Info:
ID: 1762856907718990
Operation: OperationTypeApply
Who: root@a1b2c3d4e5f6
Created: 2026-10-01 09:14:22.481 +0000 UTC

Terraform keeps your platform’s state in a Cloud Storage bucket and locks it while it changes infrastructure, so that two runs cannot write at the same time. The lock is released when the run ends.

The usual cause is a run that did not end. A build cancelled by hand, a build that hit its timeout, or a session closed mid-apply leaves the lock behind with nobody holding it. Every later run then waits — the teardown waits 60 seconds — and fails.

The second cause is genuine concurrency: a bootstrap and a teardown for the same platform, or two people, at the same time.

Make sure nothing is actually running. Unlocking a live operation lets a second run write the same state and can leave your platform in a state Terraform can no longer describe.

Terminal window
gcloud builds list --project=<GCP_PROJECT_ID> --region=<GCP_REGION> --ongoing

If that lists a bootstrap or teardown, wait for it. If it is empty, and nobody is running Terraform from their own machine, the lock is stale.

Take the ID from the error and release the lock from the same directory and the same backend configuration the run used:

Terminal window
cd iac/terraform
terraform init -backend-config="bucket=<STATE_BUCKET>" -backend-config="prefix=<ENV>"
terraform force-unlock 1762856907718990

The init is needed: force-unlock acts on the configured backend, and a fresh checkout has none. The bucket and prefix are the values the bootstrap used for this environment — your .bootstrap_env has them.

Then start the operation again.