diff --git a/builtin/providers/aws/resource_aws_ami.go b/builtin/providers/aws/resource_aws_ami.go index 8b727e105f..a78485f3f2 100644 --- a/builtin/providers/aws/resource_aws_ami.go +++ b/builtin/providers/aws/resource_aws_ami.go @@ -121,6 +121,12 @@ func resourceAwsAmiRead(d *schema.ResourceData, meta interface{}) error { res, err := client.DescribeImages(req) if err != nil { + if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidAMIID.NotFound" { + log.Printf("[DEBUG] %s no longer exists, so we'll drop it from the state", id) + d.SetId("") + return nil + } + return err }