Skip to content

Commit

Permalink
provider/aws: Remove CloudTrail Trail from state if not found
Browse files Browse the repository at this point in the history
  • Loading branch information
catsby committed Apr 5, 2016
1 parent 053ba90 commit 6f4dc98
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions builtin/providers/aws/resource_aws_cloudtrail.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,22 @@ func resourceAwsCloudTrailRead(d *schema.ResourceData, meta interface{}) error {
if err != nil {
return err
}
if len(resp.TrailList) == 0 {
return fmt.Errorf("No CloudTrail found, using name %q", name)

// CloudTrail does not return a NotFound error in the event that the Trail
// you're looking for is not found. Instead, it's simply not in the list.
var trail *cloudtrail.Trail
for _, c := range resp.TrailList {
if d.Id() == *c.Name {
trail = c
}
}

if trail == nil {
log.Printf("[WARN] CloudTrail (%s) not found", name)
d.SetId("")
return nil
}

trail := resp.TrailList[0]
log.Printf("[DEBUG] CloudTrail received: %s", trail)

d.Set("name", trail.Name)
Expand Down

0 comments on commit 6f4dc98

Please sign in to comment.