From 61d5758f06cc817425ba5cc32e8356e24018837b Mon Sep 17 00:00:00 2001 From: Julio Castillo Date: Wed, 30 Nov 2022 20:34:47 +0100 Subject: [PATCH] New test example for a module --- tests/modules/net_vpc/common.tfvars | 2 + tests/modules/net_vpc/peering.tfvars | 5 + tests/modules/net_vpc/peering.yaml | 33 ++++++ .../modules/net_vpc/psa_routes_export.tfvars | 7 ++ tests/modules/net_vpc/psa_routes_export.yaml | 46 ++++++++ .../modules/net_vpc/psa_routes_import.tfvars | 7 ++ tests/modules/net_vpc/psa_routes_import.yaml | 46 ++++++++ .../net_vpc/psa_routes_import_export.tfvars | 7 ++ .../net_vpc/psa_routes_import_export.yaml | 46 ++++++++ tests/modules/net_vpc/psa_simple.tfvars | 7 ++ tests/modules/net_vpc/psa_simple.yaml | 56 +++++++++ tests/modules/net_vpc/shared_vpc.tfvars | 2 + tests/modules/net_vpc/shared_vpc.yaml | 32 ++++++ tests/modules/net_vpc/simple.yaml | 22 ++++ tests/modules/net_vpc/subnets.tfvars | 44 ++++++++ tests/modules/net_vpc/subnets.yaml | 106 ++++++++++++++++++ tests/modules/net_vpc/test_plan.py | 50 +++------ tests/modules/net_vpc/test_plan_psa.py | 79 ++++--------- tests/modules/net_vpc/test_plan_subnets.py | 48 +------- 19 files changed, 509 insertions(+), 136 deletions(-) create mode 100644 tests/modules/net_vpc/common.tfvars create mode 100644 tests/modules/net_vpc/peering.tfvars create mode 100644 tests/modules/net_vpc/peering.yaml create mode 100644 tests/modules/net_vpc/psa_routes_export.tfvars create mode 100644 tests/modules/net_vpc/psa_routes_export.yaml create mode 100644 tests/modules/net_vpc/psa_routes_import.tfvars create mode 100644 tests/modules/net_vpc/psa_routes_import.yaml create mode 100644 tests/modules/net_vpc/psa_routes_import_export.tfvars create mode 100644 tests/modules/net_vpc/psa_routes_import_export.yaml create mode 100644 tests/modules/net_vpc/psa_simple.tfvars create mode 100644 tests/modules/net_vpc/psa_simple.yaml create mode 100644 tests/modules/net_vpc/shared_vpc.tfvars create mode 100644 tests/modules/net_vpc/shared_vpc.yaml create mode 100644 tests/modules/net_vpc/simple.yaml create mode 100644 tests/modules/net_vpc/subnets.tfvars create mode 100644 tests/modules/net_vpc/subnets.yaml diff --git a/tests/modules/net_vpc/common.tfvars b/tests/modules/net_vpc/common.tfvars new file mode 100644 index 000000000..8d9d8a957 --- /dev/null +++ b/tests/modules/net_vpc/common.tfvars @@ -0,0 +1,2 @@ +project_id = "test-project" +name = "test" diff --git a/tests/modules/net_vpc/peering.tfvars b/tests/modules/net_vpc/peering.tfvars new file mode 100644 index 000000000..eccd7ae71 --- /dev/null +++ b/tests/modules/net_vpc/peering.tfvars @@ -0,0 +1,5 @@ +peering_config = { + peer_vpc_self_link = "projects/my-project/global/networks/peer" + export_routes = true + import_routes = null +} diff --git a/tests/modules/net_vpc/peering.yaml b/tests/modules/net_vpc/peering.yaml new file mode 100644 index 000000000..659eccff3 --- /dev/null +++ b/tests/modules/net_vpc/peering.yaml @@ -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: {} diff --git a/tests/modules/net_vpc/psa_routes_export.tfvars b/tests/modules/net_vpc/psa_routes_export.tfvars new file mode 100644 index 000000000..9fbe4ddf7 --- /dev/null +++ b/tests/modules/net_vpc/psa_routes_export.tfvars @@ -0,0 +1,7 @@ +psa_config = { + ranges = { + bar = "172.16.100.0/24" + } + export_routes = true + import_routes = false +} diff --git a/tests/modules/net_vpc/psa_routes_export.yaml b/tests/modules/net_vpc/psa_routes_export.yaml new file mode 100644 index 000000000..d49d31380 --- /dev/null +++ b/tests/modules/net_vpc/psa_routes_export.yaml @@ -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: {} diff --git a/tests/modules/net_vpc/psa_routes_import.tfvars b/tests/modules/net_vpc/psa_routes_import.tfvars new file mode 100644 index 000000000..beeaf433a --- /dev/null +++ b/tests/modules/net_vpc/psa_routes_import.tfvars @@ -0,0 +1,7 @@ +psa_config = { + ranges = { + bar = "172.16.100.0/24" + } + export_routes = false + import_routes = true +} diff --git a/tests/modules/net_vpc/psa_routes_import.yaml b/tests/modules/net_vpc/psa_routes_import.yaml new file mode 100644 index 000000000..06255280f --- /dev/null +++ b/tests/modules/net_vpc/psa_routes_import.yaml @@ -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: {} diff --git a/tests/modules/net_vpc/psa_routes_import_export.tfvars b/tests/modules/net_vpc/psa_routes_import_export.tfvars new file mode 100644 index 000000000..205922311 --- /dev/null +++ b/tests/modules/net_vpc/psa_routes_import_export.tfvars @@ -0,0 +1,7 @@ +psa_config = { + ranges = { + bar = "172.16.100.0/24" + } + export_routes = true + import_routes = true +} diff --git a/tests/modules/net_vpc/psa_routes_import_export.yaml b/tests/modules/net_vpc/psa_routes_import_export.yaml new file mode 100644 index 000000000..87b795f1f --- /dev/null +++ b/tests/modules/net_vpc/psa_routes_import_export.yaml @@ -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: {} diff --git a/tests/modules/net_vpc/psa_simple.tfvars b/tests/modules/net_vpc/psa_simple.tfvars new file mode 100644 index 000000000..51289fe04 --- /dev/null +++ b/tests/modules/net_vpc/psa_simple.tfvars @@ -0,0 +1,7 @@ +psa_config = { + ranges = { + bar = "172.16.100.0/24" + foo = "172.16.101.0/24" + } + routes = null +} diff --git a/tests/modules/net_vpc/psa_simple.yaml b/tests/modules/net_vpc/psa_simple.yaml new file mode 100644 index 000000000..8b66711cc --- /dev/null +++ b/tests/modules/net_vpc/psa_simple.yaml @@ -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: {} diff --git a/tests/modules/net_vpc/shared_vpc.tfvars b/tests/modules/net_vpc/shared_vpc.tfvars new file mode 100644 index 000000000..3171539aa --- /dev/null +++ b/tests/modules/net_vpc/shared_vpc.tfvars @@ -0,0 +1,2 @@ +shared_vpc_host = true +shared_vpc_service_projects = ["tf-a", "tf-b"] diff --git a/tests/modules/net_vpc/shared_vpc.yaml b/tests/modules/net_vpc/shared_vpc.yaml new file mode 100644 index 000000000..78e6d5043 --- /dev/null +++ b/tests/modules/net_vpc/shared_vpc.yaml @@ -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: {} diff --git a/tests/modules/net_vpc/simple.yaml b/tests/modules/net_vpc/simple.yaml new file mode 100644 index 000000000..1c2d57eec --- /dev/null +++ b/tests/modules/net_vpc/simple.yaml @@ -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: {} diff --git a/tests/modules/net_vpc/subnets.tfvars b/tests/modules/net_vpc/subnets.tfvars new file mode 100644 index 000000000..499e498f4 --- /dev/null +++ b/tests/modules/net_vpc/subnets.tfvars @@ -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" + } + } +] diff --git a/tests/modules/net_vpc/subnets.yaml b/tests/modules/net_vpc/subnets.yaml new file mode 100644 index 000000000..1e44fe80c --- /dev/null +++ b/tests/modules/net_vpc/subnets.yaml @@ -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: {} diff --git a/tests/modules/net_vpc/test_plan.py b/tests/modules/net_vpc/test_plan.py index 2f49f801b..d700b38a8 100644 --- a/tests/modules/net_vpc/test_plan.py +++ b/tests/modules/net_vpc/test_plan.py @@ -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): diff --git a/tests/modules/net_vpc/test_plan_psa.py b/tests/modules/net_vpc/test_plan_psa.py index 359977d65..9ae7cdb4d 100644 --- a/tests/modules/net_vpc/test_plan_psa.py +++ b/tests/modules/net_vpc/test_plan_psa.py @@ -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']) diff --git a/tests/modules/net_vpc/test_plan_subnets.py b/tests/modules/net_vpc/test_plan_subnets.py index affea44c2..803715343 100644 --- a/tests/modules/net_vpc/test_plan_subnets.py +++ b/tests/modules/net_vpc/test_plan_subnets.py @@ -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'])