Skip to content

Commit

Permalink
Make PagerDuty api.pagerduty.com and app.pagerduty.com configurable
Browse files Browse the repository at this point in the history
Make PagerDuty api.pagerduty.com and app.pagerduty.com configurable
  • Loading branch information
jbfavre committed Sep 9, 2021
1 parent 0490db7 commit 8aab478
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pagerduty/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import (

// Config defines the configuration options for the PagerDuty client
type Config struct {
// The PagerDuty API URL
ApiURL string

// The PagerDuty APP URL
AppURL string

// The PagerDuty API V2 token
Token string

Expand Down Expand Up @@ -40,6 +46,7 @@ func (c *Config) Client() (*pagerduty.Client, error) {
httpClient.Transport = logging.NewTransport("PagerDuty", http.DefaultTransport)

config := &pagerduty.Config{
BaseURL: c.ApiURL,
Debug: logging.IsDebugOrHigher(),
HTTPClient: httpClient,
Token: c.Token,
Expand Down
14 changes: 14 additions & 0 deletions pagerduty/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ func Provider() terraform.ResourceProvider {
Required: true,
DefaultFunc: schema.EnvDefaultFunc("PAGERDUTY_TOKEN", nil),
},

"apiurl": {
Type: schema.TypeString,
Optional: true,
Default: "https://api.pagerduty.com",
},

"appurl": {
Type: schema.TypeString,
Optional: true,
Default: "https://app.pagerduty.com",
},
},

DataSourcesMap: map[string]*schema.Resource{
Expand Down Expand Up @@ -99,6 +111,8 @@ func handleNotFoundError(err error, d *schema.ResourceData) error {

func providerConfigure(data *schema.ResourceData, terraformVersion string) (interface{}, error) {
config := Config{
ApiURL: data.Get("apiurl").(string),
AppURL: data.Get("appurl").(string),
SkipCredsValidation: data.Get("skip_credentials_validation").(bool),
Token: data.Get("token").(string),
UserAgent: fmt.Sprintf("(%s %s) Terraform/%s", runtime.GOOS, runtime.GOARCH, terraformVersion),
Expand Down

0 comments on commit 8aab478

Please sign in to comment.