Allow specifying subnet name in net-vpc module (#64)

* add name attribute to net-vpc subnet variable

* update vpc variables in infra examples

* fix old project output used in shared vpc infra example
This commit is contained in:
Ludovico Magnocavallo
2020-04-30 19:29:39 +02:00
committed by GitHub
parent bf137148b3
commit 98f6b30197
12 changed files with 28 additions and 10 deletions

View File

@@ -16,6 +16,7 @@ module "vpc" {
subnets = {
subnet-1 = {
ip_cidr_range = "10.0.0.0/24"
name = "production"
region = "europe-west1"
secondary_ip_range = {
pods = "172.16.0.0/20"
@@ -24,7 +25,8 @@ module "vpc" {
}
subnet-2 = {
ip_cidr_range = "10.0.16.0/24"
region = "europe-west1"
name = "production"
region = "europe-west2"
secondary_ip_range = {}
}
}
@@ -43,6 +45,7 @@ module "vpc-spoke-1" {
subnets = {
subnet-1 = {
ip_cidr_range = "10.0.0.0/24"
name = null
region = "europe-west1"
secondary_ip_range = {
pods = "172.16.0.0/20"
@@ -68,6 +71,7 @@ module "vpc-host" {
subnets = {
subnet-1 = {
ip_cidr_range = "10.0.0.0/24"
name = null
region = "europe-west1"
secondary_ip_range = {
pods = "172.16.0.0/20"
@@ -121,7 +125,7 @@ module "vpc-host" {
| *subnet_descriptions* | Optional map of subnet descriptions, keyed by subnet name. | <code title="map&#40;string&#41;">map(string)</code> | | <code title="">{}</code> |
| *subnet_flow_logs* | Optional map of boolean to control flow logs (default is disabled), keyed by subnet name. | <code title="map&#40;bool&#41;">map(bool)</code> | | <code title="">{}</code> |
| *subnet_private_access* | Optional map of boolean to control private Google access (default is enabled), keyed by subnet name. | <code title="map&#40;bool&#41;">map(bool)</code> | | <code title="">{}</code> |
| *subnets* | The list of subnets being created | <code title="map&#40;object&#40;&#123;&#10;ip_cidr_range &#61; string&#10;region &#61; string&#10;secondary_ip_range &#61; map&#40;string&#41;&#10;&#125;&#41;&#41;">map(object({...}))</code> | | <code title="">null</code> |
| *subnets* | Subnets being created. If name is set to null, a default will be used combining network name and this map key. | <code title="map&#40;object&#40;&#123;&#10;ip_cidr_range &#61; string&#10;name &#61; string&#10;region &#61; string&#10;secondary_ip_range &#61; map&#40;string&#41;&#10;&#125;&#41;&#41;">map(object({...}))</code> | | <code title="">null</code> |
## Outputs

View File

@@ -116,7 +116,7 @@ resource "google_compute_subnetwork" "subnetwork" {
project = var.project_id
network = google_compute_network.network.name
region = each.value.region
name = "${var.name}-${each.key}"
name = each.value.name != null ? each.value.name : "${var.name}-${each.key}"
ip_cidr_range = each.value.ip_cidr_range
secondary_ip_range = each.value.secondary_ip_range == null ? [] : [
for name, range in each.value.secondary_ip_range :

View File

@@ -109,9 +109,10 @@ variable "shared_vpc_service_projects" {
}
variable "subnets" {
description = "The list of subnets being created"
description = "Subnets being created. If name is set to null, a default will be used combining network name and this map key."
type = map(object({
ip_cidr_range = string
name = string
region = string
secondary_ip_range = map(string)
}))