Community Note
Several nested Optional+Computed attributes inside settings — e.g.
collation, time_zone, backup_configuration.location,
final_backup_config.retention_days, location_preference.follow_gae_application,
location_preference.secondary_zone, ip_configuration.allocated_ip_range,
ip_configuration.server_ca_pool, sql_server_audit_config.bucket,
replication_cluster.failover_dr_replica_name, and the
read_pool_auto_scale_config numeric fields — return empty string "" / 0
from the Cloud SQL Admin API when not explicitly configured.
When these are set to null (the natural way to express "don't manage
this") in Terraform config, terraform plan shows a delete action for
these attributes on every single plan, even though the underlying GCP
value never changes. This creates a permanently "dirty" plan.
Terraform Version & Provider Version(s)
Terraform Version
Terraform v1.11.4
+ provider registry.terraform.io/hashicorp/google v5.44.0
### Affected Resource(s)
google_sql_database_instance
### Terraform Configuration
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 5.0"
}
}
}
provider "google" {
project = "your-gcp-project-id"
region = "europe-west2"
}
resource "google_sql_database_instance" "repro_instance" {
name = "repro-sql-instance-null-diff"
database_version = "MYSQL_8_0_31"
region = "europe-west2"
settings {
tier = "db-perf-optimized-N-8"
collation = null
time_zone = null
backup_configuration {
enabled = true
location = null
}
ip_configuration {
allocated_ip_range = null
server_ca_pool = null
}
}
}
### Debug Output
_No response_
### Expected Behavior
Since these are Optional+Computed, no diff should be shown when config
leaves them unset and state already matches the provider's zero-value
default.
### Actual Behavior
```text
# google_sql_database_instance.repro_instance will be updated in-place
~ resource "google_sql_database_instance" "repro_instance" {
id = "repro-sql-instance-null-diff"
name = "repro-sql-instance-null-diff"
~ settings {
- collation = "" -> null
- time_zone = "" -> null
~ backup_configuration {
- location = "" -> null
# (2 unchanged attributes hidden)
}
~ ip_configuration {
- allocated_ip_range = "" -> null
- server_ca_pool = "" -> null
# (4 unchanged attributes hidden)
}
}
}
Plan: 0 to add, 1 to change, 0 to destroy.
Steps to reproduce
- Save the minimal configuration above into
main.tf.
- Run
terraform init and terraform apply to provision the instance.
- Immediately run a subsequent
terraform plan without making any changes to main.tf or the GCP console.
- Observe that
terraform plan outputs a non-zero plan proposing to delete collation, time_zone, location, allocated_ip_range, and server_ca_pool from "" to null.
Important Factoids
This behavior is particularly impactful on production databases managed via CI/CD automation pipelines (such as Terraform Cloud), where permanent non-zero diffs make it difficult to verify zero-downtime infrastructure reconciliations.
References
No response
b/558324049
Community Note
Several nested Optional+Computed attributes inside
settings— e.g.collation, time_zone, backup_configuration.location,
final_backup_config.retention_days, location_preference.follow_gae_application,
location_preference.secondary_zone, ip_configuration.allocated_ip_range,
ip_configuration.server_ca_pool, sql_server_audit_config.bucket,
replication_cluster.failover_dr_replica_name, and the
read_pool_auto_scale_config numeric fields — return empty string "" / 0
from the Cloud SQL Admin API when not explicitly configured.
When these are set to
null(the natural way to express "don't managethis") in Terraform config,
terraform planshows adeleteaction forthese attributes on every single plan, even though the underlying GCP
value never changes. This creates a permanently "dirty" plan.
Terraform Version & Provider Version(s)
Terraform Version
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 5.0"
}
}
}
provider "google" {
project = "your-gcp-project-id"
region = "europe-west2"
}
resource "google_sql_database_instance" "repro_instance" {
name = "repro-sql-instance-null-diff"
database_version = "MYSQL_8_0_31"
region = "europe-west2"
settings {
tier = "db-perf-optimized-N-8"
collation = null
time_zone = null
}
}
Steps to reproduce
main.tf.terraform initandterraform applyto provision the instance.terraform planwithout making any changes tomain.tfor the GCP console.terraform planoutputs a non-zero plan proposing to deletecollation,time_zone,location,allocated_ip_range, andserver_ca_poolfrom""tonull.Important Factoids
This behavior is particularly impactful on production databases managed via CI/CD automation pipelines (such as Terraform Cloud), where permanent non-zero diffs make it difficult to verify zero-downtime infrastructure reconciliations.
References
No response
b/558324049