Skip to content

Commit

Permalink
gcve network peering module
Browse files Browse the repository at this point in the history
  • Loading branch information
umeshkumhar committed Jan 8, 2024
1 parent 005da39 commit 2b883d1
Show file tree
Hide file tree
Showing 10 changed files with 521 additions and 0 deletions.
39 changes: 39 additions & 0 deletions examples/gcve-network-peering/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module "gcve_network_peering" {
source = "../../modules/gcve-network-peering"
project_id = var.project_id

gcve_peer_name = var.gcve_peer_name
gcve_peer_description = var.gcve_peer_description
peer_network_type = var.peer_network_type

# vmware network
nw_name = var.nw_name
nw_location = var.nw_location
nw_project_id = var.nw_project_id

# peer network configs
peer_nw_name = var.peer_nw_name
peer_nw_location = var.peer_nw_location
peer_nw_project_id = var.peer_nw_project_id

peer_export_custom_routes = var.peer_export_custom_routes
peer_import_custom_routes = var.peer_import_custom_routes
peer_export_custom_routes_with_public_ip = var.peer_export_custom_routes_with_public_ip
peer_import_custom_routes_with_public_ip = var.peer_import_custom_routes_with_public_ip
}
26 changes: 26 additions & 0 deletions examples/gcve-network-peering/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
output "id" {
value = module.gcve_network_peering.id
}

output "state" {
value = module.gcve_network_peering.state
}

output "peering" {
value = module.gcve_network_peering.peering
}
34 changes: 34 additions & 0 deletions examples/gcve-network-peering/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

project_id = "umeshkumhar"
gcve_peer_name = "sample-network-peering"
gcve_peer_description = "Sample description"
peer_network_type = "STANDARD"

nw_name = "pc1-network"
nw_location = "global"
nw_project_id = "umeshkumhar"

peer_nw_name = "demo-network"
peer_nw_location = "global"
peer_nw_project_id = "another-gcp-project"


peer_export_custom_routes = true
peer_import_custom_routes = true
peer_export_custom_routes_with_public_ip = false
peer_import_custom_routes_with_public_ip = false
96 changes: 96 additions & 0 deletions examples/gcve-network-peering/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

variable "project_id" {
type = string
description = "The ID of the project in which the resource belongs"
}

variable "peer_network_type" {
type = string
description = "The type of the network to peer with the VMware Engine network. Possible values are: STANDARD, VMWARE_ENGINE_NETWORK, PRIVATE_SERVICES_ACCESS, NETAPP_CLOUD_VOLUMES, THIRD_PARTY_SERVICE, DELL_POWERSCALE."

validation {
condition = contains(["STANDARD", "VMWARE_ENGINE_NETWORK", "PRIVATE_SERVICES_ACCESS", "NETAPP_CLOUD_VOLUMES", "THIRD_PARTY_SERVICE", "DELL_POWERSCALE"], var.peer_network_type)
error_message = "Valid values for var: peer_network_type are (STANDARD, VMWARE_ENGINE_NETWORK, PRIVATE_SERVICES_ACCESS, NETAPP_CLOUD_VOLUMES, THIRD_PARTY_SERVICE, DELL_POWERSCALE)."
}
}

variable "nw_name" {
type = string
description = "The relative resource name of the VMware Engine network"
}

variable "nw_location" {
type = string
description = "The relative resource location of the VMware Engine network"
}

variable "nw_project_id" {
type = string
default = "The relative resource project of the VMware Engine network"
}

variable "peer_nw_name" {
type = string
description = " The relative resource name of the network to peer with a standard VMware Engine network. The provided network can be a consumer VPC network or another standard VMware Engine network."
}

variable "peer_nw_location" {
type = string
default = "global"
description = " The relative resource location of the network to peer with a standard VMware Engine network. The provided network can be a consumer VPC network or another standard VMware Engine network."
}

variable "peer_nw_project_id" {
type = string
description = " The relative resource project of the network to peer with a standard VMware Engine network. The provided network can be a consumer VPC network or another standard VMware Engine network."
}

