diff --git a/pingdom/resource_pingdom_check.go b/pingdom/resource_pingdom_check.go index 141e2af1..3de349a5 100644 --- a/pingdom/resource_pingdom_check.go +++ b/pingdom/resource_pingdom_check.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/nordcloud/go-pingdom/pingdom" ) @@ -27,114 +28,102 @@ func resourcePingdomCheck() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ForceNew: false, }, "host": { Type: schema.TypeString, Required: true, - ForceNew: false, }, "type": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{"http", "tcp", "ping"}, false), }, "paused": { Type: schema.TypeBool, Optional: true, - ForceNew: false, - Computed: true, + Default: false, }, "responsetime_threshold": { Type: schema.TypeInt, Optional: true, - ForceNew: false, Computed: true, }, "resolution": { - Type: schema.TypeInt, - Optional: true, - ForceNew: false, - Computed: true, + Type: schema.TypeInt, + Optional: true, + ForceNew: false, + Default: 5, + ValidateFunc: validation.IntInSlice([]int{1, 5, 15, 30, 60}), }, "sendnotificationwhendown": { Type: schema.TypeInt, Optional: true, - ForceNew: false, - Computed: true, + Default: 2, }, "notifyagainevery": { Type: schema.TypeInt, Optional: true, - ForceNew: false, Computed: true, }, "notifywhenbackup": { Type: schema.TypeBool, Optional: true, - ForceNew: false, - Computed: true, + Default: true, }, "integrationids": { Type: schema.TypeSet, Optional: true, - ForceNew: false, Elem: &schema.Schema{Type: schema.TypeInt}, }, "encryption": { Type: schema.TypeBool, Optional: true, - ForceNew: false, Computed: true, }, "url": { Type: schema.TypeString, Optional: true, - ForceNew: false, Default: "/", DiffSuppressFunc: diffSuppressIfNotHTTPCheck, }, "port": { - Type: schema.TypeInt, - Optional: true, - ForceNew: false, - Computed: true, + Type: schema.TypeInt, + Optional: true, + ForceNew: false, + Computed: true, + ValidateFunc: validation.IsPortNumber, }, "username": { Type: schema.TypeString, Optional: true, - ForceNew: false, }, "password": { - Type: schema.TypeString, - Optional: true, - ForceNew: false, + Type: schema.TypeString, + Optional: true, + ForceNew: false, + Sensitive: true, }, "shouldcontain": { Type: schema.TypeString, Optional: true, - ForceNew: false, }, "shouldnotcontain": { Type: schema.TypeString, Optional: true, - ForceNew: false, }, "postdata": { Type: schema.TypeString, Optional: true, - ForceNew: false, }, "requestheaders": { Type: schema.TypeMap, Optional: true, - ForceNew: false, Elem: &schema.Schema{Type: schema.TypeString}, }, "tags": { Type: schema.TypeString, Optional: true, - ForceNew: false, StateFunc: func(val interface{}) string { return sortString(val.(string), ",") }, @@ -142,51 +131,42 @@ func resourcePingdomCheck() *schema.Resource { "probefilters": { Type: schema.TypeString, Optional: true, - ForceNew: false, }, "userids": { Type: schema.TypeSet, Optional: true, - ForceNew: false, Elem: &schema.Schema{Type: schema.TypeInt}, }, "teamids": { Type: schema.TypeSet, Optional: true, - ForceNew: false, Elem: &schema.Schema{Type: schema.TypeInt}, }, "stringtosend": { Type: schema.TypeString, Optional: true, - ForceNew: false, }, "stringtoexpect": { Type: schema.TypeString, Optional: true, - ForceNew: false, }, "expectedip": { Type: schema.TypeString, Optional: true, - ForceNew: false, }, "nameserver": { Type: schema.TypeString, Optional: true, - ForceNew: false, }, "verify_certificate": { Type: schema.TypeBool, Optional: true, - ForceNew: false, Default: true, DiffSuppressFunc: diffSuppressIfNotHTTPCheck, }, "ssl_down_days_before": { Type: schema.TypeInt, Optional: true, - ForceNew: false, Computed: true, }, }, diff --git a/pingdom/resource_pingdom_contact.go b/pingdom/resource_pingdom_contact.go index 181aad5d..88a4e442 100644 --- a/pingdom/resource_pingdom_contact.go +++ b/pingdom/resource_pingdom_contact.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/nordcloud/go-pingdom/pingdom" ) @@ -49,9 +50,10 @@ func resourcePingdomContact() *schema.Resource { Required: true, }, "provider": { - Type: schema.TypeString, - Optional: true, - Default: "nexmo", + Type: schema.TypeString, + Optional: true, + Default: "nexmo", + ValidateFunc: validation.StringInSlice([]string{"nexmo", "bulksms", "esendex", "cellsynt"}, false), }, }, }, diff --git a/pingdom/resource_pingdom_maintenance.go b/pingdom/resource_pingdom_maintenance.go index f98f52c5..45509859 100644 --- a/pingdom/resource_pingdom_maintenance.go +++ b/pingdom/resource_pingdom_maintenance.go @@ -2,11 +2,13 @@ package pingdom import ( "context" + "strconv" + "strings" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/nordcloud/go-pingdom/pingdom" - "strconv" - "strings" ) func resourcePingdomMaintenance() *schema.Resource { @@ -37,9 +39,10 @@ func resourcePingdomMaintenance() *schema.Resource { Computed: true, }, "recurrencetype": { - Type: schema.TypeString, - Optional: true, - Default: "none", + Type: schema.TypeString, + Optional: true, + Default: "none", + ValidateFunc: validation.StringInSlice([]string{"none", "day", "week", "month"}, false), }, "repeatevery": { Type: schema.TypeInt, diff --git a/pingdom/resource_pingdom_team.go b/pingdom/resource_pingdom_team.go index 58c35aed..e580c5ab 100644 --- a/pingdom/resource_pingdom_team.go +++ b/pingdom/resource_pingdom_team.go @@ -23,12 +23,10 @@ func resourcePingdomTeam() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ForceNew: false, }, "member_ids": { Type: schema.TypeSet, Optional: true, - ForceNew: false, Elem: &schema.Schema{Type: schema.TypeInt}, }, }, diff --git a/pingdom/resource_pingdom_tms_check.go b/pingdom/resource_pingdom_tms_check.go index a825a2ed..2eb9c809 100644 --- a/pingdom/resource_pingdom_tms_check.go +++ b/pingdom/resource_pingdom_tms_check.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/nordcloud/go-pingdom/pingdom" ) @@ -62,10 +63,11 @@ func resourcePingdomTmsCheck() *schema.Resource { Optional: true, Elem: &schema.Schema{Type: schema.TypeInt}, }, - "interval": { // [5 10 20 60 720 1440] - Type: schema.TypeInt, - Optional: true, - Default: 10, + "interval": { + Type: schema.TypeInt, + Optional: true, + Default: 10, + ValidateFunc: validation.IntInSlice([]int{5, 10, 20, 60, 720, 1440}), }, "metadata": { Type: schema.TypeList, @@ -95,18 +97,21 @@ func resourcePingdomTmsCheck() *schema.Resource { }, }, "region": { - Type: schema.TypeString, - Optional: true, - Default: "us-east", + Type: schema.TypeString, + Optional: true, + Default: "us-east", + ValidateFunc: validation.StringInSlice([]string{"us-east", "us-west", "eu", "au"}, false), }, "send_notification_when_down": { Type: schema.TypeInt, Optional: true, + Default: 1, }, "security_level": { - Type: schema.TypeString, - Optional: true, - Default: "high", + Type: schema.TypeString, + Optional: true, + Default: "high", + ValidateFunc: validation.StringInSlice([]string{"high", "low"}, false), }, "tags": { Type: schema.TypeString,