Skip to content

Commit

Permalink
Fork from v5.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
naomichi-y committed Jul 23, 2023
1 parent e5af5a3 commit c17c84f
Show file tree
Hide file tree
Showing 17 changed files with 786 additions and 234 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.77.0
rev: v1.81.0
hooks:
- id: terraform_fmt
- id: terraform_wrapper_module_for_each
Expand Down
53 changes: 53 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,59 @@

All notable changes to this project will be documented in this file.

### [5.2.1](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/compare/v5.2.0...v5.2.1) (2023-07-06)


### Bug Fixes

* Fixed outputs for Block Devices ([#344](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/issues/344)) ([80381d2](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/commit/80381d2c94e6aec7aa308f4a6cf24732a87c8237))

## [5.2.0](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/compare/v5.1.0...v5.2.0) (2023-06-28)


### Features

* Add input variable 'instance_tags' ([#343](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/issues/343)) ([025d3b4](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/commit/025d3b4beca9835a5e997e41677a4c6441a733f4))

## [5.1.0](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/compare/v5.0.0...v5.1.0) (2023-05-30)


### Features

* Implementation of the cpu_options block and addition of support for AMD SEV-SNP ([#334](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/issues/334)) ([6a123ad](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/commit/6a123adb10393759fcdd18795fbf1484c5f44dde))

## [5.0.0](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/compare/v4.5.0...v5.0.0) (2023-04-28)


### ⚠ BREAKING CHANGES

* Raise minimum required Terraform version to 1.0+ (#331)

### Features

* Raise minimum required Terraform version to 1.0+ ([#331](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/issues/331)) ([9d4e0ca](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/commit/9d4e0ca389535522808ddf988e3a6510bb143161))

## [4.5.0](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/compare/v4.4.0...v4.5.0) (2023-04-21)


### Features

* Add unique tags to EBS block devices ([#327](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/issues/327)) ([55ed759](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/commit/55ed759b9fbc475629da2d5068a593a2ce08d8dc))

## [4.4.0](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/compare/v4.3.1...v4.4.0) (2023-04-21)


### Features

* Addition of block device information in outputs ([#319](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/issues/319)) ([884e244](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/commit/884e24466e19144e6b5a1085ab81b377174c6e0c))

### [4.3.1](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/compare/v4.3.0...v4.3.1) (2023-04-21)


### Bug Fixes

* Marked AMI id as nonsensitive ([#321](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/issues/321)) ([1ae1d5c](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/commit/1ae1d5ce73d6bef0e42821406f82ff16fe718177))

## [4.3.0](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/compare/v4.2.1...v4.3.0) (2023-01-01)


Expand Down
52 changes: 27 additions & 25 deletions README.md

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Examples

Please note - the examples provided serve two primary means:

1. Show users working examples of the various ways in which the module can be configured and features supported
2. A means of testing/validating module changes

Please do not mistake the examples provided as "best practices". It is up to users to consult the AWS service documentation for best practices, usage recommendations, etc.
16 changes: 12 additions & 4 deletions examples/complete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@ Note that this example may create resources which can cost money. Run `terraform

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.7 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.66 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.7 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.66 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_ec2_complete"></a> [ec2\_complete](#module\_ec2\_complete) | ../../ | n/a |
| <a name="module_ec2_cpu_options"></a> [ec2\_cpu\_options](#module\_ec2\_cpu\_options) | ../../ | n/a |
| <a name="module_ec2_disabled"></a> [ec2\_disabled](#module\_ec2\_disabled) | ../../ | n/a |
| <a name="module_ec2_ignore_ami_changes"></a> [ec2\_ignore\_ami\_changes](#module\_ec2\_ignore\_ami\_changes) | ../../ | n/a |
| <a name="module_ec2_metadata_options"></a> [ec2\_metadata\_options](#module\_ec2\_metadata\_options) | ../../ | n/a |
| <a name="module_ec2_multiple"></a> [ec2\_multiple](#module\_ec2\_multiple) | ../../ | n/a |
| <a name="module_ec2_network_interface"></a> [ec2\_network\_interface](#module\_ec2\_network\_interface) | ../../ | n/a |
Expand All @@ -43,7 +45,7 @@ Note that this example may create resources which can cost money. Run `terraform
| <a name="module_ec2_t3_unlimited"></a> [ec2\_t3\_unlimited](#module\_ec2\_t3\_unlimited) | ../../ | n/a |
| <a name="module_ec2_targeted_capacity_reservation"></a> [ec2\_targeted\_capacity\_reservation](#module\_ec2\_targeted\_capacity\_reservation) | ../../ | n/a |
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |

## Resources

Expand All @@ -55,6 +57,8 @@ Note that this example may create resources which can cost money. Run `terraform
| [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 |
| [aws_ami.amazon_linux](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
| [aws_ami.amazon_linux_23](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |

## Inputs

Expand All @@ -66,6 +70,8 @@ No inputs.
|------|-------------|
| <a name="output_ec2_complete_arn"></a> [ec2\_complete\_arn](#output\_ec2\_complete\_arn) | The ARN of the instance |
| <a name="output_ec2_complete_capacity_reservation_specification"></a> [ec2\_complete\_capacity\_reservation\_specification](#output\_ec2\_complete\_capacity\_reservation\_specification) | Capacity reservation specification of the instance |
| <a name="output_ec2_complete_ebs_block_device"></a> [ec2\_complete\_ebs\_block\_device](#output\_ec2\_complete\_ebs\_block\_device) | EBS block device information |
| <a name="output_ec2_complete_ephemeral_block_device"></a> [ec2\_complete\_ephemeral\_block\_device](#output\_ec2\_complete\_ephemeral\_block\_device) | Ephemeral block device information |
| <a name="output_ec2_complete_iam_instance_profile_arn"></a> [ec2\_complete\_iam\_instance\_profile\_arn](#output\_ec2\_complete\_iam\_instance\_profile\_arn) | ARN assigned by AWS to the instance profile |
| <a name="output_ec2_complete_iam_instance_profile_id"></a> [ec2\_complete\_iam\_instance\_profile\_id](#output\_ec2\_complete\_iam\_instance\_profile\_id) | Instance profile's ID |
| <a name="output_ec2_complete_iam_instance_profile_unique"></a> [ec2\_complete\_iam\_instance\_profile\_unique](#output\_ec2\_complete\_iam\_instance\_profile\_unique) | Stable and unique string identifying the IAM instance profile |
Expand All @@ -78,7 +84,9 @@ No inputs.
| <a name="output_ec2_complete_private_dns"></a> [ec2\_complete\_private\_dns](#output\_ec2\_complete\_private\_dns) | The private DNS name assigned to the instance. Can only be used inside the Amazon EC2, and only available if you've enabled DNS hostnames for your VPC |
| <a name="output_ec2_complete_public_dns"></a> [ec2\_complete\_public\_dns](#output\_ec2\_complete\_public\_dns) | The public DNS name assigned to the instance. For EC2-VPC, this is only available if you've enabled DNS hostnames for your VPC |
| <a name="output_ec2_complete_public_ip"></a> [ec2\_complete\_public\_ip](#output\_ec2\_complete\_public\_ip) | The public IP address assigned to the instance, if applicable. NOTE: If you are using an aws\_eip with your instance, you should refer to the EIP's address directly and not use `public_ip` as this field will change after the EIP is attached |
| <a name="output_ec2_complete_root_block_device"></a> [ec2\_complete\_root\_block\_device](#output\_ec2\_complete\_root\_block\_device) | Root block device information |
| <a name="output_ec2_complete_tags_all"></a> [ec2\_complete\_tags\_all](#output\_ec2\_complete\_tags\_all) | A map of tags assigned to the resource, including those inherited from the provider default\_tags configuration block |
| <a name="output_ec2_ignore_ami_changes_ami"></a> [ec2\_ignore\_ami\_changes\_ami](#output\_ec2\_ignore\_ami\_changes\_ami) | The AMI of the instance (ignore\_ami\_changes = true) |
| <a name="output_ec2_multiple"></a> [ec2\_multiple](#output\_ec2\_multiple) | The full output of the `ec2_module` module |
| <a name="output_ec2_spot_instance_arn"></a> [ec2\_spot\_instance\_arn](#output\_ec2\_spot\_instance\_arn) | The ARN of the instance |
| <a name="output_ec2_spot_instance_capacity_reservation_specification"></a> [ec2\_spot\_instance\_capacity\_reservation\_specification](#output\_ec2\_spot\_instance\_capacity\_reservation\_specification) | Capacity reservation specification of the instance |
Expand Down
148 changes: 126 additions & 22 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ provider "aws" {
region = local.region
}

data "aws_availability_zones" "available" {}

locals {
name = "example-ec2-complete"
name = "ex-${basename(path.cwd)}"
region = "eu-west-1"

vpc_cidr = "10.0.0.0/16"
azs = slice(data.aws_availability_zones.available.names, 0, 3)

user_data = <<-EOT
#!/bin/bash
echo "Hello Terraform!"
#!/bin/bash
echo "Hello Terraform!"
EOT

tags = {
Owner = "user"
Environment = "dev"
Name = local.name
Example = local.name
Repository = "https://github.com/terraform-aws-modules/terraform-aws-ec2-instance"
}
}

################################################################################
# EC2 Module
################################################################################

module "ec2_disabled" {
source = "../../"

create = false
}

module "ec2_complete" {
source = "../../"

Expand Down Expand Up @@ -54,9 +54,10 @@ module "ec2_complete" {
user_data_base64 = base64encode(local.user_data)
user_data_replace_on_change = true

cpu_core_count = 2 # default 4
cpu_threads_per_core = 1 # default 2

cpu_options = {
core_count = 2
threads_per_core = 1
}
enable_volume_tags = false
root_block_device = [
{
Expand All @@ -78,6 +79,9 @@ module "ec2_complete" {
throughput = 200
encrypted = true
kms_key_id = aws_kms_key.this.arn
tags = {
MountPoint = "/mnt/data"
}
}
]

Expand Down Expand Up @@ -150,6 +154,32 @@ module "ec2_t3_unlimited" {
tags = local.tags
}

module "ec2_disabled" {
source = "../../"

create = false
}

################################################################################
# EC2 Module - with ignore AMI changes
################################################################################

module "ec2_ignore_ami_changes" {
source = "../../"

name = local.name

ignore_ami_changes = true

ami = data.aws_ami.amazon_linux.id
instance_type = "t2.micro"
availability_zone = element(module.vpc.azs, 0)
subnet_id = element(module.vpc.private_subnets, 0)
vpc_security_group_ids = [module.security_group.security_group_id]

tags = local.tags
}

################################################################################
# EC2 Module - multiple instances with `for_each`
################################################################################
Expand Down Expand Up @@ -234,8 +264,10 @@ module "ec2_spot_instance" {

user_data_base64 = base64encode(local.user_data)

cpu_core_count = 2 # default 4
cpu_threads_per_core = 1 # default 2
cpu_options = {
core_count = 2
threads_per_core = 1
}

enable_volume_tags = false
root_block_device = [
Expand Down Expand Up @@ -324,21 +356,83 @@ resource "aws_ec2_capacity_reservation" "targeted" {
instance_match_criteria = "targeted"
}

################################################################################
# EC2 Module - CPU Options
################################################################################
module "ec2_cpu_options" {
source = "../../"

name = "${local.name}-cpu-options"

ami = data.aws_ami.amazon_linux_23.id
instance_type = "c6a.xlarge" # used to set core count below and test amd_sev_snp attribute
availability_zone = element(module.vpc.azs, 0)
subnet_id = element(module.vpc.private_subnets, 0)
vpc_security_group_ids = [module.security_group.security_group_id]
placement_group = aws_placement_group.web.id
associate_public_ip_address = true
disable_api_stop = false

create_iam_instance_profile = true
iam_role_description = "IAM role for EC2 instance"
iam_role_policies = {
AdministratorAccess = "arn:aws:iam::aws:policy/AdministratorAccess"
}

user_data_base64 = base64encode(local.user_data)
user_data_replace_on_change = true

cpu_options = {
core_count = 2
threads_per_core = 1
amd_sev_snp = "enabled"
}
enable_volume_tags = false
root_block_device = [
{
encrypted = true
volume_type = "gp3"
throughput = 200
volume_size = 50
tags = {
Name = "my-root-block"
}
},
]

ebs_block_device = [
{
device_name = "/dev/sdf"
volume_type = "gp3"
volume_size = 5
throughput = 200
encrypted = true
kms_key_id = aws_kms_key.this.arn
tags = {
MountPoint = "/mnt/data"
}
}
]

instance_tags = { Persistence = "09:00-18:00" }

tags = local.tags
}

################################################################################
# Supporting Resources
################################################################################

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 3.0"
version = "~> 5.0"

name = local.name
cidr = "10.99.0.0/18"
cidr = local.vpc_cidr

azs = ["${local.region}a", "${local.region}b", "${local.region}c"]
public_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"]
private_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"]
database_subnets = ["10.99.7.0/24", "10.99.8.0/24", "10.99.9.0/24"]
azs = local.azs
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 4, k)]
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 48)]

tags = local.tags
}
Expand All @@ -353,6 +447,16 @@ data "aws_ami" "amazon_linux" {
}
}

data "aws_ami" "amazon_linux_23" {
most_recent = true
owners = ["amazon"]

filter {
name = "name"
values = ["al2023-ami-2023*-x86_64"]
}
}

module "security_group" {
source = "terraform-aws-modules/security-group/aws"
version = "~> 4.0"
Expand Down
21 changes: 21 additions & 0 deletions examples/complete/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ output "ec2_complete_iam_instance_profile_unique" {
value = module.ec2_complete.iam_instance_profile_unique
}

output "ec2_complete_root_block_device" {
description = "Root block device information"
value = module.ec2_complete.root_block_device
}

output "ec2_complete_ebs_block_device" {
description = "EBS block device information"
value = module.ec2_complete.ebs_block_device
}

output "ec2_complete_ephemeral_block_device" {
description = "Ephemeral block device information"
value = module.ec2_complete.ephemeral_block_device
}

# EC2 T2 Unlimited
output "ec2_t2_unlimited_id" {
description = "The ID of the instance"
Expand Down Expand Up @@ -166,6 +181,12 @@ output "ec2_t3_unlimited_tags_all" {
value = module.ec2_t3_unlimited.tags_all
}

# EC2 with ignore AMI changes
output "ec2_ignore_ami_changes_ami" {
description = "The AMI of the instance (ignore_ami_changes = true)"
value = module.ec2_ignore_ami_changes.ami
}

# EC2 Multiple
output "ec2_multiple" {
description = "The full output of the `ec2_module` module"
Expand Down
Loading

0 comments on commit c17c84f

Please sign in to comment.