Skip to content

Commit

Permalink
Deny interaction when initializing Terraform (#9)
Browse files Browse the repository at this point in the history
The commands will output with DEBUG level which is hidden by default.
So the `tf` just seems to get stuck. Better to error out if interaction
is needed.
  • Loading branch information
tmatilai authored Jan 26, 2018
1 parent e7e8286 commit 21169e3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/yle_tf/action/terraform_init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
class YleTf
module Action
class TerraformInit
TF_CMD_ARGS = %w[-input=false -no-color].freeze

TF_CMD_OPTS = {
env: { 'TF_IN_AUTOMATION' => 'true' }, # Reduces some output
stdout: :debug # Hide the output to the debug level
Expand Down Expand Up @@ -35,18 +37,18 @@ def call(env)
def init_pre_0_9(backend)
cli_args = backend.cli_args
if cli_args
YleTf::System.cmd('terraform', 'remote', 'config', '-no-color', *cli_args, TF_CMD_OPTS)
YleTf::System.cmd('terraform', 'remote', 'config', *TF_CMD_ARGS, *cli_args, TF_CMD_OPTS)
end

Logger.debug('Fetching Terraform modules')
YleTf::System.cmd('terraform', 'get', '-no-color', TF_CMD_OPTS)
YleTf::System.cmd('terraform', 'get', *TF_CMD_ARGS, TF_CMD_OPTS)
end

def init(backend)
Logger.debug('Generating the backend configuration')
backend.generate_config do
Logger.debug('Initializing Terraform')
YleTf::System.cmd('terraform', 'init', '-no-color', TF_CMD_OPTS)
YleTf::System.cmd('terraform', 'init', *TF_CMD_ARGS, TF_CMD_OPTS)
end
end

Expand Down

0 comments on commit 21169e3

Please sign in to comment.