You can find plenty of information online about renaming Terraform resources for various reasons: refactoring, fixing typos, updating naming conventions, etc. What I’ve noticed is that most people either recreate the resource, create a new one, or use the moved block which isn’t as intuitive or straightforward. But it’s 2026, and there’s a simpler command that lets you rename resources without destroying them.

the command

Let’s say we made a typo when creating an EC2 instance e.g.:

resource "aws_instance" "teast" {
  ami           = "<some_ami_id>
  instance_type = "t3.micro"

  tags = {
    Name = "test"
  }
}

Now, to rename the resource update the resource name:

resource "aws_instance" "test" {

Save the file and run the following command:

terraform state mv aws_instance.teast aws_instance.test

That’s all. The resource is renamed in your state file without any recreation. Now, have fun refactoring.

bottom line

One important thing to remember: dependencies. Make sure to update every reference that points to the renamed resource throughout your codebase. Otherwise, yeah …things will break.

Shameless plug: Check out justanotheruptime.com if you’re looking for a monitoring solution to catch when things inevitably sometimes break.