Class: YleTf::Action::TerraformInit
- Inherits:
-
Object
- Object
- YleTf::Action::TerraformInit
- Defined in:
- lib/yle_tf/action/terraform_init.rb
Instance Method Summary collapse
- #backend_config(config) ⇒ Object
- #backend_proc(backend_type) ⇒ Object
- #call(env) ⇒ Object
- #init(backend) ⇒ Object
- #init_pre_0_9(backend) ⇒ Object
-
#initialize(app) ⇒ TerraformInit
constructor
A new instance of TerraformInit.
Constructor Details
#initialize(app) ⇒ TerraformInit
Returns a new instance of TerraformInit.
10 11 12 |
# File 'lib/yle_tf/action/terraform_init.rb', line 10 def initialize(app) @app = app end |
Instance Method Details
#backend_config(config) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/yle_tf/action/terraform_init.rb', line 46 def backend_config(config) backend_type = config.fetch('backend', 'type').downcase backend_proc = backend_proc(backend_type) klass = backend_proc.call klass.new.backend_config(config) end |
#backend_proc(backend_type) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/yle_tf/action/terraform_init.rb', line 54 def backend_proc(backend_type) backends = Plugin.manager.backends backends.fetch(backend_type.to_sym) do raise Error, "Unknown backend type '#{backend_type}'. " \ "Supported backends: #{backends.keys.join(', ')}" end end |
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/yle_tf/action/terraform_init.rb', line 14 def call(env) config = env[:config] backend = backend_config(config) Logger.debug('Initializing Terraform with backend configuration:') Logger.debug(backend.to_s) if VersionRequirement.pre_0_9?(env[:terraform_version]) init_pre_0_9(backend) else init(backend) end @app.call(env) end |
#init(backend) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/yle_tf/action/terraform_init.rb', line 38 def init(backend) Logger.debug('Generating the backend configuration') backend.generate_config do Logger.debug('Initializing Terraform') YleTf::System.cmd('terraform', 'init', '-no-color') end end |
#init_pre_0_9(backend) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/yle_tf/action/terraform_init.rb', line 30 def init_pre_0_9(backend) cli_args = backend.cli_args YleTf::System.cmd('terraform', 'remote', 'config', *cli_args) if cli_args Logger.debug('Fetching Terraform modules') YleTf::System.cmd('terraform', 'get') end |