Module: Proteus::Helpers::PathHelpers

Instance Method Summary collapse

Instance Method Details

#config_dirObject



26
27
28
# File 'lib/proteus/helpers/path_helpers.rb', line 26

def config_dir
  File.join(root_path, 'config')
end

#config_pathObject



30
31
32
# File 'lib/proteus/helpers/path_helpers.rb', line 30

def config_path
  File.join(config_dir, 'config.yaml')
end

#context_path(context) ⇒ Object Also known as: context_root_path



38
39
40
# File 'lib/proteus/helpers/path_helpers.rb', line 38

def context_path(context)
  File.join(contexts_path, context)
end

#context_temp_directory(context) ⇒ Object



42
43
44
# File 'lib/proteus/helpers/path_helpers.rb', line 42

def context_temp_directory(context)
  File.join(context_path(context), '.tmp')
end

#contexts_pathObject



34
35
36
# File 'lib/proteus/helpers/path_helpers.rb', line 34

def contexts_path
  File.join(root_path, 'contexts')
end

#environments_path(context) ⇒ Object



48
49
50
# File 'lib/proteus/helpers/path_helpers.rb', line 48

def environments_path(context)
  File.join(context_path(context), 'environments')
end

#module_config_path(context, module_name) ⇒ Object



73
74
75
# File 'lib/proteus/helpers/path_helpers.rb', line 73

def module_config_path(context, module_name)
  File.join(module_path(context, module_name), 'config')
end

#module_data_path(context, module_name) ⇒ Object



89
90
91
# File 'lib/proteus/helpers/path_helpers.rb', line 89

def module_data_path(context, module_name)
  File.join(module_config_path(context, module_name), 'data')
end

#module_hooks_path(context, module_name) ⇒ Object



85
86
87
# File 'lib/proteus/helpers/path_helpers.rb', line 85

def module_hooks_path(context, module_name)
  File.join(module_config_path(context, module_name), 'hooks')
end

#module_io_file(context, module_name) ⇒ Object



81
82
83
# File 'lib/proteus/helpers/path_helpers.rb', line 81

def module_io_file(context, module_name)
  File.read(File.join(module_path(context, module_name), 'io.tf'))
end

#module_path(context, module_name) ⇒ Object



64
65
66
# File 'lib/proteus/helpers/path_helpers.rb', line 64

def module_path(context, module_name)
  File.join(modules_path(context), module_name)
end

#module_templates_path(context, module_name) ⇒ Object



77
78
79
# File 'lib/proteus/helpers/path_helpers.rb', line 77

def module_templates_path(context, module_name)
  File.join(module_path(context, module_name), 'config', 'templates')
end

#modules_path(context) ⇒ Object



68
69
70
# File 'lib/proteus/helpers/path_helpers.rb', line 68

def modules_path(context)
  File.join(context_path(context), 'modules')
end

#plan_file(context, environment) ⇒ Object



56
57
58
# File 'lib/proteus/helpers/path_helpers.rb', line 56

def plan_file(context, environment)
  File.join(context_temp_directory(context), "terraform.#{environment}.tfplan")
end

#root_pathObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/proteus/helpers/path_helpers.rb', line 6

def root_path
  if ARGV.size == 1 && ARGV[0] == 'init'
    return Dir.pwd
  end

  path = ENV['PROTEUS_ROOT'].present? ? ENV['PROTEUS_ROOT'] : Dir.pwd

  unless File.directory?(File.join(path, 'contexts'))
    say "Can't find a contexts directory in #{path}. Exiting.", :red
    exit 1
  end

  unless File.directory?(File.join(path, 'config'))
    say "Can't find a config directory in #{path}. Exiting.", :red
    exit 1
  end

  File.expand_path(path)
end

#state_file(context, environment) ⇒ Object



60
61
62
# File 'lib/proteus/helpers/path_helpers.rb', line 60

def state_file(context, environment)
  File.join(context_root_path(context), '.terraform',  'terraform.tfstate')
end

#var_file(context, environment) ⇒ Object



52
53
54
# File 'lib/proteus/helpers/path_helpers.rb', line 52

def var_file(context, environment)
  File.join(environments_path(context), "terraform.#{environment}.tfvars")
end