Commit f12ac95a authored by schniber's avatar schniber Committed by GitHub

fix: Creation of an Instance with a Capacity Reservation ID (#278)

* fix bug for capacity reservation id assignment

* addition of test case

* revert of outputs in complete test case

* fix formatting and tfdocs

* fix formatting and tfdocs

* run of pre-commit hooks

* fix README

* fix README

* fix example to be deployable

* fix example to be deployable

* Update examples/complete/main.tf

* Update examples/complete/main.tf
Co-authored-by: default avatarSamuel CHNIBER <schniber@amazon.fr>
Co-authored-by: default avatarBryant Biggs <bryantbiggs@gmail.com>
parent c0f8453a
......@@ -32,6 +32,7 @@ Note that this example may create resources which can cost money. Run `terraform
| Name | Source | Version |
|------|--------|---------|
| <a name="module_ec2_capacity_reservation"></a> [ec2\_capacity\_reservation](#module\_ec2\_capacity\_reservation) | ../../ | n/a |
| <a name="module_ec2_complete"></a> [ec2\_complete](#module\_ec2\_complete) | ../../ | n/a |
| <a name="module_ec2_disabled"></a> [ec2\_disabled](#module\_ec2\_disabled) | ../../ | n/a |
| <a name="module_ec2_metadata_options"></a> [ec2\_metadata\_options](#module\_ec2\_metadata\_options) | ../../ | n/a |
......@@ -47,6 +48,7 @@ Note that this example may create resources which can cost money. Run `terraform
| Name | Type |
|------|------|
| [aws_ec2_capacity_reservation.targeted](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_capacity_reservation) | resource |
| [aws_kms_key.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |
| [aws_network_interface.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/network_interface) | resource |
| [aws_placement_group.web](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/placement_group) | resource |
......
......@@ -73,9 +73,17 @@ resource "aws_network_interface" "this" {
subnet_id = element(module.vpc.private_subnets, 0)
}
################################################################################
# EC2 Module
################################################################################
resource "aws_ec2_capacity_reservation" "targeted" {
instance_type = "t3.micro"
instance_platform = "Linux/UNIX"
availability_zone = "${local.region}a"
instance_count = 1
instance_match_criteria = "targeted"
}
# ################################################################################
# # EC2 Module
# ################################################################################
module "ec2_disabled" {
source = "../../"
......@@ -328,3 +336,27 @@ module "ec2_spot_instance" {
tags = local.tags
}
################################################################################
# EC2 Module - Capacity Reservation
################################################################################
module "ec2_capacity_reservation" {
source = "../../"
name = "${local.name}-capacity-reservation"
ami = data.aws_ami.amazon_linux.id
instance_type = "t3.micro"
subnet_id = element(module.vpc.private_subnets, 0)
vpc_security_group_ids = [module.security_group.security_group_id]
associate_public_ip_address = true
capacity_reservation_specification = {
capacity_reservation_target = {
capacity_reservation_id = aws_ec2_capacity_reservation.targeted.id
}
}
tags = local.tags
}
......@@ -42,7 +42,7 @@ resource "aws_instance" "this" {
dynamic "capacity_reservation_target" {
for_each = lookup(capacity_reservation_specification.value, "capacity_reservation_target", [])
content {
capacity_reservation_id = lookup(capacity_reservation_target.value, "capacity_reservation_id", null)
capacity_reservation_id = lookup(capacity_reservation_target, "capacity_reservation_id", null)
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment