Module: TerraformWrapper

Defined in:
lib/terraform-wrapper.rb,
lib/terraform-wrapper/common.rb,
lib/terraform-wrapper/version.rb,
lib/terraform-wrapper/tasks/fmt.rb,
lib/terraform-wrapper/tasks/init.rb,
lib/terraform-wrapper/tasks/plan.rb,
lib/terraform-wrapper/shared/code.rb,
lib/terraform-wrapper/tasks/apply.rb,
lib/terraform-wrapper/tasks/clean.rb,
lib/terraform-wrapper/tasks/taint.rb,
lib/terraform-wrapper/tasks/binary.rb,
lib/terraform-wrapper/tasks/import.rb,
lib/terraform-wrapper/shared/binary.rb,
lib/terraform-wrapper/shared/config.rb,
lib/terraform-wrapper/shared/latest.rb,
lib/terraform-wrapper/shared/logger.rb,
lib/terraform-wrapper/shared/runner.rb,
lib/terraform-wrapper/tasks/destroy.rb,
lib/terraform-wrapper/tasks/upgrade.rb,
lib/terraform-wrapper/shared/logging.rb,
lib/terraform-wrapper/tasks/validate.rb,
lib/terraform-wrapper/shared/provider.rb,
lib/terraform-wrapper/shared/variables.rb,
lib/terraform-wrapper/tasks/plandestroy.rb,
lib/terraform-wrapper/shared/auths/azure.rb,
lib/terraform-wrapper/shared/auths/common.rb,
lib/terraform-wrapper/shared/backends/aws.rb,
lib/terraform-wrapper/shared/backends/azure.rb,
lib/terraform-wrapper/shared/backends/local.rb,
lib/terraform-wrapper/shared/backends/common.rb

Defined Under Namespace

Modules: Shared, Tasks

Constant Summary collapse

VERSION =
'1.3.3'

Class Method Summary collapse

Class Method Details

.create_directory(directory:, exists: true, purpose: nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/terraform-wrapper/common.rb', line 7

def self.create_directory(directory:, exists: true, purpose: nil)
  return exists if File.directory?(directory)

  result = false

  if not purpose.nil? and purpose.kind_of?(String) and not purpose.strip.empty? then
    @logger.info("Creating directory for: #{purpose}, path: #{directory}")
  else
    @logger.info("Creating directory: #{directory}")
  end

  FileUtils.mkdir_p(directory)

  result = File.directory?(directory)
end

.deployment_tasks(component:, service:, options: {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/terraform-wrapper.rb', line 24

def self.deployment_tasks(component:, service:, options: {})
  @logger.info("Building tasks for service: #{service}, component: #{component}...")

  @logger.fatal('Options must be specified as a hash!') unless options.is_a?(Hash)

  binary_options = {}
  binary_options['base'] =
    options.key?('binary-base') ? options['binary-base'] : File.join(Dir.pwd, 'vendor', 'terraform')
  binary_options['version'] =
    options.key?('binary-version') ? options['binary-version'] : Shared::Latest.instance.version

  code_options = {}
  code_options['base'] = options.key?('code-base') ? options['code-base'] : File.join(Dir.pwd, 'terraform')
  code_options['name'] = component

  config_options = {}
  config_options['auth-azure'] =
    options.key?('config-auth-azure') ? options['config-auth-azure'] : false
  config_options['auth-azure-options'] =
    options.key?('config-auth-azure-options') ? options['config-auth-azure-options'] : {}
  config_options['base'] =
    options.key?('config-base') ? options['config-base'] : File.join(Dir.pwd, 'config')
  config_options['backend'] =
    options.key?('config-backend') ? options['config-backend'] : 'local'
  config_options['backend-options'] =
    options.key?('config-backend-options') ? options['config-backend-options'] : {}
  config_options['service'] = service

  provider_options = {}
  provider_options['platforms'] = options.key?('provider-platforms') ? options['provider-platforms'] : []

  provider = TerraformWrapper::Shared::Provider.new(options: provider_options)
  binary   = TerraformWrapper::Shared::Binary.new(options: binary_options, provider: provider)
  code     = TerraformWrapper::Shared::Code.new(options: code_options)

  tasks = []
  tasks << TerraformWrapper::Tasks::Apply.new(binary: binary, code: code, options: config_options)
  tasks << TerraformWrapper::Tasks::Binary.new(binary: binary)
  tasks << TerraformWrapper::Tasks::Clean.new(code: code)
  tasks << TerraformWrapper::Tasks::Destroy.new(binary: binary, code: code, options: config_options)
  tasks << TerraformWrapper::Tasks::Fmt.new(binary: binary, code: code)
  tasks << TerraformWrapper::Tasks::Import.new(binary: binary, code: code, options: config_options)
  tasks << TerraformWrapper::Tasks::Init.new(binary: binary, code: code, options: config_options)
  tasks << TerraformWrapper::Tasks::Plan.new(binary: binary, code: code, options: config_options)
  tasks << TerraformWrapper::Tasks::PlanDestroy.new(binary: binary, code: code, options: config_options)
  tasks << TerraformWrapper::Tasks::Taint.new(binary: binary, code: code, options: config_options)
  tasks << TerraformWrapper::Tasks::Upgrade.new(binary: binary, code: code)
  tasks << TerraformWrapper::Tasks::Validate.new(binary: binary, code: code)
  tasks
end

.find(base:, name:, exts:, description: "File") ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/terraform-wrapper/common.rb', line 25

def self.find(base:, name:, exts:, description: "File")
  exts.each do |ext|
    path = File.join(base, name + ext)
    return path if File.file?(path)
  end

  @logger.fatal("#{description} name: #{name} not found in location: #{base}!")
end