Skip to content

Commit

Permalink
Fix handling of already existing watches.
Browse files Browse the repository at this point in the history
Closes #35
  • Loading branch information
phillbaker committed Jan 6, 2020
1 parent 48579b4 commit fd75ea5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions resource_elasticsearch_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ func resourceElasticsearchWatch() *schema.Resource {
}

func resourceElasticsearchWatchCreate(d *schema.ResourceData, m interface{}) error {
// Determine whether the watch already exists.
// Determine whether the watch already exists, otherwise the API will
// override an existing watch with the name.
watchID := d.Get("watch_id").(string)
_, err := resourceElasticsearchGetWatch(watchID, m)
if !elastic6.IsNotFound(err) && !elastic7.IsNotFound(err) {

if err == nil {
log.Printf("[INFO] watch exists: %+v", err)
return fmt.Errorf("watch already exists with ID: %v", watchID)
} else if err != nil && !elastic6.IsNotFound(err) && !elastic7.IsNotFound(err) {
return err
}

watchID, err = resourceElasticsearchPutWatch(d, m)
Expand Down

0 comments on commit fd75ea5

Please sign in to comment.