Rename infrastructure resources
In order to rename terraform resources in code, the changes must first be applied to the terraform code itself (e.g. hcloud_server.idm1
becomes hcloud_server.primary
). Once the code is updated, however, the resources specified in the code no longer map to the resources described in the terraform state. To rename the resources in state, the moved
resource can be used.
moved {
from = hcloud_server.idm1
to = hcloud_server.primary
}
The operator can then run terraform plan
to verify that existing cloud resources will not be destructively replaced, then they can apply the migration with terraform apply -auto-approve
. Once the migration changes have been applied, the moved
resources can be safely removed.