Skip to content

Commit ea613ce

Browse files
author
Lee Johnson
committed
Adding ability to add and update contact groups using the terraform statuscake provider
1 parent 511101a commit ea613ce

3 files changed

Lines changed: 93 additions & 1 deletion

File tree

builtin/providers/statuscake/resource_statuscaketest.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ func resourceStatusCakeTest() *schema.Resource {
3333
Required: true,
3434
},
3535

36+
"contact_id": &schema.Schema{
37+
Type: schema.TypeInt,
38+
Optional: true,
39+
},
40+
3641
"check_rate": &schema.Schema{
3742
Type: schema.TypeInt,
3843
Optional: true,
@@ -65,6 +70,7 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error {
6570
WebsiteURL: d.Get("website_url").(string),
6671
TestType: d.Get("test_type").(string),
6772
CheckRate: d.Get("check_rate").(int),
73+
ContactID: d.Get("contact_id").(int),
6874
}
6975

7076
log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string))
@@ -142,6 +148,9 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test {
142148
if v, ok := d.GetOk("check_rate"); ok {
143149
test.CheckRate = v.(int)
144150
}
151+
if v, ok := d.GetOk("contact_id"); ok {
152+
test.ContactID = v.(int)
153+
}
145154
if v, ok := d.GetOk("test_type"); ok {
146155
test.TestType = v.(string)
147156
}

builtin/providers/statuscake/resource_statuscaketest_test.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package statuscake
22

33
import (
44
"fmt"
5+
"os"
56
"strconv"
67
"testing"
78

@@ -10,6 +11,19 @@ import (
1011
"github.com/hashicorp/terraform/terraform"
1112
)
1213

14+
// check to ensure that contact group id is provided before running
15+
// tests on it.
16+
func testAccContactGroupPreCheck(t *testing.T, testAlt bool) {
17+
if v := os.Getenv("CONTACT_GROUP"); v == "" {
18+
t.Fatal("CONTACT_GROUP must be set for contact group acceptance tests")
19+
}
20+
if testAlt {
21+
if v := os.Getenv("ALT_CONTACT_GROUP"); v == "" {
22+
t.Fatal("ALT_CONTACT_GROUP must be set for contact group acceptance tests")
23+
}
24+
}
25+
}
26+
1327
func TestAccStatusCake_basic(t *testing.T) {
1428
var test statuscake.Test
1529

@@ -55,6 +69,57 @@ func TestAccStatusCake_withUpdate(t *testing.T) {
5569
})
5670
}
5771

72+
func TestAccStatusCake_contactGroup_basic(t *testing.T) {
73+
var test statuscake.Test
74+
75+
resource.Test(t, resource.TestCase{
76+
PreCheck: func() {
77+
testAccPreCheck(t)
78+
testAccContactGroupPreCheck(t, false)
79+
},
80+
Providers: testAccProviders,
81+
CheckDestroy: testAccTestCheckDestroy(&test),
82+
Steps: []resource.TestStep{
83+
resource.TestStep{
84+
Config: testAccTestConfig_contactGroup,
85+
Check: resource.ComposeTestCheckFunc(
86+
testAccTestCheckExists("statuscake_test.google", &test),
87+
),
88+
},
89+
},
90+
})
91+
}
92+
93+
func TestAccStatusCake_contactGroup_withUpdate(t *testing.T) {
94+
var test statuscake.Test
95+
var altContactGroup = os.Getenv("ALT_CONTACT_GROUP")
96+
97+
resource.Test(t, resource.TestCase{
98+
PreCheck: func() {
99+
testAccPreCheck(t)
100+
testAccContactGroupPreCheck(t, true)
101+
},
102+
Providers: testAccProviders,
103+
CheckDestroy: testAccTestCheckDestroy(&test),
104+
Steps: []resource.TestStep{
105+
resource.TestStep{
106+
Config: testAccTestConfig_contactGroup,
107+
Check: resource.ComposeTestCheckFunc(
108+
testAccTestCheckExists("statuscake_test.google", &test),
109+
),
110+
},
111+
// make sure to creat
112+
resource.TestStep{
113+
Config: testAccTestConfig_contactGroup_update,
114+
Check: resource.ComposeTestCheckFunc(
115+
testAccTestCheckExists("statuscake_test.google", &test),
116+
resource.TestCheckResourceAttr("statuscake_test.google", "contact_id", altContactGroup),
117+
),
118+
},
119+
},
120+
})
121+
}
122+
58123
func testAccTestCheckExists(rn string, test *statuscake.Test) resource.TestCheckFunc {
59124
return func(s *terraform.State) error {
60125
rs, ok := s.RootModule().Resources[rn]
@@ -113,3 +178,21 @@ resource "statuscake_test" "google" {
113178
paused = true
114179
}
115180
`
181+
182+
var testAccTestConfig_contactGroup string = `` +
183+
`resource "statuscake_test" "google" {
184+
website_name = "google.com"
185+
website_url = "www.google.com"
186+
test_type = "HTTP"
187+
check_rate = 300
188+
contact_id = ` + os.Getenv("CONTACT_GROUP") + `
189+
}`
190+
191+
var testAccTestConfig_contactGroup_update string = `` +
192+
`resource "statuscake_test" "google" {
193+
website_name = "google.com"
194+
website_url = "www.google.com"
195+
test_type = "HTTP"
196+
check_rate = 300
197+
contact_id = ` + os.Getenv("ALT_CONTACT_GROUP") + `
198+
}`

vendor/github.com/DreamItGetIT/statuscake/tests.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)