-
Notifications
You must be signed in to change notification settings - Fork 319
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
Enable custom UserAgent #451
Conversation
For the user agent, can we use https://github.com/hashicorp/terraform-plugin-sdk/blob/9da7cbac0dfcd4c7096105eeda94ea69f53c1101/helper/schema/provider.go#L451 ? Thanks! |
How much work is it to go to the v2 of the sdk? |
Not sure but there is a lot of breaking changes between 1.x and 2.x: https://github.com/hashicorp/terraform-plugin-sdk/blob/master/CHANGELOG.md |
In 1.0 we have httpclient which has the function we want |
Nice good find! |
@bishtawi thanks for this. So what is the strong generated by Basically our goal here is to be able to identify API requests originating from the terraform gitlab provider. |
|
||
// NOTE: httpclient.TerraformUserAgent is deprecated and removed in Terraform SDK v2 | ||
// After upgrading the SDK to v2 replace with p.UserAgent() | ||
TerraformUserAgent: httpclient.TerraformUserAgent(p.TerraformVersion), | ||
} | ||
|
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.
client := provider.Client()
client.UserAgent = httpclient.TerraformUserAgent(p.TerraformVersion)
return client
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. Personally I am not a fan of the providerConfigure
function customizing the client
as that seems to be the responsibility of the Client()
function but the code is indeed simpler.
|
||
ConfigureFunc: providerConfigure, | ||
provider.ConfigureFunc = func(d *schema.ResourceData) (interface{}, error) { | ||
return providerConfigure(provider, d) | ||
} |
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 is not needed
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.
Why do you think this is not needed? The providerConfigure
function needs the provider
object to get the Terraform version number. Wrapping the providerConfigure
function allows us to do this. Is there another way to accomplish it?
It looks like this pull request is way too complicated and it could all be done in gitlab/provider.go |
@roidelapluie Sure I can simplify it; I was just trying to keep with the existing code structure by having all the specific Gitlab Client customizations in the @nicholasklick No, the |
Useragent will look like
|
@bishtawi that useragent string looks good thanks! |
@roidelapluie @armsnyder if this looks good I would love to merge and ship a new release. |
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.
LGTM. A possible future improvement is to include the terraform-provider-gitlab provider version in the string somewhere. GoReleaser supports setting a version variable at release time, using ldflags, which could do this. https://goreleaser.com/customization/build/
Resolves https://github.com/gitlabhq/terraform-provider-gitlab/issues/450