diff --git a/blueprints/gke-serverless/README.md b/blueprints/gke/README.md similarity index 100% rename from blueprints/gke-serverless/README.md rename to blueprints/gke/README.md diff --git a/blueprints/gke-serverless/multitenant-fleet/README.md b/blueprints/gke/multitenant-fleet/README.md similarity index 100% rename from blueprints/gke-serverless/multitenant-fleet/README.md rename to blueprints/gke/multitenant-fleet/README.md diff --git a/blueprints/gke-serverless/multitenant-fleet/diagram.png b/blueprints/gke/multitenant-fleet/diagram.png similarity index 100% rename from blueprints/gke-serverless/multitenant-fleet/diagram.png rename to blueprints/gke/multitenant-fleet/diagram.png diff --git a/blueprints/gke-serverless/multitenant-fleet/gke-clusters.tf b/blueprints/gke/multitenant-fleet/gke-clusters.tf similarity index 100% rename from blueprints/gke-serverless/multitenant-fleet/gke-clusters.tf rename to blueprints/gke/multitenant-fleet/gke-clusters.tf diff --git a/blueprints/gke-serverless/multitenant-fleet/gke-hub.tf b/blueprints/gke/multitenant-fleet/gke-hub.tf similarity index 100% rename from blueprints/gke-serverless/multitenant-fleet/gke-hub.tf rename to blueprints/gke/multitenant-fleet/gke-hub.tf diff --git a/blueprints/gke-serverless/multitenant-fleet/gke-nodepools.tf b/blueprints/gke/multitenant-fleet/gke-nodepools.tf similarity index 100% rename from blueprints/gke-serverless/multitenant-fleet/gke-nodepools.tf rename to blueprints/gke/multitenant-fleet/gke-nodepools.tf diff --git a/blueprints/gke-serverless/multitenant-fleet/main.tf b/blueprints/gke/multitenant-fleet/main.tf similarity index 100% rename from blueprints/gke-serverless/multitenant-fleet/main.tf rename to blueprints/gke/multitenant-fleet/main.tf diff --git a/blueprints/gke-serverless/multitenant-fleet/outputs.tf b/blueprints/gke/multitenant-fleet/outputs.tf similarity index 100% rename from blueprints/gke-serverless/multitenant-fleet/outputs.tf rename to blueprints/gke/multitenant-fleet/outputs.tf diff --git a/blueprints/gke-serverless/multitenant-fleet/variables.tf b/blueprints/gke/multitenant-fleet/variables.tf similarity index 100% rename from blueprints/gke-serverless/multitenant-fleet/variables.tf rename to blueprints/gke/multitenant-fleet/variables.tf diff --git a/fast/stages/03-gke-multitenant/dev/main.tf b/fast/stages/03-gke-multitenant/dev/main.tf index a6ed3d47..db4fe092 100644 --- a/fast/stages/03-gke-multitenant/dev/main.tf +++ b/fast/stages/03-gke-multitenant/dev/main.tf @@ -17,7 +17,7 @@ # tfdoc:file:description GKE multitenant for development environment. module "gke-multitenant" { - source = "../../../../blueprints/gke-serverless/multitenant-fleet" + source = "../../../../blueprints/gke/multitenant-fleet" billing_account_id = var.billing_account.id folder_id = var.folder_ids.gke-dev project_id = "gke-clusters-0" diff --git a/tests/fast/conftest.py b/tests/fast/conftest.py index d96af5dc..976637eb 100644 --- a/tests/fast/conftest.py +++ b/tests/fast/conftest.py @@ -11,7 +11,6 @@ # 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. - "Shared fixtures" import inspect @@ -21,28 +20,39 @@ import types import pytest import tftest - BASEDIR = os.path.dirname(os.path.dirname(__file__)) @pytest.fixture(scope='session') def fast_e2e_plan_runner(_plan_runner): "Plan runner for end-to-end root module, returns modules and resources." + def run_plan(fixture_path=None, targets=None, refresh=True, include_bare_resources=False, compute_sums=True, **tf_vars): "Runs Terraform plan on a root module using defaults, returns data." plan = _plan_runner(fixture_path, targets=targets, refresh=refresh, **tf_vars) root_module = plan.root_module['child_modules'][0] - modules = { - m['address'].removeprefix(root_module['address'])[1:]: m['resources'] - for m in root_module['child_modules'] - } + + # Count all modules and resources up to 2 levels deep. We include + # the second level to account for wrapper modules used by stages 3 + modules = {} + for m in root_module['child_modules']: + key = m['address'].removeprefix(root_module['address'])[1:] + modules[key] = m.get('resources', []) + if m.get('child_modules'): + for m2 in m['child_modules']: + key2 = m2['address'].removeprefix(root_module['address'])[1:] + modules[key2] = m2.get('resources', []) + resources = [r for m in modules.values() for r in m] if include_bare_resources: bare_resources = root_module['resources'] resources.extend(bare_resources) if compute_sums: - return len(modules), len(resources), {k: len(v) for k, v in modules.items()} + return len(modules), len(resources), { + k: len(v) for k, v in modules.items() + } return modules, resources + return run_plan diff --git a/tests/fast/stages/s03_data_platform/fixture/__init__.py b/tests/fast/stages/s03_gke_multitenant/__init__.py similarity index 100% rename from tests/fast/stages/s03_data_platform/fixture/__init__.py rename to tests/fast/stages/s03_gke_multitenant/__init__.py diff --git a/tests/fast/stages/s03_gke_multitenant/fixture/main.tf b/tests/fast/stages/s03_gke_multitenant/fixture/main.tf new file mode 100644 index 00000000..2ee6e4f3 --- /dev/null +++ b/tests/fast/stages/s03_gke_multitenant/fixture/main.tf @@ -0,0 +1,65 @@ +/** + * 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. + */ + +# tfdoc: Data platform stage test + +module "stage" { + source = "../../../../../fast/stages/03-gke-multitenant/dev/" + automation = { + outputs_bucket = "test" + } + billing_account = { + id = "012345-67890A-BCDEF0", + organization_id = 123456 + } + clusters = { + mycluster = { + cluster_autoscaling = null + description = "My cluster" + dns_domain = null + location = "europe-west1" + labels = {} + net = { + master_range = "172.17.16.0/28" + pods = "pods" + services = "services" + subnet = "projects/my-host-project-id/regions/europe-west1/subnetworks/mycluster-subnet" + } + overrides = null + } + } + nodepools = { + mycluster = { + mynodepool = { + initial_node_count = 1 + node_count = 1 + node_type = "n2-standard-4" + overrides = null + spot = false + } + } + } + folder_ids = { + gke-dev = "folders/12345678" + } + host_project_ids = { + dev-spoke-0 = "fast-dev-net-spoke-0" + } + prefix = "fast" + vpc_self_links = { + dev-spoke-0 = "projects/fast-dev-net-spoke-0/global/networks/dev-spoke-0" + } +} diff --git a/tests/fast/stages/s03_gke_multitenant/test_plan.py b/tests/fast/stages/s03_gke_multitenant/test_plan.py new file mode 100644 index 00000000..6189f62e --- /dev/null +++ b/tests/fast/stages/s03_gke_multitenant/test_plan.py @@ -0,0 +1,20 @@ +# 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_counts(fast_e2e_plan_runner): + "Test stage." + num_modules, num_resources, _ = fast_e2e_plan_runner() + # TODO: to re-enable per-module resource count check print _, then test + assert num_modules > 0 and num_resources > 0