'terraform state mv or sed for resource renaming in Terraform?
Context: we're developing a TF provider.
Currently we are prefixing the resources with foobar_: e.g., foobar_user but we're going to rename (effective immediately) the prefix to just foo: foo_user (we know that the official guidance is a little bit different).
Assume that a typical user of TF provider would have 10 resources in their TF state, which of the following option is better: 1.
# Update TF configuration
sed -i 's/foobar_user/foo_user/' main.tf
# Update TF state
terraform state mv foobar_user.example_1 foo_user.example_1
terraform state mv foobar_user.example_2 foo_user.example_2
...
terraform state mv foobar_user.example_10 foo_user.example_10
terraform plan
# Hopefully no changes
# Update TF configuration
sed -i 's/foobar_user/foo_user/' main.tf
# Update TF state
terraform state pull > current.state
cp current.state updated.state
sed -i 's/foobar_user/foo_user/' updated.state
terraform state push -force updated.state
terraform plan
# Hopefully no changes
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
