cloudposse / cloudposse/terraform-aws-ec2-instance

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

Open
#120 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
HCL
Stars
169
Forks
216
PR merge metrics
No merged PRs in 30d

Description

Have a question? Please checkout our [Slack Community](https://slack.cloudposse.com) or visit our [Slack Archive](https://archive.sweetops.com/).

[![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)

## 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

```terraform
# 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:
```terraform
variable "capacity_reservation_id" {
type = string
default = null
description = "The ID of the Capacity Reservation in which to run the instance"
}
```

* main.tf:
```terraform
resource "aws_instance" "default" {
...
...
capacity_reservation_specification {
capacity_reservation_target {
capacity_reservation_id = var.capacity_reservation_id != null ? var.capacity_reservation_id : null
}
}
...
...
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.