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.34k stars 1.75k forks source link

Adding `secondary_ip_range` to existing redis instance results in `Invalid value: auto` #16970

Open hspens opened 10 months ago

hspens commented 10 months ago

Community Note

Terraform Version

Terraform v1.6.6
on darwin_arm64
+ provider registry.terraform.io/hashicorp/archive v2.4.1
+ provider registry.terraform.io/hashicorp/google v5.10.0
+ provider registry.terraform.io/hashicorp/google-beta v5.10.0
+ provider registry.terraform.io/hashicorp/helm v2.12.1
+ provider registry.terraform.io/hashicorp/kubernetes v2.25.1
+ provider registry.terraform.io/hashicorp/random v3.6.0
+ provider registry.terraform.io/hashicorp/time v0.10.0

Affected Resource(s)

Terraform Configuration Files

resource "google_redis_instance" "instance" {
  name          = "instance-a"
  project       = var.cluster_project
  redis_version = "REDIS_6_X"
  region        = "europe-north1"

  tier               = "STANDARD_HA"
  read_replicas_mode = "READ_REPLICAS_ENABLED"
  replica_count      = 1
  memory_size_gb     = 5

  authorized_network      = data.google_compute_network.host_network.id
  transit_encryption_mode = "SERVER_AUTHENTICATION"
  connect_mode            = "PRIVATE_SERVICE_ACCESS"
  auth_enabled            = true

  timeouts {
    create = var.redis_create_timeout
    update = var.redis_update_timeout
    delete = var.redis_delete_timeout
  }

  maintenance_policy {
    weekly_maintenance_window {
      day = var.maintenance_day
      start_time {
        hours   = var.maintenance_hour
        minutes = 0
        seconds = 0
        nanos   = 0
      }
    }
  }

  labels = {
    service = "service-a"
    team    = "team-a"
  }

  depends_on = [
    google_kms_crypto_key_iam_member.crypto_key_iam
  ]

  customer_managed_key = google_kms_crypto_key.crypto_key.id
}

Debug Output

Error: Error updating Instance "projects/{project-id}/locations/europe-north1/instances/{instance-id}": googleapi: Error 400: > Secondary IP Range can not be updated on instances that use read replicas com.google.apps.framework.request.StatusException: generic::INVALID_ARGUMENT: > Secondary IP Range can not be updated on instances that use read replicas Details:

[
  {
    "@type": "type.googleapis.com/google.rpc.BadRequest",
    "fieldViolations": [
      {
        "description": "Invalid value: auto",
       "field": "instance.secondary_ip_range"
     }
    ]
  }
]

Expected Behavior

It should have worked since the secondary_ip_range was set to auto prior to terraform apply.

Actual Behavior

Failes.

Steps to Reproduce

  1. Create the above redis instance without specifying any value for seconday_ip_range
  2. terraform apply
  3. Add secondary_ip_range = "auto"
  4. terraform apply will now report 1 addition, secondary_ip_range = auto but the terraform state already indicate it's set to auto.
  5. Apply fails with above error message

Important Factoids

The initial creation didn't specify a secondary_ip_range, so I assume auto was used implicitly under the hood. Setting it explicitly to auto after the instance has been created results in an error.

It works if secondary_ip_range is set explicitly to null.

b/319824812

edwardmedia commented 10 months ago

I can repro. It appears secondary_ip_range needs to be set ForceNew()

AmandaHassoun commented 5 months ago

hey @edwardmedia , any updates on this? We're also running into the same error..