terraform-google-modules / terraform-google-cloud-router

Manages a Cloud Router on Google Cloud
https://registry.terraform.io/modules/terraform-google-modules/cloud-router/google
Apache License 2.0
48 stars 51 forks source link

Module won't add "advertised_ip_ranges" #40

Closed tightly-clutched closed 2 years ago

tightly-clutched commented 2 years ago

TL;DR

When I try to insert advertised_ip_ranges in the module, terraform plan fails with Error: Unsupported attribute

I need some guidance on using this attribute correctly.

Expected behavior

I expect the advertised_ip_ranges to be added to the cloud_router definition

Observed behavior

Output of terraform plan

Error: Unsupported attribute

on .terraform/modules/cloud_router-ue4/main.tf line 37, in resource "google_compute_router" "router": 37: range = advertised_ip_ranges.value.range |---------------- | advertised_ip_ranges.value is "aws subnets"

This value does not have any attributes.

Error: Unsupported attribute

on .terraform/modules/cloud_router-ue4/main.tf line 37, in resource "google_compute_router" "router": 37: range = advertised_ip_ranges.value.range |---------------- | advertised_ip_ranges.value is "10.0.0.0/16"

This value does not have any attributes.

Error: Invalid function argument

on .terraform/modules/cloud_router-ue4/main.tf line 38, in resource "google_compute_router" "router": 38: description = lookup(advertised_ip_ranges.value, "description", null) |---------------- | advertised_ip_ranges.value is "aws subnets"

Invalid value for "inputMap" parameter: lookup() requires a map as the first argument.

Error: Invalid function argument

on .terraform/modules/cloud_router-ue4/main.tf line 38, in resource "google_compute_router" "router": 38: description = lookup(advertised_ip_ranges.value, "description", null) |---------------- | advertised_ip_ranges.value is "10.0.0.0/16"

Invalid value for "inputMap" parameter: lookup() requires a map as the first argument.

Terraform Configuration

module "cloud_router-ue4" {
  source  = "terraform-google-modules/cloud-router/google"
  version = "0.3.0"

  name    = "stage-router-ue4"
  project = var.project_id
  region  = var.region3
  network = module.vpc.network_name
  bgp = {
      asn               = 65000
      advertise_mode    = "CUSTOM"
      advertised_groups = ["ALL_SUBNETS"]
      advertised_ip_ranges = {
        description = "aws subnets"
        range       = "10.0.0.0/16"
      }
  }
  nats = [{
    name                               = "stage-gateway-ue4"
    nat_ip_allocate_option             = "AUTO_ONLY"
    source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
    min_ports_per_vm  = 512
    subnetworks = [{
        name                    = "stage-private-us-east4"
        source_ip_ranges_to_nat = ["ALL_IP_RANGES"]
      },
      {
        name                    = "stage-private-us-east4-1"
        source_ip_ranges_to_nat = ["ALL_IP_RANGES"]
      },
      {
        name                    = "stage-private-us-east4-2"
        source_ip_ranges_to_nat = ["ALL_IP_RANGES"]
      },
      {
        name                    = "stage-private-us-east4-3"
        source_ip_ranges_to_nat = ["ALL_IP_RANGES"]
      },
      {
        name                    = "stage-private-us-east1-7"
        source_ip_ranges_to_nat = ["ALL_IP_RANGES"]
      },
      {
        name                    = "stage-private-us-east1-8"
        source_ip_ranges_to_nat = ["ALL_IP_RANGES"]
      },
    ]
  }]
}

Terraform Version

mike.james@mjames2 stage % terraform version
Terraform v0.13.5
+ provider registry.terraform.io/hashicorp/google v3.46.0

Additional information

No response

kaariger commented 2 years ago

@tightly-clutched the error is due to how the advertised_ip_ranges is constructed. The module expects this to be a list. However, the example creates this as a single map. You can convert this into a list as follows:

- advertised_ip_ranges = {
+ advertised_ip_ranges = [{
        description = "aws subnets"
        range       = "10.0.0.0/16"
-     }
+      }]
       description = "aws subnets"
        range       = "10.0.0.0/16"

This should resolve the error.

tightly-clutched commented 2 years ago

@kaariger That worked perfectly! Thanks for your help. I'll be using that construction in future, I'm sure.