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.33k stars 1.73k forks source link

google_apigee_instance is created before destroyed when need to be replaced #10969

Open matihost opened 2 years ago

matihost commented 2 years ago

Community Note

Terraform Version

1.1.4

Affected Resource(s)

Terraform Configuration Files


resource "google_apigee_instance" "instance" {
  name = "${var.env}-${google_apigee_organization.org.name}-${var.region}"

  # only single instance per region is possible
  location    = var.region
  description = "Apigee Runtime Instance in ${var.region}"
  org_id      = google_apigee_organization.org.id

  # disk encyption only for paid subscription only
  # disk_encryption_key_name = google_kms_crypto_key.apigee-key.id

  # change by removing peering_cidr_range with ip_range
  # peering_cidr_range = "SLASH_22"
  ip_range = "10.9.0.0/22"
}

Panic Output

  # google_apigee_instance.instance must be replaced
+/- resource "google_apigee_instance" "instance" {
      ~ host               = "10.9.0.2" -> (known after apply)
      ~ id                 = "organizations/.../instances/dev-myproject-us-central1" -> (known after apply)
      + ip_range           = "10.9.0.0/22" # forces replacement
        name               = "dev-myproject-us-central1"
      ~ peering_cidr_range = "SLASH_22" -> (known after apply)
      ~ port               = "443" -> (known after apply)
        # (3 unchanged attributes hidden)
    }
..
google_apigee_instance.instance: Creating...
╷
│ Error: Error creating Instance: googleapi: Error 409: instance "organizations/myproject/instances/dev-myproject-us-central1" already exists
│ Details:
│ [
│   {
│     "@type": "type.googleapis.com/google.rpc.RequestInfo",
│     "requestId": "10999007824841964626"
│   }
│ ]
│ 
│   with google_apigee_instance.instance,
│   on instances.tf line 2, in resource "google_apigee_instance" "instance":
│    2: resource "google_apigee_instance" "instance" {
│ 

Expected Behavior

Terraform should first destroy google_apigee_instance before creation of updated one.

Currently it behaves like :

  lifecycle {
    create_before_destroy = true
  }

but it is NOT set. Trying to add

  lifecycle {
    create_before_destroy = false
  }

explicitly does not work.

Actual Behavior

Terraform creates new apigee instance with update field and failed as the name is the same, but it should actually destory apigee instance first.

Steps to Reproduce

  1. terraform apply
melinath commented 1 year ago

b/270217243

jogoldberg commented 1 year ago

I'm experiencing the same problem. Please help.