Method: RubyTerraform::ClassMethods#apply

Defined in:
lib/ruby_terraform.rb

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

Invokes the terraform apply command which creates or updates infrastructure according to terraform configuration files in the provided directory.

By default, terraform will generate a new plan and present it for approval before taking any action. Alternatively, the command accepts a plan file created by a previous invocation, in which case terraform will take the actions described in that plan without any confirmation prompt.

Examples:

Basic Invocation

RubyTerraform.apply(
  directory: 'infra/networking',
  vars: {
    region: 'eu-central'
  })

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):

  • :directory (String)

    The path to a directory containing terraform configuration (deprecated in terraform 0.14, removed in terraform 0.15, use :chdir instead).

  • :plan (String)

    The path to a pre-computed plan to be applied.

  • :chdir (String)

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

  • :auto_approve (Boolean) — default: false

    If true, skips interactive approval of the generated plan before applying.

  • :backup (String)

    The path to backup the existing state file before modifying; defaults to the :state_out path with “.backup” extension; set :no_backup to true to skip backups entirely.

  • :compact_warnings (Boolean) — default: false

    When true, if terraform produces any warnings that are not accompanied by errors, they are shown in a more compact form that includes only the summary messages.

  • :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.

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

    The duration to retry a state lock.

  • :no_backup (Boolean) — default: false

    When true, no backup file will be written.

  • :no_color (Boolean) — default: false

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

  • :parallelism (Integer) — default: 10

    The number of parallel resource operations.

  • :refresh (Boolean) — default: true

    When true, updates state prior to checking for differences; when false uses locally available state; this has no effect when :plan is provided.

  • :replace (String)

    Force replacement of a resource instance using its resource address. If the apply would’ve normally produced an update or no-op action for this instance, Terraform will replace it instead.

  • :replaces (Array<String>)

    An array of resource addresses to replace; if both replace and replaces are provided, all resources will be replaced.

  • :state (String) — default: "terraform.tfstate"

    The path to the state file from which to read state and in which to store state (unless :state_out is specified).

  • :state_out (String)

    The path to write state to that is different than :state; this can be used to preserve the old state.

  • :target (String)

    The address of a resource to target; if both :target and :targets are provided, all targets will be passed to terraform.

  • :targets (Array<String>)

    An array of resource addresses to target; if both :target and :targets are provided, all targets will be passed to terraform.

  • :vars (Hash<String, Object>)

    A map of variables to be passed to the terraform configuration.

  • :var_file (String)

    The path to a terraform var file; if both :var_file and :var_files are provided, all var files will be passed to terraform.

  • :var_files (Array<String>)

    An array of paths to terraform var files; if both :var_file and :var_files are provided, all var files will be passed to terraform.

Options Hash (invocation_options):

  • :environment (Hash<String, String>)

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



111
112
113
# File 'lib/ruby_terraform.rb', line 111

def apply(parameters = {}, invocation_options = {})
  exec(RubyTerraform::Commands::Apply, parameters, invocation_options)
end