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 #5275

Merged
merged 4 commits into from
Nov 3, 2021
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
2 changes: 2 additions & 0 deletions mmv1/products/billingbudget/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides
default_from_api: true
budgetFilter.labels: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
custom_expand: 'templates/terraform/custom_expand/billing_budget_budget_filter_labels.erb'
custom_flatten: "templates/terraform/custom_flatten/billing_budget_budget_filter_labels.erb"
budgetFilter.projects: !ruby/object:Overrides::Terraform::PropertyOverride
is_set: true

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (map[string][]string, error) {
if v == nil {
return map[string][]string{}, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What an unusual type for the API to expect, especially given it's restricted anyways. From the API docs: Currently, multiple entries or multiple values per entry are not allowed.

}
m := make(map[string][]string)
for k, val := range v.(map[string]interface{}) {
m[k] = []string{val.(string)}
}
return m, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} {
/*
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
}
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