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)
161 return fmt.Errorf("Error creating StatusCake Ssl: %s", err.Error())
164 d.Set("ssl_id", response.ID)
165 d.Set("contact_groups", response.ContactGroups)
166 d.Set("paused", response.Paused)
167 d.Set("issuer_cn", response.IssuerCn)
168 d.Set("cert_score", response.CertScore)
169 d.Set("cipher_score", response.CipherScore)
170 d.Set("cert_status", response.CertStatus)
171 d.Set("cipher", response.Cipher)
172 d.Set("valid_from_utc", response.ValidFromUtc)
173 d.Set("valid_until_utc", response.ValidUntilUtc)
174 d.Set("mixed_content", response.MixedContent)
175 d.Set("flags", response.Flags)
176 d.Set("last_reminder", response.LastReminder)
177 d.Set("last_updated_utc", response.LastUpdatedUtc)
180 return ReadSsl(d, meta)
183 func UpdateSsl(d *schema.ResourceData, meta interface{}) error {
184 client := meta.(*statuscake.Client)
186 params := getStatusCakeSslInput(d)
188 log.Printf("[DEBUG] StatusCake Ssl Update for %s", d.Id())
189 _, err := statuscake.NewSsls(client).Update(params)
191 return fmt.Errorf("Error Updating StatusCake Ssl: %s", err.Error())
196 func DeleteSsl(d *schema.ResourceData, meta interface{}) error {
197 client := meta.(*statuscake.Client)
199 log.Printf("[DEBUG] Deleting StatusCake Ssl: %s", d.Id())
200 err := statuscake.NewSsls(client).Delete(d.Id())
205 func ReadSsl(d *schema.ResourceData, meta interface{}) error {
206 client := meta.(*statuscake.Client)
208 response, err := statuscake.NewSsls(client).Detail(d.Id())
210 return fmt.Errorf("Error Getting StatusCake Ssl Details for %s: Error: %s", d.Id(), err)
212 d.Set("domain", response.Domain)
213 d.Set("checkrate", response.Checkrate)
214 d.Set("contact_groups_c", response.ContactGroupsC)
215 d.Set("alert_reminder", response.AlertReminder)
216 d.Set("alert_expiry", response.AlertExpiry)
217 d.Set("alert_broken", response.AlertBroken)
218 d.Set("alert_mixed", response.AlertMixed)
219 d.Set("alert_at", response.AlertAt)
220 d.Set("ssl_id", response.ID)
221 d.Set("contact_groups", response.ContactGroups)
222 d.Set("paused", response.Paused)
223 d.Set("issuer_cn", response.IssuerCn)
224 d.Set("cert_score", response.CertScore)
225 d.Set("cipher_score", response.CipherScore)
226 d.Set("cert_status", response.CertStatus)
227 d.Set("cipher", response.Cipher)
228 d.Set("valid_from_utc", response.ValidFromUtc)
229 d.Set("valid_until_utc", response.ValidUntilUtc)
230 d.Set("mixed_content", response.MixedContent)
231 d.Set("flags", response.Flags)
232 d.Set("last_reminder", response.LastReminder)
233 d.Set("last_updated_utc", response.LastUpdatedUtc)
239 func getStatusCakeSslInput(d *schema.ResourceData) *statuscake.PartialSsl {
240 sslId, parseErr := strconv.Atoi(d.Id())
242 log.Printf("[DEBUG] Error Parsing StatusCake Id: %s", d.Id())
244 ssl := &statuscake.PartialSsl{
248 if v, ok := d.GetOk("domain"); ok {
249 ssl.Domain = v.(string)
252 if v, ok := d.GetOk("checkrate"); ok {
253 ssl.Checkrate = strconv.Itoa(v.(int))
256 if v, ok := d.GetOk("contact_groups_c"); ok {
257 ssl.ContactGroupsC = v.(string)
260 if v, ok := d.GetOk("alert_reminder"); ok {
261 ssl.AlertReminder = v.(bool)
264 if v, ok := d.GetOk("alert_expiry"); ok {
265 ssl.AlertExpiry = v.(bool)
268 if v, ok := d.GetOk("alert_broken"); ok {
269 ssl.AlertBroken = v.(bool)
272 if v, ok := d.GetOk("alert_mixed"); ok {
273 ssl.AlertMixed = v.(bool)
276 if v, ok := d.GetOk("alert_at"); ok {
277 ssl.AlertAt = v.(string)