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