Manipulating State

The command terraform state can be used to manipulate your terraform state file.

Command

Description

terraform state list

List the state

terraform state mv

move / rename an item in the state

terraform state pull

Pull current state and output to stdout

terraform state push

Overwrite state by pushing local file to statefile

terraform state replace-provider

Replace a provider in the state file

terraform state rm

Remove item from state

terraform state show

Show item in state

Few scenarios where we might have to modify the state:

  • When upgrading between versions

  • When we want to rename a resource in terraform without recraeting it

  • When we changed a key in a for-each but don't want to recreate the resource

  • Change position of a resource in a list

  • When we want to stop managing a resource, but we don't want to destroy the resource

  • When we want to show the attributes un the state of a resource

Last updated