subnets with the same name in different regions (#67)

* support for subnets with the same name in different regions

* fix net-vpc tests
This commit is contained in:
Roberto Jung Drebes
2020-05-04 08:25:53 +02:00
committed by GitHub
parent 711f113cf0
commit 14ec791556
9 changed files with 166 additions and 155 deletions

View File

@@ -97,13 +97,14 @@ variable "shared_vpc_service_projects" {
variable "subnets" {
description = "The list of subnets being created"
type = map(object({
type = list(object({
name = string
ip_cidr_range = string
name = string
region = string
secondary_ip_range = map(string)
}))
default = null
default = []
}
variable "subnet_descriptions" {

View File

@@ -19,22 +19,14 @@ import pytest
FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'fixture')
_VAR_SUBNETS = (
'{ '
'a={region = "europe-west1", ip_cidr_range = "10.0.0.0/24",'
' name=null, secondary_ip_range=null},'
'b={region = "europe-west1", ip_cidr_range = "10.0.1.0/24",'
' name=null, secondary_ip_range=null},'
'c={region = "europe-west1", ip_cidr_range = "10.0.2.0/24",'
' name="c", secondary_ip_range={a="192.168.0.0/24", b="192.168.1.0/24"}},'
'}'
)
_VAR_LOG_CONFIG = '{a = { flow_sampling = 0.1 }}'
_VAR_LOG_CONFIG_DEFAULTS = (
'{'
'aggregation_interval = "INTERVAL_10_MIN", '
'flow_sampling = 0.5, '
'metadata = "INCLUDE_ALL_METADATA"'
'}'
'[ '
'{name = "a", region = "europe-west1", ip_cidr_range = "10.0.0.0/24",'
' secondary_ip_range=null},'
'{name = "b", region = "europe-west1", ip_cidr_range = "10.0.1.0/24",'
' secondary_ip_range=null},'
'{name = "c", region = "europe-west1", ip_cidr_range = "10.0.2.0/24",'
' secondary_ip_range={a="192.168.0.0/24", b="192.168.1.0/24"}},'
']'
)
@@ -45,16 +37,22 @@ def test_subnets_simple(plan_runner):
subnets = [r['values']
for r in resources if r['type'] == 'google_compute_subnetwork']
assert set(s['name'] for s in subnets) == set(
['my-vpc-a', 'my-vpc-b', 'c'])
['a', 'b', 'c'])
assert set(len(s['secondary_ip_range']) for s in subnets) == set([0, 0, 2])
def test_subnet_log_configs(plan_runner):
"Test subnets flow logs configuration and defaults."
log_config = '{"europe-west1/a" = { flow_sampling = 0.1 }}'
log_config_defaults = (
'{aggregation_interval = "INTERVAL_10_MIN", flow_sampling = 0.5, '
'metadata = "INCLUDE_ALL_METADATA"}'
)
subnet_flow_logs = '{"europe-west1/a"=true, "europe-west1/b"=true}'
_, resources = plan_runner(FIXTURES_DIR, subnets=_VAR_SUBNETS,
log_configs=_VAR_LOG_CONFIG,
log_config_defaults=_VAR_LOG_CONFIG_DEFAULTS,
subnet_flow_logs='{a=true, b=true}')
log_configs=log_config,
log_config_defaults=log_config_defaults,
subnet_flow_logs=subnet_flow_logs)
assert len(resources) == 4
flow_logs = {}
for r in resources:
@@ -63,13 +61,13 @@ def test_subnet_log_configs(plan_runner):
flow_logs[r['values']['name']] = r['values']['log_config']
assert flow_logs == {
# enable, override one default option
'my-vpc-a': [{
'a': [{
'aggregation_interval': 'INTERVAL_10_MIN',
'flow_sampling': 0.1,
'metadata': 'INCLUDE_ALL_METADATA'
}],
# enable, use defaults
'my-vpc-b': [{
'b': [{
'aggregation_interval': 'INTERVAL_10_MIN',
'flow_sampling': 0.5,
'metadata': 'INCLUDE_ALL_METADATA'