Skip to content

Commit

Permalink
use a new 'create_router' variable to trigger router creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ludoo committed Sep 28, 2019
1 parent 319cfba commit c4e5256
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ locals {
# locals for google_compute_router_nat
nat_ip_allocate_option = var.nat_ip_allocate_option ? var.nat_ip_allocate_option : local.default_nat_ip_allocate_option
name = var.name != "" ? var.name : local.default_name
router = var.router == "" ? google_compute_router.router[0].name : var.router
router = var.create_router ? google_compute_router.router[0].name : var.router
}

resource "google_compute_router" "router" {
count = var.router == "" ? 1 : 0
name = "${local.name}-router"
count = var.create_router ? 1 : 0
name = var.router
project = var.project_id
region = var.region
network = var.network
Expand Down
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ output "region" {

output "router_name" {
description = "Cloud NAT router name"
value = var.router
value = local.router
}

6 changes: 5 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ variable "network" {
default = ""
}

variable "create_router" {
description = "Create router instead of using an existing one, uses 'router' variable for new resource name."
default = false
}

variable "router" {
description = "The name of the router in which this NAT will be configured. Changing this forces a new NAT to be created."
default = ""
}

variable "router_asn" {
Expand Down

0 comments on commit c4e5256

Please sign in to comment.