Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Apr 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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