Skip to content

Commit 189a946

Browse files
feat(billingbudget): support project level recicipients on budgets (#10926) (#18437)
[upstream:81488b892dcb7a9e33c3718a1fbcbdd434860d7c] Signed-off-by: Modular Magician <[email protected]>
1 parent cd20486 commit 189a946

File tree

4 files changed

+129
-1
lines changed

4 files changed

+129
-1
lines changed

.changelog/10926.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
billingbudget: added `enable_project_level_recipients` field to `google_billing_budget` resource
3+
```

google/services/billing/resource_billing_budget.go

+29-1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ those with Billing Account Administrators and Billing
152152
Account Users IAM roles for the target account.`,
153153
Default: false,
154154
},
155+
"enable_project_level_recipients": {
156+
Type: schema.TypeBool,
157+
Optional: true,
158+
Description: `When set to true, and when the budget has a single project configured,
159+
notifications will be sent to project level recipients of that project.
160+
This field will be ignored if the budget has multiple or no project configured.
161+
162+
Currently, project level recipients are the users with Owner role on a cloud project.`,
163+
Default: false,
164+
},
155165
"monitoring_notification_channels": {
156166
Type: schema.TypeList,
157167
Optional: true,
@@ -651,7 +661,8 @@ func resourceBillingBudgetUpdate(d *schema.ResourceData, meta interface{}) error
651661
updateMask = append(updateMask, "notificationsRule.pubsubTopic",
652662
"notificationsRule.schemaVersion",
653663
"notificationsRule.monitoringNotificationChannels",
654-
"notificationsRule.disableDefaultIamRecipients")
664+
"notificationsRule.disableDefaultIamRecipients",
665+
"notificationsRule.enableProjectLevelRecipients")
655666
}
656667

657668
if d.HasChange("ownership_scope") {
@@ -1110,6 +1121,8 @@ func flattenBillingBudgetAllUpdatesRule(v interface{}, d *schema.ResourceData, c
11101121
flattenBillingBudgetAllUpdatesRuleMonitoringNotificationChannels(original["monitoringNotificationChannels"], d, config)
11111122
transformed["disable_default_iam_recipients"] =
11121123
flattenBillingBudgetAllUpdatesRuleDisableDefaultIamRecipients(original["disableDefaultIamRecipients"], d, config)
1124+
transformed["enable_project_level_recipients"] =
1125+
flattenBillingBudgetAllUpdatesRuleEnableProjectLevelRecipients(original["enableProjectLevelRecipients"], d, config)
11131126
return []interface{}{transformed}
11141127
}
11151128
func flattenBillingBudgetAllUpdatesRulePubsubTopic(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
@@ -1132,6 +1145,10 @@ func flattenBillingBudgetAllUpdatesRuleDisableDefaultIamRecipients(v interface{}
11321145
return v
11331146
}
11341147

1148+
func flattenBillingBudgetAllUpdatesRuleEnableProjectLevelRecipients(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1149+
return v
1150+
}
1151+
11351152
func flattenBillingBudgetOwnershipScope(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
11361153
return v
11371154
}
@@ -1525,6 +1542,13 @@ func expandBillingBudgetAllUpdatesRule(v interface{}, d tpgresource.TerraformRes
15251542
transformed["disableDefaultIamRecipients"] = transformedDisableDefaultIamRecipients
15261543
}
15271544

1545+
transformedEnableProjectLevelRecipients, err := expandBillingBudgetAllUpdatesRuleEnableProjectLevelRecipients(original["enable_project_level_recipients"], d, config)
1546+
if err != nil {
1547+
return nil, err
1548+
} else if val := reflect.ValueOf(transformedEnableProjectLevelRecipients); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1549+
transformed["enableProjectLevelRecipients"] = transformedEnableProjectLevelRecipients
1550+
}
1551+
15281552
return transformed, nil
15291553
}
15301554

@@ -1544,6 +1568,10 @@ func expandBillingBudgetAllUpdatesRuleDisableDefaultIamRecipients(v interface{},
15441568
return v, nil
15451569
}
15461570

