-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix: set ClientOption for quota project when possible #9636
fix: set ClientOption for quota project when possible #9636
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.
My concern with this approach is that the older / presumably more-in-use method of associating a quota account (direct project) can only be determined at apply time, and won't be supported by this method.
However, since billing_project
wins against direct projects it probably won't matter in those cases. There are a few resources (google_cloud_asset_*
) which have resource-level billing_project
fields, and that should have precedence over the provider level one. Can you confirm what headers get sent for one of them when you've configured a billing project in both places?
To confirm I'm on the same page: you're referring to
I agree, which is why I think that this solution doesn't prevent a later solution that solves for when there is only the I do think that any future solution would need to be at least aware of this solution, as to not override the header, but that seems easy enough to me.
I'll try! It might be hard considering I am not familiar with those resources, but at a minimum I could probably dump the generated request to confirm the correct header is being sent. |
This commit partially addresses hashicorp#9454, in the case when the provider is configured with both the user_project_override AND billing_project setting, by setting a header in the LoadAndValidate function stage on the HTTP client used by all handwritten resources. Originally this commit used a Google API client ClientOption [1], but unfortunately headers set by the Google API client's transport implementation [2] aren't visible by the logging transport [3]. I thought it would be better to include the header at a higher level in order to aid with debugging in the future. If [4] is ever merged, moving the logging transport _inside_ of the API client and switching to a ClientOption for the header would probably be a better way. Finally, this does not address having user_project_override set to true without the billing_project setting, as that would require more logic to determine which project the resource is referring to. [1] https://pkg.go.dev/google.golang.org/api/option#WithQuotaProject [2] https://github.com/googleapis/google-api-go-client/blob/3e2b6a25f224e301409d11443d464af92671d2f0/transport/http/dial.go#L86-L88 [3] https://github.com/hashicorp/terraform-provider-google/blob/0e315b07d9ed37bd884a1060c22681908d23f270/google/config.go#L373-L374 [4] googleapis/google-cloud-go#1962
56cb594
to
a35fcd2
Compare
Okay @rileykarson, this was quite a journey but I'm glad I looked into this more. Unfortunately because the logging transport is set up after the Google API client transport [1], the There doesn't appear to be a way to wrap the logging transport with the Google API client transport, so I opted to use the existing With the following provider "google" {
user_project_override = true
billing_project = "billing-project-set-by-provider"
}
resource "google_logging_project_sink" "my-sink" {
name = "my-pubsub-instance-sink"
# Can export to pubsub, cloud storage, or bigquery
destination = "pubsub.googleapis.com/projects/my-project/topics/instance-activity"
# Log all WARN or higher severity messages relating to instances
filter = "resource.type = gce_instance AND severity >= WARNING"
# Use a unique writer (creates a unique service account used for writing)
unique_writer_identity = true
project = "project-set-by-resource"
}
resource "google_cloud_asset_organization_feed" "test" {
billing_project = "billing-project-set-by-resource"
org_id = "123456789"
feed_id = "network-updates"
content_type = "RESOURCE"
asset_types = [
"compute.googleapis.com/Subnetwork",
"compute.googleapis.com/Network",
]
feed_output_config {
pubsub_destination {
topic = "some-topic"
}
}
} ...you will see the correct headers being set in the
I noted it in the commit message, but if googleapis/google-cloud-go#1962 is ever merged, switching the ordering of the transports and then going back to using a [1] terraform-provider-google/google/config.go Lines 362 to 374 in 0e315b0
|
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.
Awesome, thanks for exercising that path and making those changes! I'm sufficiently convinced this is backwards compatible enough to release in a minor version, LGTM.
I'm going to upstream the change to https://github.com/GoogleCloudPlatform/magic-modules so this applies to google-beta
as well, and retouch some related documentation while I'm at it. I can't do that immediately- my Mondays are loaded- but should be able to get to it later today / tomorrow. Ping here if there's been no activity by EOD Wednesday.
There's no other action needed from you, I'll merge this PR simultaneously w/ the upstream PR or supersede it, just depending how the change shakes out.
Sounds good to me! Appreciate you looking into this, and feel free to do whatever you think is necessary to merge the change. |
Superseded w/ GoogleCloudPlatform/magic-modules#5086, given there's a merge conflict from other changes in this branch. |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Hey @rileykarson, I wanted to get your opinion on this proposed fix for our particular use-case. I think that a fix that addresses
user_project_override
without an associatedbilling_project
is achievable, but would require more work, and we've ran into an additional two issues that makes it more pressing for us to have this solved for at least whenuser_project_override
andbilling_project
is set.If this particular implementation isn't tenable, that's fine, but I'd really like to see something along these lines so that we can move forward without needing to enable 50+ APIs in the "host project" for our
terraform
service accounts. I'm also happy to make any changes requested to this PR.Thanks!