diff --git a/examples/complete/README.md b/examples/complete/README.md index 9455766e..008f8307 100644 --- a/examples/complete/README.md +++ b/examples/complete/README.md @@ -32,6 +32,7 @@ Note that this example may create resources which can cost money. Run `terraform | Name | Source | Version | |------|--------|---------| +| [ec2\_capacity\_reservation](#module\_ec2\_capacity\_reservation) | ../../ | n/a | | [ec2\_complete](#module\_ec2\_complete) | ../../ | n/a | | [ec2\_disabled](#module\_ec2\_disabled) | ../../ | n/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 | diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 257ff71c..c2cd951a 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -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 +} diff --git a/main.tf b/main.tf index b4eb9d3b..5d0ec624 100644 --- a/main.tf +++ b/main.tf @@ -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) } } }