From 461f7780c225e084a757d0029438b79faf482a5f Mon Sep 17 00:00:00 2001 From: Julio Castillo Date: Fri, 14 Apr 2023 17:44:37 +0200 Subject: [PATCH] Migrate bigtable-instance tests --- modules/bigtable-instance/README.md | 14 ++--- modules/container-registry/README.md | 2 +- .../examples/autoscaling1.yaml | 29 +++++++++++ .../examples/autoscaling2.yaml | 30 +++++++++++ .../bigtable_instance/examples/columns.yaml | 38 ++++++++++++++ .../bigtable_instance/examples/gc.yaml | 29 +++++++++++ .../examples/replication.yaml | 36 +++++++++++++ .../bigtable_instance/examples/simple.yaml | 52 +++++++++++++++++++ .../{__init__.py => examples/static.yaml} | 16 +++++- .../modules/bigtable_instance/fixture/main.tf | 36 ------------- .../bigtable_instance/fixture/variables.tf | 20 ------- tests/modules/bigtable_instance/test_plan.py | 42 --------------- 12 files changed, 237 insertions(+), 107 deletions(-) create mode 100644 tests/modules/bigtable_instance/examples/autoscaling1.yaml create mode 100644 tests/modules/bigtable_instance/examples/autoscaling2.yaml create mode 100644 tests/modules/bigtable_instance/examples/columns.yaml create mode 100644 tests/modules/bigtable_instance/examples/gc.yaml create mode 100644 tests/modules/bigtable_instance/examples/replication.yaml create mode 100644 tests/modules/bigtable_instance/examples/simple.yaml rename tests/modules/bigtable_instance/{__init__.py => examples/static.yaml} (63%) delete mode 100644 tests/modules/bigtable_instance/fixture/main.tf delete mode 100644 tests/modules/bigtable_instance/fixture/variables.tf delete mode 100644 tests/modules/bigtable_instance/test_plan.py diff --git a/modules/bigtable-instance/README.md b/modules/bigtable-instance/README.md index 39e0bc53..06c85cca 100644 --- a/modules/bigtable-instance/README.md +++ b/modules/bigtable-instance/README.md @@ -32,7 +32,7 @@ module "bigtable-instance" { "roles/bigtable.user" = ["user:viewer@testdomain.com"] } } -# tftest modules=1 resources=4 +# tftest modules=1 resources=4 inventory=simple.yaml ``` ### Instance with tables and column families @@ -65,7 +65,7 @@ module "bigtable-instance" { } } } -# tftest modules=1 resources=4 +# tftest modules=1 resources=4 inventory=columns.yaml ``` ### Instance with replication enabled @@ -88,7 +88,7 @@ module "bigtable-instance" { } } } -# tftest modules=1 resources=1 +# tftest modules=1 resources=1 inventory=replication.yaml ``` ### Instance with garbage collection policy @@ -118,7 +118,7 @@ module "bigtable-instance" { } } } -# tftest modules=1 resources=3 +# tftest modules=1 resources=3 inventory=gc.yaml ``` ### Instance with default garbage collection policy @@ -172,7 +172,7 @@ module "bigtable-instance" { } } } -# tftest modules=1 resources=1 +# tftest modules=1 resources=1 inventory=static.yaml ``` ### Instance with autoscaling (based on CPU only) @@ -198,7 +198,7 @@ module "bigtable-instance" { } -# tftest modules=1 resources=1 +# tftest modules=1 resources=1 inventory=autoscaling1.yaml ``` ### Instance with autoscaling (based on CPU and/or storage) @@ -222,7 +222,7 @@ module "bigtable-instance" { } } } -# tftest modules=1 resources=1 +# tftest modules=1 resources=1 inventory=autoscaling2.yaml ``` diff --git a/modules/container-registry/README.md b/modules/container-registry/README.md index bf049970..7e7f42f4 100644 --- a/modules/container-registry/README.md +++ b/modules/container-registry/README.md @@ -13,7 +13,7 @@ module "container_registry" { "roles/storage.admin" = ["group:cicd@example.com"] } } -# tftest modules=1 resources=2 +# tftest modules=1 resources=2 inventory=simple.yaml ``` diff --git a/tests/modules/bigtable_instance/examples/autoscaling1.yaml b/tests/modules/bigtable_instance/examples/autoscaling1.yaml new file mode 100644 index 00000000..1c0854f7 --- /dev/null +++ b/tests/modules/bigtable_instance/examples/autoscaling1.yaml @@ -0,0 +1,29 @@ +# 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.bigtable-instance.google_bigtable_instance.default: + cluster: + - autoscaling_config: + - cpu_target: 70 + max_nodes: 7 + min_nodes: 3 + cluster_id: my-cluster + storage_type: SSD + zone: europe-southwest1-b + name: instance + project: my-project + +counts: + google_bigtable_instance: 1 diff --git a/tests/modules/bigtable_instance/examples/autoscaling2.yaml b/tests/modules/bigtable_instance/examples/autoscaling2.yaml new file mode 100644 index 00000000..4179e84d --- /dev/null +++ b/tests/modules/bigtable_instance/examples/autoscaling2.yaml @@ -0,0 +1,30 @@ +# 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.bigtable-instance.google_bigtable_instance.default: + cluster: + - autoscaling_config: + - cpu_target: 70 + max_nodes: 7 + min_nodes: 3 + storage_target: 4096 + cluster_id: my-cluster + storage_type: SSD + zone: europe-southwest1-a + name: instance + project: my-project + +counts: + google_bigtable_instance: 1 diff --git a/tests/modules/bigtable_instance/examples/columns.yaml b/tests/modules/bigtable_instance/examples/columns.yaml new file mode 100644 index 00000000..0c9b6655 --- /dev/null +++ b/tests/modules/bigtable_instance/examples/columns.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.bigtable-instance.google_bigtable_table.default["test2"]: + column_family: + - family: cf1 + - family: cf2 + - family: cf3 + instance_name: instance + name: test2 + project: my-project + split_keys: + - a + - b + - c + module.bigtable-instance.google_bigtable_table.default["test3"]: + column_family: + - family: cf1 + instance_name: instance + name: test3 + project: my-project + split_keys: [] + +counts: + google_bigtable_instance: 1 + google_bigtable_table: 3 diff --git a/tests/modules/bigtable_instance/examples/gc.yaml b/tests/modules/bigtable_instance/examples/gc.yaml new file mode 100644 index 00000000..47955dcc --- /dev/null +++ b/tests/modules/bigtable_instance/examples/gc.yaml @@ -0,0 +1,29 @@ +# 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.bigtable-instance.google_bigtable_gc_policy.default["0"]: + column_family: cf1 + deletion_policy: ABANDON + gc_rules: null + instance_name: instance + max_age: + - duration: 18h + max_version: [] + mode: null + project: my-project + table: test1 + +counts: + google_bigtable_gc_policy: 1 diff --git a/tests/modules/bigtable_instance/examples/replication.yaml b/tests/modules/bigtable_instance/examples/replication.yaml new file mode 100644 index 00000000..3eeb2737 --- /dev/null +++ b/tests/modules/bigtable_instance/examples/replication.yaml @@ -0,0 +1,36 @@ +# 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.bigtable-instance.google_bigtable_instance.default: + cluster: + - autoscaling_config: [] + cluster_id: first-cluster + storage_type: SSD + zone: europe-west1-b + - autoscaling_config: [] + cluster_id: second-cluster + storage_type: SSD + zone: europe-southwest1-a + - autoscaling_config: [] + cluster_id: third-cluster + storage_type: SSD + zone: us-central1-b + deletion_protection: true + instance_type: PRODUCTION + name: instance + project: my-project + +counts: + google_bigtable_instance: 1 diff --git a/tests/modules/bigtable_instance/examples/simple.yaml b/tests/modules/bigtable_instance/examples/simple.yaml new file mode 100644 index 00000000..23cc9f8b --- /dev/null +++ b/tests/modules/bigtable_instance/examples/simple.yaml @@ -0,0 +1,52 @@ +# 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.bigtable-instance.google_bigtable_instance.default: + cluster: + - autoscaling_config: [] + cluster_id: my-cluster + storage_type: SSD + zone: europe-west1-b + deletion_protection: true + instance_type: PRODUCTION + name: instance + project: my-project + module.bigtable-instance.google_bigtable_instance_iam_binding.default["roles/bigtable.user"]: + condition: [] + instance: instance + members: + - user:viewer@testdomain.com + project: my-project + role: roles/bigtable.user + module.bigtable-instance.google_bigtable_table.default["test1"]: + column_family: [] + instance_name: instance + name: test1 + project: my-project + split_keys: [] + module.bigtable-instance.google_bigtable_table.default["test2"]: + column_family: [] + instance_name: instance + name: test2 + project: my-project + split_keys: + - a + - b + - c + +counts: + google_bigtable_instance: 1 + google_bigtable_instance_iam_binding: 1 + google_bigtable_table: 2 diff --git a/tests/modules/bigtable_instance/__init__.py b/tests/modules/bigtable_instance/examples/static.yaml similarity index 63% rename from tests/modules/bigtable_instance/__init__.py rename to tests/modules/bigtable_instance/examples/static.yaml index 6d6d1266..21ea0f0c 100644 --- a/tests/modules/bigtable_instance/__init__.py +++ b/tests/modules/bigtable_instance/examples/static.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,17 @@ # 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.bigtable-instance.google_bigtable_instance.default: + cluster: + - autoscaling_config: [] + cluster_id: my-cluster + num_nodes: 5 + storage_type: SSD + zone: europe-west1-b + name: instance + project: my-project + +counts: + google_bigtable_instance: 1 diff --git a/tests/modules/bigtable_instance/fixture/main.tf b/tests/modules/bigtable_instance/fixture/main.tf deleted file mode 100644 index 4fa83ce2..00000000 --- a/tests/modules/bigtable_instance/fixture/main.tf +++ /dev/null @@ -1,36 +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/bigtable-instance" - project_id = "my-project" - name = "test" - iam = { - "roles/bigtable.user" = ["user:me@example.com"] - } - tables = { - test-1 = {}, - test-2 = { - split_keys = ["a", "b", "c"] - } - - } - clusters = { - test = { - zone = var.zone - } - } -} diff --git a/tests/modules/bigtable_instance/fixture/variables.tf b/tests/modules/bigtable_instance/fixture/variables.tf deleted file mode 100644 index c8a4b5da..00000000 --- a/tests/modules/bigtable_instance/fixture/variables.tf +++ /dev/null @@ -1,20 +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 "zone" { - type = string - default = "europe-west1-b" -} diff --git a/tests/modules/bigtable_instance/test_plan.py b/tests/modules/bigtable_instance/test_plan.py deleted file mode 100644 index 95368c01..00000000 --- a/tests/modules/bigtable_instance/test_plan.py +++ /dev/null @@ -1,42 +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. - -import pytest - - -@pytest.fixture -def resources(plan_runner): - _, resources = plan_runner() - return resources - - -def test_resource_count(resources): - "Test number of resources created." - assert len(resources) == 4 - - -def test_iam(resources): - "Test IAM binding resources." - bindings = [r['values'] for r in resources if r['type'] - == 'google_bigtable_instance_iam_binding'] - assert len(bindings) == 1 - assert bindings[0]['role'] == 'roles/bigtable.user' - - -def test_tables(resources): - "Test table resources." - subs = [r['values'] for r in resources if r['type'] - == 'google_bigtable_table'] - assert len(subs) == 2 - assert set(s['name'] for s in subs) == set(['test-1', 'test-2'])