aboutsummaryrefslogtreecommitdiffhomepage
path: root/resource_statuscaketest.go
diff options
context:
space:
mode:
Diffstat (limited to 'resource_statuscaketest.go')
-rw-r--r--resource_statuscaketest.go88
1 files changed, 86 insertions, 2 deletions
diff --git a/resource_statuscaketest.go b/resource_statuscaketest.go
index f34a97a..8eb5401 100644
--- a/resource_statuscaketest.go
+++ b/resource_statuscaketest.go
@@ -1,6 +1,14 @@
1package statuscake 1package statuscake
2 2
3import "github.com/hashicorp/terraform/helper/schema" 3import (
4 "fmt"
5 "strconv"
6
7 "log"
8
9 "github.com/DreamItGetIT/statuscake"
10 "github.com/hashicorp/terraform/helper/schema"
11)
4 12
5func resourceStatusCakeTest() *schema.Resource { 13func resourceStatusCakeTest() *schema.Resource {
6 return &schema.Resource{ 14 return &schema.Resource{
@@ -8,11 +16,73 @@ func resourceStatusCakeTest() *schema.Resource {
8 Update: UpdateTest, 16 Update: UpdateTest,
9 Delete: DeleteTest, 17 Delete: DeleteTest,
10 Read: ReadTest, 18 Read: ReadTest,
19
20 Schema: map[string]*schema.Schema{
21 "test_id": &schema.Schema{
22 Type: schema.TypeString,
23 Computed: true,
24 },
25
26 "website_name": &schema.Schema{
27 Type: schema.TypeString,
28 Required: true,
29 },
30
31 "website_url": &schema.Schema{
32 Type: schema.TypeString,
33 Required: true,
34 },
35
36 "check_rate": &schema.Schema{
37 Type: schema.TypeInt,
38 Optional: true,
39 Default: 300,
40 },
41
42 "test_type": &schema.Schema{
43 Type: schema.TypeString,
44 Required: true,
45 },
46
47 "paused": &schema.Schema{
48 Type: schema.TypeBool,
49 Optional: true,
50 Default: false,
51 },
52 },
11 } 53 }
12} 54}
13 55
14func CreateTest(d *schema.ResourceData, meta interface{}) error { 56func CreateTest(d *schema.ResourceData, meta interface{}) error {
15 return nil 57 client := meta.(*statuscake.Client)
58
59 newTest := &statuscake.Test{
60 WebsiteName: "posters.dreamitget.it",
61 WebsiteURL: "https://posters.dreamitget.it",
62 TestType: "HTTP",
63 CheckRate: 500,
64 }
65
66 // newTest := &statuscake.Test{
67 // WebsiteName: d.Get("website_name").(string),
68 // WebsiteURL: d.Get("website_url").(string),
69 // TestType: d.Get("test_type").(string),
70 // CheckRate: 500,
71 // }
72
73 log.Printf("[DEBUG] Check Rate: %d", d.Get("check_rate").(int))
74 log.Printf("[DEBUG] TestType: %s", d.Get("test_type").(string))
75 log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string))
76
77 response, err := client.Tests().Put(newTest)
78 if err != nil {
79 return fmt.Errorf("Error creating StatusCake Test: %s", err.Error())
80 }
81
82 d.Set("test_id", fmt.Sprintf("%d", response.TestID))
83 d.SetId(fmt.Sprintf("%d", response.TestID))
84
85 return UpdateTest(d, meta)
16} 86}
17 87
18func UpdateTest(d *schema.ResourceData, meta interface{}) error { 88func UpdateTest(d *schema.ResourceData, meta interface{}) error {
@@ -20,6 +90,20 @@ func UpdateTest(d *schema.ResourceData, meta interface{}) error {
20} 90}
21 91
22func DeleteTest(d *schema.ResourceData, meta interface{}) error { 92func DeleteTest(d *schema.ResourceData, meta interface{}) error {
93 client := meta.(*statuscake.Client)
94
95 testId, parseErr := strconv.Atoi(d.Id())
96 if parseErr != nil {
97 return parseErr
98 }
99 testIntId := int(testId)
100
101 log.Printf("[DEBUG] Deleting StatusCake Test: %s", d.Id())
102 err := client.Tests().Delete(testIntId)
103 if err != nil {
104 return err
105 }
106
23 return nil 107 return nil
24} 108}
25 109