hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.36k stars 1.75k forks source link

CloudSQL-data_cache_enabled resource #19144

Open BenRamosG opened 3 months ago

BenRamosG commented 3 months ago

Community Note

Terraform Version & Provider Version(s)

Terraform v1.8.3

Affected Resource(s)

google_sql_database_instance

Terraform Configuration

resource "google_sql_database_instance" "instance" {
  name             = var.instance_conf.name
  region           = var.instance_conf.region
  database_version = var.instance_conf.version
  root_password    = var.instance_conf.password

  deletion_protection = var.instance_conf.settings.delete_protection
  settings {
    tier              = var.instance_conf.settings.tier
    edition           = var.instance_conf.settings.edition
    availability_type = var.instance_conf.settings.availability
    data_cache_config {
      data_cache_enabled = var.instance_conf.settings.data_cache
    }
    deletion_protection_enabled = var.instance_conf.settings.delete_protection

    ip_configuration {
      ipv4_enabled = false
      psc_config {
        psc_enabled               = true
        allowed_consumer_projects = var.instance_conf.settings.allow_projects
      }
      ssl_mode = var.instance_conf.settings.ssl_mode
    }

    disk_type       = var.instance_conf.disk.disk_type
    disk_size       = var.instance_conf.disk.disk_size
    disk_autoresize = var.instance_conf.disk.disk_autoresize

    backup_configuration {
      enabled    = var.instance_conf.backup.enable
      start_time = var.instance_conf.backup.hour
      location   = var.instance_conf.backup.location
      backup_retention_settings {
        retained_backups = var.instance_conf.backup.retention
      }
      point_in_time_recovery_enabled = var.instance_conf.point_time.enable
      transaction_log_retention_days = var.instance_conf.point_time.retention
    }

    maintenance_window {
      day          = var.instance_conf.maintenance.day
      hour         = var.instance_conf.maintenance.hour
      update_track = var.instance_conf.maintenance.when
    }

    database_flags {
      name  = "cloudsql.iam_authentication"
      value = "on"
    }

    user_labels = var.instance_conf.labels

  }
}

Debug Output

No response

Expected Behavior

State file must contain data_cache_enabled attribute in its document, because once created this resource and exeute an apply command again, it shows data_cache_enabled will be modfied even if you don't modified data_cache_enabled.

Actual Behavior

Don't show cache enable in the state file

Steps to reproduce

  1. terraform apply

Important Factoids

No response

References

No response

ggtisc commented 3 months ago

Hi @BenRamosG!

I tried to replicate this issue, but the steps are not clear. I executed a 1st terraform apply to create the resource and then executed a 2nd terraform apply without making changes. In both cases I checked the tfstate file but the data_cache_enabled value didn't change.

Could you confirm if the steps are correct? because in the steps to reproduce you put just 1 terraform apply, and with this is the same the data_cache_enabled value was here.

If you changed any other value please let me know.

BenRamosG commented 2 months ago

I've checked and there is a ticket for my situation: https://github.com/hashicorp/terraform-provider-google/issues/15227

I use Enterprise edition for my cloud sql instance with data_cache_enabled in false. The resource is created correctly, but when I want to modify something later in this resource, this mentioned it:

     + data_cache_config {
          + data_cache_enabled = false
        }

When I didn't modify this attribute in the resource.
ggtisc commented 2 months ago

The issue was replicated with the next configuration since you are not sharing the variable values and the result was successful without errors or differences.

resource "google_sql_database_instance" "sql_db_instance_19144" {
  name             = "sql-db-instance-19144"
  project          = "my-project"
  region           = "us-central1"
  database_version = "MYSQL_8_0_31"

  settings {
    tier      = "db-perf-optimized-N-2"
    edition   = "ENTERPRISE_PLUS"

    data_cache_config {
      data_cache_enabled = true
    }
  }

  deletion_protection = false
}

If you continue with issues share the complete configuration of your code to make another try, because we don't have access to your variable values. For sensitive data you could use examples like: