-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Fixes EC2 capacity reservation in state not found #9862
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @thlacroix - thanks for this fix! One optional change if you'd like to make it, but otherwise looks good! 👍
Test output:
--- SKIP: TestAccAWSEc2CapacityReservation_tenancy (0.00s)
--- PASS: TestAccAWSEc2CapacityReservation_basic (9.63s)
--- PASS: TestAccAWSEc2CapacityReservation_ebsOptimized (10.78s)
--- PASS: TestAccAWSEc2CapacityReservation_instanceMatchCriteria (10.88s)
--- PASS: TestAccAWSEc2CapacityReservation_ephemeralStorage (11.73s)
--- PASS: TestAccAWSEc2CapacityReservation_instanceType (17.48s)
--- PASS: TestAccAWSEc2CapacityReservation_instanceCount (17.82s)
--- PASS: TestAccAWSEc2CapacityReservation_endDate (18.29s)
--- PASS: TestAccAWSEc2CapacityReservation_tags (23.53s)
--- PASS: TestAccAWSEc2CapacityReservation_endDateType (23.56s)
@@ -165,13 +166,16 @@ func resourceAwsEc2CapacityReservationRead(d *schema.ResourceData, meta interfac | |||
}) | |||
|
|||
if err != nil { | |||
return fmt.Errorf("Error describing EC2 Capacity Reservations: %s", err) | |||
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidCapacityReservationId.NotFound" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another way to do this would be the isAWSErr
helper function:
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidCapacityReservationId.NotFound" { | |
if isAWSErr(err, "InvalidCapacityReservationId.NotFound", "") { |
If you wanted to make this change and remove the associated awserr
import (and re-run the tests 🙂) that would be super - but this is perfectly functional as it is. The isAWSErr
is just a slightly neater-looking style convention we're trying to move towards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ryndaniels, thanks for the review / comment, will make the change quickly
Suggested improvement added, and output from acceptance testing updated. |
Awesome, thanks again @thlacroix! 🚀
|
This has been released in version 2.26.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
When an EC2 Capacity Reservation is created with terraform, but is then manually deleted, the next
terraform plan
gives:Error describing EC2 Capacity Reservations: InvalidCapacityReservationId.NotFound: An error occurred when calling the DescribeCapacityReservations operation: The capacity reservation ID 'cr-xxx' was not found
As the EC2 Capacity Reservation ID is still in the state, terraform tries to read it, but the error handling doesn't check the
InvalidCapacityReservationId.NotFound
case. It returns the error directly, instead of doing a simpled.SetId(""); return nil
to notify that the resource doesn't exist anymore.I used a structure similar to https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/resource_aws_ebs_volume.go#L242 to fix the issue.
Community Note
Release note for CHANGELOG:
Output from acceptance testing: