1 min read

Move resources in Terraform state


Refactor without destroying

Rename a resource in state:

state_mv.sh
terraform state mv azurerm_resource_group.old azurerm_resource_group.new

Move a resource into a module:

state_mv_module.sh
terraform state mv azurerm_storage_account.sa module.storage.azurerm_storage_account.sa

List all resources in state:

state_list.sh
terraform state list

Show details of a specific resource:

state_show.sh
terraform state show azurerm_resource_group.main

Tip: Always run terraform plan after moving state to verify no changes are detected.