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

fixed labels for array value #10490

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/5275.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
billingbudget: fixed unable to provide `labels` on `google_billing_budget`
```
31 changes: 26 additions & 5 deletions google/resource_billing_budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,28 @@ func flattenBillingBudgetBudgetFilterSubaccounts(v interface{}, d *schema.Resour
}

func flattenBillingBudgetBudgetFilterLabels(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
/*
note: api only accepts below format. Also only takes a single element in the array
labels = {
foo = ["bar"]
}
until now, sdk does not take array for the map value
*/
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
for key, val := range original {
l := val.([]interface{})
for _, v := range l {
transformed[key] = v.(string)
}
}
return transformed
}

func flattenBillingBudgetAmount(v interface{}, d *schema.ResourceData, config *Config) interface{} {
Expand Down Expand Up @@ -828,13 +849,13 @@ func expandBillingBudgetBudgetFilterSubaccounts(v interface{}, d TerraformResour
return v, nil
}

func expandBillingBudgetBudgetFilterLabels(v interface{}, d TerraformResourceData, config *Config) (map[string]string, error) {
func expandBillingBudgetBudgetFilterLabels(v interface{}, d TerraformResourceData, config *Config) (map[string][]string, error) {
if v == nil {
return map[string]string{}, nil
return map[string][]string{}, nil
}
m := make(map[string]string)
m := make(map[string][]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
m[k] = []string{val.(string)}
}
return m, nil
}
Expand Down
3 changes: 3 additions & 0 deletions google/resource_billing_budget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ resource "google_billing_budget" "budget" {

budget_filter {
projects = ["projects/${data.google_project.project.number}"]
labels = {
label = "bar"
}
}

amount {
Expand Down