-4

Examples of behavior in terraform:

  • You have created 2 S3 buckets, each via separate resource line. Deployed the code. Now you are changing the code to use for_each or other loop. The new code does produce the equivalent resources, however it does not apply easily because the resource address in the state has changed - now it has an iterator index. You have to either move parts of the state or re-create the resources.
  • You have created a bunch resources in a main module. Deployed the code. Now you decided to move some of them into a submodule, and call it from main. The new code does produce the equivalent resources, however it does not apply easily because the resource address in the state has changed - now it includes module name. You have to either move parts of the state or re-create the resources.

Are there any cases when pulumi does have similar issue with a state files? Can you refactor the code freely and apply with no changes, given that you don't change the resulting behavior?

Max Lobur
  • 5,662
  • 22
  • 35
  • 2
    Are you aware Terraform has a built in `moved {}` configuration block you can use to migrate these? It's explicitly for stuff like "we moved all these into a module" scenarios. https://developer.hashicorp.com/terraform/tutorials/configuration-language/move-config#move-your-resources-with-the-moved-configuration-block – ceejayoz Aug 15 '23 at 15:15
  • 1
    Thanks for reminding that! I've found that pulumi has similar https://www.pulumi.com/docs/concepts/options/aliases/ (broad example https://www.pulumi.com/blog/cumundi-guest-post/). Although Pulumi doesn't seem to suffer from tying state to a particular code structure like modules or loops, they still have a manual dependency field "parent" which will affect state path and thus hit the same issue. What I didn't understand from their example is why creating a serviceAccount with an explicit reference to a parent's projectId did not automatically set "parent" for that object, like in terraform. – Max Lobur Aug 15 '23 at 16:50
  • So sounds like pulumi has less of this. But given that they don't set a parent automatically, you may mess with that initially and thus have more use of `aliases` - still enough headache during the refactoring. – Max Lobur Aug 15 '23 at 16:54

0 Answers0