Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error when destroying and recreating google_compute_per_instance_config/google_compute_region_per_instance_config #9042

Assignees
Labels
bug forward/review In review; remove label to forward service/compute-managed

Comments

@adrian-gierakowski
Copy link

When a google_compute_per_instance_config is created, both a vm and the instance config linked to it are created.

However when google_compute_per_instance_config is destroyed, the is vm remains untouched

This leads to errors when a deleted google_compute_per_instance_config is subsequently recreated, since a vm with given name already exists as part of the mig.

google_compute_per_instance_config should (on destruction( either delete the vm instance it initially creates (via instanceGroupManagers/deleteInstances), or provide a flag to toggle this behaviour.

I'm happy to submit a PR.

Note: in the example below google_compute_region_instance_group_manager.target_size is set to null for the reason provided in the comment.

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 --version

Terraform v0.13.6
+ provider registry.terraform.io/hashicorp/google v3.66.1

Your version of Terraform is out of date! The latest version

Affected Resource(s)

  • google_compute_region_per_instance_config
  • google_compute_per_instance_config

Terraform Configuration Files

provider "google" {
  project    = "my-test-project-ar90s"
  region     = "us-central1"
  # Version set to prevent automatic major version upgrades.
  version    = "~> 3.66.1"
}

variable "size" {
  description = "Number of instances to create"
}

resource "google_compute_network" "vpc_network" {
  name = "vpc-network"
}

data "google_compute_image" "my_image" {
  family  = "debian-9"
  project = "debian-cloud"
}

resource "google_compute_instance_template" "igm-basic" {
  name           = "my-template"
  machine_type   = "e2-small"
  can_ip_forward = false
  tags           = ["foo", "bar"]

  disk {
    source_image = data.google_compute_image.my_image.self_link
    auto_delete  = true
    boot         = true
  }

  network_interface {
    network = google_compute_network.vpc_network.name
  }

  service_account {
    scopes = ["userinfo-email", "compute-ro", "storage-ro"]
  }
}

resource "google_compute_region_instance_group_manager" "rigm" {
  description = "Terraform test instance group manager"
  name        = "my-rigm"

  version {
    name              = "prod"
    instance_template = google_compute_instance_template.igm-basic.self_link
  }

  base_instance_name = "rigm"
  region             = google_compute_instance_template.igm-basic.region
  # Needs to be set to null, and not var.size, since otherwise "random" instance
  # will be deleted when target_size decreases, while we want metadata.index of
  # all existing instances to be contiguous (with values between: 0 and 
  # var.size - 1)
  target_size        = null

  update_policy {
    instance_redistribution_type = "NONE"
    type                         = "OPPORTUNISTIC"
    minimal_action               = "REPLACE"
    max_surge_fixed              = 0
    max_surge_percent            = null
    max_unavailable_fixed        = 3
    max_unavailable_percent      = null
    min_ready_sec                = 30
  }
}

resource "google_compute_region_per_instance_config" "configs" {
  count = var.size

  region = google_compute_region_instance_group_manager.rigm.region
  region_instance_group_manager = google_compute_region_instance_group_manager.rigm.name

  name = "my-rigm-instance-${count.index}"

  preserved_state {
    metadata = {
      index = count.index
    }
  }

  remove_instance_state_on_destroy = true
}

Debug Output

Panic Output

Expected Behavior

Actual Behavior

Steps to Reproduce

after running:

terraform init
terraform apply -var size=2
terraform apply -var size=1
terraform apply -var size=2

I get the following error:

...
google_compute_region_per_instance_config.configs[1]: Creating...
google_compute_region_per_instance_config.configs[1]: Still creating... [10s elapsed]

Error: Error waiting to create RegionPerInstanceConfig: Error waiting for Creating RegionPerInstanceConfig: Resource projects/my-test-project-ar90s/zones/us-central1-f/instances/my-rigm-instance-1 is already a member of projects/my-test-project-ar90s/regions/us-central1/instanceGroupManagers/my-rigm.


  on main.tf line 71, in resource "google_compute_region_per_instance_config" "configs":
  71: resource "google_compute_region_per_instance_config" "configs" {

Important Factoids

References

  • #0000
@adrian-gierakowski
Copy link
Author

note that this can be worked around by calling gcloud compute instance-groups managed delete-instances ... from within local-exec provisioner executed on destroy of google_compute_region_per_instance_config, but the solution should really be incorporated natively into the resource itself

adrian-gierakowski added a commit to adrian-gierakowski/terraform-google-nat-gateway that referenced this issue Apr 30, 2021
@github-actions github-actions bot added forward/review In review; remove label to forward service/compute-managed labels Nov 16, 2023
drcapulet added a commit to drcapulet/magic-modules that referenced this issue Dec 6, 2023
…resources.

It's a bit counterintuitive that creating a per-instance config in an IGM
spins up an instance but destroying it leaves the instance behind.

Also fixed a bug related to the operation to detach the disk from the
instance failing due to the instance having been deleted.

Fixes hashicorp/terraform-provider-google#9042 & hashicorp/terraform-provider-google#16621.
drcapulet added a commit to drcapulet/magic-modules that referenced this issue Dec 6, 2023
…resources

It's a bit counterintuitive that creating a per-instance config in an IGM
spins up an instance but destroying it leaves the instance behind.

Also fixed a bug related to the operation to detach the disk from the
instance failing due to the instance having been deleted.

Fixes hashicorp/terraform-provider-google#9042 & hashicorp/terraform-provider-google#16621.
drcapulet added a commit to drcapulet/magic-modules that referenced this issue Dec 6, 2023
…resources

It's a bit counterintuitive that creating a per-instance config in an IGM
spins up an instance but destroying it leaves the instance behind.

Also fixed a bug related to the operation to detach the disk from the
instance failing due to the instance having been deleted. Other than
the tests for the new per-instance config behavior, I was unable to
devise an isolated test to trigger this issue.

Fixes hashicorp/terraform-provider-google#9042 & hashicorp/terraform-provider-google#16621.
drcapulet added a commit to drcapulet/magic-modules that referenced this issue Dec 6, 2023
…resources

It's a bit counterintuitive that creating a per-instance config in an IGM
spins up an instance but destroying it leaves the instance behind.

Also fixed a bug related to the operation to detach the disk from the
instance failing due to the instance having been deleted. Other than
the tests for the new per-instance config behavior, I was unable to
devise an isolated test to trigger this issue.

Fixes hashicorp/terraform-provider-google#9042 & hashicorp/terraform-provider-google#16621.
drcapulet added a commit to drcapulet/magic-modules that referenced this issue Dec 6, 2023
…resources

It's a bit counterintuitive that creating a per-instance config in an IGM
spins up an instance but destroying it leaves the instance behind.

Also fixed a bug related to the operation to detach the disk from the
instance failing due to the instance having been deleted. Other than
the tests for the new per-instance config behavior, I was unable to
devise an isolated test to trigger this issue.

Fixes hashicorp/terraform-provider-google#9042 & hashicorp/terraform-provider-google#16621.
zli82016 pushed a commit to GoogleCloudPlatform/magic-modules that referenced this issue Dec 7, 2023
…resources (#9588)

It's a bit counterintuitive that creating a per-instance config in an IGM
spins up an instance but destroying it leaves the instance behind.

Also fixed a bug related to the operation to detach the disk from the
instance failing due to the instance having been deleted. Other than
the tests for the new per-instance config behavior, I was unable to
devise an isolated test to trigger this issue.

Fixes hashicorp/terraform-provider-google#9042 & hashicorp/terraform-provider-google#16621.
modular-magician added a commit to modular-magician/terraform-provider-google-beta that referenced this issue Dec 7, 2023
…resources (#9588)

It's a bit counterintuitive that creating a per-instance config in an IGM
spins up an instance but destroying it leaves the instance behind.

Also fixed a bug related to the operation to detach the disk from the
instance failing due to the instance having been deleted. Other than
the tests for the new per-instance config behavior, I was unable to
devise an isolated test to trigger this issue.

Fixes hashicorp/terraform-provider-google#9042 & hashicorp/terraform-provider-google#16621.
[upstream:4153866aaf018b769837b565a1088095fb25ae61]

Signed-off-by: Modular Magician <magic-modules@google.com>
modular-magician added a commit that referenced this issue Dec 7, 2023
…resources (#9588) (#16729)

It's a bit counterintuitive that creating a per-instance config in an IGM
spins up an instance but destroying it leaves the instance behind.

Also fixed a bug related to the operation to detach the disk from the
instance failing due to the instance having been deleted. Other than
the tests for the new per-instance config behavior, I was unable to
devise an isolated test to trigger this issue.

Fixes #9042 & #16621.
[upstream:4153866aaf018b769837b565a1088095fb25ae61]

Signed-off-by: Modular Magician <magic-modules@google.com>
modular-magician added a commit to hashicorp/terraform-provider-google-beta that referenced this issue Dec 7, 2023
…resources (#9588) (#6724)

It's a bit counterintuitive that creating a per-instance config in an IGM
spins up an instance but destroying it leaves the instance behind.

Also fixed a bug related to the operation to detach the disk from the
instance failing due to the instance having been deleted. Other than
the tests for the new per-instance config behavior, I was unable to
devise an isolated test to trigger this issue.

Fixes hashicorp/terraform-provider-google#9042 & hashicorp/terraform-provider-google#16621.
[upstream:4153866aaf018b769837b565a1088095fb25ae61]

Signed-off-by: Modular Magician <magic-modules@google.com>
modular-magician added a commit to modular-magician/terraform-provider-google that referenced this issue Dec 7, 2023
…resources (hashicorp#9588)

It's a bit counterintuitive that creating a per-instance config in an IGM
spins up an instance but destroying it leaves the instance behind.

Also fixed a bug related to the operation to detach the disk from the
instance failing due to the instance having been deleted. Other than
the tests for the new per-instance config behavior, I was unable to
devise an isolated test to trigger this issue.

Fixes hashicorp#9042 & hashicorp#16621.
[upstream:4153866aaf018b769837b565a1088095fb25ae61]

Signed-off-by: Modular Magician <magic-modules@google.com>
modular-magician added a commit to modular-magician/terraform-google-conversion that referenced this issue Dec 7, 2023
…resources (#9588)

It's a bit counterintuitive that creating a per-instance config in an IGM
spins up an instance but destroying it leaves the instance behind.

Also fixed a bug related to the operation to detach the disk from the
instance failing due to the instance having been deleted. Other than
the tests for the new per-instance config behavior, I was unable to
devise an isolated test to trigger this issue.

Fixes hashicorp/terraform-provider-google#9042 & hashicorp/terraform-provider-google#16621.
[upstream:4153866aaf018b769837b565a1088095fb25ae61]

Signed-off-by: Modular Magician <magic-modules@google.com>
modular-magician added a commit to GoogleCloudPlatform/terraform-google-conversion that referenced this issue Dec 7, 2023
…resources (#9588) (#1767)

It's a bit counterintuitive that creating a per-instance config in an IGM
spins up an instance but destroying it leaves the instance behind.

Also fixed a bug related to the operation to detach the disk from the
instance failing due to the instance having been deleted. Other than
the tests for the new per-instance config behavior, I was unable to
devise an isolated test to trigger this issue.

Fixes hashicorp/terraform-provider-google#9042 & hashicorp/terraform-provider-google#16621.
[upstream:4153866aaf018b769837b565a1088095fb25ae61]

Signed-off-by: Modular Magician <magic-modules@google.com>
trodge pushed a commit to trodge/magic-modules that referenced this issue Dec 8, 2023
…resources (GoogleCloudPlatform#9588)

It's a bit counterintuitive that creating a per-instance config in an IGM
spins up an instance but destroying it leaves the instance behind.

Also fixed a bug related to the operation to detach the disk from the
instance failing due to the instance having been deleted. Other than
the tests for the new per-instance config behavior, I was unable to
devise an isolated test to trigger this issue.

Fixes hashicorp/terraform-provider-google#9042 & hashicorp/terraform-provider-google#16621.
Copy link

github-actions bot commented Jan 7, 2024

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 7, 2024
balanaguharsha pushed a commit to balanaguharsha/magic-modules that referenced this issue May 2, 2024
…resources (GoogleCloudPlatform#9588)

It's a bit counterintuitive that creating a per-instance config in an IGM
spins up an instance but destroying it leaves the instance behind.

Also fixed a bug related to the operation to detach the disk from the
instance failing due to the instance having been deleted. Other than
the tests for the new per-instance config behavior, I was unable to
devise an isolated test to trigger this issue.

Fixes hashicorp/terraform-provider-google#9042 & hashicorp/terraform-provider-google#16621.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.