terraform-provider-google: Importing CloudSQL replica instance causes errors with settings.maintenance_window

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave “+1” or “me too” comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
  • If an issue is assigned to the “modular-magician” user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to “hashibot”, a community member has claimed the issue already.

Terraform Version

Terraform v0.10.8 Google provider 2.9.1

Affected Resource(s)

  • google_sql_database_instance

Terraform Configuration Files

resource "google_sql_database_instance" "replica" {
  name                 = "${local.db_instance_name}-failover"
  database_version     = "${var.db_version}"
  region               = "${var.gcp_region}"
  master_instance_name = "${google_sql_database_instance.primary.name}"

  replica_configuration {
    failover_target = true
  }

  settings {
    tier                   = "${var.instance_type}"
    disk_type              = "${var.disk_type}"
    disk_size              = "${var.disk_size}"
    disk_autoresize        = true
    crash_safe_replication = true

    ip_configuration {
      ipv4_enabled    = true
      private_network = "${data.google_compute_network.network.self_link}"
    }

    maintenance_window {
      day          = "2"
      hour         = "9"
    }
  }

  depends_on = ["google_sql_database_instance.primary"]
}

Expected Behavior

CloudSQL replica imported with terraform import with matching configuration should show no changes.

Actual Behavior

When setting the settings.maintenance_window options to match the configuration in Google Cloud, terraform plan shows

I, [2019-06-27T11:55:07.517805 #507]  INFO -- :       settings.0.maintenance_window.0.day:                                         "0" => "2"
I, [2019-06-27T11:55:07.517954 #507]  INFO -- :       settings.0.maintenance_window.0.hour:                                        "0" => "9"

When attempting to apply this Google API returns

module.[redacted].google_sql_database_instance.replica: Modifying... (ID:[redacted]-failover)
  settings.0.maintenance_window.0.day:                                         "0" => "2"
  settings.0.maintenance_window.0.hour:                                        "0" => "9"
google_sql_database_instance.replica: Error, failed to update instance settings for : googleapi: Error 400: Invalid request: Cannot update maintenance window for replica instances., invalid

Setting the parameters to 0 returns a Terraform error with plan

Error: module.[redacted].google_sql_database_instance.replica: expected settings.0.maintenance_window.0.day to be in the range (1 - 7), got 0

Removing the entire maintenance_window and running terraform apply with any other change to the google_sql_database_instance resource returns

module.[redacted].google_sql_database_instance.replica: Modifying... (ID: [redacted]-failover)
  settings.0.maintenance_window.#:                                             "1" => "0"
google_sql_database_instance.replica: Error, failed to update instance settings for : googleapi: Error 400: Invalid request: Cannot update maintenance window for replica instances., invalid

Adding

  lifecycle{
    ignore_changes = ["settings.0.maintenance_window"]
  }

and running apply with any other change to the google_sql_database_instance returns

google_sql_database_instance.replica: Error, failed to update instance settings for : googleapi: Error 400: Invalid request: Invalid maintenance window. Day of week is unspecified., invalid

Steps to Reproduce

  1. import a google_sql_database_instance replica via terraform import resource
  2. make any change to the google_sql_database_instance resource

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 8
  • Comments: 19

Most upvoted comments

I was actually able to work around it by removing those replicas completely from remote state, then re-importing them without the maintenance_window defined