Method: RubyTerraform::ClassMethods#init

Defined in:
lib/ruby_terraform.rb

#init(parameters = {}) ⇒ Object

Invokes the terraform init command which initializes a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.

This is the first command that should be run for any new or existing Terraform configuration per machine. This sets up all the local data necessary to run Terraform that is typically not committed to version control.

This command is always safe to run multiple times. Though subsequent runs may give errors, this command will never delete your configuration or state. Even so, if you have important information, please back it up prior to running this command, just in case.

Examples:

Basic Invocation

RubyTerraform.init(
  from_module: 'some/module/path',
  path: 'infra/module')

Parameters:

  • parameters (defaults to: {})

    The parameters used to invoke the command

Options Hash (parameters):

  • :path (String)

    The path to initialize; defaults to the current directory (deprecated in terraform 0.14, removed in terraform 0.15, use :chdir instead).

  • :chdir (String)

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

  • :backend (Boolean) — default: true

    Whether or not to configure the backend for this configuration.

  • :backend_config (Hash<String,Object>)

    A map of backend specific configuration parameters.

  • :force_copy (Boolean) — default: false

    If true, suppresses prompts about copying state data; this is equivalent to providing a “yes” to all confirmation prompts.

  • :from_module (String)

    copies the contents of the given module into the target directory before initialization.

  • :get (Boolean) — default: true

    Whether or not to download any modules for this configuration.

  • :get_plugins (Boolean) — default: true

    Whether or not to install plugins for this configuration (deprecated, removed in terraform 0.15).

  • :input (Boolean) — default: true

    When false, will not ask for input for variables not directly set.

  • :lock (Boolean) — default: true

    When true, locks the state file when locking is supported; when false, does not lock the state file (deprecated, removed in terraform 0.15).

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

    The duration to retry a state lock (deprecated, removed in terraform 0.15).

  • :no_color (Boolean) — default: false

    Whether or not the output from the command should be in color.

  • :plugin_dir (String)

    The path to a directory containing plugin binaries; this overrides all default search paths for plugins, and prevents the automatic installation of plugins; if both :plugin_dir and :plugin_dirs are provided, all plugin directories will be passed to Terraform.

  • :plugin_dirs+: (Array<String>)

    An array of paths to directories containing plugin binaries; this overrides all default search paths for plugins, and prevents the automatic installation of plugins; if both :plugin_dir and :plugin_dirs are provided, all plugin directories will be passed to Terraform.

  • :reconfigure (Boolean) — default: false

    If true, reconfigures the backend, ignoring any saved configuration.

  • :upgrade (Boolean) — default: false

    If true, when installing modules or plugins, ignores previously-downloaded objects and installs the latest version allowed within configured constraints.

  • :verify_plugins (Boolean) — default: true

    Whether or not to verify plugins for this configuration (deprecated, removed in terraform 0.15).

  • :lockfile (String)

    Sets a dependency lockfile mode; currently only “readonly” is valid.



468
469
470
# File 'lib/ruby_terraform.rb', line 468

def init(parameters = {})
  exec(RubyTerraform::Commands::Init, parameters)
end