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 'google_billing_account' data source #889

Merged
merged 8 commits into from
Dec 22, 2017
Merged

Add 'google_billing_account' data source #889

merged 8 commits into from
Dec 22, 2017

Conversation

ewbankkit
Copy link
Contributor

Fixes #888.

@ewbankkit
Copy link
Contributor Author

make testacc TEST=./google/ TESTARGS='-run=TestAccDataSourceGoogleBillingAccount_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./google/ -v -run=TestAccDataSourceGoogleBillingAccount_ -timeout 120m
=== RUN   TestAccDataSourceGoogleBillingAccount_basic
--- PASS: TestAccDataSourceGoogleBillingAccount_basic (1.75s)
PASS
ok  	github.com/terraform-providers/terraform-provider-google/google	1.762s

Copy link
Contributor

@rosbo rosbo left a 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}`.
Copy link
Contributor

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?

https://github.com/terraform-providers/terraform-provider-google/blob/master/google/iam_folder.go#L81

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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"},
  ...
}

Copy link
Contributor Author

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()
Copy link
Contributor

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

Copy link
Contributor Author

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.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, makes sense,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@rosbo rosbo self-assigned this Dec 21, 2017
Copy link
Contributor

@rosbo rosbo left a 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

@ewbankkit
Copy link
Contributor Author

make testacc TEST=./google/ TESTARGS='-run=TestAccDataSourceGoogleBillingAccount_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./google/ -v -run=TestAccDataSourceGoogleBillingAccount_ -timeout 120m
=== RUN   TestAccDataSourceGoogleBillingAccount_byFullName
--- PASS: TestAccDataSourceGoogleBillingAccount_byFullName (1.90s)
=== RUN   TestAccDataSourceGoogleBillingAccount_byShortName
--- PASS: TestAccDataSourceGoogleBillingAccount_byShortName (1.57s)
=== RUN   TestAccDataSourceGoogleBillingAccount_byFullNameClosed
--- PASS: TestAccDataSourceGoogleBillingAccount_byFullNameClosed (0.25s)
=== RUN   TestAccDataSourceGoogleBillingAccount_byDisplayName
--- PASS: TestAccDataSourceGoogleBillingAccount_byDisplayName (0.29s)
PASS
ok  	github.com/terraform-providers/terraform-provider-google/google	4.021s

Copy link
Contributor

@rosbo rosbo left a comment

Choose a reason for hiding this comment

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

Great work!

@rosbo rosbo merged commit a086e70 into hashicorp:master Dec 22, 2017
@ewbankkit ewbankkit deleted the google_billing_account-data-source branch January 8, 2018 15:28
chrisst pushed a commit to chrisst/terraform-provider-google that referenced this pull request Nov 9, 2018
* 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.
modular-magician added a commit to modular-magician/terraform-provider-google that referenced this pull request Sep 27, 2019
@ghost
Copy link

ghost commented Mar 30, 2020

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!

@ghost ghost unassigned rosbo Mar 30, 2020
@ghost ghost locked and limited conversation to collaborators Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New data source: Billing Account
2 participants