Skip to content

Commit

Permalink
Merge pull request #182 from terraform-providers/f-user-agent
Browse files Browse the repository at this point in the history
provider: Use real Terraform version in UA header
  • Loading branch information
philippschulte authored Oct 9, 2019
2 parents bf98a19 + 116120b commit c5e67a8
Show file tree
Hide file tree
Showing 295 changed files with 8,401 additions and 5,247 deletions.
9 changes: 6 additions & 3 deletions fastly/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const TerraformProviderProductUserAgent = "terraform-provider-fastly"
type Config struct {
ApiKey string
BaseURL string

terraformVersion string
}

type FastlyClient struct {
Expand All @@ -27,9 +29,10 @@ func (c *Config) Client() (interface{}, error) {
return nil, fmt.Errorf("[Err] No API key for Fastly")
}

composedUserAgent := fmt.Sprintf("%s %s/%s", httpclient.UserAgentString(), TerraformProviderProductUserAgent, version.ProviderVersion)

gofastly.UserAgent = composedUserAgent
tfUserAgent := httpclient.TerraformUserAgent(c.terraformVersion)
providerUserAgent := fmt.Sprintf("%s/%s", TerraformProviderProductUserAgent, version.ProviderVersion)
ua := fmt.Sprintf("%s %s", tfUserAgent, providerUserAgent)
gofastly.UserAgent = ua

fastlyClient, err := gofastly.NewClientForEndpoint(c.ApiKey, c.BaseURL)
if err != nil {
Expand Down
21 changes: 16 additions & 5 deletions fastly/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// Provider returns a terraform.ResourceProvider.
func Provider() terraform.ResourceProvider {
return &schema.Provider{
provider := &schema.Provider{
Schema: map[string]*schema.Schema{
"api_key": {
Type: schema.TypeString,
Expand All @@ -32,15 +32,26 @@ func Provider() terraform.ResourceProvider {
"fastly_service_dictionary_items_v1": resourceServiceDictionaryItemsV1(),
"fastly_service_dynamic_snippet_content_v1": resourceServiceDynamicSnippetContentV1(),
},
}

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
}

func providerConfigure(d *schema.ResourceData) (interface{}, error) {
func providerConfigure(d *schema.ResourceData, terraformVersion string) (interface{}, error) {
config := Config{
ApiKey: d.Get("api_key").(string),
BaseURL: d.Get("base_url").(string),
ApiKey: d.Get("api_key").(string),
BaseURL: d.Get("base_url").(string),
terraformVersion: terraformVersion,
}
return config.Client()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ require (
github.com/fastly/go-fastly v1.2.1
github.com/google/jsonapi v0.0.0-20180313013858-2dcc18f43696 // indirect
github.com/hashicorp/go-cleanhttp v0.5.0
github.com/hashicorp/terraform v0.12.3
github.com/hashicorp/terraform v0.12.7
)
169 changes: 139 additions & 30 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vendor/github.com/aws/aws-sdk-go/aws/awserr/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions vendor/github.com/aws/aws-sdk-go/aws/awsutil/path_value.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions vendor/github.com/aws/aws-sdk-go/aws/client/logger.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 44 additions & 21 deletions vendor/github.com/aws/aws-sdk-go/aws/csm/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 28 additions & 6 deletions vendor/github.com/aws/aws-sdk-go/aws/csm/enable.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c5e67a8

Please sign in to comment.