Skip to content

Commit

Permalink
terraform: Use real version in UA header (#1107)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored and paddycarver committed Aug 29, 2019
1 parent 6e7028c commit e5df69e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
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

0 comments on commit e5df69e

Please sign in to comment.