Skip to content
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

terraform: Use real version in UA header #1107

Merged
merged 1 commit into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions google-beta/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ type Config struct {
BatchingConfig *batchingConfig
UserProjectOverride bool

client *http.Client
userAgent string
client *http.Client
terraformVersion string
userAgent string

tokenSource oauth2.TokenSource

Expand Down Expand Up @@ -263,10 +264,9 @@ func (c *Config) LoadAndValidate() error {
// timeout for the maximum amount of time a logical request can take.
client.Timeout, _ = time.ParseDuration("30s")

terraformVersion := httpclient.UserAgentString()
tfUserAgent := httpclient.TerraformUserAgent(c.terraformVersion)
providerVersion := fmt.Sprintf("terraform-provider-google-beta/%s", version.ProviderVersion)
terraformWebsite := "(+https://www.terraform.io)"
userAgent := fmt.Sprintf("%s %s %s", terraformVersion, terraformWebsite, providerVersion)
userAgent := fmt.Sprintf("%s %s", tfUserAgent, providerVersion)

c.client = client
c.userAgent = userAgent
Expand Down
17 changes: 14 additions & 3 deletions google-beta/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var mutexKV = mutexkv.NewMutexKV()

// Provider returns a terraform.ResourceProvider.
func Provider() terraform.ResourceProvider {
return &schema.Provider{
provider := &schema.Provider{
Schema: map[string]*schema.Schema{
"credentials": {
Type: schema.TypeString,
Expand Down Expand Up @@ -434,9 +434,19 @@ func Provider() terraform.ResourceProvider {
},

ResourcesMap: ResourceMap(),
}

ConfigureFunc: providerConfigure,
provider.ConfigureFunc = func(d *schema.ResourceData) (interface{}, error) {
terraformVersion := provider.TerraformVersion
if terraformVersion == "" {
// Terraform 0.12 introduced this field to the protocol
// We can therefore assume that if it's missing it's 0.10 or 0.11
terraformVersion = "0.11+compatible"
}
return providerConfigure(d, terraformVersion)
}

return provider
}

// Generated resources: 88
Expand Down Expand Up @@ -681,12 +691,13 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
)
}

func providerConfigure(d *schema.ResourceData) (interface{}, error) {
func providerConfigure(d *schema.ResourceData, terraformVersion string) (interface{}, error) {
config := Config{
Project: d.Get("project").(string),
Region: d.Get("region").(string),
Zone: d.Get("zone").(string),
UserProjectOverride: d.Get("user_project_override").(bool),
terraformVersion: terraformVersion,
}

// Add credential source
Expand Down