New test example for a module
This commit is contained in:
2
tests/modules/net_vpc/common.tfvars
Normal file
2
tests/modules/net_vpc/common.tfvars
Normal file
@@ -0,0 +1,2 @@
|
||||
project_id = "test-project"
|
||||
name = "test"
|
||||
5
tests/modules/net_vpc/peering.tfvars
Normal file
5
tests/modules/net_vpc/peering.tfvars
Normal file
@@ -0,0 +1,5 @@
|
||||
peering_config = {
|
||||
peer_vpc_self_link = "projects/my-project/global/networks/peer"
|
||||
export_routes = true
|
||||
import_routes = null
|
||||
}
|
||||
33
tests/modules/net_vpc/peering.yaml
Normal file
33
tests/modules/net_vpc/peering.yaml
Normal file
@@ -0,0 +1,33 @@
|
||||
values:
|
||||
google_compute_network.network[0]:
|
||||
auto_create_subnetworks: false
|
||||
delete_default_routes_on_create: false
|
||||
description: Terraform-managed.
|
||||
name: test
|
||||
project: test-project
|
||||
routing_mode: GLOBAL
|
||||
google_compute_network_peering.local[0]:
|
||||
export_custom_routes: true
|
||||
import_custom_routes: false
|
||||
name: test-peer
|
||||
peer_network: projects/my-project/global/networks/peer
|
||||
google_compute_network_peering.remote[0]:
|
||||
export_custom_routes: false
|
||||
import_custom_routes: true
|
||||
name: peer-test
|
||||
network: projects/my-project/global/networks/peer
|
||||
|
||||
counts:
|
||||
google_compute_network: 1
|
||||
google_compute_network_peering: 2
|
||||
|
||||
outputs:
|
||||
bindings: {}
|
||||
project_id: test-project
|
||||
subnet_ips: {}
|
||||
subnet_regions: {}
|
||||
subnet_secondary_ranges: {}
|
||||
subnet_self_links: {}
|
||||
subnets: {}
|
||||
subnets_proxy_only: {}
|
||||
subnets_psc: {}
|
||||
7
tests/modules/net_vpc/psa_routes_export.tfvars
Normal file
7
tests/modules/net_vpc/psa_routes_export.tfvars
Normal file
@@ -0,0 +1,7 @@
|
||||
psa_config = {
|
||||
ranges = {
|
||||
bar = "172.16.100.0/24"
|
||||
}
|
||||
export_routes = true
|
||||
import_routes = false
|
||||
}
|
||||
46
tests/modules/net_vpc/psa_routes_export.yaml
Normal file
46
tests/modules/net_vpc/psa_routes_export.yaml
Normal file
@@ -0,0 +1,46 @@
|
||||
values:
|
||||
google_compute_global_address.psa_ranges["bar"]:
|
||||
address: 172.16.100.0
|
||||
address_type: INTERNAL
|
||||
description: null
|
||||
ip_version: null
|
||||
name: bar
|
||||
prefix_length: 24
|
||||
project: test-project
|
||||
purpose: VPC_PEERING
|
||||
google_compute_network.network[0]:
|
||||
auto_create_subnetworks: false
|
||||
delete_default_routes_on_create: false
|
||||
description: Terraform-managed.
|
||||
enable_ula_internal_ipv6: null
|
||||
name: test
|
||||
project: test-project
|
||||
routing_mode: GLOBAL
|
||||
google_compute_network_peering_routes_config.psa_routes["1"]:
|
||||
export_custom_routes: true
|
||||
import_custom_routes: false
|
||||
project: test-project
|
||||
google_service_networking_connection.psa_connection["1"]:
|
||||
reserved_peering_ranges:
|
||||
- bar
|
||||
service: servicenetworking.googleapis.com
|
||||
|
||||
counts:
|
||||
google_compute_global_address: 1
|
||||
google_compute_network: 1
|
||||
google_compute_network_peering_routes_config: 1
|
||||
google_service_networking_connection: 1
|
||||
|
||||
outputs:
|
||||
bindings: {}
|
||||
name: __missing__
|
||||
network: __missing__
|
||||
project_id: test-project
|
||||
self_link: __missing__
|
||||
subnet_ips: {}
|
||||
subnet_regions: {}
|
||||
subnet_secondary_ranges: {}
|
||||
subnet_self_links: {}
|
||||
subnets: {}
|
||||
subnets_proxy_only: {}
|
||||
subnets_psc: {}
|
||||
7
tests/modules/net_vpc/psa_routes_import.tfvars
Normal file
7
tests/modules/net_vpc/psa_routes_import.tfvars
Normal file
@@ -0,0 +1,7 @@
|
||||
psa_config = {
|
||||
ranges = {
|
||||
bar = "172.16.100.0/24"
|
||||
}
|
||||
export_routes = false
|
||||
import_routes = true
|
||||
}
|
||||
46
tests/modules/net_vpc/psa_routes_import.yaml
Normal file
46
tests/modules/net_vpc/psa_routes_import.yaml
Normal file
@@ -0,0 +1,46 @@
|
||||
values:
|
||||
google_compute_global_address.psa_ranges["bar"]:
|
||||
address: 172.16.100.0
|
||||
address_type: INTERNAL
|
||||
description: null
|
||||
ip_version: null
|
||||
name: bar
|
||||
prefix_length: 24
|
||||
project: test-project
|
||||
purpose: VPC_PEERING
|
||||
google_compute_network.network[0]:
|
||||
auto_create_subnetworks: false
|
||||
delete_default_routes_on_create: false
|
||||
description: Terraform-managed.
|
||||
enable_ula_internal_ipv6: null
|
||||
name: test
|
||||
project: test-project
|
||||
routing_mode: GLOBAL
|
||||
google_compute_network_peering_routes_config.psa_routes["1"]:
|
||||
export_custom_routes: false
|
||||
import_custom_routes: true
|
||||
project: test-project
|
||||
google_service_networking_connection.psa_connection["1"]:
|
||||
reserved_peering_ranges:
|
||||
- bar
|
||||
service: servicenetworking.googleapis.com
|
||||
|
||||
counts:
|
||||
google_compute_global_address: 1
|
||||
google_compute_network: 1
|
||||
google_compute_network_peering_routes_config: 1
|
||||
google_service_networking_connection: 1
|
||||
|
||||
outputs:
|
||||
bindings: {}
|
||||
name: __missing__
|
||||
network: __missing__
|
||||
project_id: test-project
|
||||
self_link: __missing__
|
||||
subnet_ips: {}
|
||||
subnet_regions: {}
|
||||
subnet_secondary_ranges: {}
|
||||
subnet_self_links: {}
|
||||
subnets: {}
|
||||
subnets_proxy_only: {}
|
||||
subnets_psc: {}
|
||||
7
tests/modules/net_vpc/psa_routes_import_export.tfvars
Normal file
7
tests/modules/net_vpc/psa_routes_import_export.tfvars
Normal file
@@ -0,0 +1,7 @@
|
||||
psa_config = {
|
||||
ranges = {
|
||||
bar = "172.16.100.0/24"
|
||||
}
|
||||
export_routes = true
|
||||
import_routes = true
|
||||
}
|
||||
46
tests/modules/net_vpc/psa_routes_import_export.yaml
Normal file
46
tests/modules/net_vpc/psa_routes_import_export.yaml
Normal file
@@ -0,0 +1,46 @@
|
||||
values:
|
||||
google_compute_global_address.psa_ranges["bar"]:
|
||||
address: 172.16.100.0
|
||||
address_type: INTERNAL
|
||||
description: null
|
||||
ip_version: null
|
||||
name: bar
|
||||
prefix_length: 24
|
||||
project: test-project
|
||||
purpose: VPC_PEERING
|
||||
google_compute_network.network[0]:
|
||||
auto_create_subnetworks: false
|
||||
delete_default_routes_on_create: false
|
||||
description: Terraform-managed.
|
||||
enable_ula_internal_ipv6: null
|
||||
name: test
|
||||
project: test-project
|
||||
routing_mode: GLOBAL
|
||||
google_compute_network_peering_routes_config.psa_routes["1"]:
|
||||
export_custom_routes: true
|
||||
import_custom_routes: true
|
||||
project: test-project
|
||||
google_service_networking_connection.psa_connection["1"]:
|
||||
reserved_peering_ranges:
|
||||
- bar
|
||||
service: servicenetworking.googleapis.com
|
||||
|
||||
counts:
|
||||
google_compute_global_address: 1
|
||||
google_compute_network: 1
|
||||
google_compute_network_peering_routes_config: 1
|
||||
google_service_networking_connection: 1
|
||||
|
||||
outputs:
|
||||
bindings: {}
|
||||
name: __missing__
|
||||
network: __missing__
|
||||
project_id: test-project
|
||||
self_link: __missing__
|
||||
subnet_ips: {}
|
||||
subnet_regions: {}
|
||||
subnet_secondary_ranges: {}
|
||||
subnet_self_links: {}
|
||||
subnets: {}
|
||||
subnets_proxy_only: {}
|
||||
subnets_psc: {}
|
||||
7
tests/modules/net_vpc/psa_simple.tfvars
Normal file
7
tests/modules/net_vpc/psa_simple.tfvars
Normal file
@@ -0,0 +1,7 @@
|
||||
psa_config = {
|
||||
ranges = {
|
||||
bar = "172.16.100.0/24"
|
||||
foo = "172.16.101.0/24"
|
||||
}
|
||||
routes = null
|
||||
}
|
||||
56
tests/modules/net_vpc/psa_simple.yaml
Normal file
56
tests/modules/net_vpc/psa_simple.yaml
Normal file
@@ -0,0 +1,56 @@
|
||||
values:
|
||||
google_compute_global_address.psa_ranges["bar"]:
|
||||
address: 172.16.100.0
|
||||
address_type: INTERNAL
|
||||
description: null
|
||||
ip_version: null
|
||||
name: bar
|
||||
prefix_length: 24
|
||||
project: test-project
|
||||
purpose: VPC_PEERING
|
||||
google_compute_global_address.psa_ranges["foo"]:
|
||||
address: 172.16.101.0
|
||||
address_type: INTERNAL
|
||||
description: null
|
||||
ip_version: null
|
||||
name: foo
|
||||
prefix_length: 24
|
||||
project: test-project
|
||||
purpose: VPC_PEERING
|
||||
google_compute_network.network[0]:
|
||||
auto_create_subnetworks: false
|
||||
delete_default_routes_on_create: false
|
||||
description: Terraform-managed.
|
||||
enable_ula_internal_ipv6: null
|
||||
name: test
|
||||
project: test-project
|
||||
routing_mode: GLOBAL
|
||||
google_compute_network_peering_routes_config.psa_routes["1"]:
|
||||
export_custom_routes: false
|
||||
import_custom_routes: false
|
||||
project: test-project
|
||||
google_service_networking_connection.psa_connection["1"]:
|
||||
reserved_peering_ranges:
|
||||
- bar
|
||||
- foo
|
||||
service: servicenetworking.googleapis.com
|
||||
|
||||
counts:
|
||||
google_compute_global_address: 2
|
||||
google_compute_network: 1
|
||||
google_compute_network_peering_routes_config: 1
|
||||
google_service_networking_connection: 1
|
||||
|
||||
outputs:
|
||||
bindings: {}
|
||||
name: __missing__
|
||||
network: __missing__
|
||||
project_id: test-project
|
||||
self_link: __missing__
|
||||
subnet_ips: {}
|
||||
subnet_regions: {}
|
||||
subnet_secondary_ranges: {}
|
||||
subnet_self_links: {}
|
||||
subnets: {}
|
||||
subnets_proxy_only: {}
|
||||
subnets_psc: {}
|
||||
2
tests/modules/net_vpc/shared_vpc.tfvars
Normal file
2
tests/modules/net_vpc/shared_vpc.tfvars
Normal file
@@ -0,0 +1,2 @@
|
||||
shared_vpc_host = true
|
||||
shared_vpc_service_projects = ["tf-a", "tf-b"]
|
||||
32
tests/modules/net_vpc/shared_vpc.yaml
Normal file
32
tests/modules/net_vpc/shared_vpc.yaml
Normal file
@@ -0,0 +1,32 @@
|
||||
values:
|
||||
google_compute_network.network[0]:
|
||||
auto_create_subnetworks: false
|
||||
delete_default_routes_on_create: false
|
||||
description: Terraform-managed.
|
||||
name: test
|
||||
project: test-project
|
||||
routing_mode: GLOBAL
|
||||
google_compute_shared_vpc_host_project.shared_vpc_host[0]:
|
||||
project: test-project
|
||||
google_compute_shared_vpc_service_project.service_projects["tf-a"]:
|
||||
host_project: test-project
|
||||
service_project: tf-a
|
||||
google_compute_shared_vpc_service_project.service_projects["tf-b"]:
|
||||
host_project: test-project
|
||||
service_project: tf-b
|
||||
|
||||
counts:
|
||||
google_compute_network: 1
|
||||
google_compute_shared_vpc_host_project: 1
|
||||
google_compute_shared_vpc_service_project: 2
|
||||
|
||||
outputs:
|
||||
bindings: {}
|
||||
project_id: test-project
|
||||
subnet_ips: {}
|
||||
subnet_regions: {}
|
||||
subnet_secondary_ranges: {}
|
||||
subnet_self_links: {}
|
||||
subnets: {}
|
||||
subnets_proxy_only: {}
|
||||
subnets_psc: {}
|
||||
22
tests/modules/net_vpc/simple.yaml
Normal file
22
tests/modules/net_vpc/simple.yaml
Normal file
@@ -0,0 +1,22 @@
|
||||
values:
|
||||
google_compute_network.network[0]:
|
||||
auto_create_subnetworks: false
|
||||
delete_default_routes_on_create: false
|
||||
description: Terraform-managed.
|
||||
name: test
|
||||
project: test-project
|
||||
routing_mode: GLOBAL
|
||||
|
||||
counts:
|
||||
google_compute_network: 1
|
||||
|
||||
outputs:
|
||||
bindings: {}
|
||||
project_id: test-project
|
||||
subnet_ips: {}
|
||||
subnet_regions: {}
|
||||
subnet_secondary_ranges: {}
|
||||
subnet_self_links: {}
|
||||
subnets: {}
|
||||
subnets_proxy_only: {}
|
||||
subnets_psc: {}
|
||||
44
tests/modules/net_vpc/subnets.tfvars
Normal file
44
tests/modules/net_vpc/subnets.tfvars
Normal file
@@ -0,0 +1,44 @@
|
||||
subnet_iam = {
|
||||
"europe-west1/a" = {
|
||||
"roles/compute.networkUser" = [
|
||||
"user:a@example.com", "group:g-a@example.com"
|
||||
]
|
||||
}
|
||||
"europe-west1/c" = {
|
||||
"roles/compute.networkUser" = [
|
||||
"user:c@example.com", "group:g-c@example.com"
|
||||
]
|
||||
}
|
||||
}
|
||||
subnets = [
|
||||
{
|
||||
name = "a"
|
||||
region = "europe-west1"
|
||||
ip_cidr_range = "10.0.0.0/24"
|
||||
},
|
||||
{
|
||||
name = "b"
|
||||
region = "europe-west1"
|
||||
ip_cidr_range = "10.0.1.0/24",
|
||||
description = "Subnet b"
|
||||
enable_private_access = false
|
||||
},
|
||||
{
|
||||
name = "c"
|
||||
region = "europe-west1"
|
||||
ip_cidr_range = "10.0.2.0/24"
|
||||
secondary_ip_ranges = {
|
||||
a = "192.168.0.0/24"
|
||||
b = "192.168.1.0/24"
|
||||
}
|
||||
},
|
||||
{
|
||||
name = "d"
|
||||
region = "europe-west1"
|
||||
ip_cidr_range = "10.0.3.0/24"
|
||||
flow_logs_config = {
|
||||
flow_sampling = 0.5
|
||||
aggregation_interval = "INTERVAL_10_MIN"
|
||||
}
|
||||
}
|
||||
]
|
||||
106
tests/modules/net_vpc/subnets.yaml
Normal file
106
tests/modules/net_vpc/subnets.yaml
Normal file
@@ -0,0 +1,106 @@
|
||||
values:
|
||||
google_compute_network.network[0]:
|
||||
auto_create_subnetworks: false
|
||||
delete_default_routes_on_create: false
|
||||
description: Terraform-managed.
|
||||
name: test
|
||||
project: test-project
|
||||
routing_mode: GLOBAL
|
||||
google_compute_subnetwork.subnetwork["europe-west1/a"]:
|
||||
description: Terraform-managed.
|
||||
ip_cidr_range: 10.0.0.0/24
|
||||
log_config: []
|
||||
name: a
|
||||
private_ip_google_access: true
|
||||
project: test-project
|
||||
region: europe-west1
|
||||
role: null
|
||||
secondary_ip_range: []
|
||||
google_compute_subnetwork.subnetwork["europe-west1/b"]:
|
||||
description: Subnet b
|
||||
ip_cidr_range: 10.0.1.0/24
|
||||
log_config: []
|
||||
name: b
|
||||
private_ip_google_access: false
|
||||
project: test-project
|
||||
region: europe-west1
|
||||
role: null
|
||||
secondary_ip_range: []
|
||||
google_compute_subnetwork.subnetwork["europe-west1/c"]:
|
||||
description: Terraform-managed.
|
||||
ip_cidr_range: 10.0.2.0/24
|
||||
ipv6_access_type: null
|
||||
log_config: []
|
||||
name: c
|
||||
private_ip_google_access: true
|
||||
project: test-project
|
||||
region: europe-west1
|
||||
role: null
|
||||
secondary_ip_range:
|
||||
- ip_cidr_range: 192.168.0.0/24
|
||||
range_name: a
|
||||
- ip_cidr_range: 192.168.1.0/24
|
||||
range_name: b
|
||||
google_compute_subnetwork.subnetwork["europe-west1/d"]:
|
||||
description: Terraform-managed.
|
||||
ip_cidr_range: 10.0.3.0/24
|
||||
log_config:
|
||||
- aggregation_interval: INTERVAL_10_MIN
|
||||
filter_expr: 'true'
|
||||
flow_sampling: 0.5
|
||||
metadata: INCLUDE_ALL_METADATA
|
||||
metadata_fields: null
|
||||
name: d
|
||||
private_ip_google_access: true
|
||||
project: test-project
|
||||
region: europe-west1
|
||||
role: null
|
||||
secondary_ip_range: []
|
||||
google_compute_subnetwork_iam_binding.binding["europe-west1/a.roles/compute.networkUser"]:
|
||||
condition: []
|
||||
members:
|
||||
- group:g-a@example.com
|
||||
- user:a@example.com
|
||||
project: test-project
|
||||
region: europe-west1
|
||||
role: roles/compute.networkUser
|
||||
subnetwork: a
|
||||
google_compute_subnetwork_iam_binding.binding["europe-west1/c.roles/compute.networkUser"]:
|
||||
condition: []
|
||||
members:
|
||||
- group:g-c@example.com
|
||||
- user:c@example.com
|
||||
project: test-project
|
||||
region: europe-west1
|
||||
role: roles/compute.networkUser
|
||||
subnetwork: c
|
||||
|
||||
counts:
|
||||
google_compute_network: 1
|
||||
google_compute_subnetwork: 4
|
||||
google_compute_subnetwork_iam_binding: 2
|
||||
|
||||
outputs:
|
||||
bindings: __missing__
|
||||
project_id: test-project
|
||||
subnet_ips:
|
||||
europe-west1/a: 10.0.0.0/24
|
||||
europe-west1/b: 10.0.1.0/24
|
||||
europe-west1/c: 10.0.2.0/24
|
||||
europe-west1/d: 10.0.3.0/24
|
||||
subnet_regions:
|
||||
europe-west1/a: europe-west1
|
||||
europe-west1/b: europe-west1
|
||||
europe-west1/c: europe-west1
|
||||
europe-west1/d: europe-west1
|
||||
subnet_secondary_ranges:
|
||||
europe-west1/a: {}
|
||||
europe-west1/b: {}
|
||||
europe-west1/c:
|
||||
a: 192.168.0.0/24
|
||||
b: 192.168.1.0/24
|
||||
europe-west1/d: {}
|
||||
subnet_self_links: __missing__
|
||||
subnets: __missing__
|
||||
subnets_proxy_only: {}
|
||||
subnets_psc: {}
|
||||
@@ -12,10 +12,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
_VAR_PEER_VPC_CONFIG = '''{
|
||||
peer_vpc_self_link="projects/my-project/global/networks/peer",
|
||||
export_routes=true, import_routes=null
|
||||
}'''
|
||||
_VAR_ROUTES_TEMPLATE = '''{
|
||||
next-hop = {
|
||||
dest_range="192.168.128.0/24", tags=null,
|
||||
@@ -33,41 +29,25 @@ _VAR_ROUTES_NEXT_HOPS = {
|
||||
'vpn_tunnel': 'regions/europe-west1/vpnTunnels/foo'
|
||||
}
|
||||
|
||||
|
||||
def test_vpc_simple(plan_runner):
|
||||
"Test vpc with no extra options."
|
||||
_, resources = plan_runner()
|
||||
assert len(resources) == 1
|
||||
assert [r['type'] for r in resources] == ['google_compute_network']
|
||||
assert [r['values']['name'] for r in resources] == ['test']
|
||||
assert [r['values']['project'] for r in resources] == ['test-project']
|
||||
import yaml
|
||||
|
||||
|
||||
def test_vpc_shared(plan_runner):
|
||||
"Test shared vpc variables."
|
||||
_, resources = plan_runner(shared_vpc_host='true',
|
||||
shared_vpc_service_projects='["tf-a", "tf-b"]')
|
||||
assert len(resources) == 4
|
||||
assert set(r['type'] for r in resources) == set([
|
||||
'google_compute_network', 'google_compute_shared_vpc_host_project',
|
||||
'google_compute_shared_vpc_service_project'
|
||||
])
|
||||
def test_simple(generic_plan_validator):
|
||||
generic_plan_validator(inventory_path='simple.yaml',
|
||||
module_path="modules/net-vpc",
|
||||
tf_var_files=['common.tfvars'])
|
||||
|
||||
|
||||
def test_vpc_peering(plan_runner):
|
||||
"Test vpc peering variables."
|
||||
_, resources = plan_runner(peering_config=_VAR_PEER_VPC_CONFIG)
|
||||
assert len(resources) == 3
|
||||
assert set(r['type'] for r in resources) == set(
|
||||
['google_compute_network', 'google_compute_network_peering'])
|
||||
peerings = [
|
||||
r['values']
|
||||
for r in resources
|
||||
if r['type'] == 'google_compute_network_peering'
|
||||
]
|
||||
assert [p['name'] for p in peerings] == ['test-peer', 'peer-test']
|
||||
assert [p['export_custom_routes'] for p in peerings] == [True, False]
|
||||
assert [p['import_custom_routes'] for p in peerings] == [False, True]
|
||||
def test_vpc_shared(generic_plan_validator):
|
||||
generic_plan_validator(inventory_path='shared_vpc.yaml',
|
||||
module_path="modules/net-vpc",
|
||||
tf_var_files=['common.tfvars', 'shared_vpc.tfvars'])
|
||||
|
||||
|
||||
def test_vpc_peering(generic_plan_validator):
|
||||
generic_plan_validator(inventory_path='peering.yaml',
|
||||
module_path="modules/net-vpc",
|
||||
tf_var_files=['common.tfvars', 'peering.tfvars'])
|
||||
|
||||
|
||||
def test_vpc_routes(plan_runner):
|
||||
|
||||
@@ -12,68 +12,29 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
def test_single_range(plan_runner):
|
||||
"Test single PSA range."
|
||||
psa_config = '''{
|
||||
ranges = {
|
||||
bar = "172.16.100.0/24"
|
||||
foo = "172.16.101.0/24"
|
||||
},
|
||||
routes = null
|
||||
}'''
|
||||
_, resources = plan_runner(psa_config=psa_config)
|
||||
assert len(resources) == 5
|
||||
for r in resources:
|
||||
if r['type'] == 'google_compute_network_peering_routes_config':
|
||||
assert not r['values']['export_custom_routes']
|
||||
assert not r['values']['import_custom_routes']
|
||||
import yaml
|
||||
|
||||
|
||||
def test_routes_export(plan_runner):
|
||||
"Test routes export."
|
||||
psa_config = '''{
|
||||
ranges = {
|
||||
bar = "172.16.100.0/24"
|
||||
}
|
||||
export_routes = true
|
||||
import_routes = false
|
||||
}'''
|
||||
_, resources = plan_runner(psa_config=psa_config)
|
||||
assert len(resources) == 4
|
||||
for r in resources:
|
||||
if r['type'] == 'google_compute_network_peering_routes_config':
|
||||
assert r['values']['export_custom_routes']
|
||||
assert not r['values']['import_custom_routes']
|
||||
def test_simple(generic_plan_validator):
|
||||
generic_plan_validator(inventory_path='psa_simple.yaml',
|
||||
module_path="modules/net-vpc",
|
||||
tf_var_files=['common.tfvars', 'psa_simple.tfvars'])
|
||||
|
||||
|
||||
def test_routes_import(plan_runner):
|
||||
"Test routes import."
|
||||
psa_config = '''{
|
||||
ranges = {
|
||||
bar = "172.16.100.0/24"
|
||||
},
|
||||
export_routes = false
|
||||
import_routes = true
|
||||
}'''
|
||||
_, resources = plan_runner(psa_config=psa_config)
|
||||
for r in resources:
|
||||
if r['type'] == 'google_compute_network_peering_routes_config':
|
||||
assert not r['values']['export_custom_routes']
|
||||
assert r['values']['import_custom_routes']
|
||||
def test_routes_export(generic_plan_validator):
|
||||
generic_plan_validator(
|
||||
inventory_path='psa_routes_export.yaml', module_path="modules/net-vpc",
|
||||
tf_var_files=['common.tfvars', 'psa_routes_export.tfvars'])
|
||||
|
||||
|
||||
def test_routes_export_import(plan_runner):
|
||||
"Test routes export and import."
|
||||
psa_config = '''{
|
||||
ranges = {
|
||||
bar = "172.16.100.0/24"
|
||||
},
|
||||
export_routes = true
|
||||
import_routes = true
|
||||
}'''
|
||||
_, resources = plan_runner(psa_config=psa_config)
|
||||
for r in resources:
|
||||
if r['type'] == 'google_compute_network_peering_routes_config':
|
||||
assert r['values']['export_custom_routes']
|
||||
assert r['values']['import_custom_routes']
|
||||
def test_routes_import(generic_plan_validator):
|
||||
generic_plan_validator(
|
||||
inventory_path='psa_routes_import.yaml', module_path="modules/net-vpc",
|
||||
tf_var_files=['common.tfvars', 'psa_routes_import.tfvars'])
|
||||
|
||||
|
||||
def test_routes_import_export(generic_plan_validator):
|
||||
generic_plan_validator(
|
||||
inventory_path='psa_routes_import_export.yaml',
|
||||
module_path="modules/net-vpc",
|
||||
tf_var_files=['common.tfvars', 'psa_routes_import_export.tfvars'])
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
DATA_FOLDER = "data"
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
def test_subnet_factory(plan_runner):
|
||||
"Test subnet factory."
|
||||
@@ -27,45 +29,7 @@ def test_subnet_factory(plan_runner):
|
||||
assert {s['private_ip_google_access'] for s in subnets} == {True, False}
|
||||
|
||||
|
||||
def test_subnets(plan_runner):
|
||||
"Test subnets variable."
|
||||
_, resources = plan_runner(tf_var_file='test.subnets.tfvars')
|
||||
assert len(resources) == 7
|
||||
subnets = [
|
||||
r['values'] for r in resources if r['type'] == 'google_compute_subnetwork'
|
||||
]
|
||||
assert {s['name'] for s in subnets} == {'a', 'b', 'c', 'd'}
|
||||
assert {len(s['secondary_ip_range']) for s in subnets} == {0, 0, 2, 0}
|
||||
log_config = {s['name']: s['log_config'] for s in subnets if s['log_config']}
|
||||
assert log_config == {
|
||||
'd': [{
|
||||
'aggregation_interval': 'INTERVAL_10_MIN',
|
||||
'filter_expr': 'true',
|
||||
'flow_sampling': 0.5,
|
||||
'metadata': 'INCLUDE_ALL_METADATA',
|
||||
'metadata_fields': None
|
||||
}]
|
||||
}
|
||||
bindings = {
|
||||
r['index']: r['values']
|
||||
for r in resources
|
||||
if r['type'] == 'google_compute_subnetwork_iam_binding'
|
||||
}
|
||||
assert bindings == {
|
||||
'europe-west1/a.roles/compute.networkUser': {
|
||||
'condition': [],
|
||||
'members': ['group:g-a@example.com', 'user:a@example.com'],
|
||||
'project': 'test-project',
|
||||
'region': 'europe-west1',
|
||||
'role': 'roles/compute.networkUser',
|
||||
'subnetwork': 'a'
|
||||
},
|
||||
'europe-west1/c.roles/compute.networkUser': {
|
||||
'condition': [],
|
||||
'members': ['group:g-c@example.com', 'user:c@example.com'],
|
||||
'project': 'test-project',
|
||||
'region': 'europe-west1',
|
||||
'role': 'roles/compute.networkUser',
|
||||
'subnetwork': 'c'
|
||||
},
|
||||
}
|
||||
def test_subnets(generic_plan_validator):
|
||||
generic_plan_validator(inventory_path='subnets.yaml',
|
||||
module_path="modules/net-vpc",
|
||||
tf_var_files=['common.tfvars', 'subnets.tfvars'])
|
||||
|
||||
Reference in New Issue
Block a user