Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OwnershipScope to the Billing Budget resource #17868

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/10459.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
billing: added `ownership_scope` field to `google_billing_budget` resource
```
34 changes: 34 additions & 0 deletions google/services/billing/resource_billing_budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,13 @@ account and all subaccounts, if they exist.
Optional: true,
Description: `User data for display name in UI. Must be <= 60 chars.`,
},
"ownership_scope": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.ValidateEnum([]string{"OWNERSHIP_SCOPE_UNSPECIFIED", "ALL_USERS", "BILLING_ACCOUNT", ""}),
Description: `The ownership scope of the budget. The ownership scope and users'
IAM permissions determine who has full access to the budget's data. Possible values: ["OWNERSHIP_SCOPE_UNSPECIFIED", "ALL_USERS", "BILLING_ACCOUNT"]`,
},
"threshold_rules": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -451,6 +458,12 @@ func resourceBillingBudgetCreate(d *schema.ResourceData, meta interface{}) error
} else if v, ok := d.GetOkExists("all_updates_rule"); !tpgresource.IsEmptyValue(reflect.ValueOf(notificationsRuleProp)) && (ok || !reflect.DeepEqual(v, notificationsRuleProp)) {
obj["notificationsRule"] = notificationsRuleProp
}
ownershipScopeProp, err := expandBillingBudgetOwnershipScope(d.Get("ownership_scope"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("ownership_scope"); !tpgresource.IsEmptyValue(reflect.ValueOf(ownershipScopeProp)) && (ok || !reflect.DeepEqual(v, ownershipScopeProp)) {
obj["ownershipScope"] = ownershipScopeProp
}

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

return nil
}
Expand Down Expand Up @@ -589,6 +605,12 @@ func resourceBillingBudgetUpdate(d *schema.ResourceData, meta interface{}) error
} else if v, ok := d.GetOkExists("all_updates_rule"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, notificationsRuleProp)) {
obj["notificationsRule"] = notificationsRuleProp
}
ownershipScopeProp, err := expandBillingBudgetOwnershipScope(d.Get("ownership_scope"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("ownership_scope"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, ownershipScopeProp)) {
obj["ownershipScope"] = ownershipScopeProp
}

url, err := tpgresource.ReplaceVars(d, config, "{{BillingBasePath}}billingAccounts/{{billing_account}}/budgets/{{name}}")
if err != nil {
Expand Down Expand Up @@ -631,6 +653,10 @@ func resourceBillingBudgetUpdate(d *schema.ResourceData, meta interface{}) error
"notificationsRule.monitoringNotificationChannels",
"notificationsRule.disableDefaultIamRecipients")
}

if d.HasChange("ownership_scope") {
updateMask = append(updateMask, "ownershipScope")
}
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
// won't set it
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
Expand Down Expand Up @@ -1106,6 +1132,10 @@ func flattenBillingBudgetAllUpdatesRuleDisableDefaultIamRecipients(v interface{}
return v
}

func flattenBillingBudgetOwnershipScope(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func expandBillingBudgetDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down Expand Up @@ -1514,6 +1544,10 @@ func expandBillingBudgetAllUpdatesRuleDisableDefaultIamRecipients(v interface{},
return v, nil
}

func expandBillingBudgetOwnershipScope(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func resourceBillingBudgetResourceV0() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ resource "google_billing_budget" "budget" {
disable_default_iam_recipients = true
pubsub_topic = google_pubsub_topic.budget.id
}

ownership_scope = "BILLING_ACCOUNT"
}

resource "google_pubsub_topic" "budget" {
Expand Down
6 changes: 6 additions & 0 deletions website/docs/r/billing_budget.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ The following arguments are supported:
using threshold rules.
Structure is [documented below](#nested_all_updates_rule).

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


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

Expand Down