module Kitchen::Terraform::Provisioner

Provisioner is the namespace for provisioner strategies.

Public Instance Methods

download_modules() click to toggle source
# File lib/kitchen/terraform/provisioner/converge.rb, line 139
def download_modules
  logger.warn "Downloading the modules needed for the Terraform configuration..."
  command_executor.run command: get, options: options do |standard_output|
  end
  logger.warn "Finished downloading the modules needed for the Terraform configuration."
end
execute_workflow() click to toggle source
# File lib/kitchen/terraform/provisioner/converge.rb, line 146
def execute_workflow
  select_workspace
  download_modules
  validate_files
  build_infrastructure
end
initialize_commands() click to toggle source
# File lib/kitchen/terraform/provisioner/converge.rb, line 153
def initialize_commands
  self.apply = ::Kitchen::Terraform::Command::Apply.new config: complete_config
  self.get = ::Kitchen::Terraform::Command::Get.new
  self.output = ::Kitchen::Terraform::Command::Output.new
  self.workspace_select = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: complete_config
  self.version = ::Kitchen::Terraform::Command::Version.new
end
initialize_outputs_handlers(client:, logger:) click to toggle source
# File lib/kitchen/terraform/provisioner/converge.rb, line 161
def initialize_outputs_handlers(client:, logger:)
  self.outputs_manager = ::Kitchen::Terraform::OutputsManager.new
  self.outputs_parser = ::Kitchen::Terraform::OutputsParser.new
  self.outputs_reader = ::Kitchen::Terraform::OutputsReader.new(
    command_executor: ::Kitchen::Terraform::CommandExecutor.new(
      client: client,
      logger: ::Kitchen::Terraform::DebugLogger.new(logger),
    ),
  )
end
parse_outputs(json_outputs:) { |parsed_outputs: parsed_outputs| ... } click to toggle source
# File lib/kitchen/terraform/provisioner/converge.rb, line 172
def parse_outputs(json_outputs:)
  logger.warn "Parsing the Terraform output variables as JSON..."
  outputs_parser.parse json_outputs: json_outputs do |parsed_outputs:|
    logger.warn "Finished parsing the Terraform output variables as JSON."

    yield parsed_outputs: parsed_outputs
  end
end
read_and_parse_outputs(&block) click to toggle source
# File lib/kitchen/terraform/provisioner/converge.rb, line 181
def read_and_parse_outputs(&block)
  logger.warn "Reading the output variables from the Terraform state..."
  outputs_reader.read command: output, options: options do |json_outputs:|
    logger.warn "Finished reading the output variables from the Terraform state."

    parse_outputs json_outputs: json_outputs, &block
  end
end
read_client_version() click to toggle source
# File lib/kitchen/terraform/provisioner/converge.rb, line 190
def read_client_version
  logger.warn "Reading the Terraform client version..."
  command_executor.run command: version, options: options do |standard_output|
    self.client_version = ::Gem::Version.new standard_output.slice /Terraform v(\d+\.\d+\.\d+)/, 1
  end
  logger.warn "Finished reading the Terraform client version."
end
save_outputs(parsed_outputs:, state:) click to toggle source
# File lib/kitchen/terraform/provisioner/converge.rb, line 198
def save_outputs(parsed_outputs:, state:)
  logger.warn "Writing the output variables to the Kitchen instance state..."
  outputs_manager.save outputs: parsed_outputs, state: state
  logger.warn "Finished writing the output variables to the Kitchen instance state."
end
save_variables_and_outputs(state:) click to toggle source
# File lib/kitchen/terraform/provisioner/converge.rb, line 204
def save_variables_and_outputs(state:)
  read_and_parse_outputs do |parsed_outputs:|
    save_outputs parsed_outputs: parsed_outputs, state: state
  end
  logger.warn "Writing the input variables to the Kitchen instance state..."
  variables_manager.save variables: variables, state: state
  logger.warn "Finished writing the input variables to the Kitchen instance state."
end
select_workspace() click to toggle source
# File lib/kitchen/terraform/provisioner/converge.rb, line 213
def select_workspace
  logger.warn "Selecting the #{workspace_name} Terraform workspace..."
  command_executor.run command: workspace_select, options: options do |standard_output|
  end
  logger.warn "Finished selecting the #{workspace_name} Terraform workspace."
end
validate_files() click to toggle source
# File lib/kitchen/terraform/provisioner/converge.rb, line 220
def validate_files
  logger.warn "Validating the Terraform configuration files..."
  command_executor.run(
    command: ::Kitchen::Terraform::Command::ValidateFactory.new(version: client_version)
      .build(config: complete_config),
    options: options,
  ) do |standard_output|
  end
  logger.warn "Finished validating the Terraform configuration files."
end