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

Not able to provide healthcheck to modules/mig #152

Closed
daisy1754 opened this issue Mar 11, 2021 · 3 comments
Closed

Not able to provide healthcheck to modules/mig #152

daisy1754 opened this issue Mar 11, 2021 · 3 comments

Comments

@daisy1754
Copy link

We currently use this module (modules/mig) to declare MIG. we also define google_compute_backend_service and google_compute_health_check in our TF file. We now want to share the existing health check between backend service and MIG but it seems there is no way of doing so without destroying and recreating existing health check. It would be nice if modules/mig can accept externally created healthcheck like google_compute_backend_service does.

Our terraform config for reference:

module "my_mig_template" {
  source               = "terraform-google-modules/vm/google//modules/instance_template"
  version              = "2.1.0"
  network              = "default"
  name_prefix          = "my-service-${local.commit-sha}"
  disk_size_gb         = "10"
  disk_type            = "pd-ssd"
  enable_shielded_vm   = true
  machine_type         = "e2-small"
  source_image_family  = "cos-stable"
  source_image_project = "cos-cloud"
  source_image = reverse(split("/", module.container.source_image))[0]
  metadata     = map(
    "gce-container-declaration", module.container.metadata_value,
    "google-logging-enabled", "true")
  labels = {
    "container-vm" = module.container.vm_container_label
  }
}

module "my_mig" {
  source            = "terraform-google-modules/vm/google//modules/mig"
  version           = "2.1.0"
  instance_template = module.my_mig_template.self_link
  region            = var.region
  target_size       = "1"
  hostname          = "myservice"
  named_ports = [
    {
      name = "http",
      port = var.image_port
    }
  ]
  network = var.network
}

resource "google_compute_backend_service" "my-service-service" {
  name                            = "my-service-service"
  port_name                       = "http"
  protocol                        = "HTTP"
  enable_cdn                      = true
  timeout_sec                     = 30
  connection_draining_timeout_sec = 35

  backend {
    group = module.my_mig.instance_group
  }

  log_config {
    enable = true
    sample_rate = 1
  }

  health_checks = [
    google_compute_health_check.my-service-http-health.self_link,
  ]
}

resource "google_compute_health_check" "my-service-http-health" {
  provider = google-beta
  name     = "my-service-http-health"

  check_interval_sec  = 5
  timeout_sec         = 5
  healthy_threshold   = 1
  unhealthy_threshold = 10

  http_health_check {
    port         = var.image_port
    request_path = "/healthz"
  }
}

@morgante
Copy link
Contributor

Instead of passing the health check in from outside the module, could you take the health check output and feed it to your backend service?

@daisy1754
Copy link
Author

I certainly can - I just prefer reusing existing one so I don't have to worry about potentially breaking something. Also google_compute_health_check looks nicer IMO because of #153

@morgante
Copy link
Contributor

Unfortunately I don't think we're likely to allow passing in an external health check as it would complicate the interface and we have a usable workaround.

#153 is definitely something we want fixed eventually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants