Skip to content

Commit

Permalink
Merge pull request #4 from truefoundry/shared-vpc
Browse files Browse the repository at this point in the history
Added support for shared VPC
  • Loading branch information
dunefro authored Mar 19, 2024
2 parents 3cbfaf7 + 3058cca commit 18cde7d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 17 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Truefoundry Google Cloud Network Module

| Name | Version |
|------|---------|
| <a name="provider_google"></a> [google](#provider\_google) | 4.81.0 |
| <a name="provider_time"></a> [time](#provider\_time) | n/a |

## Modules
Expand All @@ -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

Expand All @@ -43,14 +41,19 @@ Truefoundry Google Cloud Network Module
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | Project ID in which clusters are deployed | `string` | n/a | yes |
| <a name="input_region"></a> [region](#input\_region) | Region to deploy your cluster in | `string` | n/a | yes |
| <a name="input_routing_mode"></a> [routing\_mode](#input\_routing\_mode) | Routing mode for the network | `string` | `"GLOBAL"` | no |
| <a name="input_shared_vpc"></a> [shared\_vpc](#input\_shared\_vpc) | If true, the shim network is a shared VPC | `bool` | `false` | no |
| <a name="input_shared_vpc_host_project"></a> [shared\_vpc\_host\_project](#input\_shared\_vpc\_host\_project) | Shared VPC: Project ID of the host project | `string` | `""` | no |
| <a name="input_shared_vpc_network_name"></a> [shared\_vpc\_network\_name](#input\_shared\_vpc\_network\_name) | Shared VPC: Network name | `string` | `""` | no |
| <a name="input_shared_vpc_subnet_name"></a> [shared\_vpc\_subnet\_name](#input\_shared\_vpc\_subnet\_name) | Shared VPC: Subnet name | `string` | `""` | no |
| <a name="input_shim"></a> [shim](#input\_shim) | If true will not create the network and forward the input values to the same outputs. | `bool` | `false` | no |
| <a name="input_subnet_id"></a> [subnet\_id](#input\_subnet\_id) | SHIM: Subnetwork ID | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_network_id"></a> [network\_id](#output\_network\_id) | n/a |
| <a name="output_network_name"></a> [network\_name](#output\_network\_name) | n/a |
| <a name="output_subnet_id"></a> [subnet\_id](#output\_subnet\_id) | n/a |
| <a name="output_additional_secondary_ranges"></a> [additional\_secondary\_ranges](#output\_additional\_secondary\_ranges) | Additional secondary ranges applied to the subnet |
| <a name="output_network_id"></a> [network\_id](#output\_network\_id) | ID of the network |
| <a name="output_network_name"></a> [network\_name](#output\_network\_name) | Name of the network |
| <a name="output_subnet_id"></a> [subnet\_id](#output\_subnet\_id) | ID of the subnet |
<!-- END_TF_DOCS -->
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" {
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 18cde7d

Please sign in to comment.