I use Terraform to provision LXCs/VMs on Proxmox cluster in my homelab. One day, I noticed that a typo in the resources name as following:
resource "proxmox_virtual_environment_container" "proxmox_lxc_contoiner" {
for_each = local.lxc_containers
// The rest of the code to define Proxmox LXC container
}
Notice the typo in the resource name proxmox_lxc_contoiner instead of the correct name proxmox_lxc_container
If I fix the typo in Terraform code and run terraform plan, it tell me that it will destroy existing LXC containers and create new ones, not ideal.
Luckily, Terraform allows to move state as following (I use OpenTofu but the process should be the same for Terraform)
-
List the existing state:
tofu state listHere is the output in my case:
proxmox_virtual_environment_container.proxmox_lxc_contoiner["postgresql"] proxmox_virtual_environment_container.proxmox_lxc_contoiner["zitadel"] -
Move the state to the new names:
tofu state mv "proxmox_virtual_environment_container.proxmox_lxc_contoiner['postgresql']" "proxmox_virtual_environment_container.proxmox_lxc_container['postgresql']"Repeat this step for all the resources that you want to rename
-
Update your terraform code with the new resource name
-
Verify Terraform state with the new names
tofu planTerraform should tell you that infrastructure is up-to-date.