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.29k stars 1.72k forks source link

google_compute_region_per_instance_config fails with empty preserved_state #7365

Open riptl opened 3 years ago

riptl commented 3 years ago

Community Note

Terraform Version

Terraform v0.13.3
+ provider registry.terraform.io/hashicorp/google v3.40.0
+ provider registry.terraform.io/hashicorp/google-beta v3.40.0
+ provider registry.terraform.io/hashicorp/random v2.3.0
+ provider registry.terraform.io/hashicorp/template v2.1.2

Affected Resource(s)

Terraform Configuration Files

resource "google_compute_region_per_instance_config" "alertmanager" {
  provider = google-beta

  count = var.replicas

  project = var.project_id
  name    = "alertmanager-${var.region}-${count.index}"
  region  = var.region

  region_instance_group_manager = google_compute_region_instance_group_manager.alertmanager.name

  minimal_action = "REPLACE"

  preserved_state {} # NOTICE THIS IS EMPTY
}

Debug Output

When applying this, the provider makes two calls:

https://gist.github.com/terorie/4502ebca06aa73d5eb316b49498d0767

Expected Behavior

Apply completes.

Actual Behavior

Error: Provider produced inconsistent result after apply

Steps to Reproduce

  1. Create a managed instance group
  2. Define a per-instance config without preserved_state
  3. terraform apply

Important Factoids

The per-instance config returned by /listPerInstanceConfigs is an empty object {} if preserved_state is empty.

This behavior is wanted in a rare circumstance when instances in a MIG are supposed to have stable names but are still stateless.

Apply works when specifying some data inside preserved_state, such as a dummy metadata value, presumably because the preserved_state is not an empty object.

This leads me to believe that the provider handles empty objects erroneously.

References

slevenick commented 3 years ago

Odd... Does the instance group actually have an instance named after the empty-state per instance config? The result from the API being empty seems to indicate that the instance group does not do anything with the per-instance-config.

I don't see a way to handle this in the provider given how the API does not include the instance in the result of listPerInstanceConfigs