9 "github.com/DreamItGetIT/statuscake"
10 "github.com/hashicorp/terraform/helper/schema"
13 func resourceStatusCakeSsl() *schema.Resource {
14 return &schema.Resource{
19 Importer: &schema.ResourceImporter{
20 State: schema.ImportStatePassthrough,
23 Schema: map[string]*schema.Schema{
25 Type: schema.TypeString,
30 Type: schema.TypeString,
35 Type: schema.TypeList,
36 Elem: &schema.Schema{Type: schema.TypeString},
41 Type: schema.TypeString,
51 Type: schema.TypeString,
56 Type: schema.TypeBool,
61 Type: schema.TypeBool,
66 Type: schema.TypeBool,
71 Type: schema.TypeBool,
76 Type: schema.TypeBool,
81 Type: schema.TypeString,
86 Type: schema.TypeString,
91 Type: schema.TypeString,
96 Type: schema.TypeString,
101 Type: schema.TypeString,
106 Type: schema.TypeString,
111 Type: schema.TypeString,
116 Type: schema.TypeList,
117 Elem: &schema.Schema{
118 Type: schema.TypeMap,
119 Elem: &schema.Schema{Type: schema.TypeString},
125 Type: schema.TypeMap,
126 Elem: &schema.Schema{Type: schema.TypeBool},
131 Type: schema.TypeInt,
135 "last_updated_utc": {
136 Type: schema.TypeString,
143 func CreateSsl(d *schema.ResourceData, meta interface{}) error {
144 client := meta.(*statuscake.Client)
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),
157 log.Printf("[DEBUG] Creating new StatusCake Ssl: %s", d.Get("domain").(string))
159 response, err := statuscake.NewSsls(client).Create(newSsl)
163 return fmt.Errorf("Error creating StatusCake Ssl: %s", err.Error())
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)
182 return ReadSsl(d, meta)
185 func UpdateSsl(d *schema.ResourceData, meta interface{}) error {
186 client := meta.(*statuscake.Client)
188 params := getStatusCakeSslInput(d)
190 log.Printf("[DEBUG] StatusCake Ssl Update for %s", d.Id())
191 _, err := statuscake.NewSsls(client).Update(params)
193 return fmt.Errorf("Error Updating StatusCake Ssl: %s", err.Error())
198 func DeleteSsl(d *schema.ResourceData, meta interface{}) error {
199 client := meta.(*statuscake.Client)
201 log.Printf("[DEBUG] Deleting StatusCake Ssl: %s", d.Id())
202 err := statuscake.NewSsls(client).Delete(d.Id())
207 func ReadSsl(d *schema.ResourceData, meta interface{}) error {
208 client := meta.(*statuscake.Client)
210 response, err := statuscake.NewSsls(client).Detail(d.Id())
212 return fmt.Errorf("Error Getting StatusCake Ssl Details for %s: Error: %s", d.Id(), err)
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)
241 func getStatusCakeSslInput(d *schema.ResourceData) *statuscake.PartialSsl {
242 sslId, parseErr := strconv.Atoi(d.Id())
244 log.Printf("[DEBUG] Error Parsing StatusCake Id: %s", d.Id())
246 ssl := &statuscake.PartialSsl{
250 if v, ok := d.GetOk("domain"); ok {
251 ssl.Domain = v.(string)
254 if v, ok := d.GetOk("checkrate"); ok {
255 ssl.Checkrate = strconv.Itoa(v.(int))
258 if v, ok := d.GetOk("contact_groups_c"); ok {
259 ssl.ContactGroupsC = v.(string)
262 if v, ok := d.GetOk("alert_reminder"); ok {
263 ssl.AlertReminder = v.(bool)
266 if v, ok := d.GetOk("alert_expiry"); ok {
267 ssl.AlertExpiry = v.(bool)
270 if v, ok := d.GetOk("alert_broken"); ok {
271 ssl.AlertBroken = v.(bool)
274 if v, ok := d.GetOk("alert_mixed"); ok {
275 ssl.AlertMixed = v.(bool)
278 if v, ok := d.GetOk("alert_at"); ok {
279 ssl.AlertAt = v.(string)