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

[Bug]: ReservationCapacityExceeded error when changing capacity reservation id and instance_type of aws_instance #32458

Closed
atikhono opened this issue Jul 11, 2023 · 3 comments · Fixed by #33412 or #35745
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@atikhono
Copy link
Contributor

Terraform Core Version

1.5.2

AWS Provider Version

5.7.0

Affected Resource(s)

  • aws_instance

Expected Behavior

Instance should have new instance_type and capacity reservation ID

Actual Behavior

Instance was stopped, instance_type updated, then instance failed to start because of reservation capacity type and instance type mismatch.

I can see that instance type update is not linked to capacity reservation change, and happens earlier:
https://github.com/hashicorp/terraform-provider-aws/blob/v5.7.0/internal/service/ec2/ec2_instance.go#L1662
https://github.com/hashicorp/terraform-provider-aws/blob/v5.7.0/internal/service/ec2/ec2_instance.go#L1936
That explains the behaviour. I suppose when aws_instance has instance_type and capacity reservation ID changes, the provider should perform the changes in stop/start context. I'm willing to implement the fix, but please advise on proper behaviour here.

Relevant Error/Panic Output Snippet

Error: updating EC2 Instance (i-0db1177c4c05dc826) type: starting EC2 Instance (i-0db1177c4c05dc826): ReservationCapacityExceeded: The requested reservation does not have sufficient compatible and available capacity for this request.
status code: 400, request id: 21debb5c-604d-4c37-85d5-9cc4ff1cfd30

Terraform Configuration Files

provider "aws" {
  region = "eu-central-1"
}

variable "type" {
  default = "t3.micro"
}

resource "aws_ec2_capacity_reservation" "this" {
  availability_zone       = "eu-central-1c"
  instance_count          = 1
  instance_platform       = "Linux/UNIX"
  instance_type           = var.type
  instance_match_criteria = "targeted"
  end_date_type           = "unlimited"
  lifecycle {
    create_before_destroy = true
  }
}

resource "aws_instance" "this" {
  subnet_id     = "subnet-097a46cecc9ab465b"
  ami           = "ami-02957594f30581e82"
  instance_type = var.type
  capacity_reservation_specification {
    capacity_reservation_target {
      capacity_reservation_id = aws_ec2_capacity_reservation.this.id
    }
  }
}

Steps to Reproduce

  • terraform apply (success)
  • terraform apply -var type=t3.small (error)

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

Yes

@atikhono atikhono added bug Addresses a defect in current functionality. needs-triage Waiting for first response or review from a maintainer. labels Jul 11, 2023
@github-actions
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • 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.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added the service/ec2 Issues and PRs that pertain to the ec2 service. label Jul 11, 2023
@justinretzolk justinretzolk removed the needs-triage Waiting for first response or review from a maintainer. label Jul 11, 2023
atikhono added a commit to joomcode/terraform-provider-aws that referenced this issue Sep 21, 2023
@github-actions github-actions bot added this to the v5.37.0 milestone Feb 9, 2024
Copy link

This functionality has been released in v5.37.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. Thank you!

Copy link

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
2 participants