Skip to content

Commit bfb5cb5

Browse files
paddycarverPaddy
authored andcommitted
Add helper/schema.Provider.UserAgent helper.
Add a helper function to generate the suggested User-Agent header for provider requests.
1 parent aab3dc3 commit bfb5cb5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

helper/schema/provider.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1313
"github.com/hashicorp/terraform-plugin-sdk/v2/internal/configs/configschema"
14+
"github.com/hashicorp/terraform-plugin-sdk/v2/meta"
1415
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1516
)
1617

@@ -426,3 +427,12 @@ func (p *Provider) DataSources() []terraform.DataSource {
426427

427428
return result
428429
}
430+
431+
// UserAgent returns a string suitable for use in the User-Agent header of
432+
// requests generated by the provider. The generated string contains the
433+
// version of Terraform, the Plugin SDK, and the provider used to generate the
434+
// request. `name` should be the hyphen-separated reporting name of the
435+
// provider, and `version` should be the version of the provider.
436+
func (p *Provider) UserAgent(name, version string) string {
437+
return fmt.Sprintf("Terraform/%s (+https://www.terraform.io) Terraform-Plugin-SDK/%s %s/%s", p.TerraformVersion, meta.SDKVersionString(), name, version)
438+
}

0 commit comments

Comments
 (0)