diff --git a/modules/billing-budget/README.md b/modules/billing-budget/README.md index d995c0e0a..3db5faa32 100644 --- a/modules/billing-budget/README.md +++ b/modules/billing-budget/README.md @@ -32,7 +32,7 @@ module "budget" { emails = ["user@example.com"] } } -# tftest modules=1 resources=2 +# tftest modules=1 resources=2 inventory=email.yaml ``` ### Pubsub notification @@ -59,7 +59,7 @@ module "pubsub" { name = "budget-topic" } -# tftest modules=2 resources=2 +# tftest modules=2 resources=2 inventory=pubsub.yaml ``` diff --git a/tests/modules/billing_budget/__init__.py b/tests/modules/billing_budget/__init__.py deleted file mode 100644 index 6d6d1266c..000000000 --- a/tests/modules/billing_budget/__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/billing_budget/examples/email.yaml b/tests/modules/billing_budget/examples/email.yaml new file mode 100644 index 000000000..87c088268 --- /dev/null +++ b/tests/modules/billing_budget/examples/email.yaml @@ -0,0 +1,58 @@ +# 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.budget.google_billing_budget.budget: + all_updates_rule: + - disable_default_iam_recipients: false + pubsub_topic: null + schema_version: '1.0' + amount: + - last_period_amount: null + specified_amount: + - nanos: null + units: '100' + billing_account: 123456-123456-123456 + budget_filter: + - calendar_period: null + credit_types_treatment: INCLUDE_ALL_CREDITS + custom_period: [] + projects: + - projects/123456789000 + - projects/123456789111 + display_name: $100 budget + threshold_rules: + - spend_basis: CURRENT_SPEND + threshold_percent: 0.5 + - spend_basis: CURRENT_SPEND + threshold_percent: 0.75 + - spend_basis: CURRENT_SPEND + threshold_percent: 1 + - spend_basis: FORECASTED_SPEND + threshold_percent: 1 + module.budget.google_monitoring_notification_channel.email_channels["user@example.com"]: + description: null + display_name: $100 budget budget email notification (user@example.com) + enabled: true + force_delete: false + labels: + email_address: user@example.com + project: my-project + sensitive_labels: [] + type: email + user_labels: null + +counts: + google_billing_budget: 1 + google_monitoring_notification_channel: 1 diff --git a/tests/modules/billing_budget/examples/pubsub.yaml b/tests/modules/billing_budget/examples/pubsub.yaml new file mode 100644 index 000000000..8d09d8a2d --- /dev/null +++ b/tests/modules/billing_budget/examples/pubsub.yaml @@ -0,0 +1,39 @@ +# 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.budget.google_billing_budget.budget: + all_updates_rule: + - disable_default_iam_recipients: false + monitoring_notification_channels: [] + pubsub_topic: projects/project-id/topics/budget-topic + schema_version: '1.0' + amount: + - last_period_amount: true + specified_amount: [] + billing_account: 123456-123456-123456 + budget_filter: + - calendar_period: null + credit_types_treatment: INCLUDE_ALL_CREDITS + custom_period: [] + projects: null + display_name: previous period budget + threshold_rules: + - spend_basis: CURRENT_SPEND + threshold_percent: 1 + timeouts: null + +counts: + google_billing_budget: 1 + google_pubsub_topic: 1 diff --git a/tests/modules/billing_budget/fixture/main.tf b/tests/modules/billing_budget/fixture/main.tf deleted file mode 100644 index 25cd25f57..000000000 --- a/tests/modules/billing_budget/fixture/main.tf +++ /dev/null @@ -1,30 +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 "budget" { - source = "../../../../modules/billing-budget" - billing_account = "123456-123456-123456" - name = "my budget" - projects = var.projects - services = var.services - notify_default_recipients = var.notify_default_recipients - amount = var.amount - credit_treatment = var.credit_treatment - pubsub_topic = var.pubsub_topic - notification_channels = var.notification_channels - thresholds = var.thresholds - email_recipients = var.email_recipients -} diff --git a/tests/modules/billing_budget/fixture/variables.tf b/tests/modules/billing_budget/fixture/variables.tf deleted file mode 100644 index 0cbcb447f..000000000 --- a/tests/modules/billing_budget/fixture/variables.tf +++ /dev/null @@ -1,69 +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 "amount" { - type = number - default = 0 -} - -variable "credit_treatment" { - type = string - default = "INCLUDE_ALL_CREDITS" -} - -variable "email_recipients" { - type = object({ - project_id = string - emails = list(string) - }) - default = null -} - -variable "notification_channels" { - type = list(string) - default = null -} - -variable "notify_default_recipients" { - type = bool - default = false -} - -variable "projects" { - type = list(string) - default = null -} - -variable "pubsub_topic" { - type = string - default = null -} - -variable "services" { - type = list(string) - default = null -} - -variable "thresholds" { - type = object({ - current = list(number) - forecasted = list(number) - }) - default = { - current = [0.5, 1.0] - forecasted = [1.0] - } -} diff --git a/tests/modules/billing_budget/test_plan.py b/tests/modules/billing_budget/test_plan.py deleted file mode 100644 index 6907ab065..000000000 --- a/tests/modules/billing_budget/test_plan.py +++ /dev/null @@ -1,63 +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_pubsub(plan_runner): - "Test number of resources created." - _, resources = plan_runner(pubsub_topic='topic') - assert len(resources) == 1 - resource = resources[0] - assert resource['values']['all_updates_rule'] == [ - {'disable_default_iam_recipients': False, - 'monitoring_notification_channels': [], - 'pubsub_topic': 'topic', - 'schema_version': '1.0'} - ] - - -def test_channel(plan_runner): - _, resources = plan_runner(notification_channels='["channel"]') - assert len(resources) == 1 - resource = resources[0] - assert resource['values']['all_updates_rule'] == [ - {'disable_default_iam_recipients': True, - 'monitoring_notification_channels': ['channel'], - 'pubsub_topic': None, - 'schema_version': '1.0'} - ] - - -def test_emails(plan_runner): - email_recipients = '{project_id = "project", emails = ["a@b.com", "c@d.com"]}' - _, resources = plan_runner(email_recipients=email_recipients) - assert len(resources) == 3 - - -def test_absolute_amount(plan_runner): - "Test absolute amount budget." - _, resources = plan_runner(pubsub_topic='topic', amount="100") - assert len(resources) == 1 - resource = resources[0] - - amount = resource['values']['amount'][0] - assert amount['last_period_amount'] is None - assert amount['specified_amount'] == [{'nanos': None, 'units': '100'}] - - assert resource['values']['threshold_rules'] == [ - {'spend_basis': 'CURRENT_SPEND', - 'threshold_percent': 0.5}, - {'spend_basis': 'CURRENT_SPEND', - 'threshold_percent': 1}, - {'spend_basis': 'FORECASTED_SPEND', - 'threshold_percent': 1} - ]