Skip to content

Commit

Permalink
Added support for shared VPC
Browse files Browse the repository at this point in the history
  • Loading branch information
dunefro committed Mar 19, 2024
1 parent 3cbfaf7 commit 23260df
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
12 changes: 4 additions & 8 deletions gcn.tf
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down Expand Up @@ -79,13 +75,13 @@ module "network" {
}

resource "time_sleep" "wait_2_mins" {

Check warning on line 77 in gcn.tf

View workflow job for this annotation

GitHub Actions / tflint (ubuntu-latest)

Missing version constraint for provider "time" in `required_providers`

Check warning on line 77 in gcn.tf

View workflow job for this annotation

GitHub Actions / tflint (macos-latest)

Missing version constraint for provider "time" in `required_providers`

Check warning on line 77 in gcn.tf

View workflow job for this annotation

GitHub Actions / tflint (windows-latest)

Missing version constraint for provider "time" in `required_providers`
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}"
Expand Down
16 changes: 12 additions & 4 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -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]
}
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"
}
27 changes: 27 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
################################################################################
Expand All @@ -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
################################################################################
Expand Down

0 comments on commit 23260df

Please sign in to comment.