allow overriding name in net-vpc subnet factory (#1239)

This commit is contained in:
Ludovico Magnocavallo
2023-03-11 09:30:42 +01:00
committed by GitHub
parent 510db1b36f
commit 6ba0f8b0ba
3 changed files with 25 additions and 7 deletions

View File

@@ -306,7 +306,7 @@ module "vpc" {
### Subnet Factory
The `net-vpc` module includes a subnet factory (see [Resource Factories](../../blueprints/factories/)) for the massive creation of subnets leveraging one configuration file per subnet. The factory also supports proxy-only and PSC subnets via the `purpose` attribute.
The `net-vpc` module includes a subnet factory (see [Resource Factories](../../blueprints/factories/)) for the massive creation of subnets leveraging one configuration file per subnet. The factory also supports proxy-only and PSC subnets via the `purpose` attribute. The `name` attribute is optional and defaults to the file name, allowing to use the same name for subnets in different regions.
```hcl
module "vpc" {
@@ -315,15 +315,23 @@ module "vpc" {
name = "my-network"
data_folder = "config/subnets"
}
# tftest modules=1 resources=6 files=subnet-simple,subnet-detailed,subnet-proxy,subnet-psc inventory=factory.yaml
# tftest modules=1 resources=7 files=subnet-simple,subnet-simple-2,subnet-detailed,subnet-proxy,subnet-psc inventory=factory.yaml
```
```yaml
# tftest-file id=subnet-simple path=config/subnets/subnet-simple.yaml
name: simple
region: europe-west4
ip_cidr_range: 10.0.1.0/24
```
```yaml
# tftest-file id=subnet-simple-2 path=config/subnets/subnet-simple-2.yaml
name: simple
region: europe-west8
ip_cidr_range: 10.0.2.0/24
```
```yaml
# tftest-file id=subnet-detailed path=config/subnets/subnet-detailed.yaml
region: europe-west1

View File

@@ -22,8 +22,8 @@ locals {
trimsuffix(basename(f), ".yaml") => yamldecode(file("${var.data_folder}/${f}"))
}
_factory_subnets = {
for k, v in local._factory_data : "${v.region}/${k}" => {
name = k
for k, v in local._factory_data : "${v.region}/${try(v.name, k)}" => {
name = try(v.name, k)
ip_cidr_range = v.ip_cidr_range
region = v.region
description = try(v.description, null)