Commit 19b44d25 authored by Karan Thanvi's avatar Karan Thanvi Committed by GitHub

feat: Add cpu optimization options (#181)

parent ae09a00f
...@@ -109,7 +109,9 @@ No modules. ...@@ -109,7 +109,9 @@ No modules.
|------|-------------|------|---------|:--------:| |------|-------------|------|---------|:--------:|
| <a name="input_ami"></a> [ami](#input\_ami) | ID of AMI to use for the instance | `string` | n/a | yes | | <a name="input_ami"></a> [ami](#input\_ami) | ID of AMI to use for the instance | `string` | n/a | yes |
| <a name="input_associate_public_ip_address"></a> [associate\_public\_ip\_address](#input\_associate\_public\_ip\_address) | If true, the EC2 instance will have associated public IP address | `bool` | `null` | no | | <a name="input_associate_public_ip_address"></a> [associate\_public\_ip\_address](#input\_associate\_public\_ip\_address) | If true, the EC2 instance will have associated public IP address | `bool` | `null` | no |
| <a name="input_cpu_core_count"></a> [cpu\_core\_count](#input\_cpu\_core\_count) | Sets the number of CPU cores for an instance. | `number` | `null` | no |
| <a name="input_cpu_credits"></a> [cpu\_credits](#input\_cpu\_credits) | The credit option for CPU usage (unlimited or standard) | `string` | `"standard"` | no | | <a name="input_cpu_credits"></a> [cpu\_credits](#input\_cpu\_credits) | The credit option for CPU usage (unlimited or standard) | `string` | `"standard"` | no |
| <a name="input_cpu_threads_per_core"></a> [cpu\_threads\_per\_core](#input\_cpu\_threads\_per\_core) | Sets the number of CPU threads per core for an instance (has no effect unless cpu\_core\_count is also set). | `number` | `null` | no |
| <a name="input_disable_api_termination"></a> [disable\_api\_termination](#input\_disable\_api\_termination) | If true, enables EC2 Instance Termination Protection | `bool` | `false` | no | | <a name="input_disable_api_termination"></a> [disable\_api\_termination](#input\_disable\_api\_termination) | If true, enables EC2 Instance Termination Protection | `bool` | `false` | no |
| <a name="input_ebs_block_device"></a> [ebs\_block\_device](#input\_ebs\_block\_device) | Additional EBS block devices to attach to the instance | `list(map(string))` | `[]` | no | | <a name="input_ebs_block_device"></a> [ebs\_block\_device](#input\_ebs\_block\_device) | Additional EBS block devices to attach to the instance | `list(map(string))` | `[]` | no |
| <a name="input_ebs_optimized"></a> [ebs\_optimized](#input\_ebs\_optimized) | If true, the launched EC2 instance will be EBS-optimized | `bool` | `false` | no | | <a name="input_ebs_optimized"></a> [ebs\_optimized](#input\_ebs\_optimized) | If true, the launched EC2 instance will be EBS-optimized | `bool` | `false` | no |
......
...@@ -33,6 +33,7 @@ Note that this example may create resources which can cost money. Run `terraform ...@@ -33,6 +33,7 @@ Note that this example may create resources which can cost money. Run `terraform
| Name | Source | Version | | Name | Source | Version |
|------|--------|---------| |------|--------|---------|
| <a name="module_ec2"></a> [ec2](#module\_ec2) | ../../ | | | <a name="module_ec2"></a> [ec2](#module\_ec2) | ../../ | |
| <a name="module_ec2_optimize_cpu"></a> [ec2\_optimize\_cpu](#module\_ec2\_optimize\_cpu) | ../../ | |
| <a name="module_ec2_with_metadata_options"></a> [ec2\_with\_metadata\_options](#module\_ec2\_with\_metadata\_options) | ../../ | | | <a name="module_ec2_with_metadata_options"></a> [ec2\_with\_metadata\_options](#module\_ec2\_with\_metadata\_options) | ../../ | |
| <a name="module_ec2_with_network_interface"></a> [ec2\_with\_network\_interface](#module\_ec2\_with\_network\_interface) | ../../ | | | <a name="module_ec2_with_network_interface"></a> [ec2\_with\_network\_interface](#module\_ec2\_with\_network\_interface) | ../../ | |
| <a name="module_ec2_with_t2_unlimited"></a> [ec2\_with\_t2\_unlimited](#module\_ec2\_with\_t2\_unlimited) | ../../ | | | <a name="module_ec2_with_t2_unlimited"></a> [ec2\_with\_t2\_unlimited](#module\_ec2\_with\_t2\_unlimited) | ../../ | |
......
...@@ -196,3 +196,34 @@ module "ec2_zero" { ...@@ -196,3 +196,34 @@ module "ec2_zero" {
subnet_id = tolist(data.aws_subnet_ids.all.ids)[0] subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
vpc_security_group_ids = [module.security_group.security_group_id] vpc_security_group_ids = [module.security_group.security_group_id]
} }
module "ec2_optimize_cpu" {
source = "../../"
instance_count = 1
name = "example-optimize-cpu"
ami = data.aws_ami.amazon_linux.id
instance_type = "c4.2xlarge"
subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
vpc_security_group_ids = [module.security_group.security_group_id]
associate_public_ip_address = true
placement_group = aws_placement_group.web.id
user_data_base64 = base64encode(local.user_data)
root_block_device = [
{
volume_type = "gp2"
volume_size = 10
},
]
cpu_core_count = 2 # default 4
cpu_threads_per_core = 1 # default 2
tags = {
"Env" = "Private"
"Location" = "Secret"
}
}
...@@ -85,6 +85,8 @@ resource "aws_instance" "this" { ...@@ -85,6 +85,8 @@ resource "aws_instance" "this" {
instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior
placement_group = var.placement_group placement_group = var.placement_group
tenancy = var.tenancy tenancy = var.tenancy
cpu_core_count = var.cpu_core_count
cpu_threads_per_core = var.cpu_threads_per_core
tags = merge( tags = merge(
{ {
......
...@@ -204,3 +204,15 @@ variable "num_suffix_format" { ...@@ -204,3 +204,15 @@ variable "num_suffix_format" {
type = string type = string
default = "-%d" default = "-%d"
} }
variable "cpu_core_count" {
description = "Sets the number of CPU cores for an instance." # This option is only supported on creation of instance type that support CPU Options https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-optimize-cpu.html#cpu-options-supported-instances-values
type = number
default = null
}
variable "cpu_threads_per_core" {
description = "Sets the number of CPU threads per core for an instance (has no effect unless cpu_core_count is also set)."
type = number
default = 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