diff --git a/modules/logging-bucket/README.md b/modules/logging-bucket/README.md index 7af82ccb..0cc3380f 100644 --- a/modules/logging-bucket/README.md +++ b/modules/logging-bucket/README.md @@ -17,7 +17,7 @@ module "bucket" { parent = var.project_id id = "mybucket" } -# tftest modules=1 resources=1 +# tftest modules=1 resources=1 inventory=project.yaml ``` @@ -37,10 +37,31 @@ module "bucket-default" { id = "_Default" retention = 10 } -# tftest modules=2 resources=2 +# tftest modules=2 resources=2 inventory=retention.yaml ``` + +### Organization and billing account buckets +```hcl +module "bucket-organization" { + source = "./fabric/modules/logging-bucket" + parent_type = "organization" + parent = "organizations/012345" + id = "mybucket" +} + +module "bucket-billing-account" { + source = "./fabric/modules/logging-bucket" + parent_type = "billing_account" + parent = "012345" + id = "mybucket" +} +# tftest modules=2 resources=2 inventory=org-ba.yaml +``` + + + ## Variables | name | description | type | required | default | diff --git a/tests/modules/logging_bucket/examples/org-ba.yaml b/tests/modules/logging_bucket/examples/org-ba.yaml new file mode 100644 index 00000000..21ef2c4c --- /dev/null +++ b/tests/modules/logging_bucket/examples/org-ba.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.bucket-billing-account.google_logging_billing_account_bucket_config.bucket[0]: + billing_account: '012345' + bucket_id: mybucket + location: global + retention_days: 30 + module.bucket-organization.google_logging_organization_bucket_config.bucket[0]: + bucket_id: mybucket + location: global + organization: organizations/012345 + retention_days: 30 + +counts: + google_logging_billing_account_bucket_config: 1 + google_logging_organization_bucket_config: 1 diff --git a/tests/modules/logging_bucket/__init__.py b/tests/modules/logging_bucket/examples/project.yaml similarity index 69% rename from tests/modules/logging_bucket/__init__.py rename to tests/modules/logging_bucket/examples/project.yaml index 6d6d1266..d7bbcd6c 100644 --- a/tests/modules/logging_bucket/__init__.py +++ b/tests/modules/logging_bucket/examples/project.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,13 @@ # 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.bucket.google_logging_project_bucket_config.bucket[0]: + bucket_id: mybucket + location: global + project: project-id + retention_days: 30 + +counts: + google_logging_project_bucket_config: 1 diff --git a/tests/modules/logging_bucket/examples/retention.yaml b/tests/modules/logging_bucket/examples/retention.yaml new file mode 100644 index 00000000..97de4b1b --- /dev/null +++ b/tests/modules/logging_bucket/examples/retention.yaml @@ -0,0 +1,26 @@ +# 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.bucket-default.google_logging_folder_bucket_config.bucket[0]: + bucket_id: _Default + location: global + retention_days: 10 + module.folder.google_folder.folder[0]: + display_name: my folder + parent: folders/657104291943 + +counts: + google_folder: 1 + google_logging_folder_bucket_config: 1 diff --git a/tests/modules/logging_bucket/fixture/main.tf b/tests/modules/logging_bucket/fixture/main.tf deleted file mode 100644 index 25ddc229..00000000 --- a/tests/modules/logging_bucket/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/logging-bucket" - parent_type = var.parent_type - parent = var.parent - id = var.id - retention = var.retention - location = var.location -} diff --git a/tests/modules/logging_bucket/fixture/variables.tf b/tests/modules/logging_bucket/fixture/variables.tf deleted file mode 100644 index bfb80a18..00000000 --- a/tests/modules/logging_bucket/fixture/variables.tf +++ /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. - */ - -variable "parent" { - type = string -} - -variable "parent_type" { - type = string - validation { - condition = contains(["project", "folder", "organization", "billing_account"], var.parent_type) - error_message = "Parent type must be project, folder, organization or billing_account." - } -} - -variable "location" { - type = string - default = "global" -} - -variable "id" { - type = string - default = "mybucket" -} - -variable "retention" { - type = number - default = 30 -} diff --git a/tests/modules/logging_bucket/test_plan.py b/tests/modules/logging_bucket/test_plan.py deleted file mode 100644 index 97e9c8c5..00000000 --- a/tests/modules/logging_bucket/test_plan.py +++ /dev/null @@ -1,79 +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_project_logging_bucket(plan_runner): - "Test project logging bucket." - _, resources = plan_runner(parent_type="project", parent="myproject") - assert len(resources) == 1 - - resource = resources[0] - assert resource["type"] == "google_logging_project_bucket_config" - assert resource["values"] == { - "bucket_id": "mybucket", - "cmek_settings": [], - "enable_analytics": None, - "project": "myproject", - "location": "global", - "retention_days": 30, - } - - -def test_folder_logging_bucket(plan_runner): - "Test project logging bucket." - _, resources = plan_runner(parent_type="folder", parent="folders/0123456789") - assert len(resources) == 1 - - resource = resources[0] - assert resource["type"] == "google_logging_folder_bucket_config" - assert resource["values"] == { - "bucket_id": "mybucket", - "cmek_settings": [], - "folder": "folders/0123456789", - "location": "global", - "retention_days": 30, - } - - -def test_organization_logging_bucket(plan_runner): - "Test project logging bucket." - _, resources = plan_runner(parent_type="organization", - parent="organizations/0123456789") - assert len(resources) == 1 - - resource = resources[0] - assert resource["type"] == "google_logging_organization_bucket_config" - assert resource["values"] == { - "bucket_id": "mybucket", - "cmek_settings": [], - "organization": "organizations/0123456789", - "location": "global", - "retention_days": 30, - } - - -def test_billing_account_logging_bucket(plan_runner): - "Test project logging bucket." - _, resources = plan_runner(parent_type="billing_account", parent="0123456789") - assert len(resources) == 1 - - resource = resources[0] - assert resource["type"] == "google_logging_billing_account_bucket_config" - assert resource["values"] == { - "bucket_id": "mybucket", - "cmek_settings": [], - "billing_account": "0123456789", - "location": "global", - "retention_days": 30, - }