diff --git a/README.md b/README.md index c565995e..8e508239 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,9 @@ No modules. |------|-------------|------|---------|:--------:| | [ami](#input\_ami) | ID of AMI to use for the instance | `string` | n/a | yes | | [associate\_public\_ip\_address](#input\_associate\_public\_ip\_address) | If true, the EC2 instance will have associated public IP address | `bool` | `null` | no | +| [cpu\_core\_count](#input\_cpu\_core\_count) | Sets the number of CPU cores for an instance. | `number` | `null` | no | | [cpu\_credits](#input\_cpu\_credits) | The credit option for CPU usage (unlimited or standard) | `string` | `"standard"` | no | +| [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 | | [disable\_api\_termination](#input\_disable\_api\_termination) | If true, enables EC2 Instance Termination Protection | `bool` | `false` | no | | [ebs\_block\_device](#input\_ebs\_block\_device) | Additional EBS block devices to attach to the instance | `list(map(string))` | `[]` | no | | [ebs\_optimized](#input\_ebs\_optimized) | If true, the launched EC2 instance will be EBS-optimized | `bool` | `false` | no | diff --git a/examples/basic/README.md b/examples/basic/README.md index 9d615233..7c8cf737 100644 --- a/examples/basic/README.md +++ b/examples/basic/README.md @@ -33,6 +33,7 @@ Note that this example may create resources which can cost money. Run `terraform | Name | Source | Version | |------|--------|---------| | [ec2](#module\_ec2) | ../../ | | +| [ec2\_optimize\_cpu](#module\_ec2\_optimize\_cpu) | ../../ | | | [ec2\_with\_metadata\_options](#module\_ec2\_with\_metadata\_options) | ../../ | | | [ec2\_with\_network\_interface](#module\_ec2\_with\_network\_interface) | ../../ | | | [ec2\_with\_t2\_unlimited](#module\_ec2\_with\_t2\_unlimited) | ../../ | | diff --git a/examples/basic/main.tf b/examples/basic/main.tf index 55af7f97..e0b13a46 100644 --- a/examples/basic/main.tf +++ b/examples/basic/main.tf @@ -196,3 +196,34 @@ module "ec2_zero" { subnet_id = tolist(data.aws_subnet_ids.all.ids)[0] 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" + } +} diff --git a/main.tf b/main.tf index c67cabc8..052b7351 100644 --- a/main.tf +++ b/main.tf @@ -85,6 +85,8 @@ resource "aws_instance" "this" { instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior placement_group = var.placement_group tenancy = var.tenancy + cpu_core_count = var.cpu_core_count + cpu_threads_per_core = var.cpu_threads_per_core tags = merge( { diff --git a/variables.tf b/variables.tf index c4bd848d..72be9e4d 100644 --- a/variables.tf +++ b/variables.tf @@ -204,3 +204,15 @@ variable "num_suffix_format" { type = string 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 +}