Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Mclean committed Feb 26, 2018
2 parents d0c762b + ebb50ab commit e2f2386
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 111 deletions.
7 changes: 7 additions & 0 deletions vendor/github.com/spaceapegames/go-wavefront/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions vendor/github.com/spaceapegames/go-wavefront/alert.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions vendor/github.com/spaceapegames/go-wavefront/query.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions vendor/github.com/spaceapegames/go-wavefront/target.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,10 @@
"revisionTime": "2017-08-08T15:38:46Z"
},
{
"checksumSHA1": "9AmOrvtMgYViY18t8BiBPC9oZRY=",
"checksumSHA1": "RfNML/mJrWS8QjuIsN7AWr4lqV4=",
"path": "github.com/spaceapegames/go-wavefront",
"revision": "eadca219c8d92f2ebf3badcca3c507c4dce91b4d",
"revisionTime": "2017-12-28T18:24:44Z"
"revision": "53792d0ec4bf66c0f9479499c985442aa2059357",
"revisionTime": "2018-02-23T13:18:49Z"
},
{
"checksumSHA1": "vE43s37+4CJ2CDU6TlOUOYE0K9c=",
Expand Down
68 changes: 24 additions & 44 deletions wavefront/resource_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,50 +101,35 @@ func resourceAlertCreate(d *schema.ResourceData, m interface{}) error {
func resourceAlertRead(d *schema.ResourceData, m interface{}) error {
alerts := m.(*wavefrontClient).client.Alerts()

// search for an alert with our id. We should recieve 1 (Exact Match) or 0 (No Match)
results, err := alerts.Find(
[]*wavefront.SearchCondition{
{
Key: "id",
Value: d.Id(),
MatchingMethod: "EXACT",
},
})
alertID := d.Id()
tmpAlert := wavefront.Alert{ID: &alertID}
err := alerts.Get(&tmpAlert)
if err != nil {
return fmt.Errorf("Error finding Wavefront Alert %s. %s", d.Id(), err)
}
// resource has been deleted out of band. So unset ID
if len(results) != 1 {
d.SetId("")
return nil
return fmt.Errorf("Error finding Wavefront Alert %s. %s", d.Id(), err)
}

// Use the Wavefront ID as the Terraform ID
d.SetId(*results[0].ID)
d.Set("name", results[0].Name)
d.Set("target", results[0].Target)
d.Set("condition", results[0].Condition)
d.Set("additional_information", results[0].AdditionalInfo)
d.Set("display_expression", results[0].DisplayExpression)
d.Set("minutes", results[0].Minutes)
d.Set("resolve_after_minutes", results[0].ResolveAfterMinutes)
d.Set("severity", results[0].Severity)
d.Set("tags", results[0].Tags)
d.SetId(*tmpAlert.ID)
d.Set("name", tmpAlert.Name)
d.Set("target", tmpAlert.Target)
d.Set("condition", tmpAlert.Condition)
d.Set("additional_information", tmpAlert.AdditionalInfo)
d.Set("display_expression", tmpAlert.DisplayExpression)
d.Set("minutes", tmpAlert.Minutes)
d.Set("resolve_after_minutes", tmpAlert.ResolveAfterMinutes)
d.Set("severity", tmpAlert.Severity)
d.Set("tags", tmpAlert.Tags)

return nil
}

func resourceAlertUpdate(d *schema.ResourceData, m interface{}) error {
alerts := m.(*wavefrontClient).client.Alerts()

results, err := alerts.Find(
[]*wavefront.SearchCondition{
{
Key: "id",
Value: d.Id(),
MatchingMethod: "EXACT",
},
})
alertID := d.Id()
tmpAlert := wavefront.Alert{ID: &alertID}
err := alerts.Get(&tmpAlert)
if err != nil {
return fmt.Errorf("Error finding Wavefront Alert %s. %s", d.Id(), err)
}
Expand All @@ -154,7 +139,7 @@ func resourceAlertUpdate(d *schema.ResourceData, m interface{}) error {
tags = append(tags, tag.(string))
}

a := results[0]
a := tmpAlert
a.Name = d.Get("name").(string)
a.Target = d.Get("target").(string)
a.Condition = d.Get("condition").(string)
Expand All @@ -166,7 +151,7 @@ func resourceAlertUpdate(d *schema.ResourceData, m interface{}) error {
a.Tags = tags

// Update the alert on Wavefront
err = alerts.Update(a)
err = alerts.Update(&a)
if err != nil {
return fmt.Errorf("Error Updating Alert %s. %s", d.Get("name"), err)
}
Expand All @@ -176,21 +161,16 @@ func resourceAlertUpdate(d *schema.ResourceData, m interface{}) error {
func resourceAlertDelete(d *schema.ResourceData, m interface{}) error {
alerts := m.(*wavefrontClient).client.Alerts()

results, err := alerts.Find(
[]*wavefront.SearchCondition{
&wavefront.SearchCondition{
Key: "id",
Value: d.Id(),
MatchingMethod: "EXACT",
},
})
alertID := d.Id()
tmpAlert := wavefront.Alert{ID: &alertID}
err := alerts.Get(&tmpAlert)
if err != nil {
return fmt.Errorf("Error finding Wavefront Alert %s. %s", d.Id(), err)
}
a := results[0]
a := tmpAlert

// Delete the Alert
err = alerts.Delete(a)
err = alerts.Delete(&a)
if err != nil {
return fmt.Errorf("Failed to delete Alert %s. %s", d.Id(), err)
}
Expand Down
37 changes: 13 additions & 24 deletions wavefront/resource_alert_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,35 +102,24 @@ func resourceTargetCreate(d *schema.ResourceData, m interface{}) error {
func resourceTargetRead(d *schema.ResourceData, m interface{}) error {
targets := m.(*wavefrontClient).client.Targets()

// search for a Target with our id. We should recieve 1 (Exact Match) or 0 (No Match)
results, err := targets.Find(
[]*wavefront.SearchCondition{
{
Key: "id",
Value: d.Id(),
MatchingMethod: "EXACT",
},
})
targetID := d.Id()
tmpTarget := wavefront.Target{ID: &targetID}
err := targets.Get(&tmpTarget)
if err != nil {
return fmt.Errorf("Error finding Wavefront Target %s. %s", d.Id(), err)
}
// resource has been deleted out of band. So unset ID
if len(results) != 1 {
d.SetId("")
return nil
}

// Use the Wavefront ID as the Terraform ID
d.SetId(*results[0].ID)
d.Set("name", results[0].Title)
d.Set("description", results[0].Description)
d.Set("triggers", results[0].Triggers)
d.Set("template", results[0].Template)
d.Set("method", results[0].Method)
d.Set("recipient", results[0].Recipient)
d.Set("email_subject", results[0].EmailSubject)
d.Set("content_type", results[0].ContentType)
d.Set("custom_headers", results[0].CustomHeaders)
d.SetId(*tmpTarget.ID)
d.Set("name", tmpTarget.Title)
d.Set("description", tmpTarget.Description)
d.Set("triggers", tmpTarget.Triggers)
d.Set("template", tmpTarget.Template)
d.Set("method", tmpTarget.Method)
d.Set("recipient", tmpTarget.Recipient)
d.Set("email_subject", tmpTarget.EmailSubject)
d.Set("content_type", tmpTarget.ContentType)
d.Set("custom_headers", tmpTarget.CustomHeaders)

return nil
}
Expand Down
54 changes: 20 additions & 34 deletions wavefront/resource_alert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,17 @@ func TestAccWavefrontAlert_Basic(t *testing.T) {
resource.TestCheckResourceAttr(
"wavefront_alert.test_alert", "severity", "WARN"),
resource.TestCheckResourceAttr(
"wavefront_alert.test_alert", "tags.#", "2"),
"wavefront_alert.test_alert", "tags.#", "5"),
resource.TestCheckResourceAttr(
"wavefront_alert.test_alert", "tags.0", "terraform"),
"wavefront_alert.test_alert", "tags.0", "b"),
resource.TestCheckResourceAttr(
"wavefront_alert.test_alert", "tags.1", "test"),
"wavefront_alert.test_alert", "tags.1", "terraform"),
resource.TestCheckResourceAttr(
"wavefront_alert.test_alert", "tags.2", "c"),
resource.TestCheckResourceAttr(
"wavefront_alert.test_alert", "tags.3", "test"),
resource.TestCheckResourceAttr(
"wavefront_alert.test_alert", "tags.4", "a"),
),
},
},
Expand Down Expand Up @@ -151,8 +157,6 @@ func TestAccWavefrontAlert_RemoveOptionalAttribute(t *testing.T) {
})
}

