Skip to content

Commit

Permalink
fix to allow running provider
Browse files Browse the repository at this point in the history
  • Loading branch information
DrFaust92 committed Sep 21, 2021
1 parent 313023b commit d888d33
Show file tree
Hide file tree
Showing 7 changed files with 423 additions and 412 deletions.
27 changes: 13 additions & 14 deletions pingdom/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pingdom

import (
"errors"
"github.com/nordcloud/go-pingdom/solarwinds"
"log"
"os"

Expand All @@ -21,7 +20,7 @@ type Config struct {
type Clients struct {
Pingdom *pingdom.Client
PingdomExt *pingdomext.Client
Solarwinds *solarwinds.Client
// Solarwinds *solarwinds.Client
}

func (c *Config) Client() (*Clients, error) {
Expand All @@ -40,17 +39,17 @@ func (c *Config) Client() (*Clients, error) {
if orgID := os.Getenv("SOLARWINDS_ORG_ID"); orgID != "" {
c.SolarwindsOrgID = orgID
}
solarwindsClient, err := solarwinds.NewClient(solarwinds.ClientConfig{
Username: c.SolarwindsUser,
Password: c.SolarwindsPassword,
})
if err != nil {
return nil, err
}
err = solarwindsClient.Init()
if err != nil {
return nil, err
}
// solarwindsClient, err := solarwinds.NewClient(solarwinds.ClientConfig{
// Username: c.SolarwindsUser,
// Password: c.SolarwindsPassword,
// })
// if err != nil {
// return nil, err
// }
// err = solarwindsClient.Init()
// if err != nil {
// return nil, err
// }

pingdomClientExt, err := pingdomext.NewClientWithConfig(pingdomext.ClientConfig{
Username: c.SolarwindsUser,
Expand All @@ -65,7 +64,7 @@ func (c *Config) Client() (*Clients, error) {
return &Clients{
Pingdom: pingdomClient,
PingdomExt: pingdomClientExt,
Solarwinds: solarwindsClient,
// Solarwinds: solarwindsClient,
}, nil
}

Expand Down
6 changes: 3 additions & 3 deletions pingdom/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func Provider() *schema.Provider {
"pingdom_contact": resourcePingdomContact(),
"pingdom_integration": resourcePingdomIntegration(),
"pingdom_maintenance": resourcePingdomMaintenance(),
"pingdom_user": resourceSolarwindsUser(),
"pingdom_occurrence": resourcePingdomOccurrences(),
"pingdom_tms_check": resourcePingdomTmsCheck(),
// "pingdom_user": resourceSolarwindsUser(),
"pingdom_occurrence": resourcePingdomOccurrences(),
"pingdom_tms_check": resourcePingdomTmsCheck(),
},
DataSourcesMap: map[string]*schema.Resource{
"pingdom_contact": dataSourcePingdomContact(),
Expand Down
12 changes: 6 additions & 6 deletions pingdom/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ func testAccPreCheck(t *testing.T) {
if v := os.Getenv("PINGDOM_API_TOKEN"); v == "" {
t.Fatal("PINGDOM_API_TOKEN environment variable must be set for acceptance tests")
}
if v := os.Getenv("SOLARWINDS_USER"); v == "" {
t.Fatal("SOLARWINDS_USER environment variable must be set for acceptance tests")
}
if v := os.Getenv("SOLARWINDS_PASSWD"); v == "" {
t.Fatal("SOLARWINDS_PASSWD environment variable must be set for acceptance tests")
}
// if v := os.Getenv("SOLARWINDS_USER"); v == "" {
// t.Fatal("SOLARWINDS_USER environment variable must be set for acceptance tests")
// }
// if v := os.Getenv("SOLARWINDS_PASSWD"); v == "" {
// t.Fatal("SOLARWINDS_PASSWD environment variable must be set for acceptance tests")
// }
}

func testAccCheckPingdomResourceID(name string) resource.TestCheckFunc {
Expand Down
36 changes: 22 additions & 14 deletions pingdom/resource_pingdom_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import (
"github.com/nordcloud/go-pingdom/pingdom"
)

const (
checkTypeHttp = "http"
checkTypeTcp = "tcp"
checkTypePing = "ping"
checkTypeDns = "dns"
)

func resourcePingdomCheck() *schema.Resource {
return &schema.Resource{
CreateContext: resourcePingdomCheckCreate,
Expand All @@ -37,7 +44,7 @@ func resourcePingdomCheck() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"http", "tcp", "ping"}, false),
ValidateFunc: validation.StringInSlice([]string{checkTypeHttp, checkTypeTcp, checkTypePing, checkTypeDns}, false),
},
"paused": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -69,7 +76,7 @@ func resourcePingdomCheck() *schema.Resource {
"notifywhenbackup": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Default: false,
},
"integrationids": {
Type: schema.TypeSet,
Expand Down Expand Up @@ -165,9 +172,10 @@ func resourcePingdomCheck() *schema.Resource {
DiffSuppressFunc: diffSuppressIfNotHTTPCheck,
},
"ssl_down_days_before": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Type: schema.TypeInt,
Optional: true,
Default: 0,
DiffSuppressFunc: diffSuppressIfNotHTTPCheck,
},
},
}
Expand Down Expand Up @@ -205,7 +213,7 @@ type commonCheckParams struct {
}

func diffSuppressIfNotHTTPCheck(k string, old string, new string, d *schema.ResourceData) bool {
return d.Get("type").(string) != "http"
return d.Get("type").(string) != checkTypeHttp
}

func sortString(input string, seperator string) string {
Expand Down Expand Up @@ -349,7 +357,7 @@ func checkForResource(d *schema.ResourceData) (pingdom.Check, error) {

checkType := d.Get("type")
switch checkType {
case "http":
case checkTypeHttp:
return &pingdom.HttpCheck{
Name: checkParams.Name,
Hostname: checkParams.Hostname,
Expand All @@ -376,7 +384,7 @@ func checkForResource(d *schema.ResourceData) (pingdom.Check, error) {
VerifyCertificate: &checkParams.VerifyCertificate,
SSLDownDaysBefore: &checkParams.SSLDownDaysBefore,
}, nil
case "ping":
case checkTypePing:
return &pingdom.PingCheck{
Name: checkParams.Name,
Hostname: checkParams.Hostname,
Expand All @@ -392,7 +400,7 @@ func checkForResource(d *schema.ResourceData) (pingdom.Check, error) {
UserIds: checkParams.UserIds,
TeamIds: checkParams.TeamIds,
}, nil
case "tcp":
case checkTypeTcp:
return &pingdom.TCPCheck{
Name: checkParams.Name,
Hostname: checkParams.Hostname,
Expand All @@ -410,7 +418,7 @@ func checkForResource(d *schema.ResourceData) (pingdom.Check, error) {
StringToSend: checkParams.StringToSend,
StringToExpect: checkParams.StringToExpect,
}, nil
case "dns":
case checkTypeDns:
return &pingdom.DNSCheck{
Name: checkParams.Name,
Hostname: checkParams.Hostname,
Expand Down Expand Up @@ -566,7 +574,7 @@ func resourcePingdomCheckRead(ctx context.Context, d *schema.ResourceData, meta
}

if ck.Type.HTTP != nil {
if err := d.Set("type", "http"); err != nil {
if err := d.Set("type", checkTypeHttp); err != nil {
return diag.FromErr(err)
}
if err := d.Set("responsetime_threshold", ck.ResponseTimeThreshold); err != nil {
Expand Down Expand Up @@ -612,7 +620,7 @@ func resourcePingdomCheckRead(ctx context.Context, d *schema.ResourceData, meta
return diag.FromErr(err)
}
} else if ck.Type.TCP != nil {
if err := d.Set("type", "tcp"); err != nil {
if err := d.Set("type", checkTypeTcp); err != nil {
return diag.FromErr(err)
}
if err := d.Set("port", ck.Type.TCP.Port); err != nil {
Expand All @@ -625,7 +633,7 @@ func resourcePingdomCheckRead(ctx context.Context, d *schema.ResourceData, meta
return diag.FromErr(err)
}
} else if ck.Type.DNS != nil {
if err := d.Set("type", "dns"); err != nil {
if err := d.Set("type", checkTypeDns); err != nil {
return diag.FromErr(err)
}
if err := d.Set("expectedip", ck.Type.DNS.ExpectedIP); err != nil {
Expand All @@ -635,7 +643,7 @@ func resourcePingdomCheckRead(ctx context.Context, d *schema.ResourceData, meta
return diag.FromErr(err)
}
} else {
if err := d.Set("type", "ping"); err != nil {
if err := d.Set("type", checkTypePing); err != nil {
return diag.FromErr(err)
}
}
Expand Down
30 changes: 17 additions & 13 deletions pingdom/resource_pingdom_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestAccResourcePingdomCheck_http(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "url", "/"),
resource.TestCheckResourceAttr(resourceName, "encryption", "false"),
resource.TestCheckResourceAttr(resourceName, "port", "80"),
resource.TestCheckResourceAttr(resourceName, "responsetime_threshold", "30000"),
// resource.TestCheckResourceAttr(resourceName, "responsetime_threshold", "30000"),
resource.TestCheckResourceAttr(resourceName, "postdata", ""),
resource.TestCheckResourceAttr(resourceName, "integrationids.#", "0"),
resource.TestCheckResourceAttr(resourceName, "tags", ""),
Expand All @@ -49,9 +49,10 @@ func TestAccResourcePingdomCheck_http(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"paused"},
},
{
Config: testAccResourcePingdomCheckConfig_http_update(updatedName),
Expand Down Expand Up @@ -105,9 +106,10 @@ func TestAccResourcePingdomCheck_tcp(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"paused"},
},
{
Config: testAccResourcePingdomCheckConfig_tcp_update(updatedName),
Expand Down Expand Up @@ -143,9 +145,10 @@ func TestAccResourcePingdomCheck_ping(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"paused"},
},
{
Config: testAccResourcePingdomCheckConfig_ping_update(updatedName),
Expand Down Expand Up @@ -182,9 +185,10 @@ func TestAccResourcePingdomCheck_dns(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"paused"},
},
{
Config: testAccResourcePingdomCheckConfig_dns_update(updatedName),
Expand Down
Loading

0 comments on commit d888d33

Please sign in to comment.