Terraform Defaults and Local

From Federal Burro of Information
Revision as of 16:06, 28 February 2023 by David (talk | contribs) (Created page with " Now you tfvars file can have only defaults for larger groups of vars. <pre> variable "liveness_default" { type = map default = { health_threshold = 1 interval = 5 logging = true path = "/health" timeout = 1 unhealth_threshold = 2 } } variable "liveness" { type = map default = {} } locals { liveness = merge(var.liveness_default, var.liveness) } resource google_liveness_thing...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Now you tfvars file can have only defaults for larger groups of vars.

variable "liveness_default" {
  type = map
  default = {
    health_threshold   = 1
    interval           = 5
    logging            = true
    path               = "/health"
    timeout            = 1
    unhealth_threshold = 2
  }
}

variable "liveness" {
  type    = map
  default = {}
}

locals {
  liveness    = merge(var.liveness_default,     var.liveness)
}

resource google_liveness_thingy "mylivenessthingy" {
    name               = "${var.name}-liveness-probe"
    health_threshold   = local.liveness["health_threshold"]
    interval           = local.liveness["interval"]
    logging            = local.liveness["logging"]
    path               = local.liveness["path"]
    timeout            = local.liveness["timeout"]
    unhealth_threshold = local.liveness["unhealth_threshold"]
}