Slackbot
02/01/2024, 6:24 PMTroy Knapp
02/01/2024, 6:37 PMterraform state mv -state-out=../terraform.tfstate aws_instance.example_new aws_instance.example_new
https://developer.hashicorp.com/terraform/tutorials/state/state-cliThomas Kraus
02/02/2024, 6:51 AMmoved
keyword in your TF files (prevents CLI state changes):
https://developer.hashicorp.com/terraform/tutorials/configuration-language/move-config#move-your-resources-with-the-moved-configuration-block
You might still generate all the temporary blocks using a shell script, by `grep`ping the from
values from the original plan, and manipulating to create the to
values, perhaps in a few steps, and with that have the script “render” all moved
blocks. When creating the plan you’ll see that it plans to move the resources and after applying that once the moved
blocks are obsolete (but won’t break the next plan).Nicholas Philbrook
02/02/2024, 12:59 PMmoved
won't work between state files though - just location inside one state fileTroy Knapp
02/02/2024, 1:00 PMNicholas Philbrook
02/02/2024, 1:01 PMTroy Knapp
02/02/2024, 1:01 PMThomas Kraus
02/02/2024, 1:03 PMmoved
is just within a single state, must have overlooked this part from the question 🙈Troy Knapp
02/02/2024, 1:04 PMNicholas Philbrook
02/02/2024, 1:04 PMmoved
blocks were added in 1.1, although as noted probably not going to help you. Not sure if the state mv -state-out
option was added in somewhat newer version, looks like maybe it may be pretty old as it's not "recommended" any longer (and only works with local backends)
https://developer.hashicorp.com/terraform/language/settings/backends/local#command-line-argumentsNicholas Philbrook
02/02/2024, 1:07 PMTroy Knapp
02/02/2024, 1:16 PMterraform state list
command, then grep for something like module_name.*
then get a list of all the relevant objects and their states, then translate them into a new state file (or use the state mv -state-out
command if its available).Troy Knapp
02/02/2024, 1:21 PMOren Recht
02/02/2024, 1:27 PMmoved
block work when moving resources inside the same state as far as I know. Not sure in understand how you want to use them in my use case.Oren Recht
02/02/2024, 1:29 PMTroy Knapp
02/02/2024, 1:31 PMNicholas Philbrook
02/02/2024, 3:15 PMTroy Knapp
02/02/2024, 3:21 PMTroy Knapp
02/02/2024, 3:26 PMNicholas Philbrook
02/02/2024, 4:27 PMNicholas Philbrook
02/02/2024, 4:27 PMNicholas Philbrook
02/02/2024, 4:27 PMTroy Knapp
02/02/2024, 4:29 PMNicholas Philbrook
02/02/2024, 4:37 PMNicholas Philbrook
02/02/2024, 4:39 PMTroy Knapp
02/02/2024, 4:40 PMNicholas Philbrook
02/02/2024, 4:43 PMTroy Knapp
02/02/2024, 4:44 PMTroy Knapp
02/02/2024, 4:49 PMNicholas Philbrook
02/02/2024, 4:50 PMNicholas Philbrook
02/02/2024, 4:50 PMthe ability to define module versions outside the module source definitionDo you mean like as a local or variable?
Troy Knapp
02/02/2024, 4:51 PMNicholas Philbrook
02/02/2024, 4:52 PMTroy Knapp
02/02/2024, 4:56 PMTroy Knapp
02/02/2024, 4:59 PMI think in my past we avoided that need by just having lots of mini-monolith state files in our huge monolith repo lolsobSeriously, I will give no shade here. Managing TF at scale is terrible and you have to do some shitty things to get it done. Its just a matter of what shitty thing can you live with.
Nicholas Philbrook
02/02/2024, 5:00 PMNicholas Philbrook
02/02/2024, 5:02 PMTroy Knapp
02/02/2024, 5:03 PM