Skip to content

Commit

Permalink
feat: allow GCP cloud router to be created in the same plan/apply as …
Browse files Browse the repository at this point in the history
…the Fabric connection
  • Loading branch information
ctreatma committed Apr 3, 2024
1 parent 2bb51b5 commit bf106da
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
17 changes: 3 additions & 14 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
locals {
gcp_compute_router_name = coalesce(var.gcp_compute_router_name, lower(format("router-%s", random_string.this.result)))
gcp_compute_router_id = var.gcp_compute_create_router ? google_compute_router.this[0].id : data.google_compute_router.this[0].id
gcp_compute_router_name = lower(format("router-%s", random_string.this.result))
gcp_compute_router_id = var.gcp_compute_create_router ? google_compute_router.this[0].id : var.gcp_compute_router_id
gcp_region = coalesce(var.gcp_region, data.google_client_config.this.region)
gcp_project = coalesce(var.gcp_project, data.google_client_config.this.project)
gcp_network = data.google_compute_network.this.id
gcp_network = var.gcp_compute_network_id
gcp_bgp_addresses = try(jsondecode(data.local_file.this[0].content), null)
gcp_bgp_addresses_file_path = "${path.module}/gcp_peering_addresses.json"
}

data "google_client_config" "this" {}

data "google_compute_network" "this" {
name = var.gcp_compute_network_name
}

data "google_compute_router" "this" {
count = var.gcp_compute_create_router ? 0 : 1

name = local.gcp_compute_router_name
network = local.gcp_network
}

resource "google_compute_router" "this" {
count = var.gcp_compute_create_router ? 1 : 0

Expand Down
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ output "gcp_cloud_router_id" {

output "gcp_cloud_router_name" {
description = "Google Cloud Router Name."
value = var.gcp_compute_create_router ? google_compute_router.this[0].name : data.google_compute_router.this[0].name
value = var.gcp_compute_create_router ? google_compute_router.this[0].name : ""
}

output "gcp_cloud_router_ip_address" {
Expand Down
10 changes: 5 additions & 5 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ variable "gcp_project" {
default = ""
}

variable "gcp_compute_network_name" {
variable "gcp_compute_network_id" {
type = string
description = "The name of an existing Google Cloud VPC network. If unspecified, default regional network will be used."
default = "default"
description = "The ID of an existing Google Cloud VPC network. If unspecified, default regional network will be used."
default = ""
}

variable "gcp_compute_create_router" {
Expand All @@ -152,9 +152,9 @@ variable "gcp_compute_create_router" {
default = true
}

variable "gcp_compute_router_name" {
variable "gcp_compute_router_id" {
type = string
description = "The name for Google Cloud router. If unspecified, it will be auto-generated. Required if 'gcp_compute_create_router' is false."
description = "The ID for Google Cloud router. If unspecified, it will be auto-generated. Required if 'gcp_compute_create_router' is false."
default = ""
}

Expand Down

0 comments on commit bf106da

Please sign in to comment.