From 6f4dc98354183f162607f3a098b9d1606460b668 Mon Sep 17 00:00:00 2001 From: Clint Date: Tue, 5 Apr 2016 14:04:00 -0500 Subject: [PATCH] provider/aws: Remove CloudTrail Trail from state if not found --- .../providers/aws/resource_aws_cloudtrail.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/builtin/providers/aws/resource_aws_cloudtrail.go b/builtin/providers/aws/resource_aws_cloudtrail.go index c8c639f80..a81c9fa99 100644 --- a/builtin/providers/aws/resource_aws_cloudtrail.go +++ b/builtin/providers/aws/resource_aws_cloudtrail.go @@ -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)