Skip to content

Commit b6dfe05

Browse files
committedOct 5, 2018
Send provider version in user agent
This fixes user agents to conform to the RFC, it also takes advantage of a new build flag populating the binary version of the provider. The version sent in the user agent without the flag will be `terraform-provider-azurerm/dev` and for acceptance tests through `make testacc` `terraform-provider-azurerm/acc`. The binary should send a product in the user agent in the form of `terraform-provider-azurerm/1.2.3`.
1 parent 5e9fb57 commit b6dfe05

File tree

6 files changed

+80
-10
lines changed

6 files changed

+80
-10
lines changed
 

‎GNUmakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test: fmtcheck
2121
xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4
2222

2323
testacc: fmtcheck
24-
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 180m
24+
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 180m -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc"
2525

2626
debugacc: fmtcheck
2727
TF_ACC=1 dlv test $(TEST) --headless --listen=:2345 --api-version=2 -- -test.v $(TESTARGS)

‎azurerm/config.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"net/http/httputil"
99
"os"
10+
"strings"
1011
"sync"
1112
"time"
1213

@@ -64,9 +65,10 @@ import (
6465
"github.com/Azure/go-autorest/autorest/adal"
6566
"github.com/Azure/go-autorest/autorest/azure"
6667
uuid "github.com/hashicorp/go-uuid"
67-
"github.com/hashicorp/terraform/terraform"
68+
"github.com/hashicorp/terraform/httpclient"
6869
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/authentication"
6970
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
71+
"github.com/terraform-providers/terraform-provider-azurerm/version"
7072
)
7173

7274
// ArmClient contains the handles to all the specific Azure Resource Manager
@@ -338,18 +340,16 @@ func withRequestLogging() autorest.SendDecorator {
338340
}
339341

340342
func setUserAgent(client *autorest.Client) {
341-
tfVersion := fmt.Sprintf("HashiCorp-Terraform-v%s", terraform.VersionString())
343+
// TODO: This is the SDK version not the CLI version, once we are on 0.12, should revisit
344+
tfUserAgent := httpclient.UserAgentString()
342345

343-
// if the user agent already has a value append the Terraform user agent string
344-
if curUserAgent := client.UserAgent; curUserAgent != "" {
345-
client.UserAgent = fmt.Sprintf("%s;%s", curUserAgent, tfVersion)
346-
} else {
347-
client.UserAgent = tfVersion
348-
}
346+
pv := version.ProviderVersion
347+
providerUserAgent := fmt.Sprintf("%s terraform-provider-azurerm/%s", tfUserAgent, pv)
348+
client.UserAgent = strings.TrimSpace(fmt.Sprintf("%s %s", client.UserAgent, providerUserAgent))
349349

350350
// append the CloudShell version to the user agent if it exists
351351
if azureAgent := os.Getenv("AZURE_HTTP_USER_AGENT"); azureAgent != "" {
352-
client.UserAgent = fmt.Sprintf("%s;%s", client.UserAgent, azureAgent)
352+
client.UserAgent = fmt.Sprintf("%s %s", client.UserAgent, azureAgent)
353353
}
354354

355355
log.Printf("[DEBUG] AzureRM Client User Agent: %s\n", client.UserAgent)

‎vendor/github.com/hashicorp/terraform/httpclient/client.go

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/hashicorp/terraform/httpclient/useragent.go

+40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/vendor.json

+6
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,12 @@
10911091
"version": "=v0.11.3",
10921092
"versionExact": "v0.11.3"
10931093
},
1094+
{
1095+
"checksumSHA1": "kD1ayilNruf2cES1LDfNZjYRscQ=",
1096+
"path": "github.com/hashicorp/terraform/httpclient",
1097+
"revision": "c96155cc68b1da43e49893ddc19a609f0085af19",
1098+
"revisionTime": "2018-10-04T21:23:31Z"
1099+
},
10941100
{
10951101
"checksumSHA1": "yFWmdS6yEJZpRJzUqd/mULqCYGk=",
10961102
"path": "github.com/hashicorp/terraform/moduledeps",

‎version/version.go

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package version
2+
3+
var (
4+
// ProviderVersion is set during the release process to the release version of the binary
5+
ProviderVersion = "dev"
6+
)

0 commit comments

Comments
 (0)
Please sign in to comment.