diff --git a/google-beta/config.go b/google-beta/config.go index 0bae12b25e..d0de09213e 100644 --- a/google-beta/config.go +++ b/google-beta/config.go @@ -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 @@ -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 diff --git a/google-beta/provider.go b/google-beta/provider.go index fa47ab2cd9..31ace38796 100644 --- a/google-beta/provider.go +++ b/google-beta/provider.go @@ -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, @@ -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 @@ -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