Skip to content

provider: use the Plugin SDK default Terraform User-Agent - #1921

Open
lyoung-confluent wants to merge 1 commit into
hashicorp:mainfrom
lyoung-confluent:claude/terraform-user-agent-default-6dca50
Open

provider: use the Plugin SDK default Terraform User-Agent#1921
lyoung-confluent wants to merge 1 commit into
hashicorp:mainfrom
lyoung-confluent:claude/terraform-user-agent-default-6dca50

Conversation

@lyoung-confluent

@lyoung-confluent lyoung-confluent commented Aug 11, 2026

Copy link
Copy Markdown

Community Note

  • Please vote on this PR by adding a 👍 reaction to the original PR to help the community and maintainers prioritize for review
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for PR followers and do not help prioritize for review

Description

The provider built the Terraform / Plugin SDK / provider portion of its User-Agent header by hand in ClientOptions.userAgent, rather than using the Plugin SDK's (*schema.Provider).UserAgent helper. Two things followed from that: the value of the TF_APPEND_USER_AGENT environment 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_AGENT when set. UserAgent reads only the TerraformVersion field of its receiver, so a bare schema.Provider produces 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 HashiCorp prefix is dropped and Terraform Plugin SDK becomes Terraform-Plugin-SDK (the SDK's own spelling). The AZURE_HTTP_USER_AGENT (Cloud Shell) value and the pid-<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 append os.Getenv("TF_APPEND_USER_AGENT") explicitly — happy to switch to that instead.

Before:

HashiCorp Terraform/1.14.0 (+https://www.terraform.io) Terraform Plugin SDK/2.40.1 terraform-provider-azuread/3.9.0 HashiCorp/go-azure-sdk (Go-http-client/1.1) pid-222b7c9b-8f2c-4b8c-9b3f-a1b2c3d4e5f6

After, with TF_APPEND_USER_AGENT="my-platform/1.0":

Terraform/1.14.0 (+https://www.terraform.io) Terraform-Plugin-SDK/2.40.1 terraform-provider-azuread/3.9.0 my-platform/1.0 HashiCorp/go-azure-sdk (Go-http-client/1.1) pid-222b7c9b-8f2c-4b8c-9b3f-a1b2c3d4e5f6

Changes to existing Resource / Data Source

  • I have added an explanation of what my changes do and why I'd like you to include them (This may be covered by linking to an issue above, but may benefit from additional explanation).
  • I have written new tests for my resource or datasource changes & updated any relevant documentation.
  • I have successfully run tests with my changes locally. If not, please provide details on testing challenges that prevented you running the tests.
  • (For changes that include a state migration only). I have manually tested the migration path between relevant versions of the provider.

No resource or data source schemas change. The User-Agent is set once on the shared Microsoft Graph client in ClientOptions.Configure, so this affects every resource and data source at the transport layer only.

Testing

  • My submission includes Test coverage as described in the Contribution Guide and the tests pass. (if this is not possible for any reason, please include details of why you did or could not add test coverage)

Added TestUserAgent in internal/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. TestUserAgentAppendedValueIsNotDuplicated guards against the appended value being added twice.

$ go test ./internal/common/...
ok  	github.com/hashicorp/terraform-provider-azuread/internal/common	0.814s

These are unit tests requiring no credentials. No acceptance tests were run, as this change does not touch resource behaviour.

Change Log

This is a (please select all that apply):

  • Bug Fix
  • New Feature (ie adding a service, resource, or data source)
  • Enhancement
  • Breaking Change

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-Agent header gains the contents of an environment variable the operator sets themselves; the existing request/response DEBUG logging is unchanged, including the redaction of the Authorization header.

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>
@lyoung-confluent
lyoung-confluent marked this pull request as ready for review August 11, 2026 21:56
@lyoung-confluent
lyoung-confluent requested a review from a team as a code owner August 11, 2026 21:56
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.

Feature Request: Use the Plugin SDK's default Terraform User-Agent and support TF_APPEND_USER_AGENT

1 participant