provider: use the Plugin SDK default Terraform User-Agent - #1921
Open
lyoung-confluent wants to merge 1 commit into
Open
provider: use the Plugin SDK default Terraform User-Agent#1921lyoung-confluent wants to merge 1 commit into
lyoung-confluent wants to merge 1 commit into
Conversation
Delegate the Terraform, Plugin SDK and provider version portion of the User-Agent header to `(*schema.Provider).UserAgent`, which also appends the value of the `TF_APPEND_USER_AGENT` environment variable when set. Previously this string was built by hand and the environment variable was ignored. `UserAgent` reads only the `TerraformVersion` field of the receiver, so a bare `schema.Provider` produces the same string the provider instance would, and the acceptance test client - which builds clients without instantiating the provider - is covered by the same code path. Note this changes the format of the header: the `HashiCorp ` prefix is dropped and `Terraform Plugin SDK` becomes `Terraform-Plugin-SDK`. The `AZURE_HTTP_USER_AGENT` value and the `pid-<uuid>` partner ID token are unchanged and still trail the header. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Community Note
Description
The provider built the Terraform / Plugin SDK / provider portion of its
User-Agentheader by hand inClientOptions.userAgent, rather than using the Plugin SDK's(*schema.Provider).UserAgenthelper. Two things followed from that: the value of theTF_APPEND_USER_AGENTenvironment variable was ignored, and the emitted format drifted from the SDK default.This PR delegates that portion of the header to the SDK helper, which appends
TF_APPEND_USER_AGENTwhen set.UserAgentreads only theTerraformVersionfield of its receiver, so a bareschema.Providerproduces the same string the live provider instance would — this keeps a single code path covering both the provider and the acceptance test client, which builds clients without instantiating the provider.This changes the format of the header, which is worth a reviewer's attention: the
HashiCorpprefix is dropped andTerraform Plugin SDKbecomesTerraform-Plugin-SDK(the SDK's own spelling). TheAZURE_HTTP_USER_AGENT(Cloud Shell) value and thepid-<uuid>partner ID token are untouched and still trail the header, so partner attribution is unaffected. If any Microsoft-side telemetry depends on the current spelling, the narrower alternative is to keep the existing prefix and appendos.Getenv("TF_APPEND_USER_AGENT")explicitly — happy to switch to that instead.Before:
After, with
TF_APPEND_USER_AGENT="my-platform/1.0":Changes to existing Resource / Data Source
No resource or data source schemas change. The
User-Agentis set once on the shared Microsoft Graph client inClientOptions.Configure, so this affects every resource and data source at the transport layer only.Testing
Added
TestUserAgentininternal/common/client_options_test.go, a table test covering the base string, the go-azure-sdk agent,TF_APPEND_USER_AGENT(set, whitespace-trimmed, empty),AZURE_HTTP_USER_AGENT(set, empty), and the ordering of all four components alongside the partner ID.TestUserAgentAppendedValueIsNotDuplicatedguards against the appended value being added twice.These are unit tests requiring no credentials. No acceptance tests were run, as this change does not touch resource behaviour.
Change Log
User-Agentheader now uses the Terraform Plugin SDK default and honours theTF_APPEND_USER_AGENTenvironment variable [provider: use the Plugin SDK default Terraform User-Agent #1921]This is a (please select all that apply):
Related Issue(s)
Closes #1920
Rollback Plan
If a change needs to be reverted, we will publish an updated version of the provider.
Changes to Security Controls
No changes to access controls, encryption, or logging. The
User-Agentheader gains the contents of an environment variable the operator sets themselves; the existing request/response DEBUG logging is unchanged, including the redaction of theAuthorizationheader.