Vivi
Vivi

Reputation: 145

How to update Terraform state without apply changes

the scenario is:

So I want update the state for this new repository adding the IAM configs state and delete IAM state from the older repository but I don't want to apply changes in my infrastructure because I would have to delete all configurations from older repository and then create all again.

Is there any way to update state without apply changes?

Upvotes: 0

Views: 2272

Answers (2)

titanium_yes
titanium_yes

Reputation: 1

I think you would need to do a terraform state surgery where you pull the state file, update and push again. Or move the resources without deleting them.

https://developer.hashicorp.com/terraform/tutorials/configuration-language/move-config#move-your-resources-with-the-moved-configuration-block

Upvotes: 0

splieth
splieth

Reputation: 26

The best way would be to create the new repositories that each hold new state files. Let's say the resources created from you old repo are stored in a state called "repo1.tfstate". Then you create a new repo where you want some stuff that is split from repo1 here. You could then use terraform import to import resources into repo2. Don't forget to remove the resources you just imported from repo1 with terraform state rm.

Another way would be to do a terraform state pull > state-for-repo-2.tfstate, edit that manually, put it into repo2 and do a terraform state push. Of cause, you would have to edit the state for repo1 as well. But be aware that terraform state push will overwrite the original state file...

Upvotes: 1

Related Questions