From 230a1034ecede5c9653309f6d3af6bf53dba7198 Mon Sep 17 00:00:00 2001 From: Julio Castillo Date: Fri, 21 Apr 2023 14:36:11 +0200 Subject: [PATCH] Migrate net-address tests --- modules/net-address/README.md | 12 ++-- .../net_address/examples/external.yaml | 35 ++++++++++ .../net_address/examples/internal.yaml | 38 +++++++++++ .../{__init__.py => examples/psa.yaml} | 15 ++++- tests/modules/net_address/examples/psc.yaml | 33 ++++++++++ tests/modules/net_address/fixture/main.tf | 24 ------- tests/modules/net_address/fixture/outputs.tf | 19 ------ .../modules/net_address/fixture/variables.tf | 40 ----------- tests/modules/net_address/test_plan.py | 66 ------------------- 9 files changed, 126 insertions(+), 156 deletions(-) create mode 100644 tests/modules/net_address/examples/external.yaml create mode 100644 tests/modules/net_address/examples/internal.yaml rename tests/modules/net_address/{__init__.py => examples/psa.yaml} (61%) create mode 100644 tests/modules/net_address/examples/psc.yaml delete mode 100644 tests/modules/net_address/fixture/main.tf delete mode 100644 tests/modules/net_address/fixture/outputs.tf delete mode 100644 tests/modules/net_address/fixture/variables.tf delete mode 100644 tests/modules/net_address/test_plan.py diff --git a/modules/net-address/README.md b/modules/net-address/README.md index 23e947cd..32b66014 100644 --- a/modules/net-address/README.md +++ b/modules/net-address/README.md @@ -11,12 +11,12 @@ module "addresses" { source = "./fabric/modules/net-address" project_id = var.project_id external_addresses = { - nat-1 = var.region - vpn-remote = var.region + one = "europe-west1" + two = "europe-west2" } global_addresses = ["app-1", "app-2"] } -# tftest modules=1 resources=4 +# tftest modules=1 resources=4 inventory=external.yaml ``` ### Internal addresses @@ -38,7 +38,7 @@ module "addresses" { } } } -# tftest modules=1 resources=2 +# tftest modules=1 resources=2 inventory=internal.yaml ``` ### PSA addresses @@ -55,7 +55,7 @@ module "addresses" { } } } -# tftest modules=1 resources=1 +# tftest modules=1 resources=1 inventory=psa.yaml ``` ### PSC addresses @@ -75,7 +75,7 @@ module "addresses" { } } } -# tftest modules=1 resources=2 +# tftest modules=1 resources=2 inventory=psc.yaml ``` diff --git a/tests/modules/net_address/examples/external.yaml b/tests/modules/net_address/examples/external.yaml new file mode 100644 index 00000000..f099faf9 --- /dev/null +++ b/tests/modules/net_address/examples/external.yaml @@ -0,0 +1,35 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +values: + module.addresses.google_compute_address.external["one"]: + address_type: EXTERNAL + name: one + project: project-id + region: europe-west1 + module.addresses.google_compute_address.external["two"]: + address_type: EXTERNAL + name: two + project: project-id + region: europe-west2 + module.addresses.google_compute_global_address.global["app-1"]: + name: app-1 + project: project-id + module.addresses.google_compute_global_address.global["app-2"]: + name: app-2 + project: project-id + +counts: + google_compute_address: 2 + google_compute_global_address: 2 diff --git a/tests/modules/net_address/examples/internal.yaml b/tests/modules/net_address/examples/internal.yaml new file mode 100644 index 00000000..ab369cff --- /dev/null +++ b/tests/modules/net_address/examples/internal.yaml @@ -0,0 +1,38 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +values: + module.addresses.google_compute_address.internal["ilb-1"]: + address_type: INTERNAL + labels: null + name: ilb-1 + network: null + prefix_length: null + project: project-id + purpose: SHARED_LOADBALANCER_VIP + region: region + subnetwork: subnet_self_link + module.addresses.google_compute_address.internal["ilb-2"]: + address: 10.0.0.2 + address_type: INTERNAL + labels: null + name: ilb-2 + network: null + prefix_length: null + project: project-id + region: region + subnetwork: subnet_self_link + +counts: + google_compute_address: 2 diff --git a/tests/modules/net_address/__init__.py b/tests/modules/net_address/examples/psa.yaml similarity index 61% rename from tests/modules/net_address/__init__.py rename to tests/modules/net_address/examples/psa.yaml index 6d6d1266..d0db3309 100644 --- a/tests/modules/net_address/__init__.py +++ b/tests/modules/net_address/examples/psa.yaml @@ -1,4 +1,4 @@ -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,3 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +values: + module.addresses.google_compute_global_address.psa["cloudsql-mysql"]: + address: 10.10.10.0 + address_type: INTERNAL + name: cloudsql-mysql + network: projects/xxx/global/networks/aaa + prefix_length: 24 + project: project-id + purpose: VPC_PEERING + +counts: + google_compute_global_address: 1 diff --git a/tests/modules/net_address/examples/psc.yaml b/tests/modules/net_address/examples/psc.yaml new file mode 100644 index 00000000..bf998a0b --- /dev/null +++ b/tests/modules/net_address/examples/psc.yaml @@ -0,0 +1,33 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +values: + module.addresses.google_compute_global_address.psc["one"]: + address_type: INTERNAL + name: one + network: projects/xxx/global/networks/aaa + prefix_length: null + project: project-id + purpose: PRIVATE_SERVICE_CONNECT + module.addresses.google_compute_global_address.psc["two"]: + address: 10.0.0.32 + address_type: INTERNAL + name: two + network: projects/xxx/global/networks/aaa + prefix_length: null + project: project-id + purpose: PRIVATE_SERVICE_CONNECT + +counts: + google_compute_global_address: 2 diff --git a/tests/modules/net_address/fixture/main.tf b/tests/modules/net_address/fixture/main.tf deleted file mode 100644 index 4d41b096..00000000 --- a/tests/modules/net_address/fixture/main.tf +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright 2022 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -module "test" { - source = "../../../../modules/net-address" - external_addresses = var.external_addresses - global_addresses = var.global_addresses - internal_addresses = var.internal_addresses - psa_addresses = var.psa_addresses - project_id = var.project_id -} diff --git a/tests/modules/net_address/fixture/outputs.tf b/tests/modules/net_address/fixture/outputs.tf deleted file mode 100644 index 523c5274..00000000 --- a/tests/modules/net_address/fixture/outputs.tf +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright 2022 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -output "module" { - value = module.test -} diff --git a/tests/modules/net_address/fixture/variables.tf b/tests/modules/net_address/fixture/variables.tf deleted file mode 100644 index ebc90814..00000000 --- a/tests/modules/net_address/fixture/variables.tf +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright 2022 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -variable "external_addresses" { - type = any - default = {} -} - -variable "global_addresses" { - type = any - default = [] -} - -variable "internal_addresses" { - type = any - default = {} -} - -variable "project_id" { - type = string - default = "my-project" -} - -variable "psa_addresses" { - type = any - default = {} -} diff --git a/tests/modules/net_address/test_plan.py b/tests/modules/net_address/test_plan.py deleted file mode 100644 index 2274da6f..00000000 --- a/tests/modules/net_address/test_plan.py +++ /dev/null @@ -1,66 +0,0 @@ -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -def test_external_addresses(plan_runner): - addresses = '{one = "europe-west1", two = "europe-west2"}' - _, resources = plan_runner(external_addresses=addresses) - assert [r['values']['name'] for r in resources] == ['one', 'two'] - assert set(r['values']['address_type'] for r in resources) == set( - ['EXTERNAL']) - assert [r['values']['region'] for r in resources - ] == ['europe-west1', 'europe-west2'] - - -def test_global_addresses(plan_runner): - _, resources = plan_runner(global_addresses='["one", "two"]') - assert [r['values']['name'] for r in resources] == ['one', 'two'] - assert set(r['values']['address_type'] for r in resources) == set([None]) - - -def test_internal_addresses(plan_runner): - addresses = ('{one = {region = "europe-west1", subnetwork = "foobar"}, ' - 'two = {region = "europe-west2", subnetwork = "foobarz"}}') - _, resources = plan_runner(internal_addresses=addresses) - assert [r['values']['name'] for r in resources] == ['one', 'two'] - assert set(r['values']['address_type'] for r in resources) == set( - ['INTERNAL']) - assert [r['values']['region'] for r in resources - ] == ['europe-west1', 'europe-west2'] - - -def test_internal_addresses_config(plan_runner): - addresses = '''{ - one = { - region = "europe-west1" - subnetwork = "foobar" - address = "10.0.0.2" - purpose = "SHARED_LOADBALANCER_VIP" - }, - two = {region = "europe-west2", subnetwork = "foobarz"} - }''' - _, resources = plan_runner(internal_addresses=addresses) - assert [r['values']['name'] for r in resources] == ['one', 'two'] - assert set(r['values']['address_type'] for r in resources) == set( - ['INTERNAL']) - assert [r['values'].get('address') for r in resources] == ['10.0.0.2', None] - assert [r['values'].get('purpose') for r in resources - ] == ['SHARED_LOADBALANCER_VIP', None] - - -def test_psa_config(plan_runner): - psa_addresses = '{cloudsql-mysql={address="10.199.0.0", network="foobar", prefix_length = 24}}' - _, resources = plan_runner(psa_addresses=psa_addresses) - assert set(r['values']['purpose'] for r in resources) == set(['VPC_PEERING']) - assert set(r['values']['address'] for r in resources) == set(['10.199.0.0'])