boltops-tools / terraspace

Terraspace: The Terraform Framework
https://terraspace.cloud
Apache License 2.0
678 stars 46 forks source link

`terraspace state mv` doesn't work #291

Open vsinha opened 1 year ago

vsinha commented 1 year ago

Checklist

My Environment

Software Version
Operating System M1 MacOS darwin_arm64
Terraform 1.3.7
Terraspace 2.2.3
Ruby 3.2.0

When renaming an existing stack foo, I've tried to use the terraspace wrapper of the terraform state mv command. I believe terraspace is not properly parsing arguments for this command, especially since state mv in particular requires both SOURCE and DESTINATION parameters.

You can see in the example below that the command terraspace ultimately invokes is terraform state mv bar, which has dropped the foo parameter.

I also think the docs here for terraspace state mv are wrong, as they also presume mv takes only a single argument ("demo", in the example).

❯ terraspace state mv foo bar
Building .terraspace-cache/us-gov-west-1/dev/stacks/foo
Loading dev providers
Current directory: .terraspace-cache/us-gov-west-1/dev/stacks/foo
=> terraform state mv bar
Usage: terraform [global options] state mv [options] SOURCE DESTINATION

 This command will move an item matched by the address given to the
 destination address. This command can also move to a destination address
 in a completely different state file.

 This can be used for simple resource renaming, moving items to and from
 a module, moving entire modules, and more. And because this command can also
 move data to a completely new state, it can also be used for refactoring
 one configuration into multiple separately managed Terraform configurations.

 This command will output a backup copy of the state prior to saving any
 changes. The backup cannot be disabled. Due to the destructive nature
 of this command, backups are required.

 If you're moving an item to a different state file, a backup will be created
 for each state file.

Options:

  -dry-run                If set, prints out what would've been moved but doesn't
                          actually move anything.

  -lock=false             Don't hold a state lock during the operation. This is
                          dangerous if others might concurrently run commands
                          against the same workspace.

  -lock-timeout=0s        Duration to retry a state lock.

  -ignore-remote-version  A rare option used for the remote backend only. See
                          the remote backend documentation for more information.

  -state, state-out, and -backup are legacy options supported for the local
  backend only. For more information, see the local backend's documentation.
Exactly two arguments expected.

My guess is that there's a bug in the argument parsing for this command, and it's infrequently used enough that it hasn't been encountered and reported yet.