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 billing subaccount #2640

Merged
merged 15 commits into from
Dec 15, 2020
Merged

Add billing subaccount #2640

merged 15 commits into from
Dec 15, 2020

Conversation

adarobin
Copy link
Contributor

@adarobin adarobin commented Nov 11, 2019

This implements a new google_billing_subaccount resource and would close hashicorp/terraform-provider-google#4033

Release Note Template for Downstream PRs (will be copied)

`google_billing_subaccount`

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@adarobin
Copy link
Contributor Author

@googlebot I signed it!

@modular-magician
Copy link
Collaborator

Hello! I am a robot who works on Magic Modules PRs.

I have detected that you are a community contributor, so your PR will be assigned to someone with a commit-bit on this repo for initial review. They will authorize it to run through our CI pipeline, which will generate downstream PRs.

Thanks for your contribution! A human will be with you soon.

@rambleraptor, please review this PR or find an appropriate assignee.

@rambleraptor
Copy link
Contributor

Hello! Thanks for the PR. I've added @rileykarson who can better help get this merged in.

Before we begin, we have to make sure that @googlebot recognizes that you've signed the CLA. I'm hoping that tagging it will cause it to kick off again.

@adarobin
Copy link
Contributor Author

@googlebot I signed it!

Copy link
Member

@rileykarson rileykarson left a comment

Choose a reason for hiding this comment

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

I made a first pass, leaning fairly nitpicky for consistency with other provider resource files.

Are you able to add an acceptance test? https://github.com/terraform-providers/terraform-provider-google/blob/master/google/resource_compute_address_generated_test.go is a good reference for what most acceptance tests look like, while https://github.com/terraform-providers/terraform-provider-google/blob/master/google/resource_google_billing_account_iam_test.go is a good example of how to work with billing accounts.

@adarobin
Copy link
Contributor Author

@rileykarson I'll take a try at adding an acceptance test and go through your comments.

I'm not sure what the deal with the CLA is, a Corporate CLA was signed last week and I am a member of the group.

Copy link
Member

@rileykarson rileykarson left a comment

Choose a reason for hiding this comment

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

Can you confirm that the email listed on the second line at https://github.com/GoogleCloudPlatform/magic-modules/commit/f865406be26aa27c14f1fb7558d406f1ffeea162.patch is the email covered by your corporate CLA?

Since these changes are to a third_party directory the CLA doesn't actually apply. I'd slightly prefer that the bot is happy, but it's not strictly necessary.

@adarobin
Copy link
Contributor Author

@rileykarson I have made changes based on your comments and wrote some tests.

As far as the CLA, we had an authorized signer fill out the form late last week, but it looks like it hasn't been approved fully yet.

@sokoow
Copy link

sokoow commented Apr 10, 2020

@rileykarson @adarobin are ye still haggling on the CLA yet ? Any plans to progress this ?

@adarobin
Copy link
Contributor Author

@sokoow I am still pushing for the CLA on my end. I believe it was close, but then all of this COVID-19 stuff happened.

@sokoow
Copy link

sokoow commented Apr 16, 2020

respect, keep us posted pls

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 8 files changed, 343 insertions(+))
Terraform Beta: Diff ( 6 files changed, 337 insertions(+))

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 6 files changed, 337 insertions(+))
Terraform Beta: Diff ( 6 files changed, 337 insertions(+))

@adarobin
Copy link
Contributor Author

adarobin commented Dec 3, 2020

@googlebot I signed it!

@google-cla
Copy link

google-cla bot commented Dec 3, 2020

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: yes and removed cla: no labels Dec 3, 2020
@adarobin
Copy link
Contributor Author

adarobin commented Dec 3, 2020

@rileykarson Finally have a CLA, what are my next steps?

@adarobin
Copy link
Contributor Author

adarobin commented Dec 3, 2020

@samos123 Just realized I didn't ping you too, I have the CLA now!

Copy link
Member

@rileykarson rileykarson left a comment

Choose a reason for hiding this comment

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

Thanks for picking this back up! I've made a review pass. Sorry if any of it conflicts with previous comments of mine, it's been a while 🙂

