diff --git a/modules/service-directory/README.md b/modules/service-directory/README.md index d6961b418..191fa8a35 100644 --- a/modules/service-directory/README.md +++ b/modules/service-directory/README.md @@ -21,7 +21,7 @@ module "service-directory" { ] } } -# tftest modules=1 resources=2 +# tftest modules=1 resources=2 inventory=simple.yaml ``` ### Services with IAM and endpoints @@ -50,7 +50,7 @@ module "service-directory" { "one/second" = { address = "127.0.0.2", port = 80, metadata = {} } } } -# tftest modules=1 resources=5 +# tftest modules=1 resources=5 inventory=services.yaml ``` ### DNS based zone @@ -85,7 +85,7 @@ module "dns-sd" { client_networks = [var.vpc.self_link] service_directory_namespace = module.service-directory.id } -# tftest modules=2 resources=5 +# tftest modules=2 resources=5 inventory=dns.yaml ``` diff --git a/tests/modules/service_directory/__init__.py b/tests/modules/service_directory/__init__.py deleted file mode 100644 index 6d6d1266c..000000000 --- a/tests/modules/service_directory/__init__.py +++ /dev/null @@ -1,13 +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. diff --git a/tests/modules/service_directory/examples/dns.yaml b/tests/modules/service_directory/examples/dns.yaml new file mode 100644 index 000000000..57d49fbb3 --- /dev/null +++ b/tests/modules/service_directory/examples/dns.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.dns-sd.google_dns_managed_zone.non-public[0]: + dns_name: apps.example.org. + visibility: private + module.service-directory.google_service_directory_endpoint.default["app1/one"]: + address: 127.0.0.1 + endpoint_id: one + port: 80 + module.service-directory.google_service_directory_namespace.default: + location: europe-west1 + namespace_id: apps + project: my-project + module.service-directory.google_service_directory_service.default["app1"]: + service_id: app1 + +counts: + google_dns_managed_zone: 1 + google_service_directory_endpoint: 1 + google_service_directory_namespace: 1 + google_service_directory_namespace_iam_binding: 1 + google_service_directory_service: 1 diff --git a/tests/modules/service_directory/examples/services.yaml b/tests/modules/service_directory/examples/services.yaml new file mode 100644 index 000000000..72b776570 --- /dev/null +++ b/tests/modules/service_directory/examples/services.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.service-directory.google_service_directory_endpoint.default["one/first"]: + address: 127.0.0.1 + endpoint_id: first + port: 80 + module.service-directory.google_service_directory_endpoint.default["one/second"]: + address: 127.0.0.2 + endpoint_id: second + port: 80 + module.service-directory.google_service_directory_namespace.default: + location: europe-west1 + namespace_id: sd-1 + project: my-project + module.service-directory.google_service_directory_service.default["one"]: + metadata: null + service_id: one + +counts: + google_service_directory_endpoint: 2 + google_service_directory_namespace: 1 + google_service_directory_service: 1 + google_service_directory_service_iam_binding: 1 diff --git a/tests/modules/service_directory/examples/simple.yaml b/tests/modules/service_directory/examples/simple.yaml new file mode 100644 index 000000000..b14a61ea9 --- /dev/null +++ b/tests/modules/service_directory/examples/simple.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.service-directory.google_service_directory_namespace.default: + labels: null + location: europe-west1 + namespace_id: sd-1 + project: my-project + module.service-directory.google_service_directory_namespace_iam_binding.default["roles/servicedirectory.editor"]: + condition: [] + members: + - serviceAccount:namespace-editor@example.com + role: roles/servicedirectory.editor + +counts: + google_service_directory_namespace: 1 + google_service_directory_namespace_iam_binding: 1 + modules: 1 + resources: 2 + +outputs: {} diff --git a/tests/modules/service_directory/fixture/main.tf b/tests/modules/service_directory/fixture/main.tf deleted file mode 100644 index 007947789..000000000 --- a/tests/modules/service_directory/fixture/main.tf +++ /dev/null @@ -1,55 +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/service-directory" - project_id = "my-project" - location = "europe-west1" - name = "ns-test" - iam = { - "roles/servicedirectory.viewer" = [ - "serviceAccount:service-editor.example.com" - ] - } - services = { - srv-one = { - endpoints = ["alpha", "beta"] - metadata = null - } - srv-two = { - endpoints = ["alpha"] - metadata = null - } - } - service_iam = { - srv-one = { - "roles/servicedirectory.editor" = [ - "serviceAccount:service-editor.example.com" - ] - } - srv-two = { - "roles/servicedirectory.admin" = [ - "serviceAccount:service-editor.example.com" - ] - } - } - endpoint_config = { - "srv-one/alpha" = { address = "127.0.0.1", port = 80, metadata = {} } - "srv-one/beta" = { address = "127.0.0.2", port = 80, metadata = {} } - "srv-two/alpha" = { address = "127.0.0.3", port = 80, metadata = {} } - } - labels = var.labels -} diff --git a/tests/modules/service_directory/fixture/variables.tf b/tests/modules/service_directory/fixture/variables.tf deleted file mode 100644 index 8371c619f..000000000 --- a/tests/modules/service_directory/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 "labels" { - type = map(string) - default = {} -} diff --git a/tests/modules/service_directory/test_plan.py b/tests/modules/service_directory/test_plan.py deleted file mode 100644 index 7c218dae4..000000000 --- a/tests/modules/service_directory/test_plan.py +++ /dev/null @@ -1,52 +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) == 9 - - -def test_iam(resources): - "Test IAM binding resources." - bindings = [r['values'] for r in resources if r['type'] - == 'google_service_directory_namespace_iam_binding'] - assert len(bindings) == 1 - assert bindings[0]['role'] == 'roles/servicedirectory.viewer' - - -def test_services(resources): - "Test service resources." - services = [r['values'] for r in resources if r['type'] - == 'google_service_directory_service'] - assert len(services) == 2 - assert set(s['service_id'] for s in services) == set(['srv-one', 'srv-two']) - - -def test_service_iam(resources): - "Test service IAM binding resources." - bindings = [r['values'] for r in resources if r['type'] - == 'google_service_directory_service_iam_binding'] - assert len(bindings) == 2 - assert set(b['role'] for b in bindings) == set([ - 'roles/servicedirectory.admin', 'roles/servicedirectory.editor' - ])