Skip to content

Commit

Permalink
removes lookup for existing routers
Browse files Browse the repository at this point in the history
  • Loading branch information
g-awmalik committed Oct 18, 2023
1 parent 9ee554f commit 4a8f590
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
12 changes: 2 additions & 10 deletions modules/vpn_ha/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
locals {
router = (
var.router_name == ""
? google_compute_router.router[0].name
? google_compute_router.router.name
: var.router_name
)
peer_external_gateway = (
Expand Down Expand Up @@ -61,16 +61,8 @@ resource "google_compute_external_vpn_gateway" "external_gateway" {
}
}

data "google_compute_router" "router" {
name = var.router_name == null ? "" : var.router_name
network = var.network
project = var.project_id
region = var.region
}

resource "google_compute_router" "router" {
provider = google-beta
count = data.google_compute_router.router.name == null ? 1 : 0
provider = google-beta
name = var.router_name != "" ? var.router_name : "vpn-${var.name}"
project = var.project_id
region = var.region
Expand Down
2 changes: 1 addition & 1 deletion modules/vpn_ha/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ output "name" {

output "router" {
description = "Router resource (only if auto-created)."
value = var.router_name == "" ? google_compute_router.router[0] : null
value = var.router_name == "" ? google_compute_router.router : null
}

output "router_name" {
Expand Down

0 comments on commit 4a8f590

Please sign in to comment.