-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 'google_billing_account' data source #889
Add 'google_billing_account' data source #889
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Kit,
Thanks for adding this data sources. I have a few suggestions and comments.
The given filters must match exactly one billing account whose data will be exported as attributes. | ||
The following arguments are supported: | ||
|
||
* `name` (Optional) - The resource name of the billing account in the form `billingAccounts/{billing_account_id}`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider doing like we did for folders where you can specify either "folders/{folder_id}" or "{folder_id}".
Since we would support only "{billing_account_id}" for this field, what do you think or renaming this field account_id
or billing_account_id
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about keeping name
as a Computed-only attribute and having the argument named billing_account
specified as either {billing_account_id}
or billingAccounts/{billing_account_id}
?
GCP seems exact in its distinction between resource names and resource IDs and this argument can be either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. I like your suggestion better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
name, nameOk := d.GetOk("name") | ||
displayName, displayNameOk := d.GetOk("display_name") | ||
if nameOk == displayNameOk { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this check and use ConflictsWith in the schema definition above.
"name": {
Type: schema.TypeString
ConflictsWith: []string{"display_name"},
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
billingAccount = resp | ||
} else { | ||
resp, err := config.clientBilling.BillingAccounts.List().Do() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call has pagination.
Here is an example of how we page through results in other parts of the code:
https://github.com/terraform-providers/terraform-provider-google/blob/master/google/resource_google_project_services.go#L171
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
The following additional attributes are exported: | ||
|
||
* `id` - The billing account ID. | ||
* `open` - `true` if the billing account is open, `false` if the billing account is closed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think filtering by "open = true" might be useful?
If you think so, you can define this field both Computed and Optional. This means that if someone specifies it, it will filter, if they don't specify it, you can still set the value from the server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, makes sense,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Required changes in my previous review
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
* Add 'google_billing_account' data source. * Use 'GetResourceNameFromSelfLink'. * Use 'ConflictsWith' in schema. * Use pagination for List() API call. * Add ability to filter by 'open' attribute. * Don't use 'ForceNew' for data sources. * Add 'billing_account' argument and make 'name' an output-only attribute. * Correct error message.
Signed-off-by: Modular Magician <[email protected]>
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
Fixes #888.