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

Allow to specify the ID of a Capacity Reservation in which to run an instance - capacity_reservation_id #120

Open
joelsdc opened this issue Mar 4, 2022 · 0 comments

Comments

@joelsdc
Copy link

joelsdc commented Mar 4, 2022

Have a question? Please checkout our Slack Community or visit our Slack Archive.

Slack Community

Describe the Feature

Add option for setting capacity_reservation_id param in the aws_instance resource.

Expected Behavior

Launch an EC2 instance using a pre-existing Capacity Reservation

Describe Ideal Solution

# AWS Capacity Reservation
resource "aws_ec2_capacity_reservation" "win_g4dn_xlarge_usw2a" {
  instance_type     = "g4dn.xlarge"
  availability_zone = "us-west2-a"
  instance_platform = "Windows"
  instance_count    = 1
}

# AWS Instance
module "instance_from_capacity_reservation" {
  source = "cloudposse/ec2-instance/aws"
  version = "x.x.x"
  ...
  ...
  capacity_reservation_id = aws_ec2_capacity_reservation.win_g4dn_xlarge_usw2a.id
  ...
  ...
}

Additional Context

I'm not sure if the solution would be something as simple as adding:

  • variables.tf:
variable "capacity_reservation_id" {
  type        = string
  default     = null
  description = "The ID of the Capacity Reservation in which to run the instance"
}
  • main.tf:
resource "aws_instance" "default" {
  ...
  ...
  capacity_reservation_specification {
    capacity_reservation_target {
      capacity_reservation_id = var.capacity_reservation_id != null ? var.capacity_reservation_id : null
    }
  }
  ...
  ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant