hashicorp/terraform-provider-aws

Improve error message when AMI id was recently deregistered

Open

#26,046 opened on Jul 29, 2022

 (4 comments) (5 reactions) (0 assignees)Go (10,310 forks)github user discovery
enhancementgood first issueservice/ec2

Repository metrics

Stars
 (11,045 stars)
PR merge metrics
 (PR metrics pending)

Description

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

If you create an EC2 instance, and the AMI id doesn't exist, as a user you get a clear error message that the AMI can't be found:

https://github.com/hashicorp/terraform-provider-aws/blob/748efbed72e126c886b9e95b3af33e4b35bb97e6/internal/service/ec2/find.go#L730-L735

Somewhere in the execution flow, DescribeImages is used, but this doesn't always return a clear error code. The documentation (link below) states this:

Recently deregistered images appear in the returned results for a short interval and then return empty results. After all instances that reference a deregistered AMI are terminated, specifying the ID of the image will eventually return an error indicating that the AMI ID cannot be found.

This case is covered by the following code path in the provider:

https://github.com/hashicorp/terraform-provider-aws/blob/748efbed72e126c886b9e95b3af33e4b35bb97e6/internal/service/ec2/find.go#L741-L743

For the user, the error message is not so clear:

error collecting instance settings: empty result

There is no indication that this is related to the AMI not being found.

Would it be possible to change the error being returned in this case also to be a resource.NotFoundError?

New or Affected Resource(s)

  • aws_instance

Potential Terraform Configuration

resource "aws_instance" "web" {
  ami           = "ami-XXXXXXXX" # AMI id of a recently deregistered image
  instance_type = "t3.micro"
}

References

Contributor guide