Class: WdiTf::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/wdi_tf/project.rb

Instance Method Summary collapse

Constructor Details

#initialize(file:) ⇒ Project

Returns a new instance of Project.



5
6
7
8
# File 'lib/wdi_tf/project.rb', line 5

def initialize(file:)
    verbose("Loading the Terraform project file.")
    @project = YAML.load_file(file)
end

Instance Method Details

#load_source_filesObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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_infoObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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