diff --git a/resource_librato_alert.go b/resource_librato_alert.go index 88ca52d..dd21de7 100644 --- a/resource_librato_alert.go +++ b/resource_librato_alert.go @@ -23,61 +23,61 @@ func resourceLibratoAlert() *schema.Resource { Delete: resourceLibratoAlertDelete, Schema: map[string]*schema.Schema{ - "name": &schema.Schema{ + "name": { Type: schema.TypeString, Required: true, ForceNew: false, }, - "description": &schema.Schema{ + "description": { Type: schema.TypeString, Optional: true, }, - "active": &schema.Schema{ + "active": { Type: schema.TypeBool, Optional: true, Default: true, }, - "rearm_seconds": &schema.Schema{ + "rearm_seconds": { Type: schema.TypeInt, Optional: true, Default: 600, }, - "services": &schema.Schema{ + "services": { Type: schema.TypeSet, Optional: true, Elem: &schema.Schema{Type: schema.TypeString}, Set: schema.HashString, }, - "condition": &schema.Schema{ + "condition": { Type: schema.TypeSet, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "type": &schema.Schema{ + "type": { Type: schema.TypeString, Required: true, }, - "metric_name": &schema.Schema{ + "metric_name": { Type: schema.TypeString, Required: true, }, - "source": &schema.Schema{ + "source": { Type: schema.TypeString, Optional: true, }, - "detect_reset": &schema.Schema{ + "detect_reset": { Type: schema.TypeBool, Optional: true, }, - "duration": &schema.Schema{ + "duration": { Type: schema.TypeInt, Optional: true, }, - "threshold": &schema.Schema{ + "threshold": { Type: schema.TypeFloat, Optional: true, }, - "summary_function": &schema.Schema{ + "summary_function": { Type: schema.TypeString, Optional: true, }, @@ -85,12 +85,12 @@ func resourceLibratoAlert() *schema.Resource { }, Set: resourceLibratoAlertConditionsHash, }, - "attributes": &schema.Schema{ + "attributes": { Type: schema.TypeList, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "runbook_url": &schema.Schema{ + "runbook_url": { Type: schema.TypeString, Optional: true, }, @@ -112,9 +112,9 @@ func resourceLibratoAlertConditionsHash(v interface{}) int { buf.WriteString(fmt.Sprintf("%s-", source.(string))) } - detect_reset, present := m["detect_reset"] + detectReset, present := m["detect_reset"] if present { - buf.WriteString(fmt.Sprintf("%t-", detect_reset.(bool))) + buf.WriteString(fmt.Sprintf("%t-", detectReset.(bool))) } duration, present := m["duration"] @@ -127,9 +127,9 @@ func resourceLibratoAlertConditionsHash(v interface{}) int { buf.WriteString(fmt.Sprintf("%f-", threshold.(float64))) } - summary_function, present := m["summary_function"] + summaryFunction, present := m["summary_function"] if present { - buf.WriteString(fmt.Sprintf("%s-", summary_function.(string))) + buf.WriteString(fmt.Sprintf("%s-", summaryFunction.(string))) } return hashcode.String(buf.String()) @@ -413,9 +413,9 @@ func resourceLibratoAlertUpdate(d *schema.ResourceData, meta interface{}) error } log.Printf("[INFO] Updating Librato alert: %s", alert) - _, err = client.Alerts.Edit(uint(alertID), alert) - if err != nil { - return fmt.Errorf("Error updating Librato alert: %s", err) + _, updErr := client.Alerts.Update(uint(alertID), alert) + if updErr != nil { + return fmt.Errorf("Error updating Librato alert: %s", updErr) } log.Printf("[INFO] Updated Librato alert %d", alertID) @@ -429,9 +429,9 @@ func resourceLibratoAlertUpdate(d *schema.ResourceData, meta interface{}) error ContinuousTargetOccurence: 5, Refresh: func() (interface{}, string, error) { log.Printf("[DEBUG] Checking if Librato Alert %d was updated yet", alertID) - changedAlert, _, err := client.Alerts.Get(uint(alertID)) - if err != nil { - return changedAlert, "", err + changedAlert, _, getErr := client.Alerts.Get(uint(alertID)) + if getErr != nil { + return changedAlert, "", getErr } isEqual := reflect.DeepEqual(*fullAlert, *changedAlert) log.Printf("[DEBUG] Updated Librato Alert %d match: %t", alertID, isEqual) diff --git a/resource_librato_metric.go b/resource_librato_metric.go index abbeca1..d5313f3 100644 --- a/resource_librato_metric.go +++ b/resource_librato_metric.go @@ -151,7 +151,7 @@ func resourceLibratoMetricCreate(d *schema.ResourceData, meta interface{}) error metric.Attributes = attributes } - _, err := client.Metrics.Edit(&metric) + _, err := client.Metrics.Update(&metric) if err != nil { log.Printf("[INFO] ERROR creating Metric: %s", err) return fmt.Errorf("Error creating Librato metric: %s", err) @@ -280,7 +280,7 @@ func resourceLibratoMetricUpdate(d *schema.ResourceData, meta interface{}) error log.Printf("[INFO] Updating Librato metric: %v", structToString(metric)) - _, err := client.Metrics.Edit(metric) + _, err := client.Metrics.Update(metric) if err != nil { return fmt.Errorf("Error updating Librato metric: %s", err) } diff --git a/resource_librato_service.go b/resource_librato_service.go index e289fee..2e88a66 100644 --- a/resource_librato_service.go +++ b/resource_librato_service.go @@ -21,23 +21,23 @@ func resourceLibratoService() *schema.Resource { Delete: resourceLibratoServiceDelete, Schema: map[string]*schema.Schema{ - "id": &schema.Schema{ + "id": { Type: schema.TypeInt, Computed: true, }, - "type": &schema.Schema{ + "type": { Type: schema.TypeString, Required: true, ForceNew: true, }, - "title": &schema.Schema{ + "title": { Type: schema.TypeString, Required: true, }, - "settings": &schema.Schema{ + "settings": { Type: schema.TypeString, Required: true, - StateFunc: normalizeJson, + StateFunc: normalizeJSON, }, }, } @@ -67,7 +67,7 @@ func resourceLibratoServicesFlatten(settings map[string]string) (string, error) return string(byteArray), nil } -func normalizeJson(jsonString interface{}) string { +func normalizeJSON(jsonString interface{}) string { if jsonString == nil || jsonString == "" { return "" } @@ -91,9 +91,9 @@ func resourceLibratoServiceCreate(d *schema.ResourceData, meta interface{}) erro service.Title = librato.String(v.(string)) } if v, ok := d.GetOk("settings"); ok { - res, err := resourceLibratoServicesExpandSettings(normalizeJson(v.(string))) - if err != nil { - return fmt.Errorf("Error expanding Librato service settings: %s", err) + res, expandErr := resourceLibratoServicesExpandSettings(normalizeJSON(v.(string))) + if expandErr != nil { + return fmt.Errorf("Error expanding Librato service settings: %s", expandErr) } service.Settings = res } @@ -174,16 +174,16 @@ func resourceLibratoServiceUpdate(d *schema.ResourceData, meta interface{}) erro fullService.Title = service.Title } if d.HasChange("settings") { - res, err := resourceLibratoServicesExpandSettings(normalizeJson(d.Get("settings").(string))) - if err != nil { - return fmt.Errorf("Error expanding Librato service settings: %s", err) + res, getErr := resourceLibratoServicesExpandSettings(normalizeJSON(d.Get("settings").(string))) + if getErr != nil { + return fmt.Errorf("Error expanding Librato service settings: %s", getErr) } service.Settings = res fullService.Settings = res } log.Printf("[INFO] Updating Librato Service %d: %s", serviceID, service) - _, err = client.Services.Edit(uint(serviceID), service) + _, err = client.Services.Update(uint(serviceID), service) if err != nil { return fmt.Errorf("Error updating Librato service: %s", err) } @@ -198,9 +198,9 @@ func resourceLibratoServiceUpdate(d *schema.ResourceData, meta interface{}) erro ContinuousTargetOccurence: 5, Refresh: func() (interface{}, string, error) { log.Printf("[DEBUG] Checking if Librato Service %d was updated yet", serviceID) - changedService, _, err := client.Services.Get(uint(serviceID)) - if err != nil { - return changedService, "", err + changedService, _, getErr := client.Services.Get(uint(serviceID)) + if getErr != nil { + return changedService, "", getErr } isEqual := reflect.DeepEqual(*fullService, *changedService) log.Printf("[DEBUG] Updated Librato Service %d match: %t", serviceID, isEqual) diff --git a/resource_librato_space.go b/resource_librato_space.go index 917e3ec..f8c68c0 100644 --- a/resource_librato_space.go +++ b/resource_librato_space.go @@ -19,12 +19,12 @@ func resourceLibratoSpace() *schema.Resource { Delete: resourceLibratoSpaceDelete, Schema: map[string]*schema.Schema{ - "name": &schema.Schema{ + "name": { Type: schema.TypeString, Required: true, ForceNew: false, }, - "id": &schema.Schema{ + "id": { Type: schema.TypeInt, Computed: true, }, @@ -97,7 +97,7 @@ func resourceLibratoSpaceUpdate(d *schema.ResourceData, meta interface{}) error if d.HasChange("name") { newName := d.Get("name").(string) log.Printf("[INFO] Modifying name space attribute for %d: %#v", id, newName) - if _, err = client.Spaces.Edit(uint(id), &librato.Space{Name: &newName}); err != nil { + if _, err = client.Spaces.Update(uint(id), &librato.Space{Name: &newName}); err != nil { return err } } diff --git a/resource_librato_space_chart.go b/resource_librato_space_chart.go index a010efc..678b630 100644 --- a/resource_librato_space_chart.go +++ b/resource_librato_space_chart.go @@ -23,98 +23,98 @@ func resourceLibratoSpaceChart() *schema.Resource { Delete: resourceLibratoSpaceChartDelete, Schema: map[string]*schema.Schema{ - "space_id": &schema.Schema{ + "space_id": { Type: schema.TypeInt, Required: true, ForceNew: true, }, - "name": &schema.Schema{ + "name": { Type: schema.TypeString, Required: true, }, - "type": &schema.Schema{ + "type": { Type: schema.TypeString, Required: true, ForceNew: true, }, - "min": &schema.Schema{ + "min": { Type: schema.TypeFloat, Default: math.NaN(), Optional: true, }, - "max": &schema.Schema{ + "max": { Type: schema.TypeFloat, Default: math.NaN(), Optional: true, }, - "label": &schema.Schema{ + "label": { Type: schema.TypeString, Optional: true, }, - "related_space": &schema.Schema{ + "related_space": { Type: schema.TypeInt, Optional: true, }, - "stream": &schema.Schema{ + "stream": { Type: schema.TypeSet, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "metric": &schema.Schema{ + "metric": { Type: schema.TypeString, Optional: true, ConflictsWith: []string{"stream.composite"}, }, - "source": &schema.Schema{ + "source": { Type: schema.TypeString, Optional: true, ConflictsWith: []string{"stream.composite"}, }, - "group_function": &schema.Schema{ + "group_function": { Type: schema.TypeString, Optional: true, ConflictsWith: []string{"stream.composite"}, }, - "composite": &schema.Schema{ + "composite": { Type: schema.TypeString, Optional: true, ConflictsWith: []string{"stream.metric", "stream.source", "stream.group_function"}, }, - "summary_function": &schema.Schema{ + "summary_function": { Type: schema.TypeString, Optional: true, }, - "name": &schema.Schema{ + "name": { Type: schema.TypeString, Optional: true, }, - "color": &schema.Schema{ + "color": { Type: schema.TypeString, Optional: true, }, - "units_short": &schema.Schema{ + "units_short": { Type: schema.TypeString, Optional: true, }, - "units_long": &schema.Schema{ + "units_long": { Type: schema.TypeString, Optional: true, }, - "min": &schema.Schema{ + "min": { Type: schema.TypeFloat, Default: math.NaN(), Optional: true, }, - "max": &schema.Schema{ + "max": { Type: schema.TypeFloat, Default: math.NaN(), Optional: true, }, - "transform_function": &schema.Schema{ + "transform_function": { Type: schema.TypeString, Optional: true, }, - "period": &schema.Schema{ + "period": { Type: schema.TypeInt, Optional: true, }, @@ -420,7 +420,7 @@ func resourceLibratoSpaceChartUpdate(d *schema.ResourceData, meta interface{}) e fullChart.Streams = streams } - _, err = client.Spaces.EditChart(spaceID, uint(chartID), spaceChart) + _, err = client.Spaces.UpdateChart(spaceID, uint(chartID), spaceChart) if err != nil { return fmt.Errorf("Error updating Librato space chart %s: %s", *spaceChart.Name, err) } @@ -434,9 +434,9 @@ func resourceLibratoSpaceChartUpdate(d *schema.ResourceData, meta interface{}) e ContinuousTargetOccurence: 5, Refresh: func() (interface{}, string, error) { log.Printf("[DEBUG] Checking if Librato Space Chart %d was updated yet", chartID) - changedChart, _, err := client.Spaces.GetChart(spaceID, uint(chartID)) - if err != nil { - return changedChart, "", err + changedChart, _, getErr := client.Spaces.GetChart(spaceID, uint(chartID)) + if getErr != nil { + return changedChart, "", getErr } isEqual := reflect.DeepEqual(*fullChart, *changedChart) log.Printf("[DEBUG] Updated Librato Space Chart %d match: %t", chartID, isEqual)