Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions checkly/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"strconv"
"strings"
"time"

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

func apiCallTimeout() time.Duration {
Expand Down Expand Up @@ -105,3 +107,13 @@ func decodeNumericID(id string) (int64, error) {
func encodeNumericID(id int64) string {
return strconv.FormatInt(id, 10)
}

func optionalStringPointerFromResourceData(d *schema.ResourceData, key string) *string {
value, ok := d.GetOk(key)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetOkExists is deprecated, using GetOk instead

if !ok {
return nil
}
str := value.(string)
return &str
}

7 changes: 7 additions & 0 deletions checkly/resource_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ func resourceCheck() *schema.Resource {
Required: true,
Description: "The name of the check.",
},
"description": {
Type: schema.TypeString,
Optional: true,
Description: "A description of the check.",
},
"type": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -413,6 +418,7 @@ func resourceCheckDelete(d *schema.ResourceData, client interface{}) error {

func resourceDataFromCheck(c *checkly.Check, d *schema.ResourceData) error {
d.Set("name", c.Name)
d.Set("description", c.Description)
d.Set("type", c.Type)
d.Set("activated", c.Activated)
d.Set("muted", c.Muted)
Expand Down Expand Up @@ -525,6 +531,7 @@ func checkFromResourceData(d *schema.ResourceData) (checkly.Check, error) {
check := checkly.Check{
ID: d.Id(),
Name: d.Get("name").(string),
Description: optionalStringPointerFromResourceData(d, "description"),
Type: d.Get("type").(string),
Frequency: d.Get(frequencyAttributeName).(int),
Activated: d.Get("activated").(bool),
Expand Down
60 changes: 60 additions & 0 deletions checkly/resource_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func TestAccBrowserCheckBasic(t *testing.T) {
"name",
"Browser Check",
),
resource.TestCheckResourceAttr(
"checkly_check.test",
"description",
"Browser check description",
),
resource.TestCheckResourceAttr(
"checkly_check.test",
"type",
Expand Down Expand Up @@ -163,6 +168,11 @@ func TestAccApiCheckBasic(t *testing.T) {
"name",
"API Check 1",
),
resource.TestCheckResourceAttr(
"checkly_check.test",
"description",
"API check description",
),
resource.TestCheckResourceAttr(
"checkly_check.test",
"activated",
Expand Down Expand Up @@ -586,8 +596,11 @@ EOT
})
}

var wantCheckDescription = "My test check description"

var wantCheck = checkly.Check{
Name: "My test check",
Description: &wantCheckDescription,
Type: checkly.TypeAPI,
Frequency: 1,
Activated: true,
Expand Down Expand Up @@ -1327,9 +1340,31 @@ func TestAccCheckRetryStrategyRemoval(t *testing.T) {
})
}

func TestAccCheckDescriptionRemoval(t *testing.T) {
accTestCase(t, []resource.TestStep{
{
Config: apiCheck_basic,
Check: resource.TestCheckResourceAttr(
"checkly_check.test",
"description",
"API check description",
),
},
{
Config: apiCheck_basic_withoutDescription,
Check: resource.TestCheckResourceAttr(
"checkly_check.test",
"description",
"",
),
},
})
}

const browserCheck_basic = `
resource "checkly_check" "test" {
name = "Browser Check"
description = "Browser check description"
type = "BROWSER"
activated = true
should_fail = false
Expand Down Expand Up @@ -1358,6 +1393,31 @@ const multiStepCheck_basic = `
`

const apiCheck_basic = `
resource "checkly_check" "test" {
name = "API Check 1"
description = "API check description"
type = "API"
frequency = 60
activated = true
muted = true
double_check = true
max_response_time = 18000
locations = [ "us-east-1", "eu-central-1" ]
use_global_alert_settings = true
request {
method = "GET"
url = "https://api.checklyhq.com/public-stats"
assertion {
comparison = "EQUALS"
property = ""
source = "STATUS_CODE"
target = "200"
}
}
}
`

const apiCheck_basic_withoutDescription = `
resource "checkly_check" "test" {
name = "API Check 1"
type = "API"
Expand Down
7 changes: 7 additions & 0 deletions checkly/resource_dns_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func resourceDNSMonitor() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"description": {
Description: "A description of the monitor.",
Type: schema.TypeString,
Optional: true,
},
frequencyAttributeName: makeFrequencyAttributeSchema(FrequencyAttributeSchemaOptions{
Monitor: true,
AllowHighFrequency: true,
Expand Down Expand Up @@ -269,6 +274,7 @@ func resourceDNSMonitorDelete(d *schema.ResourceData, client interface{}) error

func resourceDataFromDNSMonitor(c *checkly.DNSMonitor, d *schema.ResourceData) error {
d.Set("name", c.Name)
d.Set("description", c.Description)
d.Set("activated", c.Activated)
d.Set("muted", c.Muted)
d.Set("run_parallel", c.RunParallel)
Expand Down Expand Up @@ -308,6 +314,7 @@ func dnsMonitorFromResourceData(d *schema.ResourceData) (checkly.DNSMonitor, err
check := checkly.DNSMonitor{
ID: d.Id(),
Name: d.Get("name").(string),
Description: optionalStringPointerFromResourceData(d, "description"),
Frequency: d.Get(frequencyAttributeName).(int),
Activated: d.Get("activated").(bool),
Muted: d.Get("muted").(bool),
Expand Down
70 changes: 70 additions & 0 deletions checkly/resource_dns_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestAccDNSMonitorBasic(t *testing.T) {
Config: `
resource "checkly_dns_monitor" "test" {
name = "DNS Monitor 1"
description = "DNS monitor description"
frequency = 60
activated = true
muted = true
Expand All @@ -63,6 +64,11 @@ func TestAccDNSMonitorBasic(t *testing.T) {
"name",
"DNS Monitor 1",
),
resource.TestCheckResourceAttr(
"checkly_dns_monitor.test",
"description",
"DNS monitor description",
),
resource.TestCheckResourceAttr(
"checkly_dns_monitor.test",
"activated",
Expand Down Expand Up @@ -113,6 +119,70 @@ func TestAccDNSMonitorBasic(t *testing.T) {
})
}

func TestAccDNSMonitorDescriptionRemoval(t *testing.T) {
accTestCase(t, []resource.TestStep{
{
Config: `
resource "checkly_dns_monitor" "test" {
name = "DNS Monitor 1"
description = "DNS monitor description"
frequency = 60
activated = true
muted = true
max_response_time = 3000
locations = ["us-east-1", "eu-central-1"]
use_global_alert_settings = true

request {
record_type = "A"
query = "welcome.checklyhq.com"

assertion {
source = "RESPONSE_CODE"
comparison = "EQUALS"
target = "NOERROR"
}
}
}
`,
Check: resource.TestCheckResourceAttr(
"checkly_dns_monitor.test",
"description",
"DNS monitor description",
),
},
{
Config: `
resource "checkly_dns_monitor" "test" {
name = "DNS Monitor 1"
frequency = 60
activated = true
muted = true
max_response_time = 3000
locations = ["us-east-1", "eu-central-1"]
use_global_alert_settings = true

request {
record_type = "A"
query = "welcome.checklyhq.com"

assertion {
source = "RESPONSE_CODE"
comparison = "EQUALS"
target = "NOERROR"
}
}
}
`,
Check: resource.TestCheckResourceAttr(
"checkly_dns_monitor.test",
"description",
"",
),
},
})
}

func TestAccDNSMonitorFull(t *testing.T) {
accTestCase(t, []resource.TestStep{
{
Expand Down
7 changes: 7 additions & 0 deletions checkly/resource_heartbeat_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func resourceHeartbeatMonitor() *schema.Resource {
Required: true,
Description: "The name of the check.",
},
"description": {
Type: schema.TypeString,
Optional: true,
Description: "A description of the monitor.",
},
"activated": {
Type: schema.TypeBool,
Required: true,
Expand Down Expand Up @@ -192,6 +197,7 @@ func heartbeatMonitorFromResourceData(d *schema.ResourceData) (checkly.Heartbeat
monitor := checkly.HeartbeatMonitor{
ID: d.Id(),
Name: d.Get("name").(string),
Description: optionalStringPointerFromResourceData(d, "description"),
Activated: d.Get("activated").(bool),
Muted: d.Get("muted").(bool),
Tags: stringsFromSet(d.Get("tags").(*schema.Set)),
Expand Down Expand Up @@ -257,6 +263,7 @@ func heartbeatMonitorFromResourceData(d *schema.ResourceData) (checkly.Heartbeat

func resourceDataFromHeartbeatMonitor(c *checkly.HeartbeatMonitor, d *schema.ResourceData) error {
d.Set("name", c.Name)
d.Set("description", c.Description)
d.Set("activated", c.Activated)
d.Set("muted", c.Muted)

Expand Down
46 changes: 46 additions & 0 deletions checkly/resource_heartbeat_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func TestAccHeartbeatMonitorCreate(t *testing.T) {
config := `resource "checkly_heartbeat_monitor" "test" {
activated = true
name = "heartbeat monitor"
description = "Heartbeat monitor description"
heartbeat {
period = 5
period_unit = "days"
Expand All @@ -176,6 +177,11 @@ func TestAccHeartbeatMonitorCreate(t *testing.T) {
"name",
"heartbeat monitor",
),
resource.TestCheckResourceAttr(
"checkly_heartbeat_monitor.test",
"description",
"Heartbeat monitor description",
),
testCheckResourceAttrExpr(
"checkly_heartbeat_monitor.test",
"heartbeat.*.period",
Expand All @@ -191,6 +197,46 @@ func TestAccHeartbeatMonitorCreate(t *testing.T) {
})
}

func TestAccHeartbeatMonitorDescriptionRemoval(t *testing.T) {
accTestCase(t, []resource.TestStep{
{
Config: `resource "checkly_heartbeat_monitor" "test" {
activated = true
name = "heartbeat monitor"
description = "Heartbeat monitor description"
heartbeat {
period = 5
period_unit = "days"
grace = 0
grace_unit = "seconds"
}
}`,
Check: resource.TestCheckResourceAttr(
"checkly_heartbeat_monitor.test",
"description",
"Heartbeat monitor description",
),
},
{
Config: `resource "checkly_heartbeat_monitor" "test" {
activated = true
name = "heartbeat monitor"
heartbeat {
period = 5
period_unit = "days"
grace = 0
grace_unit = "seconds"
}
}`,
Check: resource.TestCheckResourceAttr(
"checkly_heartbeat_monitor.test",
"description",
"",
),
},
})
}

func TestAccHeartbeatMonitorWithTriggerIncident(t *testing.T) {
heartbeatMonitorWithTriggerIncident := `
resource "checkly_status_page_service" "test_heartbeat_service" {
Expand Down
7 changes: 7 additions & 0 deletions checkly/resource_icmp_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func resourceICMPMonitor() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"description": {
Description: "A description of the monitor.",
Type: schema.TypeString,
Optional: true,
},
frequencyAttributeName: makeFrequencyAttributeSchema(FrequencyAttributeSchemaOptions{
Monitor: true,
AllowHighFrequency: true,
Expand Down Expand Up @@ -243,6 +248,7 @@ func resourceICMPMonitorDelete(d *schema.ResourceData, client interface{}) error

func resourceDataFromICMPMonitor(c *checkly.ICMPMonitor, d *schema.ResourceData) error {
d.Set("name", c.Name)
d.Set("description", c.Description)
d.Set("activated", c.Activated)
d.Set("muted", c.Muted)
d.Set("run_parallel", c.RunParallel)
Expand Down Expand Up @@ -282,6 +288,7 @@ func icmpMonitorFromResourceData(d *schema.ResourceData) (checkly.ICMPMonitor, e
monitor := checkly.ICMPMonitor{
ID: d.Id(),
Name: d.Get("name").(string),
Description: optionalStringPointerFromResourceData(d, "description"),
Frequency: d.Get(frequencyAttributeName).(int),
Activated: d.Get("activated").(bool),
Muted: d.Get("muted").(bool),
Expand Down
Loading
Loading