class TerraformWrapper::Shared::Backends::Local

Attributes

path[R]

Public Class Methods

new(options:, variables:) click to toggle source
# File lib/terraform-wrapper/shared/backends/local.rb, line 31
def initialize(options:, variables:)
  construct(options: options, variables: variables)
end

Public Instance Methods

hash() click to toggle source
# File lib/terraform-wrapper/shared/backends/local.rb, line 37
def hash()
  return {
    "path" => @path
  }
end

Private Instance Methods

specific() click to toggle source
# File lib/terraform-wrapper/shared/backends/local.rb, line 49
def specific()
  path = @options.key?("path") ? @options["path"] : File.join(Dir.pwd, "state", "terraform", "%{config}", "%{component}" + @@ext)

  logger.fatal("Local backend path must be a string!") unless path.kind_of?(String)
  logger.fatal("Local backend path must not be blank!") if path.strip.empty?

  @variables.core.keys.map{ |sym| sym.to_s }.each do |core|
    next if (core == "service") and (path.include?(Dir.pwd))
    logger.fatal("Local backend path must include %{#{core}}.") unless path.include?("%{#{core}}")
  end

  begin
    path = path % @variables.identifiers
  rescue
    logger.fatal("Local backend options contain identifiers that are not included in the configuration file!")
  end

  directory = File.dirname(path)

  logger.fatal("Failed to create state directory: #{directory}") unless ::TerraformWrapper.create_directory(directory: directory, purpose: "state")

  @path = path
end