Class: Kitchen::Terraform::Command::Init

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/terraform/command/init.rb

Overview

The working directory is initialized by running a command like the following example:

terraform init \
  -input=false \
  -lock=<lock> \
  -lock-timeout=<lock_timeout>s \
  [-no-color] \
  [-upgrade] \
  -force-copy \
  -backend=true \
  [-backend-config=<backend_configurations[0]> ...] \
  -get=true \
  -get-plugins=true \
  [-plugin-dir=<plugin_directory>] \
  -verify-plugins=true \
  <root_module_directory>

Instance Method Summary collapse

Constructor Details

#initialize(config:) ⇒ Kitchen::Terraform::Command::Init

#initialize prepares a new instance of the class.

Parameters:

  • config (Hash)

    the configuration of the driver.

Options Hash (config:):

  • :backend_configurations (Hash{String=>String})

    Terraform backend configuration arguments to complete a partial backend configuration.

  • :color (Boolean)

    a toggle of colored output from the Terraform client.

  • :command_timeout (Integer)

    the the number of seconds to wait for the command to finish running.

  • :lock (Boolean)

    a toggle of locking for the Terraform state file.

  • :lock_timeout (Integer)

    the number of seconds that the Terraform client will wait for a lock on the state to be obtained during operations.

  • :plugin_directory (String)

    the pathname of the directory which contains customized Terraform provider plugins to install in place of the official Terraform provider plugins.

  • :root_module_directory (String)

    the pathname of the directory which contains the root Terraform module.

  • :upgrade_during_init (Boolean)

    a toggle for upgrading modules and plugins.



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/kitchen/terraform/command/init.rb', line 58

def initialize(config:)
  self.backend_config = ::Kitchen::Terraform::CommandFlag::BackendConfig.new arguments: config.fetch(
    :backend_configurations
  )
  self.color = ::Kitchen::Terraform::CommandFlag::Color.new enabled: config.fetch(:color)
  self.lock = config.fetch :lock
  self.lock_timeout = ::Kitchen::Terraform::CommandFlag::LockTimeout.new duration: config.fetch(:lock_timeout)
  self.plugin_dir = ::Kitchen::Terraform::CommandFlag::PluginDir.new pathname: config.fetch(
    :plugin_directory
  )
  self.upgrade = ::Kitchen::Terraform::CommandFlag::Upgrade.new enabled: config.fetch(:upgrade_during_init)
end

Instance Method Details

#to_sString

Returns the command with flags.

Returns:

  • (String)

    the command with flags.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/kitchen/terraform/command/init.rb', line 72

def to_s
  "init " \
  "-input=false " \
  "-lock=#{lock} " \
  "#{lock_timeout} " \
  "#{color} " \
  "#{upgrade} " \
  "-force-copy " \
  "-backend=true " \
  "#{backend_config} " \
  "-get=true " \
  "-get-plugins=true " \
  "#{plugin_dir} " \
  "-verify-plugins=true"
end