Skip to main content

Triage and Remediation

Remediation

Using Console

To remediate the misconfiguration of SQL instances not configured with the latest SQL versions in GCP, follow the below steps:
  1. Login to the GCP console.
  2. Go to the SQL instances page.
  3. Identify the SQL instances that are not configured with the latest SQL versions.
  4. Click on the name of the instance that needs to be remediated.
  5. In the instance details page, click on the ‘Edit’ button.
  6. Scroll down to the ‘Database version’ section.
  7. Select the latest version of the SQL database that is available from the dropdown list.
  8. Click on the ‘Save’ button to save the changes.
  9. Wait for the instance to be updated with the latest SQL version.
By following the above steps, you have successfully remediated the misconfiguration of SQL instances not configured with the latest SQL versions in GCP.

To remediate this misconfiguration in GCP using GCP CLI, follow these steps:
  1. Open the Cloud Shell in the GCP console.
  2. Run the following command to list all the SQL instances in the project:
  3. Identify the SQL instance that needs to be updated to the latest version.
  4. Run the following command to update the SQL instance to the latest version:
    Replace [INSTANCE_NAME] with the name of the SQL instance that needs to be updated, and [LATEST_VERSION] with the latest version of the SQL database engine. For example, if the SQL instance name is my-sql-instance and the latest version is SQLSERVER_2019_STANDARD, the command would be:
  5. Wait for the update to complete. It may take several minutes for the update to finish.
  6. Verify that the SQL instance is updated to the latest version by running the following command:
    Replace [INSTANCE_NAME] with the name of the SQL instance. Check the databaseVersion field to ensure that it reflects the latest version of the SQL database engine. That’s it! The SQL instance has now been updated to the latest version.
To remediate the misconfiguration of SQL Instances not being configured with the latest SQL versions in GCP using Python, you can follow the below steps:
  1. First, you need to identify all the SQL instances that are not configured with the latest SQL versions. You can use the google-cloud-sql Python library to get a list of all the SQL instances in your GCP project.
  2. Once you have the list of SQL instances, you can check the version of each instance using the get method of the Instance class in the google-cloud-sql library. You can compare the version of each instance with the latest version available and identify the instances that are not configured with the latest version.
  3. After identifying the instances that are not configured with the latest version, you can update the SQL instances to the latest version using the patch method of the Instance class in the google-cloud-sql library. You can set the database_version parameter to the latest version available for the SQL instance.
Here is the sample Python code to remediate the misconfiguration of SQL Instances not being configured with the latest SQL versions in GCP:
Note: You need to replace <your-project-id> and <path-to-service-account-key-file> with your actual GCP project ID and the path to your service account key file, respectively. Also, you need to update the database_version parameter in the patch method with the latest version available for your SQL instance.
Replace:
  • PRIMARY_INSTANCE with your Terraform resource name.
  • PRIMARY_INSTANCE_NAME with your actual instance ID.
  • PRIMARY_INSTANCE_REGION with the instance region.
  • PRIMARY_INSTANCE_TIER with a valid tier for your workload.
  • "POSTGRES_16" with the latest supported version for your engine family:
    • PostgreSQL: e.g. POSTGRES_16
    • MySQL: e.g. MYSQL_8_0_36
    • SQL Server: e.g. SQLSERVER_2019_STANDARD
Terraform cannot track “latest” dynamically; you must explicitly update database_version whenever GCP introduces a newer version that your policy requires.Changing database_version on google_sql_database_instance generally forces replacement of the instance (new instance, data migration/restore required), which can cause downtime and data loss if not carefully planned. Check the terraform plan for google_sql_database_instance.PRIMARY_INSTANCE and verify it shows a change to database_version and (likely) -/+ replacement of the instance as expected.