diff --git a/README.md b/README.md
index 2dc3505..c06b7f5 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,6 @@ Truefoundry Google Cloud Network Module
| Name | Version |
|------|---------|
-| [google](#provider\_google) | 4.81.0 |
| [time](#provider\_time) | n/a |
## Modules
@@ -28,7 +27,6 @@ Truefoundry Google Cloud Network Module
| Name | Type |
|------|------|
| [time_sleep.wait_2_mins](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
-| [google_compute_network.gcn](https://registry.terraform.io/providers/hashicorp/google/4.81.0/docs/data-sources/compute_network) | data source |
## Inputs
@@ -43,6 +41,10 @@ Truefoundry Google Cloud Network Module
| [project\_id](#input\_project\_id) | Project ID in which clusters are deployed | `string` | n/a | yes |
| [region](#input\_region) | Region to deploy your cluster in | `string` | n/a | yes |
| [routing\_mode](#input\_routing\_mode) | Routing mode for the network | `string` | `"GLOBAL"` | no |
+| [shared\_vpc](#input\_shared\_vpc) | If true, the shim network is a shared VPC | `bool` | `false` | no |
+| [shared\_vpc\_host\_project](#input\_shared\_vpc\_host\_project) | Shared VPC: Project ID of the host project | `string` | `""` | no |
+| [shared\_vpc\_network\_name](#input\_shared\_vpc\_network\_name) | Shared VPC: Network name | `string` | `""` | no |
+| [shared\_vpc\_subnet\_name](#input\_shared\_vpc\_subnet\_name) | Shared VPC: Subnet name | `string` | `""` | no |
| [shim](#input\_shim) | If true will not create the network and forward the input values to the same outputs. | `bool` | `false` | no |
| [subnet\_id](#input\_subnet\_id) | SHIM: Subnetwork ID | `string` | n/a | yes |
@@ -50,7 +52,8 @@ Truefoundry Google Cloud Network Module
| Name | Description |
|------|-------------|
-| [network\_id](#output\_network\_id) | n/a |
-| [network\_name](#output\_network\_name) | n/a |
-| [subnet\_id](#output\_subnet\_id) | n/a |
+| [additional\_secondary\_ranges](#output\_additional\_secondary\_ranges) | Additional secondary ranges applied to the subnet |
+| [network\_id](#output\_network\_id) | ID of the network |
+| [network\_name](#output\_network\_name) | Name of the network |
+| [subnet\_id](#output\_subnet\_id) | ID of the subnet |
\ No newline at end of file
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
################################################################################