7 "github.com/DreamItGetIT/statuscake"
8 "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,
36 Elem: &schema.Schema{Type: schema.TypeString},
39 ConflictsWith: []string{"contact_groups_c"},
43 Type: schema.TypeString,
46 ConflictsWith: []string{"contact_groups"},
55 Type: schema.TypeString,
60 Type: schema.TypeBool,
65 Type: schema.TypeBool,
70 Type: schema.TypeBool,
75 Type: schema.TypeBool,
80 Type: schema.TypeBool,
85 Type: schema.TypeString,
90 Type: schema.TypeString,
95 Type: schema.TypeString,
100 Type: schema.TypeString,
105 Type: schema.TypeString,
110 Type: schema.TypeString,
115 Type: schema.TypeString,
120 Type: schema.TypeList,
121 Elem: &schema.Schema{
122 Type: schema.TypeMap,
123 Elem: &schema.Schema{Type: schema.TypeString},
129 Type: schema.TypeMap,
130 Elem: &schema.Schema{Type: schema.TypeBool},
135 Type: schema.TypeInt,
139 "last_updated_utc": {
140 Type: schema.TypeString,
147 func CreateSsl(d *schema.ResourceData, meta interface{}) error {
148 client := meta.(*statuscake.Client)
150 if v, ok := d.GetOk("contact_groups"); ok {
151 d.Set("contact_groups_c", strings.Join(castSetToSliceStrings(v.(*schema.Set).List()), ","))
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),
165 log.Printf("[DEBUG] Creating new StatusCake Ssl: %s", d.Get("domain").(string))
167 response, err := statuscake.NewSsls(client).Create(newSsl)
169 return fmt.Errorf("Error creating StatusCake Ssl: %s", err.Error())
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)
187 return ReadSsl(d, meta)
190 func UpdateSsl(d *schema.ResourceData, meta interface{}) error {
191 client := meta.(*statuscake.Client)
193 params := getStatusCakeSslInput(d)
195 log.Printf("[DEBUG] StatusCake Ssl Update for %s", d.Id())
196 _, err := statuscake.NewSsls(client).Update(params)
198 return fmt.Errorf("Error Updating StatusCake Ssl: %s", err.Error())
203 func DeleteSsl(d *schema.ResourceData, meta interface{}) error {
204 client := meta.(*statuscake.Client)
206 log.Printf("[DEBUG] Deleting StatusCake Ssl: %s", d.Id())
207 err := statuscake.NewSsls(client).Delete(d.Id())
212 func ReadSsl(d *schema.ResourceData, meta interface{}) error {
213 client := meta.(*statuscake.Client)
215 response, err := statuscake.NewSsls(client).Detail(d.Id())
217 return fmt.Errorf("Error Getting StatusCake Ssl Details for %s: Error: %s", d.Id(), err)
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)
246 func getStatusCakeSslInput(d *schema.ResourceData) *statuscake.PartialSsl {
247 sslId, parseErr := strconv.Atoi(d.Id())
249 log.Printf("[DEBUG] Error Parsing StatusCake Id: %s", d.Id())
251 ssl := &statuscake.PartialSsl{
255 if v, ok := d.GetOk("domain"); ok {
256 ssl.Domain = v.(string)
259 if v, ok := d.GetOk("checkrate"); ok {
260 ssl.Checkrate = strconv.Itoa(v.(int))
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)
269 if v, ok := d.GetOk("alert_reminder"); ok {
270 ssl.AlertReminder = v.(bool)
273 if v, ok := d.GetOk("alert_expiry"); ok {
274 ssl.AlertExpiry = v.(bool)
277 if v, ok := d.GetOk("alert_broken"); ok {
278 ssl.AlertBroken = v.(bool)
281 if v, ok := d.GetOk("alert_mixed"); ok {
282 ssl.AlertMixed = v.(bool)
285 if v, ok := d.GetOk("alert_at"); ok {
286 ssl.AlertAt = v.(string)