diff --git a/.goreleaser.yml b/.goreleaser.yml index 8097aab79..d2fac0931 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -5,7 +5,7 @@ builds: flags: - -trimpath ldflags: - - '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}' + - '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X github.com/terraform-providers/terraform-provider-pagerduty/pagerduty.version={{.Version}} -X github.com/terraform-providers/terraform-provider-pagerduty/pagerduty.commit={{.Commit}}' tags: - timetzdata goos: diff --git a/pagerduty/provider.go b/pagerduty/provider.go index 12737ca7e..63d5b759a 100644 --- a/pagerduty/provider.go +++ b/pagerduty/provider.go @@ -3,13 +3,17 @@ package pagerduty import ( "fmt" "log" - "runtime" "strings" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/heimweh/go-pagerduty/pagerduty" ) +var ( + version = "dev" + commit = "none" +) + // Provider represents a resource provider in Terraform func Provider() *schema.Provider { p := &schema.Provider{ @@ -97,13 +101,26 @@ func Provider() *schema.Provider { } p.ConfigureFunc = func(d *schema.ResourceData) (interface{}, error) { - terraformVersion := p.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" + var ServiceRegion = strings.ToLower(d.Get("service_region").(string)) + + if ServiceRegion == "us" || ServiceRegion == "" { + ServiceRegion = "" + } else { + ServiceRegion = ServiceRegion + "." } - return providerConfigure(d, terraformVersion) + + config := Config{ + ApiUrl: "https://api." + ServiceRegion + "pagerduty.com", + AppUrl: "https://app." + ServiceRegion + "pagerduty.com", + SkipCredsValidation: d.Get("skip_credentials_validation").(bool), + Token: d.Get("token").(string), + UserToken: d.Get("user_token").(string), + UserAgent: p.UserAgent("terraform-provider-pagerduty", version), + ApiUrlOverride: d.Get("api_url_override").(string), + } + + log.Println("[INFO] Initializing PagerDuty client") + return &config, nil } return p @@ -129,26 +146,3 @@ func handleNotFoundError(err error, d *schema.ResourceData) error { } return genError(err, d) } - -func providerConfigure(data *schema.ResourceData, terraformVersion string) (interface{}, error) { - var ServiceRegion = strings.ToLower(data.Get("service_region").(string)) - - if ServiceRegion == "us" || ServiceRegion == "" { - ServiceRegion = "" - } else { - ServiceRegion = ServiceRegion + "." - } - - config := Config{ - ApiUrl: "https://api." + ServiceRegion + "pagerduty.com", - AppUrl: "https://app." + ServiceRegion + "pagerduty.com", - SkipCredsValidation: data.Get("skip_credentials_validation").(bool), - Token: data.Get("token").(string), - UserToken: data.Get("user_token").(string), - UserAgent: fmt.Sprintf("(%s %s) Terraform/%s", runtime.GOOS, runtime.GOARCH, terraformVersion), - ApiUrlOverride: data.Get("api_url_override").(string), - } - - log.Println("[INFO] Initializing PagerDuty client") - return &config, nil -}