This document explains how to delete a Cloud SQL blue-green deployment, and details the critical difference in deletion behavior before and after switchover.
Before you begin
To delete or cancel a blue-green deployment, verify that you have the required roles and permissions.
Required roles and permissions
To get the permissions that you need to delete a blue-green deployment, ask your administrator to grant you the following IAM role on your project:
- Cloud SQL Admin (
roles/cloudsql.admin)
For custom roles, ensure that you have the following permissions:
cloudsql.blueGreenDeployments.deletecloudsql.blueGreenDeployments.getcloudsql.instances.deletecloudsql.operations.get
For more information about IAM roles and permissions in Cloud SQL, see Roles and permissions.
Deletion behaviors
The delete operation behaves differently depending on whether
switchover has occurred:
| Deployment stage | Default behavior | Instance impact |
|---|---|---|
| Before switchover (Cancel) |
Deletes the deployment metadata and automatically deletes the green staging instance. | Your blue production instance remains running and completely unaffected. |
| After switchover (Delete) |
Deletes the deployment metadata, but retains both instances as standalone instances by default. | The green instance continues serving production traffic as your
active read and write database instance. The blue instance is
retained as a standalone instance unless you select the
Delete old source instance option, pass the optional
--delete-old-source flag, set
delete_old_source_on_destroy = true in Terraform before
removing the blue_green_deployment code block, or set the
deleteOldSource parameter to true to delete
it. |
Case 1: Cancel a deployment before switchover
If you detect issues during validation or decide not to proceed with an upgrade, delete the deployment before triggering switchover.
Console
-
In the Cloud de Confiance console, go to the Cloud SQL Instances page.
- To open the Overview page of an instance, click the instance name.
- In the Blue Green Deployment Status card, click Details to open the Deployment overview page.
- Click Delete deployment.
- In the Delete Deployment? dialog, enter the deployment ID in the Deployment ID field to confirm.
- Click Delete.
gcloud
To cancel and delete a blue-green deployment by using the gcloud CLI,
run the
gcloud
sql blue-green-deployments delete command:
gcloud sql blue-green-deployments delete DEPLOYMENT_NAME \ --region=REGION
Replace the following:
- DEPLOYMENT_NAME: the name of your blue-green deployment.
- REGION: the Cloud de Confiance by S3NS region where the deployment was created.
Terraform
To cancel and delete a blue-green deployment before switchover using
Terraform (while the active_environment field is set to
"SOURCE"), remove the blue_green_deployment code block
from your
google_sql_database_instance
resource while keeping the database_version field set to your
blue source version:
resource "google_sql_database_instance" "primary" { name = "SOURCE_INSTANCE_ID" region = "REGION" database_version = "SOURCE_DATABASE_VERSION" settings { tier = "MACHINE_TIER" edition = "EDITION" availability_type = "REGIONAL" backup_configuration { enabled = true binary_log_enabled = true } } }
Replace the following:
- SOURCE_INSTANCE_ID: the name of your blue source instance.
- REGION: the Cloud de Confiance by S3NS region where the deployment was created.
- SOURCE_DATABASE_VERSION: the database version of your blue
source instance (for example,
MYSQL_8_0). - MACHINE_TIER: the machine type of your instance (for
example,
db-custom-2-7680). - EDITION: the Cloud SQL edition of your instance
(
ENTERPRISEorENTERPRISE_PLUS).
When you remove the blue_green_deployment code block before
switchover, Terraform cancels the deployment and deletes the green staging
instance regardless of the delete_old_source_on_destroy
setting.
To apply your Terraform configuration in a Cloud de Confiance project, complete the steps in the following sections.
Prepare Cloud Shell
- Launch Cloud Shell.
-
Set the default Cloud de Confiance project where you want to apply your Terraform configurations.
You only need to run this command once per project, and you can run it in any directory.
export GOOGLE_CLOUD_PROJECT=PROJECT_ID
Environment variables are overridden if you set explicit values in the Terraform configuration file.
Prepare the directory
Each Terraform configuration file must have its own directory (also called a root module).
-
In Cloud Shell, create a directory and a new
file within that directory. The filename must have the
.tfextension—for examplemain.tf. In this tutorial, the file is referred to asmain.tf.mkdir DIRECTORY && cd DIRECTORY && touch main.tf
-
If you are following a tutorial, you can copy the sample code in each section or step.
Copy the sample code into the newly created
main.tf.Optionally, copy the code from GitHub. This is recommended when the Terraform snippet is part of an end-to-end solution.
- Review and modify the sample parameters to apply to your environment.
- Save your changes.
-
Initialize Terraform. You only need to do this once per directory.
terraform init
Optionally, to use the latest Google provider version, include the
-upgradeoption:terraform init -upgrade
Apply the changes
-
Review the configuration and verify that the resources that Terraform is going to create or
update match your expectations:
terraform plan
Make corrections to the configuration as necessary.
-
Apply the Terraform configuration by running the following command and entering
yesat the prompt:terraform apply
Wait until Terraform displays the "Apply complete!" message.
- Open your Cloud de Confiance project to view the results. In the Cloud de Confiance console, navigate to your resources in the UI to make sure that Terraform has created or updated them.
REST v1
To cancel and delete a blue-green deployment using the Cloud SQL Admin API, send a
DELETE request to the blueGreenDeployments.delete method:
DELETE https://sqladmin.googleapis.com/v1/ projects/PROJECT_ID/locations/REGION/ blueGreenDeployments/DEPLOYMENT_NAME
Replace the following:
- PROJECT_ID: the ID of your Cloud de Confiance by S3NS project.
- REGION: the Cloud de Confiance by S3NS region where the deployment was created.
- DEPLOYMENT_NAME: the name of your blue-green deployment.
REST v1beta4
To cancel and delete a blue-green deployment using the Cloud SQL Admin API, send a
DELETE request to the blueGreenDeployments.delete method:
DELETE https://sqladmin.googleapis.com/sql/v1beta4/ projects/PROJECT_ID/locations/REGION/ blueGreenDeployments/DEPLOYMENT_NAME
Replace the following:
- PROJECT_ID: the ID of your Cloud de Confiance by S3NS project.
- REGION: the Cloud de Confiance by S3NS region where the deployment was created.
- DEPLOYMENT_NAME: the name of your blue-green deployment.
This removes the green staging instance and restores your environment to its original single-instance state without downtime.
Case 2: Delete post-switchover
After a successful switchover and verification window, you can delete the deployment along with the former blue instance to stop incurring charges on two instances.
Console
-
In the Cloud de Confiance console, go to the Cloud SQL Instances page.
- To open the Overview page of an instance, click the instance name.
- In the Blue Green Deployment Status card, click Details to open the Deployment overview page.
- Click Delete deployment.
- In the Delete Deployment? dialog, enter the deployment ID in the Deployment ID field to confirm.
- Choose whether to delete or retain the former blue instance:
- Option A (Delete the deployment and former blue instance): select the Delete old source instance checkbox.
- Option B (Delete deployment metadata only): leave the Delete old source instance checkbox cleared to retain the former blue instance as a standalone instance.
- Click Delete.
If you retain the former blue instance, both instances remain active in
your project and you continue to be billed for both. To prevent writes to the
retained instance when using it as a backup or for historical queries, set its
read_only database flag to on. For more information,
see Configure database flags.
gcloud
To delete a blue-green deployment by using the gcloud CLI, run the
gcloud
sql blue-green-deployments delete command.
Option A: Delete the deployment and former blue instance
To delete the deployment metadata and automatically delete the former blue
instance, pass the optional --delete-old-source flag:
gcloud sql blue-green-deployments delete DEPLOYMENT_NAME \ --region=REGION \ --delete-old-source
Replace the following:
- DEPLOYMENT_NAME: the name of your blue-green deployment.
- REGION: the Cloud de Confiance by S3NS region where the deployment was created.
When prompted, confirm that you want to permanently delete the former blue instance.
Option B: Delete deployment metadata only (retain the former blue instance)
To keep the former blue instance running as a standalone instance (for
example, as a backup or for historical analytical queries), omit the optional
--delete-old-source flag:
gcloud sql blue-green-deployments delete DEPLOYMENT_NAME \ --region=REGION
Replace the following:
- DEPLOYMENT_NAME: the name of your blue-green deployment.
- REGION: the Cloud de Confiance by S3NS region where the deployment was created.
This command only deletes the blue-green deployment metadata, leaving both
instances as standalone instances until you manually delete the
former blue instance. To prevent writes to the retained instance when using it
as a backup or for historical queries, set its read_only database
flag to on. For more information, see
Configure database flags. Both
instances remain active in your project, and you continue to be billed for
both.
Terraform
To clean up a blue-green deployment after switchover using Terraform
(when the active_environment field is set to
"TARGET"), remove the blue_green_deployment code block
from your
google_sql_database_instance
resource and run the terraform apply command. Whether Terraform
also deletes the former blue instance depends on the value of the
delete_old_source_on_destroy field recorded in Terraform state
before you remove the code block.
Option A: Delete the deployment and former blue instance
- If the
delete_old_source_on_destroyfield isn't already set totruein Terraform state on yourblue_green_deploymentcode block, setdelete_old_source_on_destroy = truein theblue_green_deploymentcode block and run theterraform applycommand first so that Terraform records the setting in state. - Remove the
blue_green_deploymentcode block from yourgoogle_sql_database_instanceresource (keeping thedatabase_versionfield set to your new production version) and run theterraform applycommand:
resource "google_sql_database_instance" "primary" { name = "SOURCE_INSTANCE_ID" region = "REGION" database_version = "TARGET_DATABASE_VERSION" settings { tier = "MACHINE_TIER" edition = "EDITION" availability_type = "REGIONAL" backup_configuration { enabled = true binary_log_enabled = true } } }
Replace the following:
- SOURCE_INSTANCE_ID: the name of your primary instance.
- REGION: the Cloud de Confiance by S3NS region where the deployment was created.
- TARGET_DATABASE_VERSION: the database version of your
production instance (for example,
MYSQL_8_4). - MACHINE_TIER: the machine type of your instance (for
example,
db-custom-2-7680). - EDITION: the Cloud SQL edition of your instance
(
ENTERPRISEorENTERPRISE_PLUS).
Option B: Delete deployment metadata only (retain the former blue instance)
If the delete_old_source_on_destroy field is set to
false (the default) in Terraform state, remove the
blue_green_deployment code block from your
google_sql_database_instance resource and run the
terraform apply command. Terraform deletes only the blue-green
deployment metadata and retains the former blue instance as a standalone
instance.
If you retain the former blue instance, both instances remain active in
your project and you continue to be billed for both. To prevent writes to the
retained instance when using it as a backup or for historical queries, set its
read_only database flag to on. For more information,
see Configure database flags. You
can later manage or delete the retained instance by using either of the
following methods:
- Delete the instance manually by running the following command with the
old_source_instance_nameoutput value:gcloud sql instances delete OLD_SOURCE_INSTANCE_NAME
- Declare a new
google_sql_database_instanceresource code block and import the retained instance into Terraform state:terraform import google_sql_database_instance.old_source \ projects/PROJECT_ID/instances/OLD_SOURCE_INSTANCE_NAME
Replace the following:
- OLD_SOURCE_INSTANCE_NAME: the name of the retained former
blue instance (exported in the
old_source_instance_nameattribute before code block removal). - PROJECT_ID: the ID of your Cloud de Confiance by S3NS project.
To apply your Terraform configuration in a Cloud de Confiance project, complete the steps in the following sections.
Prepare Cloud Shell
- Launch Cloud Shell.
-
Set the default Cloud de Confiance project where you want to apply your Terraform configurations.
You only need to run this command once per project, and you can run it in any directory.
export GOOGLE_CLOUD_PROJECT=PROJECT_ID
Environment variables are overridden if you set explicit values in the Terraform configuration file.
Prepare the directory
Each Terraform configuration file must have its own directory (also called a root module).
-
In Cloud Shell, create a directory and a new
file within that directory. The filename must have the
.tfextension—for examplemain.tf. In this tutorial, the file is referred to asmain.tf.mkdir DIRECTORY && cd DIRECTORY && touch main.tf
-
If you are following a tutorial, you can copy the sample code in each section or step.
Copy the sample code into the newly created
main.tf.Optionally, copy the code from GitHub. This is recommended when the Terraform snippet is part of an end-to-end solution.
- Review and modify the sample parameters to apply to your environment.
- Save your changes.
-
Initialize Terraform. You only need to do this once per directory.
terraform init
Optionally, to use the latest Google provider version, include the
-upgradeoption:terraform init -upgrade
Apply the changes
-
Review the configuration and verify that the resources that Terraform is going to create or
update match your expectations:
terraform plan
Make corrections to the configuration as necessary.
-
Apply the Terraform configuration by running the following command and entering
yesat the prompt:terraform apply
Wait until Terraform displays the "Apply complete!" message.
- Open your Cloud de Confiance project to view the results. In the Cloud de Confiance console, navigate to your resources in the UI to make sure that Terraform has created or updated them.
REST v1
To delete a blue-green deployment using the Cloud SQL Admin API, send a DELETE
request to the blueGreenDeployments.delete method.
Option A: Delete the deployment and former blue instance
To delete the deployment metadata and automatically delete the former blue
instance, set the deleteOldSource query parameter to
true:
DELETE https://sqladmin.googleapis.com/v1/ projects/PROJECT_ID/locations/REGION/ blueGreenDeployments/DEPLOYMENT_NAME?deleteOldSource=true
Replace the following:
- PROJECT_ID: the ID of your Cloud de Confiance by S3NS project.
- REGION: the Cloud de Confiance by S3NS region where the deployment was created.
- DEPLOYMENT_NAME: the name of your blue-green deployment.
Option B: Delete deployment metadata only (retain the former blue instance)
To keep the former blue instance running as a standalone instance (for
example, as a backup or for historical analytical queries), omit the
deleteOldSource query parameter:
DELETE https://sqladmin.googleapis.com/v1/ projects/PROJECT_ID/locations/REGION/ blueGreenDeployments/DEPLOYMENT_NAME
Replace the following:
- PROJECT_ID: the ID of your Cloud de Confiance by S3NS project.
- REGION: the Cloud de Confiance by S3NS region where the deployment was created.
- DEPLOYMENT_NAME: the name of your blue-green deployment.
This request only deletes the blue-green deployment metadata, leaving both
instances as standalone instances until you manually delete the
former blue instance. To prevent writes to the retained instance when using it
as a backup or for historical queries, set its read_only database
flag to on. For more information, see
Configure database flags. Both
instances remain active in your project, and you continue to be billed for
both.
REST v1beta4
To delete a blue-green deployment using the Cloud SQL Admin API, send a DELETE
request to the blueGreenDeployments.delete method.
Option A: Delete the deployment and former blue instance
To delete the deployment metadata and automatically delete the former blue
instance, set the deleteOldSource query parameter to
true:
DELETE https://sqladmin.googleapis.com/sql/v1beta4/ projects/PROJECT_ID/locations/REGION/ blueGreenDeployments/DEPLOYMENT_NAME?deleteOldSource=true
Replace the following:
- PROJECT_ID: the ID of your Cloud de Confiance by S3NS project.
- REGION: the Cloud de Confiance by S3NS region where the deployment was created.
- DEPLOYMENT_NAME: the name of your blue-green deployment.
Option B: Delete deployment metadata only (retain the former blue instance)
To keep the former blue instance running as a standalone instance (for
example, as a backup or for historical analytical queries), omit the
deleteOldSource query parameter:
DELETE https://sqladmin.googleapis.com/sql/v1beta4/ projects/PROJECT_ID/locations/REGION/ blueGreenDeployments/DEPLOYMENT_NAME
Replace the following:
- PROJECT_ID: the ID of your Cloud de Confiance by S3NS project.
- REGION: the Cloud de Confiance by S3NS region where the deployment was created.
- DEPLOYMENT_NAME: the name of your blue-green deployment.
This request only deletes the blue-green deployment metadata, leaving both
instances as standalone instances until you manually delete the
former blue instance. To prevent writes to the retained instance when using it
as a backup or for historical queries, set its read_only database
flag to on. For more information, see
Configure database flags. Both
instances remain active in your project, and you continue to be billed for
both.
What's next
- Review about blue-green deployments to understand deployment architecture and lifecycle states.
- Explore in-place major version upgrades.
- Learn about configuring high availability.