Class: Kitchen::Terraform::OutputsManager

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

Overview

OutputsManager manages Terraform outputs in the Kitchen instance state.

Instance Method Summary collapse

Constructor Details

#initializeKitchen::Terraform::OutputsManager

#initialize prepares a new instance of the class.



26
27
28
# File 'lib/kitchen/terraform/outputs_manager.rb', line 26

def initialize
  self.state_key = :kitchen_terraform_outputs
end

Instance Method Details

#load(outputs:, state:) ⇒ self

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

Parameters:

  • outputs (Hash)

    the container to which the Terraform outputs will be written.

  • state (Hash)

    the Kitchen instance state from which the Terraform outputs will be read.

Returns:

  • (self)


35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/kitchen/terraform/outputs_manager.rb', line 35

def load(outputs:, state:)
  outputs.replace state.fetch state_key

  self
rescue ::KeyError
  raise(
    ::Kitchen::ClientError,
    "Reading the Terraform output 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(outputs:, state:) ⇒ self

#save reads the Terraform outputs from container and writes them to the Kitchen instance state.

Parameters:

  • outputs (Hash)

    the container from which the Terraform outputs will be read.

  • state (Hash)

    the Kitchen instance state to which the Terraform outputs will be written.

Returns:

  • (self)


53
54
55
56
57
# File 'lib/kitchen/terraform/outputs_manager.rb', line 53

def save(outputs:, state:)
  state.store state_key, outputs.dup

  self
end