From dd1d504146d9a200de82cef9d13502dab8c370f6 Mon Sep 17 00:00:00 2001 From: Mike Rostermund Date: Fri, 10 Jan 2020 12:49:20 +0100 Subject: [PATCH 1/5] Add properties for degraded and max response time --- go.sum | 24 ++++++++++++------------ resource_check.go | 39 +++++++++++++++++++++++++++++++++++++++ resource_check_test.go | 18 ++++++++++-------- test.tf | 16 +++++++++------- 4 files changed, 70 insertions(+), 27 deletions(-) diff --git a/go.sum b/go.sum index 5bc13d9..4f3bc0f 100644 --- a/go.sum +++ b/go.sum @@ -69,16 +69,16 @@ github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/aws/aws-sdk-go v1.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM= github.com/aws/aws-sdk-go v1.25.3/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= -github.com/aws/aws-sdk-go v1.29.4 h1:w3O/LGvLCliVFJ2fGrpaWDGbRHj1f+aipB1MMfInN24= -github.com/aws/aws-sdk-go v1.29.4/go.mod h1:1KvfttTE3SPKMpo8g2c6jL3ZKfXtFvKscTgahTma5Xg= +github.com/aws/aws-sdk-go v1.29.7 h1:mwe1Bls/BsB3hB3I9CtUIWSpe1u3wdPcwdvtD9lkzsU= +github.com/aws/aws-sdk-go v1.29.7/go.mod h1:1KvfttTE3SPKMpo8g2c6jL3ZKfXtFvKscTgahTma5Xg= github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas= github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/bitfield/checkly v0.2.0 h1:jDb5pPjkPyqPePCxoM+Q5dAXCfEyHaXET135ej3zWYY= -github.com/bitfield/checkly v0.2.0/go.mod h1:f5+OOTqtCwMYBsde5tomn67BcZIhtXDxZc7FFb9Lhqw= +github.com/bitfield/checkly v0.2.1 h1:9epVKArMMls1J2kiLyZsYXhGWdwftW1cDh//m+iMz+0= +github.com/bitfield/checkly v0.2.1/go.mod h1:f5+OOTqtCwMYBsde5tomn67BcZIhtXDxZc7FFb9Lhqw= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/bmatcuk/doublestar v1.1.5 h1:2bNwBOmhyFEFcoB3tGvTD5xanq+4kyOZlB8wFYbMjkk= @@ -230,8 +230,8 @@ github.com/hashicorp/hil v0.0.0-20190212132231-97b3a9cdfa93 h1:T1Q6ag9tCwun16AW+ github.com/hashicorp/hil v0.0.0-20190212132231-97b3a9cdfa93/go.mod h1:n2TSygSNwsLJ76m8qFXTSc7beTb+auJxYdqrnoqwZWE= github.com/hashicorp/memberlist v0.1.0/go.mod h1:ncdBp14cuox2iFOq3kDiquKU6fqsTBc3W6JvZwjxxsE= github.com/hashicorp/serf v0.0.0-20160124182025-e4ec8cc423bb/go.mod h1:h/Ru6tmZazX7WO/GDmwdpS975F019L4t5ng5IgwbNrE= -github.com/hashicorp/terraform v0.12.20 h1:TnuNh1PGqnJOQBThQjygCmy5zUxLtX9/VOBHvuiKYJM= -github.com/hashicorp/terraform v0.12.20/go.mod h1:UtGvFLi7LjM1AdiOX3mY/3+2X0Fdu2rqISHNrEquWlg= +github.com/hashicorp/terraform v0.12.21 h1:0qamALIu4/g2+4k4rC5DpxMdLz4A4K67pGQA2X4prgs= +github.com/hashicorp/terraform v0.12.21/go.mod h1:eJcloDEx5ywM4a1tetIuVrlqklM0bUVRYJBYAh4CYzA= github.com/hashicorp/terraform-config-inspect v0.0.0-20191212124732-c6ae6269b9d7 h1:Pc5TCv9mbxFN6UVX0LH6CpQrdTM5YjbVI2w15237Pjk= github.com/hashicorp/terraform-config-inspect v0.0.0-20191212124732-c6ae6269b9d7/go.mod h1:p+ivJws3dpqbp1iP84+npOyAmTTOLMgCzrXd3GSdn/A= github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596 h1:hjyO2JsNZUKT1ym+FAdlBEkGPevazYsmVgIMw7dVELg= @@ -413,8 +413,8 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6 h1:Sy5bstxEqwwbYs6n0/pBuxKENqOeZUgD45Gp3Q3pqLg= -golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975 h1:/Tl7pH94bvbAAHBdZJT947M/+gp0+CqQXDtMRC0fseo= +golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -505,8 +505,8 @@ golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200217220822-9197077df867 h1:JoRuNIf+rpHl+VhScRQQvzbHed86tKkqwPMV34T8myw= -golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c h1:jceGD5YNJGgGMkJz79agzOln1K9TaZUjv5ird16qniQ= +golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -539,8 +539,8 @@ golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56 h1:DFtSed2q3HtNuVazwVDZ4nSRS/JrZEig0gz2BY4VNrg= golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200216192241-b320d3a0f5a2 h1:0sfSpGSa544Fwnbot3Oxq/U6SXqjty6Jy/3wRhVS7ig= -golang.org/x/tools v0.0.0-20200216192241-b320d3a0f5a2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200220224806-8a925fa4c0df h1:oQFmpjL+rb2xLkgPCpdGSAGDdq1geTZVvIfCMxSB/wQ= +golang.org/x/tools v0.0.0-20200220224806-8a925fa4c0df/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= diff --git a/resource_check.go b/resource_check.go index fab3a7f..d3d954d 100644 --- a/resource_check.go +++ b/resource_check.go @@ -72,6 +72,41 @@ func resourceCheck() *schema.Resource { Optional: true, Default: "", }, + "degraded_response_time": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + Default: 15000, + ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { + // Response times are hard capped to 30 seconds according to the web UI. + // Should/may require degraded response time to be less than max response time. + // https://checklyhq.com/docs/api-checks/limits/ + v := val.(int) + if !(v > 0) { + errs = append(errs, fmt.Errorf("%q must be larger than 0 ms, got: %d", key, v)) + } + if !(v <= 30000) { + errs = append(errs, fmt.Errorf("%q must be at most 30000 ms, got: %d", key, v)) + } + return warns, errs + }, + }, + "max_response_time": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + Default: 30000, + ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { + v := val.(int) + // Response times are hard capped to 30 seconds according to the web UI. + // https://checklyhq.com/docs/api-checks/limits/ + if !(v > 0) { + errs = append(errs, fmt.Errorf("%q must be larger than 0 ms, got: %d", key, v)) + } + if !(v <= 30000) { + errs = append(errs, fmt.Errorf("%q must be at most 30000 ms, got: %d", key, v)) + } + return warns, errs + }, + }, "created_at": &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -345,6 +380,8 @@ func resourceDataFromCheck(c *checkly.Check, d *schema.ResourceData) error { d.Set("should_fail", c.ShouldFail) d.Set("locations", c.Locations) d.Set("script", c.Script) + d.Set("degraded_response_time", c.DegradedResponseTime) + d.Set("max_response_time", c.MaxResponseTime) d.Set("created_at", c.CreatedAt.Format(time.RFC3339)) d.Set("updated_at", c.UpdatedAt.Format(time.RFC3339)) if err := d.Set("environment_variables", setFromEnvVars(c.EnvironmentVariables)); err != nil { @@ -463,6 +500,8 @@ func checkFromResourceData(d *schema.ResourceData) (checkly.Check, error) { ShouldFail: d.Get("should_fail").(bool), Locations: stringsFromSet(d.Get("locations").(*schema.Set)), Script: d.Get("script").(string), + DegradedResponseTime: d.Get("degraded_response_time").(int), + MaxResponseTime: d.Get("max_response_time").(int), CreatedAt: mustParseRFC3339Time(d.Get("created_at").(string)), UpdatedAt: mustParseRFC3339Time(d.Get("created_at").(string)), EnvironmentVariables: envVarsFromMap(d.Get("environment_variables").(tfMap)), diff --git a/resource_check_test.go b/resource_check_test.go index 9d0cbab..b26ff9a 100644 --- a/resource_check_test.go +++ b/resource_check_test.go @@ -24,14 +24,16 @@ func TestEncodeDecodeResource(t *testing.T) { func testCheck(name string) checkly.Check { return checkly.Check{ - Name: name, - Type: checkly.TypeAPI, - Frequency: 1, - Activated: true, - Muted: false, - ShouldFail: false, - Locations: []string{"eu-west-1"}, - Script: "foo", + Name: name, + Type: checkly.TypeAPI, + Frequency: 1, + Activated: true, + Muted: false, + ShouldFail: false, + Locations: []string{"eu-west-1"}, + Script: "foo", + DegradedResponseTime: 15000, + MaxResponseTime: 30000, EnvironmentVariables: []checkly.EnvironmentVariable{ { Key: "ENVTEST", diff --git a/test.tf b/test.tf index a71956b..8fff1a3 100644 --- a/test.tf +++ b/test.tf @@ -5,13 +5,15 @@ provider "checkly" { } resource "checkly_check" "test-check2" { - name = "My test check 2" - type = "API" - activated = true - should_fail = true - frequency = 1 - ssl_check_domain = "example.com" - double_check = true + name = "My test check 2" + type = "API" + activated = true + should_fail = true + frequency = 1 + ssl_check_domain = "example.com" + double_check = true + degraded_response_time = 15000 + max_response_time = 30000 locations = [ "us-west-1", From a94327abfa2dfe90010c9cef5923b066d36955d9 Mon Sep 17 00:00:00 2001 From: John Arundel Date: Fri, 21 Feb 2020 13:06:14 +0000 Subject: [PATCH 2/5] Bump Checkly SDK version --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 024b8d9..8fd937c 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.13 require ( cloud.google.com/go v0.53.0 // indirect github.com/aws/aws-sdk-go v1.29.4 // indirect - github.com/bitfield/checkly v0.2.0 + github.com/bitfield/checkly v0.2.1 github.com/bmatcuk/doublestar v1.2.2 // indirect github.com/fatih/color v1.9.0 // indirect github.com/google/go-cmp v0.4.0 From 88796083fa773b5c08ab8499ffa604b25dce6916 Mon Sep 17 00:00:00 2001 From: John Arundel Date: Fri, 21 Feb 2020 13:07:12 +0000 Subject: [PATCH 3/5] Update dependencies --- go.mod | 14 +++++++++----- go.sum | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 8fd937c..04f4690 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.13 require ( cloud.google.com/go v0.53.0 // indirect - github.com/aws/aws-sdk-go v1.29.4 // indirect + github.com/aws/aws-sdk-go v1.29.7 // indirect github.com/bitfield/checkly v0.2.1 github.com/bmatcuk/doublestar v1.2.2 // indirect github.com/fatih/color v1.9.0 // indirect @@ -15,7 +15,7 @@ require ( github.com/hashicorp/go-uuid v1.0.2 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/hil v0.0.0-20190212132231-97b3a9cdfa93 // indirect - github.com/hashicorp/terraform v0.12.20 + github.com/hashicorp/terraform v0.12.21 github.com/hashicorp/terraform-svchost v0.0.0-20191119180714-d2e4933b9136 // indirect github.com/hashicorp/yamux v0.0.0-20190923154419-df201c70410d // indirect github.com/magiconair/properties v1.8.1 // indirect @@ -26,8 +26,12 @@ require ( github.com/spf13/afero v1.2.2 // indirect github.com/ulikunitz/xz v0.5.6 // indirect github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect - golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6 // indirect + github.com/zclconf/go-cty v1.3.0 // indirect + golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975 // indirect golang.org/x/exp v0.0.0-20200213203834-85f925bdd4d0 // indirect - golang.org/x/sys v0.0.0-20200217220822-9197077df867 // indirect - golang.org/x/tools v0.0.0-20200216192241-b320d3a0f5a2 // indirect + golang.org/x/net v0.0.0-20200219183655-46282727080f // indirect + golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c // indirect + golang.org/x/tools v0.0.0-20200220224806-8a925fa4c0df // indirect + google.golang.org/genproto v0.0.0-20200218151345-dad8c97a84f5 // indirect + honnef.co/go/tools v0.0.1-2020.1.2 // indirect ) diff --git a/go.sum b/go.sum index 4f3bc0f..9117266 100644 --- a/go.sum +++ b/go.sum @@ -41,6 +41,7 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/ChrisTrenkamp/goxpath v0.0.0-20170922090931-c385f95c6022/go.mod h1:nuWgzSkT5PnyOd+272uUmV0dnAnAn42Mk7PiQC5VzN4= +github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM= github.com/Unknwon/com v0.0.0-20151008135407-28b053d5a292/go.mod h1:KYCjqMOeHpNuTOiFQU6WEcTG7poCJrUs0YgyHNtn1no= github.com/abdullin/seq v0.0.0-20160510034733-d5467c17e7af/go.mod h1:5Jv4cbFiHJMsVxt52+i0Ha45fjshj6wxYr1r19tB9bw= github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= @@ -270,6 +271,13 @@ github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LE github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/likexian/gokit v0.0.0-20190309162924-0a377eecf7aa/go.mod h1:QdfYv6y6qPA9pbBA2qXtoT8BMKha6UyNbxWGWl/9Jfk= +github.com/likexian/gokit v0.0.0-20190418170008-ace88ad0983b/go.mod h1:KKqSnk/VVSW8kEyO2vVCXoanzEutKdlBAPohmGXkxCk= +github.com/likexian/gokit v0.0.0-20190501133040-e77ea8b19cdc/go.mod h1:3kvONayqCaj+UgrRZGpgfXzHdMYCAO0KAt4/8n0L57Y= +github.com/likexian/gokit v0.20.15/go.mod h1:kn+nTv3tqh6yhor9BC4Lfiu58SmH8NmQ2PmEl+uM6nU= +github.com/likexian/simplejson-go v0.0.0-20190409170913-40473a74d76d/go.mod h1:Typ1BfnATYtZ/+/shXfFYLrovhFyuKvzwrdOnIDHlmg= +github.com/likexian/simplejson-go v0.0.0-20190419151922-c1f9f0b4f084/go.mod h1:U4O1vIJvIKwbMZKUJ62lppfdvkCdVd2nfMimHK81eec= +github.com/likexian/simplejson-go v0.0.0-20190502021454-d8787b4bfa0b/go.mod h1:3BWwtmKP9cXWwYCr5bkoVDEfLywacOv0s06OBEDpyt8= github.com/lusis/go-artifactory v0.0.0-20160115162124-7e4ce345df82/go.mod h1:y54tfGmO3NKssKveTEFFzH8C/akrSOy/iW9qEAUDV84= github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= @@ -322,6 +330,7 @@ github.com/mitchellh/reflectwalk v1.0.1 h1:FVzMWA5RllMAKIdUSC8mdWo3XtwoecrH79BY7 github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mozillazg/go-httpheader v0.2.1/go.mod h1:jJ8xECTlalr6ValeXYdOF8fFUISeBAdw6E61aqQma60= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= @@ -373,6 +382,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/svanharmelen/jsonapi v0.0.0-20180618144545-0c0828c3f16d/go.mod h1:BSTlc8jOjh0niykqEGVXOLXdi9o0r0kR8tCYiMvjFgw= +github.com/tencentcloud/tencentcloud-sdk-go v3.0.82+incompatible/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4= +github.com/tencentyun/cos-go-sdk-v5 v0.0.0-20190808065407-f07404cefc8c/go.mod h1:wk2XFUg6egk4tSDNZtXeKfe2G6690UVyt163PuUxBZk= github.com/terraform-providers/terraform-provider-openstack v1.15.0/go.mod h1:2aQ6n/BtChAl1y2S60vebhyJyZXBsuAI5G4+lHrT1Ew= github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v0.0.0-20180813092308-00b869d2f4a5/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ= @@ -393,6 +404,8 @@ github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLE github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= github.com/zclconf/go-cty v1.2.1 h1:vGMsygfmeCl4Xb6OA5U5XVAaQZ69FvoG7X2jUtQujb8= github.com/zclconf/go-cty v1.2.1/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= +github.com/zclconf/go-cty v1.3.0 h1:ig1G6+rJHX6jZDRjw4LUD3J8q7SBAagcmbM7bQ8ijmI= +github.com/zclconf/go-cty v1.3.0/go.mod h1:YO23e2L18AG+ZYQfSobnY4G65nvwvprPCxBHkufUH1k= github.com/zclconf/go-cty-yaml v1.0.1 h1:up11wlgAaDvlAGENcFDnZgkn0qUJurso7k6EpURKNF8= github.com/zclconf/go-cty-yaml v1.0.1/go.mod h1:IP3Ylp0wQpYm50IHK8OZWKMu6sPJIUgKa8XhiVHura0= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= @@ -465,6 +478,8 @@ golang.org/x/net v0.0.0-20191009170851-d66e71096ffb/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI= golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200219183655-46282727080f h1:dB42wwhNuwPvh8f+5zZWNcU+F2Xs/B9wXXwvUCOH7r8= +golang.org/x/net v0.0.0-20200219183655-46282727080f/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -533,6 +548,7 @@ golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= @@ -575,6 +591,8 @@ google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvx google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce h1:1mbrb1tUU+Zmt5C94IGKADBTJZjZXAd+BubWi7r9EiI= google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200218151345-dad8c97a84f5 h1:jB9+PJSvu5tBfmJHy/OVapFdjDF3WvpkqRhxqrmzoEU= +google.golang.org/genproto v0.0.0-20200218151345-dad8c97a84f5/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= @@ -602,6 +620,8 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.2 h1:8w2Ud1JmaU9M5os2j8aKMpPs4guVq+RMUN5phK2najE= +honnef.co/go/tools v0.0.1-2020.1.2/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= From 6ebc1a1565ee805e5ef0655a006bbf2dcffb62a9 Mon Sep 17 00:00:00 2001 From: John Arundel Date: Fri, 21 Feb 2020 13:21:19 +0000 Subject: [PATCH 4/5] Tweak response time validation --- resource_check.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/resource_check.go b/resource_check.go index d3d954d..1e5864d 100644 --- a/resource_check.go +++ b/resource_check.go @@ -43,7 +43,7 @@ func resourceCheck() *schema.Resource { } } if !valid { - errs = append(errs, fmt.Errorf("%q must be one of %v, got: %d", key, validFreqs, v)) + errs = append(errs, fmt.Errorf("%q must be one of %v, got %d", key, validFreqs, v)) } return warns, errs }, @@ -77,15 +77,10 @@ func resourceCheck() *schema.Resource { Optional: true, Default: 15000, ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { - // Response times are hard capped to 30 seconds according to the web UI. - // Should/may require degraded response time to be less than max response time. // https://checklyhq.com/docs/api-checks/limits/ v := val.(int) - if !(v > 0) { - errs = append(errs, fmt.Errorf("%q must be larger than 0 ms, got: %d", key, v)) - } - if !(v <= 30000) { - errs = append(errs, fmt.Errorf("%q must be at most 30000 ms, got: %d", key, v)) + if v < 0 || v > 30000 { + errs = append(errs, fmt.Errorf("%q must be 0-30000 ms, got %d", key, v)) } return warns, errs }, @@ -96,13 +91,9 @@ func resourceCheck() *schema.Resource { Default: 30000, ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { v := val.(int) - // Response times are hard capped to 30 seconds according to the web UI. // https://checklyhq.com/docs/api-checks/limits/ - if !(v > 0) { - errs = append(errs, fmt.Errorf("%q must be larger than 0 ms, got: %d", key, v)) - } - if !(v <= 30000) { - errs = append(errs, fmt.Errorf("%q must be at most 30000 ms, got: %d", key, v)) + if v < 0 || v > 30000 { + errs = append(errs, fmt.Errorf("%q must be 0-30000 ms, got: %d", key, v)) } return warns, errs }, From d7664ff770c32b97d5d474cdb882908dde375cee Mon Sep 17 00:00:00 2001 From: John Arundel Date: Fri, 21 Feb 2020 13:21:31 +0000 Subject: [PATCH 5/5] Update README --- README.md | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 91c46c0..a09d4c7 100644 --- a/README.md +++ b/README.md @@ -59,15 +59,15 @@ provider "checkly" { api_key = "${var.checkly_api_key}" } -resource "checkly_check" "checkly-public-stats" { - name = "public-stats" +resource "checkly_check" "example-check" { + name = "Example check" type = "API" activated = true should_fail = false frequency = 1 double_check = true ssl_check = true - ssl_check_domain = "api.checklyhq.com" + ssl_check_domain = "api.example.com" use_global_alert_settings = true locations = [ @@ -75,7 +75,7 @@ resource "checkly_check" "checkly-public-stats" { ] request { - url = "https://api.checklyhq.com/public-stats" + url = "https://api.example.com/" follow_redirects = true assertion { source = "STATUS_CODE" @@ -86,12 +86,88 @@ resource "checkly_check" "checkly-public-stats" { } ``` +Here's something a little more complicated, to show what you can do: + +```terraform +resource "checkly_check" "example-check2" { + name = "Example check 2" + type = "API" + activated = true + should_fail = true + frequency = 1 + ssl_check_domain = "api.example.com" + double_check = true + degraded_response_time = 5000 + max_response_time = 10000 + + locations = [ + "us-west-1", + "ap-northeast-1", + "ap-south-1", + ] + + alert_settings { + escalation_type = "RUN_BASED" + + run_based_escalation { + failed_run_threshold = 1 + } + + time_based_escalation { + minutes_failing_threshold = 5 + } + + ssl_certificates { + enabled = true + alert_threshold = 30 + } + + reminders { + amount = 1 + } + } + + request { + follow_redirects = true + url = "http://api.example.com/" + + query_parameters = { + search = "foo" + } + + headers = { + X-Bogus = "bogus" + } + + assertion { + source = "JSON_BODY" + property = "code" + comparison = "HAS_VALUE" + target = "authentication.failed" + } + + assertion { + source = "STATUS_CODE" + property = "" + comparison = "EQUALS" + target = "401" + } + + basic_auth { + username = "" + password = "" + } + } +} +``` + ## Developing the provider -Clone the repo, build the project and add it to the Terraform plugins directory. You will need to have Go installed. +Clone the repo, build the project and add it to your Terraform plugins directory. You will need to have Go installed. ```bash git clone git@github.com:bitfield/terraform-provider-checkly.git cd terraform-provider-checkly -go build +go test +go build && CHECKLY_API_KEY=XXX go test -tags=integration ``` \ No newline at end of file