class Kitchen::Terraform::VariablesManager

VariablesManager manages Terraform variables in the Kitchen instance state.

Attributes

state_key[RW]

Public Class Methods

new() click to toggle source

initialize prepares a new instance of the class.

@return [Kitchen::Terraform::VariablesManager]

# File lib/kitchen/terraform/variables_manager.rb, line 26
def initialize
  self.state_key = :kitchen_terraform_variables
end

Public Instance Methods

load(variables:, state:) click to toggle source

load reads the Terraform variables from the Kitchen instance state and writes them to a container.

@param variables [Hash] the container to which the Terraform variables will be written. @param state [Hash] the Kitchen instance state from which the Terraform variables will be read. @return [self]

# File lib/kitchen/terraform/variables_manager.rb, line 35
def load(variables:, state:)
  variables.replace state.fetch state_key

  self
rescue ::KeyError => error
  raise(
    ::Kitchen::ClientError,
    "Reading the Terraform input variables from the Kitchen instance state failed due to the absence of the " \
    "'#{state_key}' key. This error could indicate that the Kitchen-Terraform provisioner plugin was not used " \
    "to converge the Kitchen instance."
  )
end
save(variables:, state:) click to toggle source

save reads the Terraform variables from a container and writes them to the Kitchen instance state.

@param variables [Hash] the container from which the Terraform variables will be read. @param state [Hash] the Kitchen instance state to which the Terraform variables will be written. @return [self]

# File lib/kitchen/terraform/variables_manager.rb, line 53
def save(variables:, state:)
  state.store state_key, variables

  self
end