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

GCP : Not able to attach instance_group to the target pool as backend while creating loadbalancer #6870

Closed
ghost opened this issue Jul 28, 2020 · 4 comments
Assignees
Labels

Comments

@ghost
Copy link

ghost commented Jul 28, 2020

This issue was originally opened by @b-rajesh as hashicorp/terraform#25689. It was migrated here as a result of the provider split. The original body of the issue is below.


Terraform Version

0.12
...

Terraform Configuration Files

resource "google_compute_instance_template" "nginx-plus-gwy-template" {
  name        = "nginx-plus-gwy-template"
  tags = ["nginx-plus-api-gwy"]

  labels = {
    environment = "dev"
  }
  machine_type         = var.machine_type
  can_ip_forward       = false

  scheduling {
    automatic_restart   = true
    on_host_maintenance = "MIGRATE"
  }

  // Create a new boot disk from an image
  disk {
    source_image = "nginxplus-r22"
    auto_delete  = true
    boot         = true
  }
  network_interface {
    network = google_compute_network.vpc.name
    subnetwork = google_compute_subnetwork.subnet.name
    access_config {
    }
  }
  service_account {
    scopes = [
      "https://www.googleapis.com/auth/compute",
    ]
  }
  lifecycle {
    create_before_destroy = true
  }
}

resource "google_compute_instance_group_manager" "nginx-plus-gwy-group-manager" {
  name               = "nginx-plus-gwy-instance-group-manager"
  base_instance_name = "nginx-plus-api-gwy"
  zone               = var.zones
  target_size        = "3"
  version {
    instance_template = google_compute_instance_template.nginx-plus-gwy-template.id
  }
}


resource "google_compute_forwarding_rule" "gce-ext-lb-forwarding-rule" {
  depends_on            = [google_compute_subnetwork.subnet]
  name                  = "gce-external-lb"
  target                = google_compute_target_pool.default.self_link
  load_balancing_scheme = "EXTERNAL"
  network_tier           = "STANDARD"
  ip_address            = var.ip_address
  ip_protocol           = var.protocol
  port_range            = var.port_range
}

resource "google_compute_target_pool" "default" {
  name             = "ext-loadbalancer-nginx-plus"
  //instances        = google_compute_instance_group_manager.nginx-plus-gwy-group-manager.self_link
  //session_affinity = var.session_affinity
  health_checks = google_compute_http_health_check.default.*.name
}

resource "google_compute_http_health_check" "default" {
  name    = "nginx-plus-health-check"

  request_path        = var.health_check_path
  port                = var.health_check_port
  check_interval_sec  = var.health_check_interval
  healthy_threshold   = var.health_check_healthy_threshold
  unhealthy_threshold = var.health_check_unhealthy_threshold
  timeout_sec         = var.health_check_timeout
}

...

Debug Output

This above config creates external TCP load balancer successfully , however I am not able to assign the instance group as Backend through Terraform as there is no option I can see with google_compute_target_pool to achieve the same.

I have attached screenshot from the gcp console as I could achieve the same through the ui.

Screen Shot 2020-07-28 at 11 08 13 pm

Expected behaviour

Is this a bug or terraform is still yet to get this feature added to it ? I need some guidance , please help....

@edwardmedia
Copy link
Contributor

@b-rajesh could you post the debug log?

@b-rajesh
Copy link

@edwardmedia
As usual its my bad :( as I missed to refer the target pool in the google_compute_instance_group_manager . Now it works fine and load balancer can see those instances as backend.

On other note - my humble opinion too - it would have been much better if I am able to reference target_pool referencing the instance_group_manager . It would be better to do this way to understand the flow
LB --> TargetPool --> InstanceGroup
however it look like this now
LB --> TargetPool <-- InstanceGroup

Since TargetPool already have a way to reference to Instances directly then why can't we refer the instance group?

May be I am missing the big picture ? Any pointer to understand this would be much appreciated...

@edwardmedia
Copy link
Contributor

@b-rajesh I am glad your issue has been resolved. To answer your question, could you review below doc to see if that makes sense? I am closing this issue now. Please feel free to reopen it if you still need to continue the discussion. Thank you

https://cloud.google.com/compute/docs/instance-groups/adding-an-instance-group-to-a-load-balancer#adding_a_managed_instance_group_to_a_target_pool

@ghost
Copy link
Author

ghost commented Aug 30, 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!

@hashicorp hashicorp locked and limited conversation to collaborators Aug 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants