terraform-google-vm icon indicating copy to clipboard operation
terraform-google-vm copied to clipboard

FR: make fields of health_check optional

Open daisy1754 opened this issue 4 years ago • 1 comments
trafficstars

Currently all fields of mig.healthcheck is mandatory so one has to write a config below:

module "mig" {
  source                  = "terraform-google-modules/vm/google//modules/mig"
  version                 = "1.3.0"
  ...
  health_check = {
    type                = "http"
    initial_delay_sec   = 30
    check_interval_sec  = 5
    timeout_sec         = 5
    healthy_threshold   = 1
    unhealthy_threshold = 5
    response            = ""
    proxy_header        = "NONE"
    port                = 80
    request             = ""
    request_path        = "/"
    host                = ""
  }
}

It's quite verbose compared to plain google_compute_health_check which will be like

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

  initial_delay_sec   = 30
  check_interval_sec  = 5
  timeout_sec         = 5
  healthy_threshold   = 1
  unhealthy_threshold = 5

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

It would be great if modules/mig can set sane default and make params optional

daisy1754 avatar Mar 11 '21 19:03 daisy1754

I agree this is annoying currently, but unfortunately there isn't an easy solution with Terraform Core currently.

Terraform is working on adding optional attribute support for objects: https://www.terraform.io/docs/language/expressions/type-constraints.html#experimental-optional-object-type-attributes

Once that is non-experimental we should definitely add it to this module.

morgante avatar Mar 11 '21 19:03 morgante