The Terraform AWS provider throws a conflicting configuration error when both the deprecated cpu_core_count argument and the newer cpu_options block are present in the same aws_instance resource. This conflict occurs because these are two incompatible ways of specifying the same CPU configuration, with cpu_core_count being deprecated in favor of cpu_options.
The Terraform AWS provider (v5.0.0+) deprecated the cpu_core_count and cpu_threads_per_core arguments in favor of the newer cpu_options block. When Terraform detects both the old and new syntax in the same resource configuration, it raises a validation error because the two approaches are mutually exclusive. You cannot use both simultaneously—you must choose one method for configuring EC2 CPU options.
Open your Terraform configuration file (main.tf, variables.tf, etc.) and search for the aws_instance resource block. Look for lines containing either:
Old (deprecated) method:
cpu_core_count = 4
cpu_threads_per_core = 2New method:
cpu_options {
core_count = 4
threads_per_core = 2
}Note whether you have one, both, or neither of these.
Delete the deprecated top-level arguments from your aws_instance resource. For example, change this:
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "m5.large"
cpu_core_count = 4
cpu_threads_per_core = 2
}To this:
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "m5.large"
}If you need to specify custom CPU options, use the newer cpu_options block instead:
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "m5.large"
cpu_options {
core_count = 4
threads_per_core = 2
}
}The cpu_options block must include both core_count and threads_per_core if you use it. These values are set at instance launch time and cannot be changed afterward.
Check that your aws_instance resource no longer has any of these deprecated arguments:
- cpu_core_count
- cpu_threads_per_core
Run a syntax check:
terraform validateIf the validate command succeeds without errors, your syntax is correct.
Execute a plan to confirm the error is gone:
terraform planIf the plan succeeds without the conflicting configuration error, the issue is resolved. Review the proposed changes to ensure they match your intentions before applying.
If you're managing existing AWS infrastructure:
1. For new instances: The cpu_options block will be applied at creation time.
2. For existing instances: Terraform will not attempt to modify cpu_options after the instance is created (AWS does not support this). If you change cpu_options in your configuration, Terraform will require the instance to be destroyed and recreated.
To see what changes Terraform plans:
terraform plan -out=tfplan
terraform show tfplanReview carefully before applying if it shows a resource must be replaced.
Immutable CPU Options: AWS does not allow you to change CPU options after an EC2 instance is launched. The core_count and threads_per_core values are set only at instance creation time. If you modify these values in your Terraform configuration, Terraform will be forced to destroy and recreate the instance.
Terraformer Migration: If you're using Terraformer to import AWS infrastructure, it may generate code with both old and new syntax. This is a known issue (GitHub #1712). The workaround is to manually remove the deprecated arguments after import.
Not all instance types support CPU customization: The cpu_options feature is only available on certain EC2 instance types. Attempting to use cpu_options with an instance type that doesn't support it will fail. Check the AWS documentation for your instance type before using cpu_options.
Threads per core values: The threads_per_core value can only be 1 (disables hyperthreading) or 2 (default, hyperthreading enabled). Other values are not valid.
AWS Provider v5.0.0 breaking change: This deprecation was introduced in AWS provider v5.0.0 as part of a major version upgrade. If you're still using provider v4.x, you can continue using the old syntax, but plan to migrate before upgrading to v6.0.0 when these arguments will be completely removed.
Error: Error rendering template: template not found
How to fix "template not found" error in Terraform
Error: Error generating private key
How to fix 'Error generating private key' in Terraform
Error creating Kubernetes Service: field is immutable
How to fix "field is immutable" errors in Terraform
Error: Error creating local file: open: permission denied
How to fix "Error creating local file: permission denied" in Terraform
Error: line endings have changed from CRLF to LF
Line endings have changed from CRLF to LF in Terraform