variable "gcve_peer_name" {
type = string
description = "The ID of the Network Peering."
}

variable "gcve_peer_description" {
type = string
default = ""
description = " User-provided description for this network peering."
}

variable "peer_export_custom_routes" {
type = bool
default = true
description = "True if custom routes are exported to the peered network; false otherwise."
}

variable "peer_import_custom_routes" {
type = bool
default = true
description = "True if custom routes are imported from the peered network; false otherwise."
}

variable "peer_export_custom_routes_with_public_ip" {
type = bool
default = false
description = "True if all subnet routes with a public IP address range are exported; false otherwise"
}

variable "peer_import_custom_routes_with_public_ip" {
type = bool
default = false
description = "True if custom routes are imported from the peered network; false otherwise."
}
27 changes: 27 additions & 0 deletions examples/gcve-network-peering/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

terraform {
required_version = ">= 1.3.0"

required_providers {
google = {
source = "hashicorp/google-beta"
version = ">= 4.71.0"
}
}
}

76 changes: 76 additions & 0 deletions modules/gcve-network-peering/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# GCVE ESXi Cluster module

This module contains the terraform to deploy an ESXi cluster into a private cloud

<!-- BEGIN_AUTOMATED_TF_DOCS_BLOCK -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
| <a name="requirement_google-beta"></a> [google-beta](#requirement\_google-beta) | >= 4.71.0 |

## Usage
Basic usage of this module is as follows:

```hcl
module "example" {
source = "<module-path>"
# Required variables
gcve_peer_name =
nw_location =
nw_name =
peer_network_type =
peer_nw_name =
peer_nw_project_id =
project_id =
# Optional variables
gcve_peer_description = ""
nw_project_id = "The relative resource project of the VMware Engine network"
peer_export_custom_routes = true
peer_export_custom_routes_with_public_ip = false
peer_import_custom_routes = true
peer_import_custom_routes_with_public_ip = false
peer_nw_location = "global"
}
```

## Resources

| Name | Type |
|------|------|
| [google_vmwareengine_network_peering.peering](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/vmwareengine_network_peering) | resource |
| [google_compute_network.network-peering-peer-nw](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/compute_network) | data source |
| [google_vmwareengine_network.network-peering-nw](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/vmwareengine_network) | data source |
| [google_vmwareengine_network.network-peering-peer-nw](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/vmwareengine_network) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_gcve_peer_description"></a> [gcve\_peer\_description](#input\_gcve\_peer\_description) | User-provided description for this network peering. | `string` | `""` | no |
| <a name="input_gcve_peer_name"></a> [gcve\_peer\_name](#input\_gcve\_peer\_name) | The ID of the Network Peering. | `string` | n/a | yes |
| <a name="input_nw_location"></a> [nw\_location](#input\_nw\_location) | The relative resource location of the VMware Engine network | `string` | n/a | yes |
| <a name="input_nw_name"></a> [nw\_name](#input\_nw\_name) | The relative resource name of the VMware Engine network | `string` | n/a | yes |
| <a name="input_nw_project_id"></a> [nw\_project\_id](#input\_nw\_project\_id) | n/a | `string` | `"The relative resource project of the VMware Engine network"` | no |
| <a name="input_peer_export_custom_routes"></a> [peer\_export\_custom\_routes](#input\_peer\_export\_custom\_routes) | True if custom routes are exported to the peered network; false otherwise. | `bool` | `true` | no |
| <a name="input_peer_export_custom_routes_with_public_ip"></a> [peer\_export\_custom\_routes\_with\_public\_ip](#input\_peer\_export\_custom\_routes\_with\_public\_ip) | True if all subnet routes with a public IP address range are exported; false otherwise | `bool` | `false` | no |
| <a name="input_peer_import_custom_routes"></a> [peer\_import\_custom\_routes](#input\_peer\_import\_custom\_routes) | True if custom routes are imported from the peered network; false otherwise. | `bool` | `true` | no |
| <a name="input_peer_import_custom_routes_with_public_ip"></a> [peer\_import\_custom\_routes\_with\_public\_ip](#input\_peer\_import\_custom\_routes\_with\_public\_ip) | True if custom routes are imported from the peered network; false otherwise. | `bool` | `false` | no |
| <a name="input_peer_network_type"></a> [peer\_network\_type](#input\_peer\_network\_type) | The type of the network to peer with the VMware Engine network. Possible values are: STANDARD, VMWARE\_ENGINE\_NETWORK, PRIVATE\_SERVICES\_ACCESS, NETAPP\_CLOUD\_VOLUMES, THIRD\_PARTY\_SERVICE, DELL\_POWERSCALE. | `string` | n/a | yes |
| <a name="input_peer_nw_location"></a> [peer\_nw\_location](#input\_peer\_nw\_location) | The relative resource location of the network to peer with a standard VMware Engine network. The provided network can be a consumer VPC network or another standard VMware Engine network. | `string` | `"global"` | no |
| <a name="input_peer_nw_name"></a> [peer\_nw\_name](#input\_peer\_nw\_name) | The relative resource name of the network to peer with a standard VMware Engine network. The provided network can be a consumer VPC network or another standard VMware Engine network. | `string` | n/a | yes |
| <a name="input_peer_nw_project_id"></a> [peer\_nw\_project\_id](#input\_peer\_nw\_project\_id) | The relative resource project of the network to peer with a standard VMware Engine network. The provided network can be a consumer VPC network or another standard VMware Engine network. | `string` | n/a | yes |
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | he ID of the project in which the resource belongs | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_id"></a> [id](#output\_id) | n/a |
| <a name="output_peering"></a> [peering](#output\_peering) | n/a |
| <a name="output_state"></a> [state](#output\_state) | n/a |

<!-- END_AUTOMATED_TF_DOCS_BLOCK -->
73 changes: 73 additions & 0 deletions modules/gcve-network-peering/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


data "google_vmwareengine_network" "network-peering-nw" {
name = var.nw_name
location = var.nw_location
project = var.nw_project_id
}

data "google_compute_network" "network-peering-peer-nw" {
count = var.peer_network_type == "STANDARD" ? 1 : 0
name = var.peer_nw_name
project = var.peer_nw_project_id
}

data "google_vmwareengine_network" "network-peering-peer-nw" {
count = var.peer_network_type == "VMWARE_ENGINE_NETWORK" ? 1 : 0
name = var.peer_nw_name
location = var.peer_nw_location
project = var.peer_nw_project_id
}

locals {
peer_network = (

var.peer_network_type == "VMWARE_ENGINE_NETWORK" ?
data.google_vmwareengine_network.network-peering-peer-nw[0].id :

var.peer_network_type == "STANDARD" ?
data.google_compute_network.network-peering-peer-nw[0].id :

var.peer_network_type == "PRIVATE_SERVICES_ACCESS" ?
"projects/${var.peer_nw_project_id}/global/networks/${var.peer_nw_name}" :

var.peer_network_type == "NETAPP_CLOUD_VOLUMES" ?
"projects/${var.peer_nw_project_id}/global/networks/netapp-tenant-vpc" :

var.peer_network_type == "THIRD_PARTY_SERVICE" ?
"projects/${var.peer_nw_project_id}/global/networks/${var.peer_nw_name}" :

var.peer_network_type == "DELL_POWERSCALE" ?
"projects/${var.peer_nw_project_id}/global/networks/dellemc-tenant-vpc" :

"Error: wrong peer network type"
)
}

resource "google_vmwareengine_network_peering" "peering" {
name = var.gcve_peer_name
description = var.gcve_peer_description
project = var.project_id
vmware_engine_network = data.google_vmwareengine_network.network-peering-nw.id
peer_network = local.peer_network
peer_network_type = var.peer_network_type
export_custom_routes = var.peer_export_custom_routes
import_custom_routes = var.peer_import_custom_routes
export_custom_routes_with_public_ip = var.peer_export_custom_routes_with_public_ip
import_custom_routes_with_public_ip = var.peer_import_custom_routes_with_public_ip
}
Loading

0 comments on commit 2b883d1

Please sign in to comment.