CLOUD-DATABASE-ENGINEER practice question 1 of 25

Your DevOps team is using Terraform to deploy applications and Cloud SQL databases. After every new application change is rolled out, the environment is torn down and recreated, and the persistent database layer is lost. You need to prevent the database from being dropped. What should you do?

Full set: 141 questions
Answer options
A: Set Terraform deletion_protection to true. Correct answer
B: Rerun terraform apply.
C: Create a read replica.
D: Use point-in-time-recovery (PITR) to recover the database.
Correct Answer:
A. Set Terraform deletion_protection to true.
Explanation

The core issue is that the terraform destroy command, which is part of the environment teardown process, is deleting the Cloud SQL instance. The deletionprotection argument within the Terraform googlesqldatabaseinstance resource is specifically designed to prevent this. When set to true, any attempt by Terraform to destroy the instance will fail, thus protecting the persistent database layer from being lost during automated environment recreation cycles. This directly addresses the requirement to prevent the database from being dropped.

Why Incorrect

B. Rerun terraform apply: This command creates or updates resources based on the configuration. It does not prevent a resource from being deleted by a terraform destroy command.
C. Create a read replica: A read replica is for scaling read traffic or for high availability. It does not prevent the primary instance from being deleted by Terraform.
D. Use point-in-time-recovery (PITR) to recover the database: PITR is a reactive measure used to restore a database after it has been deleted or corrupted. The goal is to proactively prevent deletion. ---

References

1. Terraform Documentation for the Google Provider: The documentation for the googlesqldatabaseinstance resource explicitly lists the deletionprotection argument. It states, "Used to block Terraform from deleting a SQL Instance." This is the direct mechanism to solve the problem described.

Source: Terraform Registry, Google Provider, googlesqldatabaseinstance resource documentation, deletionprotection argument description.

2. Google Cloud SQL Documentation: The underlying feature in Google Cloud that Terraform manages is "Deletion protection." The official documentation explains that this setting protects an instance from accidental deletion. When enabled, you cannot delete the instance until the protection is disabled.

Source: Google Cloud Documentation, Cloud SQL > Documentation > How-to guides > Edit an instance, Section: "Enable and disable deletion protection".

3. Google Cloud SQL Documentation: The instance settings documentation further clarifies the purpose of deletion protection, confirming it's a safeguard for production instances.

Source: Google Cloud Documentation, Cloud SQL > Documentation > Concepts > Instances, Section: "Instance settings".

Scroll to Top