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

removing target pool from regional instance group manager doesn't take effect #6453

Closed
TSFenwick opened this issue May 22, 2020 · 2 comments · Fixed by GoogleCloudPlatform/magic-modules#3581, #6492 or hashicorp/terraform-provider-google-beta#2124
Assignees
Labels

Comments

@TSFenwick
Copy link

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.12.25

  • provider.google v3.22.0

Affected Resource(s)

  • google_compute_region_instance_group_manager
    it actually affects the target pool in the console

Terraform Configuration Files

Before

variable "project" {
  type = string
}
variable "region" {
  type = string
  default = "us-central1"
}

variable "target_size" {
  type = number
}

provider "google" {
  project = var.project
  region = var.region
  version = "3.22"
}

resource "google_compute_region_instance_group_manager" "default" {
  base_instance_name = "instance"
  name = "default-a"

  region = var.region
  target_size = var.target_size
  target_pools = [
    google_compute_target_pool.default.self_link,
  ]

  version {
    instance_template = google_compute_instance_template.template.self_link
  }
}

resource "google_compute_address" "default" {
  name = "default"
}

resource "google_compute_target_pool" "default" {
  name = "default"
  region = var.region
  instances = []
}

data "google_compute_network" "default" {
  name = "default"
}

resource "google_compute_instance_template" "template" {
  name = "template-1"
  machine_type = "f1-micro"

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

  network_interface {
    network = data.google_compute_network.default.self_link
  }
}

data "google_compute_image" "my_image" {
  family  = "ubuntu-1804-lts"
  project = "ubuntu-os-cloud"
}

output "ip-address" {
  value = google_compute_address.default.address
}

After

variable "project" {
  type = string
}
variable "region" {
  type = string
  default = "us-central1"
}

variable "target_size" {
  type = number
}

provider "google" {
  project = var.project
  region = var.region
  version = "3.22"
}

resource "google_compute_region_instance_group_manager" "default" {
  base_instance_name = "instance"
  name = "default-a"

  region = var.region
  target_size = var.target_size

  version {
    instance_template = google_compute_instance_template.template.self_link
  }
}

resource "google_compute_address" "default" {
  name = "default"
}

resource "google_compute_target_pool" "default" {
  name = "default"
  region = var.region
  instances = []
}

data "google_compute_network" "default" {
  name = "default"
}

resource "google_compute_instance_template" "template" {
  name = "template-1"
  machine_type = "f1-micro"

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

  network_interface {
    network = data.google_compute_network.default.self_link
  }
}

data "google_compute_image" "my_image" {
  family  = "ubuntu-1804-lts"
  project = "ubuntu-os-cloud"
}

output "ip-address" {
  value = google_compute_address.default.address
}

Debug Output

contains running it
https://gist.github.com/TSFenwick/0c9c88b3c4425697535c89650609e2f5

Expected Behavior

target pool no longer directs traffic to instances of regional instance group manager. Running terraform apply should have an effect.

Actual Behavior

Instead you can run terraform apply and it will always try to change the regional instance group manager.

Steps to Reproduce

  1. terraform apply
  2. remove target_pools from google_compute_region_instance_group_manager`
  3. terraform apply

The target pool will still be pointing at the regional instance group manager. and you can keep running terraform apply and it will always want to modify the regional instance group manager

Important Factoids

authenticating as a user

References

@ghost ghost added the bug label May 22, 2020
@edwardmedia edwardmedia self-assigned this May 22, 2020
@edwardmedia
Copy link
Contributor

edwardmedia commented May 23, 2020

I can repro this issue.
For removing instances from the target pool in this case, I noticed removeinstance of targetPools is called (first below). Because both google_compute_target_pool and google_compute_region_instance_group_manager are trying to set the same target_size, unless the execution order is forced, the final number of instances in the target pool seems to be uncertain. Shouldn't resize of instanceGroupManagers be called (second below) instead of removeinstance of targetPools?

POST /compute/v1/projects/myproject/regions/us-central1/targetPools/issue6453pool/removeInstance?alt=json&prettyPrint=false HTTP/1.1
{
 "instances": [
   {
    "instance": "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-f/instances/instance-pr5n"
   },
   {
     "instance": "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-b/instances/instance-kdvg"
   }
 ]
}
POST /compute/beta/projects/myproject/regions/us-central1/instanceGroupManagers/default-a/resize?alt=json&pret tyPrint=false&size=0 

@ghost
Copy link

ghost commented Jun 29, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Jun 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.