Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ module "budget" {
create_budget = var.budget_amount != null

projects = [module.project-factory.project_id]
project_numbers = [module.project-factory.project_number]
billing_account = var.billing_account
amount = var.budget_amount
alert_spent_percents = var.budget_alert_spent_percents
Expand Down
4 changes: 2 additions & 2 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,6 @@ spec:
- serviceusage.googleapis.com
providerVersions:
- source: hashicorp/google
version: ">= 5.41, < 7"
version: ">= 5.41, < 8"
- source: hashicorp/google-beta
version: ">= 5.41, < 7"
version: ">= 5.41, < 8"
1 change: 1 addition & 0 deletions modules/budget/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module "project_myproject" {
| display\_name | The display name of the budget. If not set defaults to `Budget For <projects[0]|All Projects>` | `string` | `null` | no |
| labels | A single label and value pair specifying that usage from only this set of labeled resources should be included in the budget. | `map(string)` | `{}` | no |
| monitoring\_notification\_channels | A list of monitoring notification channels in the form `[projects/{project_id}/notificationChannels/{channel_id}]`. A maximum of 5 channels are allowed. | `list(string)` | `[]` | no |
| project\_numbers | The project numbers to include in this budget. If empty project numbers will be determined automatically from the projects variable | `list(string)` | `[]` | no |
| projects | The project ids to include in this budget. If empty budget will include all projects | `list(string)` | n/a | yes |
| services | A list of services ids to be included in the budget. If omitted, all services will be included in the budget. Service ids can be found at https://cloud.google.com/skus/ | `list(string)` | `null` | no |

Expand Down
11 changes: 7 additions & 4 deletions modules/budget/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@
*/

locals {
project_name = length(var.projects) == 0 ? "All Projects" : var.projects[0]
project_name = length(var.project_numbers) == 0 && length(var.projects) == 0 ? "All Projects" : try(var.projects[0], var.project_numbers[0])
display_name = var.display_name == null ? "Budget For ${local.project_name}" : var.display_name
all_updates_rule = var.alert_pubsub_topic == null && length(var.monitoring_notification_channels) == 0 ? [] : ["1"]
custom_period = var.calendar_period == "CUSTOM" ? [1] : []
start_date = length(local.custom_period) != 0 ? split("-", var.custom_period_start_date) : null
end_date = length(local.custom_period) != 0 ? split("-", var.custom_period_end_date) : null

projects = length(var.projects) == 0 ? null : [
projects = length(var.project_numbers) > 0 ? [
for project_number in var.project_numbers :
"projects/${project_number}"
] : length(var.projects) > 0 ? [
for project in data.google_project.project :
"projects/${project.number}"
]
] : null
services = var.services == null ? null : [
for id in var.services :
"services/${id}"
Expand All @@ -34,7 +37,7 @@ locals {

data "google_project" "project" {
depends_on = [var.projects]
count = var.create_budget ? length(var.projects) : 0
count = var.create_budget && length(var.project_numbers) == 0 ? length(var.projects) : 0
project_id = element(var.projects, count.index)
}

Expand Down
6 changes: 5 additions & 1 deletion modules/budget/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ spec:
description: The project ids to include in this budget. If empty budget will include all projects
varType: list(string)
required: true
- name: project_numbers
description: The project numbers to include in this budget. If empty project numbers will be determined automatically from the projects variable
varType: list(string)
defaultValue: []
- name: amount
description: The amount to use as the budget
varType: number
Expand Down Expand Up @@ -145,4 +149,4 @@ spec:
- serviceusage.googleapis.com
providerVersions:
- source: hashicorp/google
version: ">= 4.28, < 7"
version: ">= 4.28, < 8"
10 changes: 10 additions & 0 deletions modules/budget/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ variable "projects" {
type = list(string)
}

variable "project_numbers" {
description = "The project numbers to include in this budget. If empty project numbers will be determined automatically from the projects variable"
type = list(string)
default = []
validation {
condition = length(var.project_numbers) == 0 || length(var.project_numbers) == length(var.projects)
error_message = "Length of project_numbers must match length of projects if project_numbers are provided."
}
}

variable "amount" {
description = "The amount to use as the budget"
type = number
Expand Down
4 changes: 2 additions & 2 deletions modules/essential_contacts/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ spec:
- serviceusage.googleapis.com
providerVersions:
- source: hashicorp/google
version: ">= 3.43, < 7"
version: ">= 3.43, < 8"
- source: hashicorp/google-beta
version: ">= 3.43, < 7"
version: ">= 3.43, < 8"
2 changes: 1 addition & 1 deletion modules/fabric-project/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,4 @@ spec:
- serviceusage.googleapis.com
providerVersions:
- source: hashicorp/google
version: ">= 5.41, < 7"
version: ">= 5.41, < 8"
4 changes: 2 additions & 2 deletions modules/gsuite_enabled/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,6 @@ spec:
- source: DeviaVir/gsuite
version: ~> 0.1
- source: hashicorp/google
version: ">= 4.11, < 7"
version: ">= 4.11, < 8"
- source: hashicorp/google-beta
version: ">= 4.11, < 7"
version: ">= 4.11, < 8"
4 changes: 2 additions & 2 deletions modules/project_services/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,6 @@ spec:
- serviceusage.googleapis.com
providerVersions:
- source: hashicorp/google
version: ">= 3.43, < 7"
version: ">= 3.43, < 8"
- source: hashicorp/google-beta
version: ">= 3.43, < 7"
version: ">= 3.43, < 8"
2 changes: 1 addition & 1 deletion modules/quota_manager/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ spec:
- serviceusage.googleapis.com
providerVersions:
- source: hashicorp/google-beta
version: ">= 4.11, < 7"
version: ">= 4.11, < 8"
4 changes: 2 additions & 2 deletions modules/shared_vpc_access/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,6 @@ spec:
- serviceusage.googleapis.com
providerVersions:
- source: hashicorp/google
version: ">= 3.43, < 7"
version: ">= 3.43, < 8"
- source: hashicorp/google-beta
version: ">= 3.43, < 7"
version: ">= 3.43, < 8"
4 changes: 2 additions & 2 deletions modules/svpc_service_project/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,6 @@ spec:
- serviceusage.googleapis.com
providerVersions:
- source: hashicorp/google
version: ">= 4.5, < 7"
version: ">= 4.5, < 8"
- source: hashicorp/google-beta
version: ">= 4.5, < 7"
version: ">= 4.5, < 8"