Skip to content

Commit

Permalink
Add Exists for graph resource.
Browse files Browse the repository at this point in the history
  • Loading branch information
ojongerius committed Aug 6, 2015
1 parent ebb876d commit 5311849
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions datadog/resource_datadog_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"strconv"
"time"
"strings"

"github.com/zorkian/go-datadog-api"

Expand All @@ -22,6 +23,7 @@ type GraphDefintionRequests struct {
func resourceDatadogGraph() *schema.Resource {
return &schema.Resource{
Create: resourceDatadogGraphCreate,
Exists: resourceDatadogGraphExists,
Read: resourceDatadogGraphRead,
Delete: resourceDatadogGraphDelete,
Update: resourceDatadogGraphUpdate,
Expand Down Expand Up @@ -99,6 +101,34 @@ func resourceDatadogGraphCreate(d *schema.ResourceData, meta interface{}) error
return nil
}

func resourceDatadogGraphExists(d *schema.ResourceData, meta interface{}) (bool, error) {
client := meta.(*datadog.Client)

// TODO:
// * Does the dashboard exist? TODO: create a helper function for this one

_, err := client.GetDashboard(d.Get("dashboard_id").(int))

if err != nil {
if strings.EqualFold(err.Error(), "API error: 404 Not Found") {
return false, nil
}

return false, fmt.Errorf("Error retrieving dashboard: %s", err)
}


// * Does the graph exist?

err = resourceDatadogGraphRead(d, meta)

if err != nil {
return false, err
}

return true, nil
}

func resourceDatadogGraphRead(d *schema.ResourceData, meta interface{}) error {
err := resourceDatadogGraphRetrieve(d, meta)

Expand Down

0 comments on commit 5311849

Please sign in to comment.