aboutsummaryrefslogtreecommitdiffhomepage
path: root/statuscake/resource_statuscakessl.go
diff options
context:
space:
mode:
Diffstat (limited to 'statuscake/resource_statuscakessl.go')
-rw-r--r--statuscake/resource_statuscakessl.go290
1 files changed, 290 insertions, 0 deletions
diff --git a/statuscake/resource_statuscakessl.go b/statuscake/resource_statuscakessl.go
new file mode 100644
index 0000000..2ee50e6
--- /dev/null
+++ b/statuscake/resource_statuscakessl.go
@@ -0,0 +1,290 @@
1package statuscake
2
3import (
4 "fmt"
5 "strconv"
6
7 "github.com/DreamItGetIT/statuscake"
8 "github.com/hashicorp/terraform/helper/schema"
9 "log"
10 "strings"
11)
12
13func resourceStatusCakeSsl() *schema.Resource {
14 return &schema.Resource{
15 Create: CreateSsl,
16 Update: UpdateSsl,
17 Delete: DeleteSsl,
18 Read: ReadSsl,
19 Importer: &schema.ResourceImporter{
20 State: schema.ImportStatePassthrough,
21 },
22
23 Schema: map[string]*schema.Schema{
24 "ssl_id": {
25 Type: schema.TypeString,
26 Computed: true,
27 },
28
29 "domain": {
30 Type: schema.TypeString,
31 Required: true,
32 },
33
34 "contact_groups": {
35 Type: schema.TypeSet,
36 Elem: &schema.Schema{Type: schema.TypeString},
37 Optional: true,
38 Computed: true,
39 ConflictsWith: []string{"contact_groups_c"},
40 },
41
42 "contact_groups_c": {
43 Type: schema.TypeString,
44 Optional: true,
45 Computed: true,
46 ConflictsWith: []string{"contact_groups"},
47 },
48
49 "checkrate": {
50 Type: schema.TypeInt,
51 Required: true,
52 },
53
54 "alert_at": {
55 Type: schema.TypeString,
56 Required: true,
57 },
58
59 "alert_reminder": {
60 Type: schema.TypeBool,
61 Required: true,
62 },
63
64 "alert_expiry": {
65 Type: schema.TypeBool,
66 Required: true,
67 },
68
69 "alert_broken": {
70 Type: schema.TypeBool,
71 Required: true,
72 },
73
74 "alert_mixed": {
75 Type: schema.TypeBool,
76 Required: true,
77 },
78
79 "paused": {
80 Type: schema.TypeBool,
81 Computed: true,
82 },
83
84 "issuer_cn": {
85 Type: schema.TypeString,
86 Computed: true,
87 },
88
89 "cert_score": {
90 Type: schema.TypeString,
91 Computed: true,
92 },
93
94 "cipher_score": {
95 Type: schema.TypeString,
96 Computed: true,
97 },
98
99 "cert_status": {
100 Type: schema.TypeString,
101 Computed: true,
102 },
103
104 "cipher": {
105 Type: schema.TypeString,
106 Computed: true,
107 },
108
109 "valid_from_utc": {
110 Type: schema.TypeString,
111 Computed: true,
112 },
113
114 "valid_until_utc": {
115 Type: schema.TypeString,
116 Computed: true,
117 },
118
119 "mixed_content": {
120 Type: schema.TypeList,
121 Elem: &schema.Schema{
122 Type: schema.TypeMap,
123 Elem: &schema.Schema{Type: schema.TypeString},
124 },
125 Computed: true,
126 },
127
128 "flags": {
129 Type: schema.TypeMap,
130 Elem: &schema.Schema{Type: schema.TypeBool},
131 Computed: true,
132 },
133
134 "last_reminder": {
135 Type: schema.TypeInt,
136 Computed: true,
137 },
138
139 "last_updated_utc": {
140 Type: schema.TypeString,
141 Computed: true,
142 },
143 },
144 }
145}
146
147func CreateSsl(d *schema.ResourceData, meta interface{}) error {
148 client := meta.(*statuscake.Client)
149
150 if v, ok := d.GetOk("contact_groups"); ok {
151 d.Set("contact_groups_c", strings.Join(castSetToSliceStrings(v.(*schema.Set).List()), ","))
152 }
153
154 newSsl := &statuscake.PartialSsl{
155 Domain: d.Get("domain").(string),
156 Checkrate: strconv.Itoa(d.Get("checkrate").(int)),
157 ContactGroupsC: d.Get("contact_groups_c").(string),
158 AlertReminder: d.Get("alert_reminder").(bool),
159 AlertExpiry: d.Get("alert_expiry").(bool),
160 AlertBroken: d.Get("alert_broken").(bool),
161 AlertMixed: d.Get("alert_mixed").(bool),
162 AlertAt: d.Get("alert_at").(string),
163 }
164
165 log.Printf("[DEBUG] Creating new StatusCake Ssl: %s", d.Get("domain").(string))
166
167 response, err := statuscake.NewSsls(client).Create(newSsl)
168 if err != nil {
169 return fmt.Errorf("Error creating StatusCake Ssl: %s", err.Error())
170 }
171
172 d.Set("ssl_id", response.ID)
173 d.Set("paused", response.Paused)
174 d.Set("issuer_cn", response.IssuerCn)
175 d.Set("cert_score", response.CertScore)
176 d.Set("cipher_score", response.CipherScore)
177 d.Set("cert_status", response.CertStatus)
178 d.Set("cipher", response.Cipher)
179 d.Set("valid_from_utc", response.ValidFromUtc)
180 d.Set("valid_until_utc", response.ValidUntilUtc)
181 d.Set("mixed_content", response.MixedContent)
182 d.Set("flags", response.Flags)
183 d.Set("last_reminder", response.LastReminder)
184 d.Set("last_updated_utc", response.LastUpdatedUtc)
185 d.SetId(response.ID)
186
187 return ReadSsl(d, meta)
188}
189
190func UpdateSsl(d *schema.ResourceData, meta interface{}) error {
191 client := meta.(*statuscake.Client)
192
193 params := getStatusCakeSslInput(d)
194
195 log.Printf("[DEBUG] StatusCake Ssl Update for %s", d.Id())
196 _, err := statuscake.NewSsls(client).Update(params)
197 if err != nil {
198 return fmt.Errorf("Error Updating StatusCake Ssl: %s", err.Error())
199 }
200 return nil
201}
202
203func DeleteSsl(d *schema.ResourceData, meta interface{}) error {
204 client := meta.(*statuscake.Client)
205
206 log.Printf("[DEBUG] Deleting StatusCake Ssl: %s", d.Id())
207 err := statuscake.NewSsls(client).Delete(d.Id())
208
209 return err
210}
211
212func ReadSsl(d *schema.ResourceData, meta interface{}) error {
213 client := meta.(*statuscake.Client)
214
215 response, err := statuscake.NewSsls(client).Detail(d.Id())
216 if err != nil {
217 return fmt.Errorf("Error Getting StatusCake Ssl Details for %s: Error: %s", d.Id(), err)
218 }
219 d.Set("domain", response.Domain)
220 d.Set("checkrate", response.Checkrate)
221 d.Set("contact_groups_c", response.ContactGroupsC)
222 d.Set("alert_reminder", response.AlertReminder)
223 d.Set("alert_expiry", response.AlertExpiry)
224 d.Set("alert_broken", response.AlertBroken)
225 d.Set("alert_mixed", response.AlertMixed)
226 d.Set("alert_at", response.AlertAt)
227 d.Set("ssl_id", response.ID)
228 d.Set("contact_groups", response.ContactGroups)
229 d.Set("paused", response.Paused)
230 d.Set("issuer_cn", response.IssuerCn)
231 d.Set("cert_score", response.CertScore)
232 d.Set("cipher_score", response.CipherScore)
233 d.Set("cert_status", response.CertStatus)
234 d.Set("cipher", response.Cipher)
235 d.Set("valid_from_utc", response.ValidFromUtc)
236 d.Set("valid_until_utc", response.ValidUntilUtc)
237 d.Set("mixed_content", response.MixedContent)
238 d.Set("flags", response.Flags)
239 d.Set("last_reminder", response.LastReminder)
240 d.Set("last_updated_utc", response.LastUpdatedUtc)
241 d.SetId(response.ID)
242
243 return nil
244}
245
246func getStatusCakeSslInput(d *schema.ResourceData) *statuscake.PartialSsl {
247 sslId, parseErr := strconv.Atoi(d.Id())
248 if parseErr != nil {
249 log.Printf("[DEBUG] Error Parsing StatusCake Id: %s", d.Id())
250 }
251 ssl := &statuscake.PartialSsl{
252 ID: sslId,
253 }
254
255 if v, ok := d.GetOk("domain"); ok {
256 ssl.Domain = v.(string)
257 }
258
259 if v, ok := d.GetOk("checkrate"); ok {
260 ssl.Checkrate = strconv.Itoa(v.(int))
261 }
262
263 if v, ok := d.GetOk("contact_groups"); ok {
264 ssl.ContactGroupsC = strings.Join(castSetToSliceStrings(v.(*schema.Set).List()), ",")
265 } else if v, ok := d.GetOk("contact_groups_c"); ok {
266 ssl.ContactGroupsC = v.(string)
267 }
268
269 if v, ok := d.GetOk("alert_reminder"); ok {
270 ssl.AlertReminder = v.(bool)
271 }
272
273 if v, ok := d.GetOk("alert_expiry"); ok {
274 ssl.AlertExpiry = v.(bool)
275 }
276
277 if v, ok := d.GetOk("alert_broken"); ok {
278 ssl.AlertBroken = v.(bool)
279 }
280
281 if v, ok := d.GetOk("alert_mixed"); ok {
282 ssl.AlertMixed = v.(bool)
283 }
284
285 if v, ok := d.GetOk("alert_at"); ok {
286 ssl.AlertAt = v.(string)
287 }
288
289 return ssl
290}