1571+
func expandBillingBudgetAllUpdatesRuleEnableProjectLevelRecipients(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1572+
return v, nil
1573+
}
1574+
15471575
func expandBillingBudgetOwnershipScope(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
15481576
return v, nil
15491577
}

google/services/billing/resource_billing_budget_generated_test.go

+58
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,64 @@ resource "google_monitoring_notification_channel" "notification_channel" {
279279
`, context)
280280
}
281281

282+
func TestAccBillingBudget_billingBudgetNotifyProjectRecipientExample(t *testing.T) {
283+
t.Parallel()
284+
285+
context := map[string]interface{}{
286+
"billing_acct": envvar.GetTestMasterBillingAccountFromEnv(t),
287+
"random_suffix": acctest.RandString(t, 10),
288+
}
289+
290+
acctest.VcrTest(t, resource.TestCase{
291+
PreCheck: func() { acctest.AccTestPreCheck(t) },
292+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
293+
CheckDestroy: testAccCheckBillingBudgetDestroyProducer(t),
294+
Steps: []resource.TestStep{
295+
{
296+
Config: testAccBillingBudget_billingBudgetNotifyProjectRecipientExample(context),
297+
},
298+
{
299+
ResourceName: "google_billing_budget.budget",
300+
ImportState: true,
301+
ImportStateVerify: true,
302+
ImportStateVerifyIgnore: []string{"billing_account"},
303+
},
304+
},
305+
})
306+
}
307+
308+
func testAccBillingBudget_billingBudgetNotifyProjectRecipientExample(context map[string]interface{}) string {
309+
return acctest.Nprintf(`
310+
data "google_billing_account" "account" {
311+
billing_account = "%{billing_acct}"
312+
}
313+
314+
data "google_project" "project" {
315+
}
316+
317+
resource "google_billing_budget" "budget" {
318+
billing_account = data.google_billing_account.account.id
319+
display_name = "Example Billing Budget%{random_suffix}"
320+
321+
budget_filter {
322+
projects = ["projects/${data.google_project.project.number}"]
323+
}
324+
325+
amount {
326+
specified_amount {
327+
currency_code = "USD"
328+
units = "100000"
329+
}
330+
}
331+
332+
all_updates_rule {
333+
monitoring_notification_channels = []
334+
enable_project_level_recipients = true
335+
}
336+
}
337+
`, context)
338+
}
339+
282340
func TestAccBillingBudget_billingBudgetCustomperiodExample(t *testing.T) {
283341
t.Parallel()
284342

website/docs/r/billing_budget.html.markdown

+39
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,38 @@ resource "google_monitoring_notification_channel" "notification_channel" {
177177
}
178178
}
179179
```
180+
## Example Usage - Billing Budget Notify Project Recipient
181+
182+
183+
```hcl
184+
data "google_billing_account" "account" {
185+
billing_account = "000000-0000000-0000000-000000"
186+
}
187+
188+
data "google_project" "project" {
189+
}
190+
191+
resource "google_billing_budget" "budget" {
192+
billing_account = data.google_billing_account.account.id
193+
display_name = "Example Billing Budget"
194+
195+
budget_filter {
196+
projects = ["projects/${data.google_project.project.number}"]
197+
}
198+
199+
amount {
200+
specified_amount {
201+
currency_code = "USD"
202+
units = "100000"
203+
}
204+
}
205+
206+
all_updates_rule {
207+
monitoring_notification_channels = []
208+
enable_project_level_recipients = true
209+
}
210+
}
211+
```
180212
## Example Usage - Billing Budget Customperiod
181213

182214

@@ -470,6 +502,13 @@ The following arguments are supported:
470502
those with Billing Account Administrators and Billing
471503
Account Users IAM roles for the target account.
472504

505+
* `enable_project_level_recipients` -
506+
(Optional)
507+
When set to true, and when the budget has a single project configured,
508+
notifications will be sent to project level recipients of that project.
509+
This field will be ignored if the budget has multiple or no project configured.
510+
Currently, project level recipients are the users with Owner role on a cloud project.
511+
473512
## Attributes Reference
474513

475514
In addition to the arguments listed above, the following computed attributes are exported:

0 commit comments

Comments
 (0)