Method: RubyTerraform::ClassMethods#state_push

Defined in:
lib/ruby_terraform.rb

#state_push(parameters = {}, invocation_options = {}) ⇒ Object

Invokes the terraform state push command which updates remote state from a local state file.

This command “pushes” a local state and overwrites remote state with a local state file. The command will protect you against writing an older serial or a different state file lineage unless you pass true for the :force option.

This command works with local state (it will overwrite the local state), but is less useful for this use case.

If :path is “-”, then this command will read the state to push from stdin. Data from stdin is not streamed to the backend: it is loaded completely (until pipe close), verified, and then pushed.

Examples:

Basic Invocation

RubyTerraform.state_push(
  path: 'some/statefile.tfstate')

Parameters:

  • parameters (defaults to: {})

    The parameters used to invoke the command

  • invocation_options (Hash<String, Object>) (defaults to: {})

    Additional options controlling the invocation of the command.

Options Hash (parameters):

  • :path (String)

    The path to the state file to push; when passed “-” will read state from standard input.

  • :chdir (String)

    The path of a working directory to switch to before executing the given subcommand.

  • :force (Boolean) — default: false

    When true, writes the state even if lineages don’t match or the remote serial is higher.

  • :lock (Boolean) — default: true

    When true, locks the state file when locking is supported; when false, does not lock the state file.

  • :lock_timeout (String) — default: "0s"

    The duration to retry a state lock.

  • :ignore_remote_version (Boolean)

    Whether or not to continue even if remote and local Terraform versions are incompatible; this may result in an unusable workspace, and should be used with extreme caution.

Options Hash (invocation_options):

  • :environment (Hash<String, String>)

    A map of environment variables to expose at command invocation time.



1125
1126
1127
1128
# File 'lib/ruby_terraform.rb', line 1125

def state_push(parameters = {}, invocation_options = {})
  exec(RubyTerraform::Commands::StatePush,
       parameters, invocation_options)
end