Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Migrate to new sdk (PagerDuty#158)
Browse files Browse the repository at this point in the history
* prepare for sdk migration: remove depracated versionString

* Migrate from github.com/hashicorp/terraform to github.com/hashicorp/terraform-plugin-sdk
  • Loading branch information
gordonbondon authored and heimweh committed Oct 20, 2019
1 parent 1118af8 commit 98f5396
Show file tree
Hide file tree
Showing 1,080 changed files with 49,302 additions and 39,192 deletions.
6 changes: 4 additions & 2 deletions go.mod
@@ -1,7 +1,9 @@
module github.com/terraform-providers/terraform-provider-pagerduty

require (
github.com/hashicorp/go-hclog v0.7.0 // indirect
github.com/hashicorp/terraform v0.12.0
github.com/google/go-querystring v1.0.0 // indirect
github.com/hashicorp/terraform-plugin-sdk v1.0.0
github.com/heimweh/go-pagerduty v0.0.0-20190807171021-2a6540956dc5
)

go 1.13
427 changes: 135 additions & 292 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion main.go
@@ -1,7 +1,7 @@
package main

import (
"github.com/hashicorp/terraform/plugin"
"github.com/hashicorp/terraform-plugin-sdk/plugin"
"github.com/terraform-providers/terraform-provider-pagerduty/pagerduty"
)

Expand Down
9 changes: 5 additions & 4 deletions pagerduty/config.go
Expand Up @@ -4,10 +4,8 @@ import (
"fmt"
"log"
"net/http"
"runtime"

"github.com/hashicorp/terraform/helper/logging"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform-plugin-sdk/helper/logging"
"github.com/heimweh/go-pagerduty/pagerduty"
)

Expand All @@ -18,6 +16,9 @@ type Config struct {

// Skip validation of the token against the PagerDuty API
SkipCredsValidation bool

// UserAgent for API Client
UserAgent string
}

const invalidCreds = `
Expand All @@ -42,7 +43,7 @@ func (c *Config) Client() (*pagerduty.Client, error) {
Debug: logging.IsDebugOrHigher(),
HTTPClient: httpClient,
Token: c.Token,
UserAgent: fmt.Sprintf("(%s %s) Terraform/%s", runtime.GOOS, runtime.GOARCH, terraform.VersionString()),
UserAgent: c.UserAgent,
}

client, err := pagerduty.NewClient(config)
Expand Down
2 changes: 1 addition & 1 deletion pagerduty/data_source_pagerduty_escalation_policy.go
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/heimweh/go-pagerduty/pagerduty"
)

Expand Down
6 changes: 3 additions & 3 deletions pagerduty/data_source_pagerduty_escalation_policy_test.go
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

func TestAccDataSourcePagerDutyEscalationPolicy_Basic(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pagerduty/data_source_pagerduty_extension_schema.go
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"strings"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/heimweh/go-pagerduty/pagerduty"
)

Expand Down
4 changes: 2 additions & 2 deletions pagerduty/data_source_pagerduty_extension_schema_test.go
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

func TestAccDataSourcePagerDutyExtensionSchema_Basic(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pagerduty/data_source_pagerduty_schedule.go
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/heimweh/go-pagerduty/pagerduty"
)

Expand Down
6 changes: 3 additions & 3 deletions pagerduty/data_source_pagerduty_schedule_test.go
Expand Up @@ -5,9 +5,9 @@ import (
"testing"
"time"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

func TestAccDataSourcePagerDutySchedule_Basic(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pagerduty/data_source_pagerduty_service.go
Expand Up @@ -2,7 +2,7 @@ package pagerduty

import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/heimweh/go-pagerduty/pagerduty"
"log"
)
Expand Down
6 changes: 3 additions & 3 deletions pagerduty/data_source_pagerduty_service_test.go
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

func TestAccDataSourcePagerDutyService_Basic(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pagerduty/data_source_pagerduty_team.go
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/heimweh/go-pagerduty/pagerduty"
)

Expand Down
6 changes: 3 additions & 3 deletions pagerduty/data_source_pagerduty_team_test.go
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

func TestAccDataSourcePagerDutyTeam_Basic(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pagerduty/data_source_pagerduty_user.go
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/heimweh/go-pagerduty/pagerduty"
)

Expand Down
6 changes: 3 additions & 3 deletions pagerduty/data_source_pagerduty_user_test.go
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

func TestAccDataSourcePagerDutyUser_Basic(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pagerduty/data_source_pagerduty_vendor.go
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"regexp"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/heimweh/go-pagerduty/pagerduty"
)

Expand Down
2 changes: 1 addition & 1 deletion pagerduty/data_source_pagerduty_vendor_test.go
Expand Up @@ -3,7 +3,7 @@ package pagerduty
import (
"testing"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccDataSourcePagerDutyVendor_Basic(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pagerduty/import_pagerduty_escalation_policy_test.go
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccPagerDutyEscalationPolicy_import(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pagerduty/import_pagerduty_event_rule_test.go
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccPagerDutyEventRule_import(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pagerduty/import_pagerduty_extension_test.go
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccPagerDutyExtension_import(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pagerduty/import_pagerduty_maintenance_window_test.go
Expand Up @@ -5,8 +5,8 @@ import (
"testing"
"time"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccPagerDutyMaintenanceWindow_import(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pagerduty/import_pagerduty_schedule_test.go
Expand Up @@ -5,8 +5,8 @@ import (
"testing"
"time"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccPagerDutySchedule_import(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions pagerduty/import_pagerduty_service_integration_test.go
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

func TestAccPagerDutyServiceIntegration_import(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pagerduty/import_pagerduty_service_test.go
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccPagerDutyService_import(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pagerduty/import_pagerduty_team_membership_test.go
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccPagerDutyTeamMembership_import(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pagerduty/import_pagerduty_team_test.go
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccPagerDutyTeam_import(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions pagerduty/import_pagerduty_user_contact_method_test.go
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

func TestAccPagerDutyUserContactMethod_import(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pagerduty/import_pagerduty_user_test.go
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccPagerDutyUser_import(t *testing.T) {
Expand Down
22 changes: 17 additions & 5 deletions pagerduty/provider.go
Expand Up @@ -3,15 +3,16 @@ package pagerduty
import (
"fmt"
"log"
"runtime"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/heimweh/go-pagerduty/pagerduty"
)

// Provider represents a resource provider in Terraform
func Provider() terraform.ResourceProvider {
return &schema.Provider{
p := &schema.Provider{
Schema: map[string]*schema.Schema{
"skip_credentials_validation": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -50,9 +51,19 @@ func Provider() terraform.ResourceProvider {
"pagerduty_extension": resourcePagerDutyExtension(),
"pagerduty_event_rule": resourcePagerDutyEventRule(),
},
}

ConfigureFunc: providerConfigure,
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"
}
return providerConfigure(d, terraformVersion)
}

return p
}

func isErrCode(err error, code int) bool {
Expand All @@ -73,10 +84,11 @@ func handleNotFoundError(err error, d *schema.ResourceData) error {
return fmt.Errorf("Error reading: %s: %s", d.Id(), err)
}

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

log.Println("[INFO] Initializing PagerDuty client")
Expand Down
4 changes: 2 additions & 2 deletions pagerduty/provider_test.go
Expand Up @@ -6,8 +6,8 @@ import (
"testing"
"time"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

var testAccProviders map[string]terraform.ResourceProvider
Expand Down
2 changes: 1 addition & 1 deletion pagerduty/resource_pagerduty_addon.go
Expand Up @@ -3,7 +3,7 @@ package pagerduty
import (
"log"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/heimweh/go-pagerduty/pagerduty"
)

Expand Down

0 comments on commit 98f5396

Please sign in to comment.