Class: YleTf

Inherits:
Object
  • Object
show all
Defined in:
lib/yle_tf.rb,
lib/yle_tf/cli.rb,
lib/yle_tf/error.rb,
lib/yle_tf/action.rb,
lib/yle_tf/config.rb,
lib/yle_tf/logger.rb,
lib/yle_tf/plugin.rb,
lib/yle_tf/system.rb,
lib/yle_tf/tf_hook.rb,
lib/yle_tf/version.rb,
lib/yle_tf/vars_file.rb,
lib/yle_tf/config/erb.rb,
lib/yle_tf/config/file.rb,
lib/yle_tf/action/tmpdir.rb,
lib/yle_tf/config/loader.rb,
lib/yle_tf/plugin/loader.rb,
lib/yle_tf/action/builder.rb,
lib/yle_tf/action/command.rb,
lib/yle_tf/backend_config.rb,
lib/yle_tf/plugin/manager.rb,
lib/yle_tf/tf_hook/runner.rb,
lib/yle_tf/action/tf_hooks.rb,
lib/yle_tf/config/defaults.rb,
lib/yle_tf/logger/colorize.rb,
lib/yle_tf/action/load_config.rb,
lib/yle_tf/plugin/action_hook.rb,
lib/yle_tf/system/io_handlers.rb,
lib/yle_tf/version_requirement.rb,
lib/yle_tf/action/verify_tf_env.rb,
lib/yle_tf/system/output_logger.rb,
lib/yle_tf/action/terraform_init.rb,
lib/yle_tf/action/copy_root_module.rb,
lib/yle_tf/action/generate_vars_file.rb,
lib/yle_tf/system/tf_hook_output_logger.rb,
lib/yle_tf/action/verify_terraform_version.rb

Defined Under Namespace

Modules: Action, Logger Classes: BackendConfig, CLI, Config, Plugin, System, TfHook, VarsFile, VersionRequirement

Constant Summary collapse

Error =

Base class for yle_tf errors

Class.new(StandardError)
VERSION =
'0.3.0'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tf_options, tf_env, tf_command, tf_command_args = []) ⇒ YleTf

Returns a new instance of YleTf.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/yle_tf.rb', line 12

def initialize(tf_options, tf_env, tf_command, tf_command_args = [])
  Logger.debug("YleTf version: #{VERSION}")
  Logger.debug("Ruby version: #{RUBY_VERSION}")
  Logger.debug("tf_options: #{tf_options.inspect}")
  Logger.debug("tf_env: #{tf_env.inspect}")
  Logger.debug("tf_command: #{tf_command.inspect}")
  Logger.debug("tf_command_args: #{tf_command_args.inspect}")

  @tf_options      = tf_options
  @tf_env          = tf_env
  @tf_command      = tf_command
  @tf_command_args = tf_command_args

  Plugin::Loader.load_plugins
end

Instance Attribute Details

#actionsObject



37
38
39
# File 'lib/yle_tf.rb', line 37

def actions
  @actions ||= build_action_stack
end

#tf_commandObject (readonly)

Returns the value of attribute tf_command.



9
10
11
# File 'lib/yle_tf.rb', line 9

def tf_command
  @tf_command
end

#tf_command_argsObject (readonly)

Returns the value of attribute tf_command_args.



9
10
11
# File 'lib/yle_tf.rb', line 9

def tf_command_args
  @tf_command_args
end

#tf_envObject (readonly)

Returns the value of attribute tf_env.



9
10
11
# File 'lib/yle_tf.rb', line 9

def tf_env
  @tf_env
end

#tf_optionsObject (readonly)

Returns the value of attribute tf_options.



9
10
11
# File 'lib/yle_tf.rb', line 9

def tf_options
  @tf_options
end

Instance Method Details

#action_envObject



55
56
57
58
59
60
61
62
63
# File 'lib/yle_tf.rb', line 55

def action_env
  {
    tf_options:      tf_options,
    tf_env:          tf_env,
    tf_command:      tf_command,
    tf_command_args: tf_command_args,
    tfvars:          default_tfvars,
  }
end

#apply_action_hooksObject



47
48
49
50
51
52
53
# File 'lib/yle_tf.rb', line 47

def apply_action_hooks
  hooks = Plugin.manager.action_hooks
  Logger.debug("Applying #{hooks.length} action hooks")
  Plugin::ActionHook.new(actions).tap do |h|
    hooks.each { |hook_proc| hook_proc.call(h) }
  end
end

#build_action_stackObject



41
42
43
44
45
# File 'lib/yle_tf.rb', line 41

def build_action_stack
  command_data = Plugin.manager.commands[tf_command]
  command_proc = command_data[:proc]
  command_proc.call
end

#default_tfvarsObject



65
66
67
68
69
# File 'lib/yle_tf.rb', line 65

def default_tfvars
  {
    'env' => tf_env,
  }
end

#run(env = {}) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/yle_tf.rb', line 28

def run(env = {})
  Logger.debug('Building and running the stack')
  apply_action_hooks
  Logger.debug("actions: #{actions.inspect}")
  env.merge!(action_env)
  Logger.debug("env: #{env.inspect}")
  actions.call(env)
end