class WdiTf::Project

Public Class Methods

new(file:) click to toggle source
# File lib/wdi_tf/project.rb, line 5
def initialize(file:)
    verbose("Loading the Terraform project file.")
    @project = YAML.load_file(file)
end

Public Instance Methods

load_source_files() click to toggle source
# File lib/wdi_tf/project.rb, line 10
def load_source_files
    files = {}
    conflict = false
    
    if @project.has_key?('source')
        verbose("Load the source files from the Project file.")
        
        @project['source'].each do |file|
            if Dir.exists?(file)
                Dir["#{ file }/*.tf"].each do |f|
                    @project['source'].push(f)
                end
            else
                base = File.basename(file)
                
                if files.has_key?(base)
                    verbose("  conflict #{ file } (local file with same name)")
                    conflict = true
                else
                    if File.extname(file) == ".tf"
                        verbose("  using #{ file }")
                        files[base] = file
                    else
                        verbose("  skipping #{ file } (not a *.tf file)")
                    end
                end
            end
        end
    end
    
    if conflict
        error(msg: "One or more files are conflicting with files already in the workspace with the same name.", code: 1)
    end
    
    return files
end
load_vars_info() click to toggle source
# File lib/wdi_tf/project.rb, line 47
def load_vars_info
    vars = {}
    
    if @project.has_key?('variables')
        verbose("Load the variables from the Project file")
        
        @project['variables'].each do |var, val|
            verbose("  #{ var } = \"#{ val }\"")
            vars[var] = val
        end
    end
    
    return vars
end