-
Notifications
You must be signed in to change notification settings - Fork 48
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
tailscale: fix default User-Agent header to include terraform version #361
Conversation
a418631
to
0af5102
Compare
@@ -8,24 +8,10 @@ import ( | |||
"github.com/tailscale/terraform-provider-tailscale/tailscale" | |||
) | |||
|
|||
// version is filled by goreleaser at build time. | |||
var version = "dev" |
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.
Moved this to provider.go
as that is the one place it is used currently and to avoid messiness with having to pass the version into the Provider
method.
@@ -84,14 +91,18 @@ func Provider(options ...ProviderOption) *schema.Provider { | |||
}, | |||
} | |||
|
|||
provider.ConfigureContextFunc = func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) { |
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.
Moved setting ConfigureContextFunc
here so we can pass the provider into providerConfigure
.
@@ -113,6 +124,9 @@ func providerConfigure(_ context.Context, d *schema.ResourceData) (interface{}, | |||
} | |||
|
|||
userAgent := d.Get("user_agent").(string) | |||
if userAgent == "" { | |||
userAgent = provider.UserAgent("terraform-provider-tailscale", providerVersion) |
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 essentially an identical call to what we were making before, but at this point the underlying provider.TerraformVersion
value used in the UserAgent call is populated properly.
@@ -5,7 +5,7 @@ builds: | |||
flags: | |||
- -trimpath | |||
ldflags: | |||
- "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}" | |||
- "-s -w -X github.com/tailscale/terraform-provider-tailscale/tailscale.providerVersion={{.Version}} -X main.commit={{.Commit}}" |
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 needs to be the fully qualified path since it no longer lives in main.go
. See here in the AzureRM Terraform provider for similar usage.
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.
Nice! Ty for digging into this
The `schema.Provider.UserAgent` helper function was previously being called at a point in the plugin lifecycle before the `TerraformVersion` for the provider was set by Terraform Core. This was resulting in the Terraform version information being missing from the User-Agent header. The call to `schema.Provider.UserAgent` has now been moved into the `providerConfigure` func as this is called later in the configure lifecycle where the Terraform version is properly set. Fixes tailscale/corp#19630 Signed-off-by: Mario Minardi <mario@tailscale.com>
0af5102
to
5aaffc9
Compare
The
schema.Provider.UserAgent
helper function was previously being called at a point in the plugin lifecycle before theTerraformVersion
for the provider was set by Terraform Core. This was resulting in the Terraform version information being missing from the User-Agent header. The call toschema.Provider.UserAgent
has now been moved into theproviderConfigure
func as this is called later in the configure lifecycle where the Terraform version is properly set.Header Before
Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.33.0 terraform-provider-tailscale/dev
Header After
Terraform/1.8.2 (+https://www.terraform.io) Terraform-Plugin-SDK/2.33.0 terraform-provider-tailscale/dev
Fixes /~https://github.com/tailscale/corp/issues/19630