diff --git a/modules/net-vpc/README.md b/modules/net-vpc/README.md index ab7c3cc2..83d69238 100644 --- a/modules/net-vpc/README.md +++ b/modules/net-vpc/README.md @@ -482,7 +482,7 @@ module "vpc" { | [name](variables.tf#L83) | The name of the network being created. | string | ✓ | | | [project_id](variables.tf#L99) | The ID of the project where this VPC will be created. | string | ✓ | | | [auto_create_subnetworks](variables.tf#L17) | Set to true to create an auto mode subnet, defaults to custom mode. | bool | | false | -| [create_googleapis_routes](variables.tf#L23) | Toggle creation of googleapis private/restricted routes. Set to null to disable creation. | object({…}) | | {} | +| [create_googleapis_routes](variables.tf#L23) | Toggle creation of googleapis private/restricted routes. Disabled when vpc creation is turned off, or when set to null. | object({…}) | | {} | | [data_folder](variables.tf#L34) | An optional folder containing the subnet configurations in YaML format. | string | | null | | [delete_default_routes_on_create](variables.tf#L40) | Set to true to delete the default routes at creation time. | bool | | false | | [description](variables.tf#L46) | An optional description of this resource (triggers recreation on change). | string | | "Terraform-managed." | diff --git a/modules/net-vpc/routes.tf b/modules/net-vpc/routes.tf index 7280f904..8b7ae7ae 100644 --- a/modules/net-vpc/routes.tf +++ b/modules/net-vpc/routes.tf @@ -31,7 +31,10 @@ locals { priority = 1000 tags = null } - if lookup(coalesce(var.create_googleapis_routes, {}), k, false) + if( + var.vpc_create && + lookup(coalesce(var.create_googleapis_routes, {}), k, false) + ) } _routes = merge(local._googleapis_routes, coalesce(var.routes, {})) routes = { diff --git a/modules/net-vpc/variables.tf b/modules/net-vpc/variables.tf index b20e54fe..40a8bb2c 100644 --- a/modules/net-vpc/variables.tf +++ b/modules/net-vpc/variables.tf @@ -21,7 +21,7 @@ variable "auto_create_subnetworks" { } variable "create_googleapis_routes" { - description = "Toggle creation of googleapis private/restricted routes. Set to null to disable creation." + description = "Toggle creation of googleapis private/restricted routes. Disabled when vpc creation is turned off, or when set to null." type = object({ private = optional(bool, true) private-6 = optional(bool, false)