no-instance-cpu-count-attributes
Flag the top-level cpu_core_count and cpu_threads_per_core arguments on an aws_instance resource. Both were removed from the schema in AWS provider v6; move their values into a cpu_options block using core_count and threads_per_core.
Why
The AWS provider v6 upgrade guide removed the deprecated cpu_core_count and cpu_threads_per_core arguments from aws_instance. A plan against v6 fails with an unsupported-argument error until the values move into the nested cpu_options block, where they are expressed as core_count and threads_per_core.
What it flags
resource "aws_instance" "web" {
instance_type = "t3.micro"
cpu_core_count = 2 # removed in v6
cpu_threads_per_core = 1 # removed in v6
}Accepted:
resource "aws_instance" "web" {
instance_type = "t3.micro"
cpu_options {
core_count = 2
threads_per_core = 1
}
}What it does not flag
- A
data "aws_instance"source carrying these names: data sources are never migrated. - Any other resource type that happens to use the same argument names.
- An
aws_instancethat already declares the values inside acpu_optionsblock.
Autofix
When every offending value is a literal and the resource has no existing cpu_options block, the arguments are consolidated into a new cpu_options block:
resource "aws_instance" "web" { # before
cpu_core_count = 2
cpu_threads_per_core = 1
}
resource "aws_instance" "web" { # after
cpu_options {
core_count = 2
threads_per_core = 1
}
}The rule reports without a fix in two cases, because neither can be migrated safely by a text edit:
- An offending value is a non-literal expression, such as
cpu_core_count = var.cores. - The resource already has a
cpu_optionsblock; merging into it could clobber existing settings.
Options
None.
Future work
aws_spot_instance_request carries the same removed arguments and the same migration. It is out of scope for this rule and could become its own rule later.