diff --git a/gcn.tf b/gcn.tf index c435258..66251cc 100644 --- a/gcn.tf +++ b/gcn.tf @@ -1,11 +1,7 @@ -# Create a VPC network -data "google_compute_network" "gcn" { - count = var.shim ? 1 : 0 - name = var.network_name -} +# # Create a VPC network module "network" { - count = var.shim ? 0 : 1 + count = var.shim || var.shared_vpc ? 0 : 1 source = "terraform-google-modules/network/google" version = "7.3.0" description = "Truefoundry network for ${var.cluster_name}" @@ -79,13 +75,13 @@ module "network" { } resource "time_sleep" "wait_2_mins" { - count = var.shim ? 0 : 1 + count = var.shim || var.shared_vpc ? 0 : 1 depends_on = [module.network[0]] create_duration = "2m" } module "cloud_router" { - count = var.shim ? 0 : 1 + count = var.shim || var.shared_vpc ? 0 : 1 source = "terraform-google-modules/cloud-router/google" version = "6.0.1" description = "Truefoundry NAT router for ${var.cluster_name}" diff --git a/outputs.tf b/outputs.tf index 0528dd1..0c91fcb 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,11 +1,19 @@ output "network_name" { - value = var.shim ? var.network_name : module.network[0].network_name + value = var.shim || var.shared_vpc ? var.shared_vpc ? var.shared_vpc_network_name : var.network_name : module.network[0].network_name + description = "Name of the network" } output "network_id" { - value = var.shim ? data.google_compute_network.gcn[0].id : module.network[0].network_id + value = var.shim || var.shared_vpc ? var.shared_vpc ? "projects/${var.shared_vpc_host_project}/global/networks/${var.shared_vpc_network_name}" : "projects/${var.project_id}/global/networks/${var.network_name}" : module.network[0].network_id + description = "ID of the network" } output "subnet_id" { - value = var.shim ? var.subnet_id : module.network[0].subnets_ids[0] -} \ No newline at end of file + value = var.shim || var.shared_vpc ? var.shared_vpc ? "projects/${var.shared_vpc_host_project}/regions/${var.region}/subnetworks/${var.shared_vpc_subnet_name}" : var.subnet_id : module.network[0].subnets_ids[0] + description = "ID of the subnet" +} + +output "additional_secondary_ranges" { + value = var.shim || var.shared_vpc ? var.shared_vpc ? [] : [] : module.network[0].subnets_secondary_ranges + description = "Additional secondary ranges applied to the subnet" +} \ No newline at end of file diff --git a/variables.tf b/variables.tf index 256acb1..b4c7fc4 100644 --- a/variables.tf +++ b/variables.tf @@ -29,6 +29,12 @@ variable "shim" { default = false } +variable "shared_vpc" { + description = "If true, the shim network is a shared VPC" + type = bool + default = false +} + ################################################################################ # Network SHIM ################################################################################ @@ -41,6 +47,27 @@ variable "subnet_id" { type = string } +################################################################################ +# Shared VPC +################################################################################ + +variable "shared_vpc_host_project" { + description = "Shared VPC: Project ID of the host project" + type = string + default = "" +} + +variable "shared_vpc_network_name" { + description = "Shared VPC: Network name" + type = string + default = "" +} + +variable "shared_vpc_subnet_name" { + description = "Shared VPC: Subnet name" + type = string + default = "" +} ################################################################################ # Network NON-SHIM ################################################################################