Skip to content

Commit

Permalink
provider: Use real Terraform version in UA header
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Sep 17, 2019
1 parent ed7a47f commit 0e183c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 4 additions & 2 deletions aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ import (
"github.com/aws/aws-sdk-go/service/xray"
awsbase "github.com/hashicorp/aws-sdk-go-base"
"github.com/hashicorp/terraform/helper/logging"
"github.com/hashicorp/terraform/terraform"
)

type Config struct {
Expand Down Expand Up @@ -166,6 +165,8 @@ type Config struct {
SkipRequestingAccountId bool
SkipMetadataApiCheck bool
S3ForcePathStyle bool

terraformVersion string
}

type AWSClient struct {
Expand Down Expand Up @@ -335,7 +336,8 @@ func (c *Config) Client() (interface{}, error) {
UserAgentProducts: []*awsbase.UserAgentProduct{
{Name: "APN", Version: "1.0"},
{Name: "HashiCorp", Version: "1.0"},
{Name: "Terraform", Version: terraform.VersionString()},
{Name: "Terraform", Version: c.terraformVersion,
Extra: []string{"+https://www.terraform.io"}},
},
}

Expand Down
18 changes: 15 additions & 3 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func Provider() terraform.ResourceProvider {
// TODO: Move the configuration to this, requires validation

// The actual provider
return &schema.Provider{
provider := &schema.Provider{
Schema: map[string]*schema.Schema{
"access_key": {
Type: schema.TypeString,
Expand Down Expand Up @@ -827,8 +827,19 @@ func Provider() terraform.ResourceProvider {
"aws_alb_target_group_attachment": resourceAwsLbTargetGroupAttachment(),
"aws_lb_target_group_attachment": resourceAwsLbTargetGroupAttachment(),
},
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
}

var descriptions map[string]string
Expand Down Expand Up @@ -1025,7 +1036,7 @@ func init() {
}
}

func providerConfigure(d *schema.ResourceData) (interface{}, error) {
func providerConfigure(d *schema.ResourceData, terraformVersion string) (interface{}, error) {
config := Config{
AccessKey: d.Get("access_key").(string),
SecretKey: d.Get("secret_key").(string),
Expand All @@ -1041,6 +1052,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
SkipRequestingAccountId: d.Get("skip_requesting_account_id").(bool),
SkipMetadataApiCheck: d.Get("skip_metadata_api_check").(bool),
S3ForcePathStyle: d.Get("s3_force_path_style").(bool),
terraformVersion: terraformVersion,
}

// Set CredsFilename, expanding home directory
Expand Down

0 comments on commit 0e183c1

Please sign in to comment.