Add Network Endpoint Group module (#91)
* Add Network Endpoint Group module * Update CHANGELOG * Move neg to experimental * Revert "Update CHANGELOG" This reverts commit 9282932f88655089e642a9e9954504f19528621e. * Revert README changes
This commit is contained in:
parent
62836cb7a4
commit
2e597e2c58
|
@ -0,0 +1,46 @@
|
||||||
|
# Network Endpoint Group Module
|
||||||
|
|
||||||
|
This modules allows creating zonal network endpoint groups.
|
||||||
|
|
||||||
|
Note: this module will integrated into a general-purpose load balancing module in the future.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
```hcl
|
||||||
|
module "neg" {
|
||||||
|
source = "./modules/net-neg"
|
||||||
|
project_id = "myproject"
|
||||||
|
name = "myneg"
|
||||||
|
network = module.vpc.self_link
|
||||||
|
subnetwork = module.vpc.subnet_self_links["europe-west1/default"]
|
||||||
|
zone = "europe-west1-b"
|
||||||
|
endpoints = [
|
||||||
|
for instance in module.vm.instances :
|
||||||
|
{
|
||||||
|
instance = instance.name
|
||||||
|
port = 80
|
||||||
|
ip_address = instance.network_interface[0].network_ip
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
<!-- BEGIN TFDOC -->
|
||||||
|
## Variables
|
||||||
|
|
||||||
|
| name | description | type | required | default |
|
||||||
|
|---|---|:---: |:---:|:---:|
|
||||||
|
| endpoints | List of (instance, port, address) of the NEG | <code title="list(object({ instance = string port = number ip_address = string }))">list(object({...}))</code> | ✓ | |
|
||||||
|
| name | NEG name | <code title="">string</code> | ✓ | |
|
||||||
|
| network | Name or self link of the VPC used for the NEG. Use the self link for Shared VPC. | <code title="">string</code> | ✓ | |
|
||||||
|
| project_id | NEG project id. | <code title="">string</code> | ✓ | |
|
||||||
|
| subnetwork | VPC subnetwork name or self link. | <code title="">string</code> | ✓ | |
|
||||||
|
| zone | NEG zone | <code title="">string</code> | ✓ | |
|
||||||
|
|
||||||
|
## Outputs
|
||||||
|
|
||||||
|
| name | description | sensitive |
|
||||||
|
|---|---|:---:|
|
||||||
|
| id | Network endpoint group ID | |
|
||||||
|
| self_lnk | Network endpoint group self link | |
|
||||||
|
| size | Size of the network endpoint group | |
|
||||||
|
<!-- END TFDOC -->
|
|
@ -0,0 +1,33 @@
|
||||||
|
/**
|
||||||
|
* Copyright 2020 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
resource "google_compute_network_endpoint_group" "group" {
|
||||||
|
project = var.project_id
|
||||||
|
name = var.name
|
||||||
|
network = var.network
|
||||||
|
subnetwork = var.subnetwork
|
||||||
|
zone = var.zone
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_compute_network_endpoint" "endpoint" {
|
||||||
|
for_each = { for endpoint in var.endpoints : endpoint.instance => endpoint }
|
||||||
|
project = var.project_id
|
||||||
|
network_endpoint_group = google_compute_network_endpoint_group.group.name
|
||||||
|
instance = each.value.instance
|
||||||
|
port = each.value.port
|
||||||
|
ip_address = each.value.ip_address
|
||||||
|
zone = var.zone
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
/**
|
||||||
|
* Copyright 2020 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" {
|
||||||
|
description = "Network endpoint group ID"
|
||||||
|
value = google_compute_network_endpoint_group.group.name
|
||||||
|
}
|
||||||
|
|
||||||
|
output "size" {
|
||||||
|
description = "Size of the network endpoint group"
|
||||||
|
value = google_compute_network_endpoint_group.group.size
|
||||||
|
}
|
||||||
|
|
||||||
|
output "self_lnk" {
|
||||||
|
description = "Network endpoint group self link"
|
||||||
|
value = google_compute_network_endpoint_group.group.self_link
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
/**
|
||||||
|
* Copyright 2020 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" {
|
||||||
|
description = "NEG project id."
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "name" {
|
||||||
|
description = "NEG name"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "network" {
|
||||||
|
description = "Name or self link of the VPC used for the NEG. Use the self link for Shared VPC."
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "subnetwork" {
|
||||||
|
description = "VPC subnetwork name or self link."
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "zone" {
|
||||||
|
description = "NEG zone"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "endpoints" {
|
||||||
|
description = "List of (instance, port, address) of the NEG"
|
||||||
|
type = list(object({
|
||||||
|
instance = string
|
||||||
|
port = number
|
||||||
|
ip_address = string
|
||||||
|
}))
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
/**
|
||||||
|
* Copyright 2020 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 = ">= 0.12.6"
|
||||||
|
}
|
Loading…
Reference in New Issue