terraform-google-modules/terraform-google-cloud-nat

Why does nat_ip_allocation_option exist? Bug?

agosto-calvinbehling opened this issue · 6 comments

It's a string that should be either "MANUAL_ONLY" or "AUTO_ONLY" but it is used as a boolean.
It seems to me that this might be a bug or that the variable is entirely unnecessary.

Error: Incorrect condition type

  on main.tf line 29, in locals:
  29:   nat_ip_allocate_option = var.nat_ip_allocate_option ? var.nat_ip_allocate_option : local.default_nat_ip_allocate_option
    |----------------
    | var.nat_ip_allocate_option is "AUTO_ONLY"

The condition expression must be of type bool.

https://github.com/terraform-google-modules/terraform-google-cloud-nat/blob/master/main.tf#L27-L29

locals {
  default_nat_ip_allocate_option = local.nat_ips_length > 0 ? "MANUAL_ONLY" : "AUTO_ONLY"
  nat_ip_allocate_option = var.nat_ip_allocate_option ? var.nat_ip_allocate_option : local.default_nat_ip_allocate_option
}

agree and the condition doesn't make sense at all

if someone were to use the value
nat_ip_allocate_option =true

the condition breaks
nat_ip_allocate_option = var.nat_ip_allocate_option ? var.nat_ip_allocate_option : local.default_nat_ip_allocate_option

would render to
nat_ip_allocate_option = true instead of nat_ip_allocate_option=MANUAL_ONLY

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

Got the same:
When
nat_ip_allocate_option = "AUTO_ONLY"
getting

│ Error: Incorrect condition type
│ 
│   on .terraform/modules/cloud-nat/main.tf line 29, in locals:
│   29:   nat_ip_allocate_option = var.nat_ip_allocate_option ? var.nat_ip_allocate_option : local.default_nat_ip_allocate_option
│     ├────────────────
│     │ var.nat_ip_allocate_option is "AUTO_ONLY"
│ 
│ The condition expression must be of type bool.

and when setting it to
nat_ip_allocate_option = true
getting

│ Error: expected nat_ip_allocate_option to be one of [MANUAL_ONLY AUTO_ONLY], got true
│ 
│   with module.cloud-nat.google_compute_router_nat.main,
│   on .terraform/modules/cloud-nat/main.tf line 51, in resource "google_compute_router_nat" "main":
│   51:   nat_ip_allocate_option              = local.nat_ip_allocate_option

Either this parameter is not needed, or should be fixed. :)

Was this bug already fixed?

I doubt that.

Works for me, when


module "cloud-nat" {
    source                             = "terraform-google-modules/cloud-nat/google"
    project_id                         = var.projectId
    region                             = var.regionLong
    network                            = "vpc-0"
    create_router                      = true
    router                             = "nat-router-0"
    name                               = "nat-gateway-0"
    nat_ips                            = google_compute_address.address.*.self_link
}

Indeed, without nat_ip_allocate_option works.