//Fails due to Wavefront known issue - creating multiple tagged alerts causes a race condition. Only one will succeed.
//Uncomment when that is fixed.
func TestAccWavefrontAlert_Multiple(t *testing.T) {
var record wavefront.Alert

Expand Down Expand Up @@ -187,18 +191,10 @@ func testAccCheckWavefrontAlertDestroy(s *terraform.State) error {
continue
}

results, err := alerts.Find(
[]*wavefront.SearchCondition{
{
Key: "id",
Value: rs.Primary.ID,
MatchingMethod: "EXACT",
},
})
if err != nil {
return fmt.Errorf("Error finding Wavefront Alert. %s", err)
}
if len(results) > 0 {
tmpAlert := wavefront.Alert{ID: &rs.Primary.ID}

err := alerts.Get(&tmpAlert)
if err == nil {
return fmt.Errorf("Alert still exists")
}
}
Expand Down Expand Up @@ -263,27 +259,14 @@ func testAccCheckWavefrontAlertExists(n string, alert *wavefront.Alert) resource
}

alerts := testAccProvider.Meta().(*wavefrontClient).client.Alerts()
tmpAlert := wavefront.Alert{ID: &rs.Primary.ID}

results, err := alerts.Find(
[]*wavefront.SearchCondition{
{
Key: "id",
Value: rs.Primary.ID,
MatchingMethod: "EXACT",
},
})
err := alerts.Get(&tmpAlert)
if err != nil {
return fmt.Errorf("Error finding Wavefront Alert %s", err)
}
// resource has been deleted out of band. So unset ID
if len(results) != 1 {
return fmt.Errorf("No Alerts Found")
}
if *results[0].ID != rs.Primary.ID {
return fmt.Errorf("Alert not found")
}

*alert = *results[0]
*alert = tmpAlert

return nil
}
Expand All @@ -301,8 +284,11 @@ resource "wavefront_alert" "test_alert" {
resolve_after_minutes = 5
severity = "WARN"
tags = [
"b",
"terraform",
"test"
"c",
"test",
"a"
]
}
`)
Expand Down
Loading

0 comments on commit e2f2386

Please sign in to comment.