diff --git a/pingdom/config.go b/pingdom/config.go index 43c861b4..90f71166 100644 --- a/pingdom/config.go +++ b/pingdom/config.go @@ -2,7 +2,6 @@ package pingdom import ( "errors" - "github.com/nordcloud/go-pingdom/solarwinds" "log" "os" @@ -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) { @@ -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, @@ -65,7 +64,7 @@ func (c *Config) Client() (*Clients, error) { return &Clients{ Pingdom: pingdomClient, PingdomExt: pingdomClientExt, - Solarwinds: solarwindsClient, + // Solarwinds: solarwindsClient, }, nil } diff --git a/pingdom/provider.go b/pingdom/provider.go index a7942339..ed61d37f 100644 --- a/pingdom/provider.go +++ b/pingdom/provider.go @@ -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(), diff --git a/pingdom/provider_test.go b/pingdom/provider_test.go index 800e86f1..d8abffae 100644 --- a/pingdom/provider_test.go +++ b/pingdom/provider_test.go @@ -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 { diff --git a/pingdom/resource_pingdom_check.go b/pingdom/resource_pingdom_check.go index 3de349a5..26eb2c4e 100644 --- a/pingdom/resource_pingdom_check.go +++ b/pingdom/resource_pingdom_check.go @@ -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, @@ -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, @@ -69,7 +76,7 @@ func resourcePingdomCheck() *schema.Resource { "notifywhenbackup": { Type: schema.TypeBool, Optional: true, - Default: true, + Default: false, }, "integrationids": { Type: schema.TypeSet, @@ -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, }, }, } @@ -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 { @@ -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, @@ -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, @@ -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, @@ -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, @@ -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 { @@ -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 { @@ -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 { @@ -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) } } diff --git a/pingdom/resource_pingdom_check_test.go b/pingdom/resource_pingdom_check_test.go index a59435a2..8de20f90 100644 --- a/pingdom/resource_pingdom_check_test.go +++ b/pingdom/resource_pingdom_check_test.go @@ -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", ""), @@ -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), @@ -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), @@ -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), @@ -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), diff --git a/pingdom/resource_pingdom_user.go b/pingdom/resource_pingdom_user.go index fa10bbd0..6493ca7d 100644 --- a/pingdom/resource_pingdom_user.go +++ b/pingdom/resource_pingdom_user.go @@ -1,202 +1,202 @@ package pingdom -import ( - "context" - "errors" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/nordcloud/go-pingdom/solarwinds" - "log" - "time" -) - -const ( - DeleteUserRetryTimeout = 1 * time.Minute -) - -func resourceSolarwindsUser() *schema.Resource { - return &schema.Resource{ - CreateContext: resourceSolarwindsUserCreate, - ReadContext: resourceSolarwindsUserRead, - UpdateContext: resourceSolarwindsUserUpdate, - DeleteContext: resourceSolarwindsUserDelete, - Importer: &schema.ResourceImporter{ - StateContext: schema.ImportStatePassthroughContext, - }, - Schema: map[string]*schema.Schema{ - "email": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - "role": { - Type: schema.TypeString, - Required: true, - ForceNew: false, - }, - "products": { - Type: schema.TypeSet, - Optional: true, - ForceNew: false, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - }, - "role": { - Type: schema.TypeString, - Required: true, - }, - }, - }, - }, - }, - } -} - -func userFromResource(d *schema.ResourceData) (*solarwinds.User, error) { - user := solarwinds.User{} - - // required - if v, ok := d.GetOk("email"); ok { - user.Email = v.(string) - } - - if v, ok := d.GetOk("role"); ok { - user.Role = v.(string) - } - - if v, ok := d.GetOk("products"); ok { - interfaceSlice := v.(*schema.Set).List() - user.Products = expandUserProducts(interfaceSlice) - } - - return &user, nil -} - -func expandUserProducts(l []interface{}) []solarwinds.Product { - if len(l) == 0 || l[0] == nil { - return nil - } - - m := make([]solarwinds.Product, 0, len(l)) - for _, tfMapRaw := range l { - tfMap, ok := tfMapRaw.(map[string]interface{}) - if !ok { - continue - } - product := solarwinds.Product{} - if name, ok := tfMap["name"].(string); ok && name != "" { - product.Name = name - } - if role, ok := tfMap["role"].(string); ok && role != "" { - product.Role = role - } - m = append(m, product) - } - - return m -} - -func resourceSolarwindsUserCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - client := meta.(*Clients).Solarwinds - - user, err := userFromResource(d) - if err != nil { - return diag.FromErr(err) - } - - log.Printf("[DEBUG] User create configuration: %#v", d.Get("email")) - err = client.UserService.Create(*user) - if err != nil { - return diag.FromErr(err) - } - - d.SetId(user.Email) - return resourceSolarwindsUserRead(ctx, d, meta) -} - -func resourceSolarwindsUserRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - client := meta.(*Clients).Solarwinds - - email := d.Id() - user, err := client.UserService.Retrieve(email) - if err != nil { - return diag.Errorf("error retrieving user with email %v", email) - } - if user == nil { - d.SetId("") - return nil - } - - for k, v := range map[string]interface{}{ - "email": user.Email, - "role": user.Role, - "products": flattenUserProducts(user.Products), - } { - if err := d.Set(k, v); err != nil { - return diag.FromErr(err) - } - } - - return nil -} - -func flattenUserProducts(l []solarwinds.Product) []interface{} { - if l == nil { - return []interface{}{} - } - sets := make([]interface{}, 0, len(l)) - for _, item := range l { - tfMap := map[string]interface{}{ - "name": item.Name, - "role": item.Role, - } - sets = append(sets, tfMap) - } - - return sets -} - -func resourceSolarwindsUserUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - client := meta.(*Clients).Solarwinds - if d.HasChanges("role", "products") { - user, err := userFromResource(d) - if err != nil { - return diag.FromErr(err) - } - - log.Printf("[DEBUG] User update configuration: %#v", user) - - if err = client.UserService.Update(*user); err != nil { - return diag.Errorf("Error updating user: %s", err) - } - } - - return resourceSolarwindsUserRead(ctx, d, meta) -} - -func resourceSolarwindsUserDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - client := meta.(*Clients).Solarwinds - - id := d.Id() - err := resource.RetryContext(ctx, DeleteUserRetryTimeout, func() *resource.RetryError { - if err := client.UserService.Delete(id); err != nil { - var clientErr *solarwinds.ClientError - ok := errors.As(err, &clientErr) - if ok && solarwinds.ErrCodeDeleteActiveUserException == clientErr.StatusCode { - return resource.NonRetryableError(err) - } - return resource.RetryableError(err) - } - return nil - }) - - if err != nil { - return diag.Errorf("error deleting user: %s", err) - } - - return nil -} +// import ( +// "context" +// "errors" +// "github.com/hashicorp/terraform-plugin-sdk/v2/diag" +// "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +// "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +// "github.com/nordcloud/go-pingdom/solarwinds" +// "log" +// "time" +// ) + +// const ( +// DeleteUserRetryTimeout = 1 * time.Minute +// ) + +// func resourceSolarwindsUser() *schema.Resource { +// return &schema.Resource{ +// CreateContext: resourceSolarwindsUserCreate, +// ReadContext: resourceSolarwindsUserRead, +// UpdateContext: resourceSolarwindsUserUpdate, +// DeleteContext: resourceSolarwindsUserDelete, +// Importer: &schema.ResourceImporter{ +// StateContext: schema.ImportStatePassthroughContext, +// }, +// Schema: map[string]*schema.Schema{ +// "email": { +// Type: schema.TypeString, +// Required: true, +// ForceNew: true, +// }, +// "role": { +// Type: schema.TypeString, +// Required: true, +// ForceNew: false, +// }, +// "products": { +// Type: schema.TypeSet, +// Optional: true, +// ForceNew: false, +// Elem: &schema.Resource{ +// Schema: map[string]*schema.Schema{ +// "name": { +// Type: schema.TypeString, +// Required: true, +// }, +// "role": { +// Type: schema.TypeString, +// Required: true, +// }, +// }, +// }, +// }, +// }, +// } +// } + +// func userFromResource(d *schema.ResourceData) (*solarwinds.User, error) { +// user := solarwinds.User{} + +// // required +// if v, ok := d.GetOk("email"); ok { +// user.Email = v.(string) +// } + +// if v, ok := d.GetOk("role"); ok { +// user.Role = v.(string) +// } + +// if v, ok := d.GetOk("products"); ok { +// interfaceSlice := v.(*schema.Set).List() +// user.Products = expandUserProducts(interfaceSlice) +// } + +// return &user, nil +// } + +// func expandUserProducts(l []interface{}) []solarwinds.Product { +// if len(l) == 0 || l[0] == nil { +// return nil +// } + +// m := make([]solarwinds.Product, 0, len(l)) +// for _, tfMapRaw := range l { +// tfMap, ok := tfMapRaw.(map[string]interface{}) +// if !ok { +// continue +// } +// product := solarwinds.Product{} +// if name, ok := tfMap["name"].(string); ok && name != "" { +// product.Name = name +// } +// if role, ok := tfMap["role"].(string); ok && role != "" { +// product.Role = role +// } +// m = append(m, product) +// } + +// return m +// } + +// func resourceSolarwindsUserCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +// client := meta.(*Clients).Solarwinds + +// user, err := userFromResource(d) +// if err != nil { +// return diag.FromErr(err) +// } + +// log.Printf("[DEBUG] User create configuration: %#v", d.Get("email")) +// err = client.UserService.Create(*user) +// if err != nil { +// return diag.FromErr(err) +// } + +// d.SetId(user.Email) +// return resourceSolarwindsUserRead(ctx, d, meta) +// } + +// func resourceSolarwindsUserRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +// client := meta.(*Clients).Solarwinds + +// email := d.Id() +// user, err := client.UserService.Retrieve(email) +// if err != nil { +// return diag.Errorf("error retrieving user with email %v", email) +// } +// if user == nil { +// d.SetId("") +// return nil +// } + +// for k, v := range map[string]interface{}{ +// "email": user.Email, +// "role": user.Role, +// "products": flattenUserProducts(user.Products), +// } { +// if err := d.Set(k, v); err != nil { +// return diag.FromErr(err) +// } +// } + +// return nil +// } + +// func flattenUserProducts(l []solarwinds.Product) []interface{} { +// if l == nil { +// return []interface{}{} +// } +// sets := make([]interface{}, 0, len(l)) +// for _, item := range l { +// tfMap := map[string]interface{}{ +// "name": item.Name, +// "role": item.Role, +// } +// sets = append(sets, tfMap) +// } + +// return sets +// } + +// func resourceSolarwindsUserUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +// client := meta.(*Clients).Solarwinds +// if d.HasChanges("role", "products") { +// user, err := userFromResource(d) +// if err != nil { +// return diag.FromErr(err) +// } + +// log.Printf("[DEBUG] User update configuration: %#v", user) + +// if err = client.UserService.Update(*user); err != nil { +// return diag.Errorf("Error updating user: %s", err) +// } +// } + +// return resourceSolarwindsUserRead(ctx, d, meta) +// } + +// func resourceSolarwindsUserDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +// client := meta.(*Clients).Solarwinds + +// id := d.Id() +// err := resource.RetryContext(ctx, DeleteUserRetryTimeout, func() *resource.RetryError { +// if err := client.UserService.Delete(id); err != nil { +// var clientErr *solarwinds.ClientError +// ok := errors.As(err, &clientErr) +// if ok && solarwinds.ErrCodeDeleteActiveUserException == clientErr.StatusCode { +// return resource.NonRetryableError(err) +// } +// return resource.RetryableError(err) +// } +// return nil +// }) + +// if err != nil { +// return diag.Errorf("error deleting user: %s", err) +// } + +// return nil +// } diff --git a/pingdom/resource_pingdom_user_test.go b/pingdom/resource_pingdom_user_test.go index 3683c6e4..d493f407 100644 --- a/pingdom/resource_pingdom_user_test.go +++ b/pingdom/resource_pingdom_user_test.go @@ -1,175 +1,175 @@ package pingdom -import ( - "bytes" - "fmt" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/nordcloud/go-pingdom/solarwinds" - "html/template" - "testing" -) +// import ( +// "bytes" +// "fmt" +// "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" +// "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +// "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +// "github.com/nordcloud/go-pingdom/solarwinds" +// "html/template" +// "testing" +// ) -func TestAccUser_basic(t *testing.T) { - email := acctest.RandString(10) + "@foo.com" - resourceName := "pingdom_user.test" - user := solarwinds.User{ - Email: email, - Role: "MEMBER", - Products: []solarwinds.Product{ - { - Name: "APPOPTICS", - Role: "MEMBER", - }, - }, - } +// func TestAccUser_basic(t *testing.T) { +// email := acctest.RandString(10) + "@foo.com" +// resourceName := "pingdom_user.test" +// user := solarwinds.User{ +// Email: email, +// Role: "MEMBER", +// Products: []solarwinds.Product{ +// { +// Name: "APPOPTICS", +// Role: "MEMBER", +// }, +// }, +// } - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckUserDestroy, - Steps: []resource.TestStep{ - { - Config: testAccUserBasicConfig(user), - Check: resource.ComposeTestCheckFunc( - testAccCheckUserExist(resourceName), - resource.TestCheckResourceAttr(resourceName, "role", "MEMBER"), - resource.TestCheckResourceAttr(resourceName, "products.#", "1"), - resource.TestCheckResourceAttr(resourceName, "products.0.name", "APPOPTICS"), - resource.TestCheckResourceAttr(resourceName, "products.0.role", "MEMBER"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} +// resource.ParallelTest(t, resource.TestCase{ +// PreCheck: func() { testAccPreCheck(t) }, +// Providers: testAccProviders, +// CheckDestroy: testAccCheckUserDestroy, +// Steps: []resource.TestStep{ +// { +// Config: testAccUserBasicConfig(user), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckUserExist(resourceName), +// resource.TestCheckResourceAttr(resourceName, "role", "MEMBER"), +// resource.TestCheckResourceAttr(resourceName, "products.#", "1"), +// resource.TestCheckResourceAttr(resourceName, "products.0.name", "APPOPTICS"), +// resource.TestCheckResourceAttr(resourceName, "products.0.role", "MEMBER"), +// ), +// }, +// { +// ResourceName: resourceName, +// ImportState: true, +// ImportStateVerify: true, +// }, +// }, +// }) +// } -func TestAccUser_update(t *testing.T) { - email := acctest.RandString(10) + "@foo.com" - resourceName := "pingdom_user.test" - user := solarwinds.User{ - Email: email, - Role: "MEMBER", - Products: []solarwinds.Product{ - { - Name: "APPOPTICS", - Role: "MEMBER", - }, - }, - } - userUpdate := user - userUpdate.Role = "ADMIN" - userUpdate.Products = append(userUpdate.Products, solarwinds.Product{ - Name: "PINGDOM", - Role: "VIEWER", - }) +// func TestAccUser_update(t *testing.T) { +// email := acctest.RandString(10) + "@foo.com" +// resourceName := "pingdom_user.test" +// user := solarwinds.User{ +// Email: email, +// Role: "MEMBER", +// Products: []solarwinds.Product{ +// { +// Name: "APPOPTICS", +// Role: "MEMBER", +// }, +// }, +// } +// userUpdate := user +// userUpdate.Role = "ADMIN" +// userUpdate.Products = append(userUpdate.Products, solarwinds.Product{ +// Name: "PINGDOM", +// Role: "VIEWER", +// }) - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckUserDestroy, - Steps: []resource.TestStep{ - { - Config: testAccUserBasicConfig(user), - Check: resource.ComposeTestCheckFunc( - testAccCheckUserExist(resourceName), - resource.TestCheckResourceAttr(resourceName, "role", user.Role), - resource.TestCheckResourceAttr(resourceName, "products.#", fmt.Sprint(len(user.Products))), - resource.TestCheckResourceAttr(resourceName, "products.0.name", user.Products[0].Name), - resource.TestCheckResourceAttr(resourceName, "products.0.role", user.Products[0].Role), - ), - }, - { - Config: testAccUserBasicConfig(userUpdate), - Check: resource.ComposeTestCheckFunc( - testAccCheckUserExist(resourceName), - resource.TestCheckResourceAttr(resourceName, "role", userUpdate.Role), - resource.TestCheckResourceAttr(resourceName, "products.#", fmt.Sprint(len(userUpdate.Products))), - resource.TestCheckTypeSetElemNestedAttrs(resourceName, "products.*", map[string]string{ - "name": userUpdate.Products[0].Name, - "role": userUpdate.Products[0].Role, - }), - resource.TestCheckTypeSetElemNestedAttrs(resourceName, "products.*", map[string]string{ - "name": userUpdate.Products[1].Name, - "role": userUpdate.Products[1].Role, - }), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} +// resource.ParallelTest(t, resource.TestCase{ +// PreCheck: func() { testAccPreCheck(t) }, +// Providers: testAccProviders, +// CheckDestroy: testAccCheckUserDestroy, +// Steps: []resource.TestStep{ +// { +// Config: testAccUserBasicConfig(user), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckUserExist(resourceName), +// resource.TestCheckResourceAttr(resourceName, "role", user.Role), +// resource.TestCheckResourceAttr(resourceName, "products.#", fmt.Sprint(len(user.Products))), +// resource.TestCheckResourceAttr(resourceName, "products.0.name", user.Products[0].Name), +// resource.TestCheckResourceAttr(resourceName, "products.0.role", user.Products[0].Role), +// ), +// }, +// { +// Config: testAccUserBasicConfig(userUpdate), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckUserExist(resourceName), +// resource.TestCheckResourceAttr(resourceName, "role", userUpdate.Role), +// resource.TestCheckResourceAttr(resourceName, "products.#", fmt.Sprint(len(userUpdate.Products))), +// resource.TestCheckTypeSetElemNestedAttrs(resourceName, "products.*", map[string]string{ +// "name": userUpdate.Products[0].Name, +// "role": userUpdate.Products[0].Role, +// }), +// resource.TestCheckTypeSetElemNestedAttrs(resourceName, "products.*", map[string]string{ +// "name": userUpdate.Products[1].Name, +// "role": userUpdate.Products[1].Role, +// }), +// ), +// }, +// { +// ResourceName: resourceName, +// ImportState: true, +// ImportStateVerify: true, +// }, +// }, +// }) +// } -func testAccCheckUserDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*Clients).Solarwinds +// func testAccCheckUserDestroy(s *terraform.State) error { +// client := testAccProvider.Meta().(*Clients).Solarwinds - for _, rs := range s.RootModule().Resources { - if rs.Type != "pingdom_user" { - continue - } +// for _, rs := range s.RootModule().Resources { +// if rs.Type != "pingdom_user" { +// continue +// } - email := rs.Primary.ID - user, err := client.UserService.Retrieve(email) - if err != nil { - return err - } - if user != nil { - return fmt.Errorf("user for resource (%s) still exists", email) - } - } - return nil -} +// email := rs.Primary.ID +// user, err := client.UserService.Retrieve(email) +// if err != nil { +// return err +// } +// if user != nil { +// return fmt.Errorf("user for resource (%s) still exists", email) +// } +// } +// return nil +// } -func testAccCheckUserExist(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("not found: %s", n) - } +// func testAccCheckUserExist(n string) resource.TestCheckFunc { +// return func(s *terraform.State) error { +// rs, ok := s.RootModule().Resources[n] +// if !ok { +// return fmt.Errorf("not found: %s", n) +// } - if rs.Primary.ID == "" { - return fmt.Errorf("no id is set") - } +// if rs.Primary.ID == "" { +// return fmt.Errorf("no id is set") +// } - email := rs.Primary.ID - client := testAccProvider.Meta().(*Clients).Solarwinds - user, err := client.UserService.Retrieve(email) - if err != nil { - return err - } - if user == nil { - return fmt.Errorf("user for resource (%s) not found", email) - } - return nil - } -} +// email := rs.Primary.ID +// client := testAccProvider.Meta().(*Clients).Solarwinds +// user, err := client.UserService.Retrieve(email) +// if err != nil { +// return err +// } +// if user == nil { +// return fmt.Errorf("user for resource (%s) not found", email) +// } +// return nil +// } +// } -func testAccUserBasicConfig(user solarwinds.User) string { - t := template.Must(template.New("basicConfig").Parse(` -resource "pingdom_user" "test" { - email = "{{.Email}}" - role = "{{.Role}}" - {{range .Products}} - products { - name = "{{.Name}}" - role = "{{.Role}}" - } - {{end}} -} -`)) - var buf bytes.Buffer - if err := t.Execute(&buf, user); err != nil { - panic(err) - } - result := buf.String() - return result -} +// func testAccUserBasicConfig(user solarwinds.User) string { +// t := template.Must(template.New("basicConfig").Parse(` +// resource "pingdom_user" "test" { +// email = "{{.Email}}" +// role = "{{.Role}}" +// {{range .Products}} +// products { +// name = "{{.Name}}" +// role = "{{.Role}}" +// } +// {{end}} +// } +// `)) +// var buf bytes.Buffer +// if err := t.Execute(&buf, user); err != nil { +// panic(err) +// } +// result := buf.String() +// return result +// }