Skip to content

Commit b059250

Browse files
Add OwnershipScope to the Billing Budget resource (#10459) (#17868)
[upstream:60a85738f569bbfa2731097270db8b19d5dcfebd] Signed-off-by: Modular Magician <[email protected]>
1 parent 8028059 commit b059250

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

.changelog/10459.txt

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

google/services/billing/resource_billing_budget.go

+34
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,13 @@ account and all subaccounts, if they exist.
376376
Optional: true,
377377
Description: `User data for display name in UI. Must be <= 60 chars.`,
378378
},
379+
"ownership_scope": {
380+
Type: schema.TypeString,
381+
Optional: true,
382+
ValidateFunc: verify.ValidateEnum([]string{"OWNERSHIP_SCOPE_UNSPECIFIED", "ALL_USERS", "BILLING_ACCOUNT", ""}),
383+
Description: `The ownership scope of the budget. The ownership scope and users'
384+
IAM permissions determine who has full access to the budget's data. Possible values: ["OWNERSHIP_SCOPE_UNSPECIFIED", "ALL_USERS", "BILLING_ACCOUNT"]`,
385+
},
379386
"threshold_rules": {
380387
Type: schema.TypeList,
381388
Optional: true,
@@ -451,6 +458,12 @@ func resourceBillingBudgetCreate(d *schema.ResourceData, meta interface{}) error
451458
} else if v, ok := d.GetOkExists("all_updates_rule"); !tpgresource.IsEmptyValue(reflect.ValueOf(notificationsRuleProp)) && (ok || !reflect.DeepEqual(v, notificationsRuleProp)) {
452459
obj["notificationsRule"] = notificationsRuleProp
453460
}
461+
ownershipScopeProp, err := expandBillingBudgetOwnershipScope(d.Get("ownership_scope"), d, config)
462+
if err != nil {
463+
return err
464+
} else if v, ok := d.GetOkExists("ownership_scope"); !tpgresource.IsEmptyValue(reflect.ValueOf(ownershipScopeProp)) && (ok || !reflect.DeepEqual(v, ownershipScopeProp)) {
465+
obj["ownershipScope"] = ownershipScopeProp
466+
}
454467

455468
url, err := tpgresource.ReplaceVars(d, config, "{{BillingBasePath}}billingAccounts/{{billing_account}}/budgets")
456469
if err != nil {
@@ -545,6 +558,9 @@ func resourceBillingBudgetRead(d *schema.ResourceData, meta interface{}) error {
545558
if err := d.Set("all_updates_rule", flattenBillingBudgetAllUpdatesRule(res["notificationsRule"], d, config)); err != nil {
546559
return fmt.Errorf("Error reading Budget: %s", err)
547560
}
561+
if err := d.Set("ownership_scope", flattenBillingBudgetOwnershipScope(res["ownershipScope"], d, config)); err != nil {
562+
return fmt.Errorf("Error reading Budget: %s", err)
563+
}
548564

549565
return nil
550566
}
@@ -589,6 +605,12 @@ func resourceBillingBudgetUpdate(d *schema.ResourceData, meta interface{}) error
589605
} else if v, ok := d.GetOkExists("all_updates_rule"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, notificationsRuleProp)) {
590606
obj["notificationsRule"] = notificationsRuleProp
591607
}
608+
ownershipScopeProp, err := expandBillingBudgetOwnershipScope(d.Get("ownership_scope"), d, config)
609+
if err != nil {
610+
return err
611+
} else if v, ok := d.GetOkExists("ownership_scope"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, ownershipScopeProp)) {
612+
obj["ownershipScope"] = ownershipScopeProp
613+
}
592614

593615
url, err := tpgresource.ReplaceVars(d, config, "{{BillingBasePath}}billingAccounts/{{billing_account}}/budgets/{{name}}")
594616
if err != nil {
@@ -631,6 +653,10 @@ func resourceBillingBudgetUpdate(d *schema.ResourceData, meta interface{}) error
631653
"notificationsRule.monitoringNotificationChannels",
632654
"notificationsRule.disableDefaultIamRecipients")
633655
}
656+
657+
if d.HasChange("ownership_scope") {
658+
updateMask = append(updateMask, "ownershipScope")
659+
}
634660
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
635661
// won't set it
636662
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
@@ -1106,6 +1132,10 @@ func flattenBillingBudgetAllUpdatesRuleDisableDefaultIamRecipients(v interface{}
11061132
return v
11071133
}
11081134

1135+
func flattenBillingBudgetOwnershipScope(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1136+
return v
1137+
}
1138+
11091139
func expandBillingBudgetDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
11101140
return v, nil
11111141
}
@@ -1514,6 +1544,10 @@ func expandBillingBudgetAllUpdatesRuleDisableDefaultIamRecipients(v interface{},
15141544
return v, nil
15151545
}
15161546

1547+
func expandBillingBudgetOwnershipScope(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1548+
return v, nil
1549+
}
1550+
15171551
func resourceBillingBudgetResourceV0() *schema.Resource {
15181552
return &schema.Resource{
15191553
Schema: map[string]*schema.Schema{

google/services/billing/resource_billing_budget_generated_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ resource "google_billing_budget" "budget" {
401401
disable_default_iam_recipients = true
402402
pubsub_topic = google_pubsub_topic.budget.id
403403
}
404+
405+
ownership_scope = "BILLING_ACCOUNT"
404406
}
405407
406408
resource "google_pubsub_topic" "budget" {

website/docs/r/billing_budget.html.markdown

+6
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,12 @@ The following arguments are supported:
307307
using threshold rules.
308308
Structure is [documented below](#nested_all_updates_rule).
309309

310+
* `ownership_scope` -
311+
(Optional)
312+
The ownership scope of the budget. The ownership scope and users'
313+
IAM permissions determine who has full access to the budget's data.
314+
Possible values are: `OWNERSHIP_SCOPE_UNSPECIFIED`, `ALL_USERS`, `BILLING_ACCOUNT`.
315+
310316

311317
<a name="nested_budget_filter"></a>The `budget_filter` block supports:
312318

0 commit comments

Comments
 (0)