diff --git a/modules/cloudsql-instance/README.md b/modules/cloudsql-instance/README.md
index 8494396f3..925e0a84a 100644
--- a/modules/cloudsql-instance/README.md
+++ b/modules/cloudsql-instance/README.md
@@ -20,7 +20,6 @@ Note that this module assumes that some options are the same for both the primar
- [Password Validation Policy and Root Password Config](#password-validation-policy-and-root-password-config)
- [Variables](#variables)
- [Outputs](#outputs)
-- [Fixtures](#fixtures)
## Examples
@@ -406,37 +405,37 @@ module "db" {
| name | description | type | required | default |
|---|---|:---:|:---:|:---:|
-| [database_version](variables.tf#L75) | Database type and version to create. | string | ✓ | |
-| [name](variables.tf#L179) | Name of primary instance. | string | ✓ | |
-| [network_config](variables.tf#L184) | Network configuration for the instance. Only one between private_network and psc_config can be used. | object({…}) | ✓ | |
-| [project_id](variables.tf#L231) | The ID of the project where this instances will be created. | string | ✓ | |
-| [region](variables.tf#L236) | Region of the primary instance. | string | ✓ | |
-| [tier](variables.tf#L287) | The machine type to use for the instances. | string | ✓ | |
+| [database_version](variables.tf#L77) | Database type and version to create. | string | ✓ | |
+| [name](variables.tf#L181) | Name of primary instance. | string | ✓ | |
+| [network_config](variables.tf#L186) | Network configuration for the instance. Only one between private_network and psc_config can be used. | object({…}) | ✓ | |
+| [project_id](variables.tf#L233) | The ID of the project where this instances will be created. | string | ✓ | |
+| [region](variables.tf#L238) | Region of the primary instance. | string | ✓ | |
+| [tier](variables.tf#L289) | The machine type to use for the instances. | string | ✓ | |
| [activation_policy](variables.tf#L16) | This variable specifies when the instance should be active. Can be either ALWAYS, NEVER or ON_DEMAND. Default is ALWAYS. | string | | "ALWAYS" |
| [availability_type](variables.tf#L27) | Availability type for the primary replica. Either `ZONAL` or `REGIONAL`. | string | | "ZONAL" |
-| [backup_configuration](variables.tf#L33) | Backup settings for primary instance. Will be automatically enabled if using MySQL with one or more replicas. | object({…}) | | {…} |
-| [collation](variables.tf#L56) | The name of server instance collation. | string | | null |
-| [connector_enforcement](variables.tf#L62) | Specifies if connections must use Cloud SQL connectors. | string | | null |
-| [data_cache](variables.tf#L68) | Enable data cache. Only used for Enterprise MYSQL and PostgreSQL. | bool | | false |
-| [databases](variables.tf#L80) | Databases to create once the primary instance is created. | list(string) | | null |
-| [disk_autoresize_limit](variables.tf#L86) | The maximum size to which storage capacity can be automatically increased. The default value is 0, which specifies that there is no limit. | number | | 0 |
-| [disk_size](variables.tf#L92) | Disk size in GB. Set to null to enable autoresize. | number | | null |
-| [disk_type](variables.tf#L98) | The type of data disk: `PD_SSD` or `PD_HDD`. | string | | "PD_SSD" |
-| [edition](variables.tf#L104) | The edition of the instance, can be ENTERPRISE or ENTERPRISE_PLUS. | string | | "ENTERPRISE" |
-| [encryption_key_name](variables.tf#L110) | The full path to the encryption key used for the CMEK disk encryption of the primary instance. | string | | null |
-| [flags](variables.tf#L116) | Map FLAG_NAME=>VALUE for database-specific tuning. | map(string) | | null |
-| [gcp_deletion_protection](variables.tf#L122) | Set Google's deletion protection attribute which applies across all surfaces (UI, API, & Terraform). | bool | | true |
-| [insights_config](variables.tf#L129) | Query Insights configuration. Defaults to null which disables Query Insights. | object({…}) | | null |
-| [labels](variables.tf#L140) | Labels to be attached to all instances. | map(string) | | null |
-| [maintenance_config](variables.tf#L146) | Set maintenance window configuration and maintenance deny period (up to 90 days). Date format: 'yyyy-mm-dd'. | object({…}) | | {} |
-| [password_validation_policy](variables.tf#L207) | Password validation policy configuration for instances. | object({…}) | | null |
-| [prefix](variables.tf#L221) | Optional prefix used to generate instance names. | string | | null |
-| [replicas](variables.tf#L241) | Map of NAME=> {REGION, KMS_KEY} for additional read replicas. Set to null to disable replica creation. | map(object({…})) | | {} |
-| [root_password](variables.tf#L251) | Root password of the Cloud SQL instance, or flag to create a random password. Required for MS SQL Server. | object({…}) | | {} |
-| [ssl](variables.tf#L265) | Setting to enable SSL, set config and certificates. | object({…}) | | {} |
-| [terraform_deletion_protection](variables.tf#L280) | Prevent terraform from deleting instances. | bool | | true |
-| [time_zone](variables.tf#L292) | The time_zone to be used by the database engine (supported only for SQL Server), in SQL Server timezone format. | string | | null |
-| [users](variables.tf#L298) | Map of users to create in the primary instance (and replicated to other replicas). For MySQL, anything after the first `@` (if present) will be used as the user's host. Set PASSWORD to null if you want to get an autogenerated password. The user types available are: 'BUILT_IN', 'CLOUD_IAM_USER' or 'CLOUD_IAM_SERVICE_ACCOUNT'. | map(object({…})) | | null |
+| [backup_configuration](variables.tf#L33) | Backup settings for primary instance. Will be automatically enabled if using MySQL with one or more replicas. | object({…}) | | {…} |
+| [collation](variables.tf#L58) | The name of server instance collation. | string | | null |
+| [connector_enforcement](variables.tf#L64) | Specifies if connections must use Cloud SQL connectors. | string | | null |
+| [data_cache](variables.tf#L70) | Enable data cache. Only used for Enterprise MYSQL and PostgreSQL. | bool | | false |
+| [databases](variables.tf#L82) | Databases to create once the primary instance is created. | list(string) | | null |
+| [disk_autoresize_limit](variables.tf#L88) | The maximum size to which storage capacity can be automatically increased. The default value is 0, which specifies that there is no limit. | number | | 0 |
+| [disk_size](variables.tf#L94) | Disk size in GB. Set to null to enable autoresize. | number | | null |
+| [disk_type](variables.tf#L100) | The type of data disk: `PD_SSD` or `PD_HDD`. | string | | "PD_SSD" |
+| [edition](variables.tf#L106) | The edition of the instance, can be ENTERPRISE or ENTERPRISE_PLUS. | string | | "ENTERPRISE" |
+| [encryption_key_name](variables.tf#L112) | The full path to the encryption key used for the CMEK disk encryption of the primary instance. | string | | null |
+| [flags](variables.tf#L118) | Map FLAG_NAME=>VALUE for database-specific tuning. | map(string) | | null |
+| [gcp_deletion_protection](variables.tf#L124) | Set Google's deletion protection attribute which applies across all surfaces (UI, API, & Terraform). | bool | | true |
+| [insights_config](variables.tf#L131) | Query Insights configuration. Defaults to null which disables Query Insights. | object({…}) | | null |
+| [labels](variables.tf#L142) | Labels to be attached to all instances. | map(string) | | null |
+| [maintenance_config](variables.tf#L148) | Set maintenance window configuration and maintenance deny period (up to 90 days). Date format: 'yyyy-mm-dd'. | object({…}) | | {} |
+| [password_validation_policy](variables.tf#L209) | Password validation policy configuration for instances. | object({…}) | | null |
+| [prefix](variables.tf#L223) | Optional prefix used to generate instance names. | string | | null |
+| [replicas](variables.tf#L243) | Map of NAME=> {REGION, KMS_KEY} for additional read replicas. Set to null to disable replica creation. | map(object({…})) | | {} |
+| [root_password](variables.tf#L253) | Root password of the Cloud SQL instance, or flag to create a random password. Required for MS SQL Server. | object({…}) | | {} |
+| [ssl](variables.tf#L267) | Setting to enable SSL, set config and certificates. | object({…}) | | {} |
+| [terraform_deletion_protection](variables.tf#L282) | Prevent terraform from deleting instances. | bool | | true |
+| [time_zone](variables.tf#L294) | The time_zone to be used by the database engine (supported only for SQL Server), in SQL Server timezone format. | string | | null |
+| [users](variables.tf#L300) | Map of users to create in the primary instance (and replicated to other replicas). For MySQL, anything after the first `@` (if present) will be used as the user's host. Set PASSWORD to null if you want to get an autogenerated password. The user types available are: 'BUILT_IN', 'CLOUD_IAM_USER' or 'CLOUD_IAM_SERVICE_ACCOUNT'. | map(object({…})) | | null |
## Outputs
@@ -459,8 +458,4 @@ module "db" {
| [self_link](outputs.tf#L114) | Self link of the primary instance. | |
| [self_links](outputs.tf#L119) | Self links of all instances. | |
| [user_passwords](outputs.tf#L127) | Map of containing the password of all users created through terraform. | ✓ |
-
-## Fixtures
-
-- [iam-service-account.tf](../../tests/fixtures/iam-service-account.tf)
diff --git a/modules/cloudsql-instance/main.tf b/modules/cloudsql-instance/main.tf
index e64ee383b..671dfa95e 100644
--- a/modules/cloudsql-instance/main.tf
+++ b/modules/cloudsql-instance/main.tf
@@ -58,6 +58,7 @@ resource "google_sql_database_instance" "primary" {
tier = var.tier
edition = var.edition
deletion_protection_enabled = var.gcp_deletion_protection
+ retain_backups_on_delete = var.backup_configuration.retain_backups_on_delete
disk_autoresize = var.disk_size == null
disk_autoresize_limit = var.disk_autoresize_limit
disk_size = var.disk_size
@@ -218,6 +219,7 @@ resource "google_sql_database_instance" "replicas" {
tier = var.tier
edition = var.edition
deletion_protection_enabled = var.gcp_deletion_protection
+ retain_backups_on_delete = var.backup_configuration.retain_backups_on_delete
disk_autoresize = var.disk_size == null
disk_autoresize_limit = var.disk_autoresize_limit
disk_size = var.disk_size
diff --git a/modules/cloudsql-instance/variables.tf b/modules/cloudsql-instance/variables.tf
index 87616b233..91e7ad3dd 100644
--- a/modules/cloudsql-instance/variables.tf
+++ b/modules/cloudsql-instance/variables.tf
@@ -41,6 +41,7 @@ variable "backup_configuration" {
log_retention_days = optional(number, 7)
point_in_time_recovery_enabled = optional(bool)
retention_count = optional(number, 7)
+ retain_backups_on_delete = optional(bool, true)
})
default = {
enabled = false
@@ -50,6 +51,7 @@ variable "backup_configuration" {
log_retention_days = 7
point_in_time_recovery_enabled = null
retention_count = 7
+ retain_backups_on_delete = true
}
}