diff --git a/modules/source-repository/README.md b/modules/source-repository/README.md index 389de9e9..b84d4fe2 100644 --- a/modules/source-repository/README.md +++ b/modules/source-repository/README.md @@ -15,7 +15,7 @@ module "repo" { "roles/source.reader" = ["user:foo@example.com"] } } -# tftest modules=1 resources=2 +# tftest modules=1 resources=2 inventory=simple.yaml ``` ### Repository with Cloud Build trigger @@ -41,7 +41,7 @@ module "repo" { } } } -# tftest modules=1 resources=2 +# tftest modules=1 resources=2 inventory=trigger.yaml ``` diff --git a/tests/modules/source_repository/__init__.py b/tests/modules/source_repository/examples/simple.yaml similarity index 53% rename from tests/modules/source_repository/__init__.py rename to tests/modules/source_repository/examples/simple.yaml index 6d6d1266..41d6aea6 100644 --- a/tests/modules/source_repository/__init__.py +++ b/tests/modules/source_repository/examples/simple.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,20 @@ # 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.repo.google_sourcerepo_repository.default: + name: my-repo + project: my-project + pubsub_configs: [] + module.repo.google_sourcerepo_repository_iam_binding.authoritative["roles/source.reader"]: + condition: [] + members: + - user:foo@example.com + project: my-project + repository: my-repo + role: roles/source.reader + +counts: + google_sourcerepo_repository: 1 + google_sourcerepo_repository_iam_binding: 1 diff --git a/tests/modules/source_repository/examples/trigger.yaml b/tests/modules/source_repository/examples/trigger.yaml new file mode 100644 index 00000000..22a10640 --- /dev/null +++ b/tests/modules/source_repository/examples/trigger.yaml @@ -0,0 +1,40 @@ +# 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.repo.google_cloudbuild_trigger.default["foo"]: + filename: ci/workflow-foo.yaml + included_files: + - '**/*tf' + location: global + name: foo + project: my-project + substitutions: + BAR: '1' + trigger_template: + - branch_name: main + commit_sha: null + dir: null + invert_regex: null + repo_name: my-repo + tag_name: null + webhook_config: [] + module.repo.google_sourcerepo_repository.default: + name: my-repo + project: my-project + pubsub_configs: [] + +counts: + google_cloudbuild_trigger: 1 + google_sourcerepo_repository: 1 diff --git a/tests/modules/source_repository/fixture/main.tf b/tests/modules/source_repository/fixture/main.tf deleted file mode 100644 index 122556ba..00000000 --- a/tests/modules/source_repository/fixture/main.tf +++ /dev/null @@ -1,65 +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 "group_iam" { - type = any - default = {} -} - -variable "iam" { - type = any - default = {} - nullable = false -} - -variable "iam_additive" { - type = any - default = {} - nullable = false -} - -variable "iam_additive_members" { - type = any - default = {} -} - -variable "name" { - description = "Repository name." - type = string - default = "test" -} - -variable "project_id" { - description = "Project used for resources." - type = string - default = "test" -} - -variable "triggers" { - type = any - default = null -} - -module "test" { - source = "../../../../modules/source-repository" - project_id = var.project_id - name = var.name - group_iam = var.group_iam - iam = var.iam - iam_additive = var.iam_additive - iam_additive_members = var.iam_additive_members - triggers = var.triggers -} diff --git a/tests/modules/source_repository/test_plan.py b/tests/modules/source_repository/test_plan.py deleted file mode 100644 index 83b27ee2..00000000 --- a/tests/modules/source_repository/test_plan.py +++ /dev/null @@ -1,60 +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_resource_count(plan_runner): - 'Test number of resources created.' - _, resources = plan_runner() - assert len(resources) == 1 - - -def test_iam(plan_runner): - 'Test IAM binding resources.' - group_iam = '{"fooers@example.org"=["roles/owner"]}' - iam = '''{ - "roles/editor" = ["user:a@example.org", "user:b@example.org"] - "roles/owner" = ["user:c@example.org"] - }''' - _, resources = plan_runner(group_iam=group_iam, iam=iam) - bindings = { - r['values']['role']: r['values']['members'] - for r in resources - if r['type'] == 'google_sourcerepo_repository_iam_binding' - } - assert bindings == { - 'roles/editor': ['user:a@example.org', 'user:b@example.org'], - 'roles/owner': ['group:fooers@example.org', 'user:c@example.org'] - } - - -def test_triggers(plan_runner): - 'Test trigger resources.' - triggers = '''{ - foo = { - filename = "ci/foo.yaml" - included_files = ["**/*yaml"] - service_account = null - substitutions = null - template = { - branch_name = null - project_id = null - tag_name = "foo" - } - } - }''' - _, resources = plan_runner(triggers=triggers) - triggers = [ - r['index'] for r in resources if r['type'] == 'google_cloudbuild_trigger' - ] - assert triggers == ['foo'] \ No newline at end of file