provider/aws: Remove CloudTrail Trail from state if not found

This commit is contained in:
Clint 2016-04-05 14:04:00 -05:00
parent 053ba9005d
commit 6f4dc98354
1 changed files with 14 additions and 3 deletions

View File

@ -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)