class Biosphere::TerraformProxy

Attributes

actions[RW]
export[RW]
resources[RW]
src_path[R]

Public Class Methods

new(script_name, suite) click to toggle source
# File lib/biosphere/terraformproxy.rb, line 113
def initialize(script_name, suite)
    @script_name = script_name
    @src_path = [File.dirname(script_name)]

    @export = {
        "provider" => {},
        "resource" => {},
        "variable" => {},
        "output" => {}
    }
    @suite = suite
    @actions = {}
    @deployments = []

end

Public Instance Methods

action(name, description, &block) click to toggle source
# File lib/biosphere/terraformproxy.rb, line 172
def action(name, description, &block)
    @actions[name] = {
        :name => name,
        :description => description,
        :block => block,
        :location => caller[0],
        :src_path => @src_path.clone
    }
end
call_action(name, context) click to toggle source
# File lib/biosphere/terraformproxy.rb, line 182
def call_action(name, context)
    context.caller = self
    context.src_path = @actions[name][:src_path]

    context.instance_eval(&@actions[name][:block])
end
find_dir(dirname) click to toggle source
# File lib/biosphere/terraformproxy.rb, line 146
def find_dir(dirname)
    return Pathname.new(@src_path.last).cleanpath.to_s
end
find_file(filename) click to toggle source
# File lib/biosphere/terraformproxy.rb, line 141
def find_file(filename)
    src_path = Pathname.new(@src_path.last + "/" + File.dirname(filename)).cleanpath.to_s
    return src_path + "/" + File.basename(filename)
end
id_of(type,name) click to toggle source
# File lib/biosphere/terraformproxy.rb, line 189
def id_of(type,name)
    "${#{type}.#{name}.id}"
end
load(filename) click to toggle source
# File lib/biosphere/terraformproxy.rb, line 150
def load(filename)
    src_path = Pathname.new(@src_path.last + "/" + File.dirname(filename)).cleanpath.to_s
    # Push current src_path and overwrite @src_path so that it tracks recursive loads
    @src_path << src_path
    $current_biosphere_path_stack = src_path

    #puts "Trying to open file: " + src_path + "/" + File.basename(filename)
    if File.exists?(src_path + "/" + File.basename(filename))
        self.from_file(src_path + "/" + File.basename(filename))
    elsif File.exists?(src_path + "/" + File.basename(filename) + ".rb")
        self.from_file(src_path + "/" + File.basename(filename) + ".rb")
    else
        raise "Can't find #{filename}"
    end

    # Restore it as we are unwinding the call stack
    @src_path.pop
    $current_biosphere_path_stack = @src_path.last
end
load_from_block(&block) click to toggle source
# File lib/biosphere/terraformproxy.rb, line 137
def load_from_block(&block)
    self.instance_eval(&block)
end
load_from_file() click to toggle source
# File lib/biosphere/terraformproxy.rb, line 133
def load_from_file()
    self.from_file(@script_name)
end
output_of(type, name, *values) click to toggle source
# File lib/biosphere/terraformproxy.rb, line 193
def output_of(type, name, *values)
    "${#{type}.#{name}.#{values.join(".")}}"
end
register(deployment) click to toggle source
# File lib/biosphere/terraformproxy.rb, line 129
def register(deployment)
    @suite.register(deployment)
end
state() click to toggle source
# File lib/biosphere/terraformproxy.rb, line 197
def state
    return @suite.state
end
suite() click to toggle source
# File lib/biosphere/terraformproxy.rb, line 201
def suite
    return @suite
end