Type: schema.TypeString,
Computed: true,
},
"rename_on_destroy": {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of {{action}}_on_destroy, can you call this field deletion_policy and allow "" and "RENAME_ON_DESTROY" to be specified? https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_user#deletion_policy is a good model, where we've done the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked at that resource and I think I have implemented it as you have requested

@google-cla
Copy link

google-cla bot commented Dec 11, 2020

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 6 files changed, 352 insertions(+))
Terraform Beta: Diff ( 6 files changed, 352 insertions(+))

Copy link
Member

@rileykarson rileykarson left a comment

Choose a reason for hiding this comment

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

I'm working on getting a test master billing account, I'll get back to this once I've done so. I've submitted a ticket- that hopefully won't be long!

Copy link
Member

@rileykarson rileykarson left a comment

Choose a reason for hiding this comment

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

Alright, environment set up. _basic succeeded, _renameOnDestroy failed- I think it's just because we're still using the old rename_on_destroy field (inline).

@google-cla
Copy link

google-cla bot commented Dec 15, 2020

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 6 files changed, 352 insertions(+))
Terraform Beta: Diff ( 6 files changed, 352 insertions(+))

Copy link
Member

@rileykarson rileykarson left a comment

Choose a reason for hiding this comment

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

Alright, just a couple of lint errors left. Sorry for not catching these in my prior pass! I lost track when digging into registering a parent billing account.

==> Checking source code against linters...
google/resource_google_billing_subaccount.go:96:7: Error return value of `d.Set` is not checked (errcheck)
	d.Set("name", billingAccount.Name)
	     ^
google/resource_google_billing_subaccount.go:97:7: Error return value of `d.Set` is not checked (errcheck)
	d.Set("display_name", billingAccount.DisplayName)
	     ^
google/resource_google_billing_subaccount.go:98:7: Error return value of `d.Set` is not checked (errcheck)
	d.Set("open", billingAccount.Open)
	     ^
google/resource_google_billing_subaccount.go:99:7: Error return value of `d.Set` is not checked (errcheck)
	d.Set("master_billing_account", billingAccount.MasterBillingAccount)
	     ^
google/resource_google_billing_subaccount.go:100:7: Error return value of `d.Set` is not checked (errcheck)
	d.Set("billing_account_id", strings.TrimPrefix(d.Get("name").(string), "billingAccounts/"))
	     ^
google/resource_google_billing_subaccount_test.go:92:6: `testAccBillingSubccount_updateRenameOnDestroy` is unused (deadcode)
func testAccBillingSubccount_updateRenameOnDestroy(masterBillingAccountId string) string {
     ^
make: *** [lint] Error 1

`, masterBillingAccountId)
}

func testAccBillingSubccount_updateRenameOnDestroy(masterBillingAccountId string) string {
Copy link
Member

Choose a reason for hiding this comment

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

This is unused, and can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed testAccBillingSubccount_updateRenameOnDestroy

return handleNotFoundError(err, d, fmt.Sprintf("Billing Subaccount Not Found : %s", id))
}

d.Set("name", billingAccount.Name)
Copy link
Member

Choose a reason for hiding this comment

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

Mind checking the error returned from these d.Set calls, and returning a message including the field name if there's a problem? Like in https://github.com/hashicorp/terraform-provider-google-beta/blob/master/google-beta/resource_container_cluster.go#L1584.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added error checking for d.Set calls

@google-cla
Copy link

google-cla bot commented Dec 15, 2020

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 6 files changed, 352 insertions(+))
Terraform Beta: Diff ( 7 files changed, 353 insertions(+), 1 deletion(-))

Copy link
Member

@rileykarson rileykarson left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @adarobin!

@upodroid
Copy link
Contributor

upodroid commented Jan 11, 2021

Hi

I saw this in the new release of the provider and I was wondering why a new resource was made instead of adding master_billing_account field to the google_billing_account resource?

nvm

https://cloud.google.com/billing/docs/reference/rest/v1/billingAccounts#BillingAccount

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support cloudbilling APIs / Billing Sub Accounts
8 participants