yle_tf 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 89780c316c7e6aba53458bb71b37b8c050b41eca
4
- data.tar.gz: '068f7d640747c7b3fb4d36d3e31878425dc3078a'
2
+ SHA256:
3
+ metadata.gz: 95dbeb71fae7b996332d0392c7e1c0710e8cfce4898be87574817308626ca9cf
4
+ data.tar.gz: 90b6c63351a1e30f6bee26825274cbca0aaeb8d5cd05d1a256bef8f9d8408c81
5
5
  SHA512:
6
- metadata.gz: 55746eb13356d123a2d29db472425230f4bf1de9a41de21ab09ce2372b19c6b9be72ec97444ed3f7ab801a4e52335462ad933d328e58b10f183888a29bee0a48
7
- data.tar.gz: 4161e0d3d3a127eed59e3266604b08ff069a6c52e97e90614568464213dab3636f9a05c29d5de67fbcc986ad310609a561838133a75fa2d263239794bfb0ed53
6
+ metadata.gz: 7a00736661dba53738ab1c44ac48f990264c955c0747c50795a01c893bf9ac1e69da9c82e66a62edbe0a3464d0c42a6ceb84e1f41a40da98e22a15231c7e54cb
7
+ data.tar.gz: a97abc8c99fb34b8db0881ef3c972f706a03667759aeca420b38dda4f3c549724b0125f3909ff9b77346d1e4119f99ec07e208820a1acfc38cfbe87714cff6ae
data/bin/tf CHANGED
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ # Catch Ctrl+C to avoid stack traces
4
+ Signal.trap('INT') { abort }
5
+
3
6
  require 'bundler/setup' if File.exist?(File.expand_path('../../Gemfile', __FILE__))
4
7
  require 'yle_tf/cli'
5
8
 
@@ -7,6 +7,13 @@ require 'yle_tf/version_requirement'
7
7
  class YleTf
8
8
  module Action
9
9
  class TerraformInit
10
+ TF_CMD_ARGS = %w[-input=false -no-color].freeze
11
+
12
+ TF_CMD_OPTS = {
13
+ env: { 'TF_IN_AUTOMATION' => 'true' }, # Reduces some output
14
+ stdout: :debug # Hide the output to the debug level
15
+ }.freeze
16
+
10
17
  def initialize(app)
11
18
  @app = app
12
19
  end
@@ -30,20 +37,18 @@ class YleTf
30
37
  def init_pre_0_9(backend)
31
38
  cli_args = backend.cli_args
32
39
  if cli_args
33
- YleTf::System.cmd('terraform', 'remote', 'config',
34
- '-no-color', *cli_args,
35
- stdout: :debug)
40
+ YleTf::System.cmd('terraform', 'remote', 'config', *TF_CMD_ARGS, *cli_args, TF_CMD_OPTS)
36
41
  end
37
42
 
38
43
  Logger.debug('Fetching Terraform modules')
39
- YleTf::System.cmd('terraform', 'get', '-no-color', stdout: :debug)
44
+ YleTf::System.cmd('terraform', 'get', *TF_CMD_ARGS, TF_CMD_OPTS)
40
45
  end
41
46
 
42
47
  def init(backend)
43
48
  Logger.debug('Generating the backend configuration')
44
49
  backend.generate_config do
45
50
  Logger.debug('Initializing Terraform')
46
- YleTf::System.cmd('terraform', 'init', '-no-color', stdout: :debug)
51
+ YleTf::System.cmd('terraform', 'init', *TF_CMD_ARGS, TF_CMD_OPTS)
47
52
  end
48
53
  end
49
54
 
@@ -12,9 +12,7 @@ class YleTf
12
12
  config = env[:config]
13
13
  all_envs = VarsFile.list_all_envs(config)
14
14
 
15
- if all_envs.empty?
16
- raise Error, "No Terraform vars files found in '#{VarsFile::ENV_DIR}/'"
17
- end
15
+ raise(Error, "No Terraform vars files found in '#{VarsFile::ENV_DIR}/'") if all_envs.empty?
18
16
 
19
17
  if !all_envs.include?(config.tf_env)
20
18
  raise Error, "Terraform vars file not found for the '#{config.tf_env}' " \
data/lib/yle_tf/cli.rb CHANGED
@@ -68,6 +68,8 @@ class YleTf
68
68
  self.debug = true if @tf_options[:debug]
69
69
  YleTf::Logger.color = false if @tf_options[:no_color]
70
70
  end
71
+ # rubocop:enable Metrics/AbcSize, Metrics/BlockLength, Metrics/MethodLength
72
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
71
73
 
72
74
  # Returns `Symbol` for the arg, e.g. `"--foo-bar"` -> `:foo_bar`
73
75
  def key(arg)
@@ -8,15 +8,11 @@ class YleTf
8
8
  end
9
9
 
10
10
  def before(existing, new, *args, &block)
11
- if actions.include?(existing)
12
- actions.insert_before(existing, new, *args, &block)
13
- end
11
+ actions.insert_before(existing, new, *args, &block) if actions.include?(existing)
14
12
  end
15
13
 
16
14
  def after(existing, new, *args, &block)
17
- if actions.include?(existing)
18
- actions.insert_after(existing, new, *args, &block)
19
- end
15
+ actions.insert_after(existing, new, *args, &block) if actions.include?(existing)
20
16
  end
21
17
  end
22
18
  end
@@ -78,13 +78,7 @@ class YleTf
78
78
  def self.io_input(source)
79
79
  lambda do |target, *|
80
80
  Thread.new do
81
- begin
82
- while (data = source.readpartial(BLOCK_SIZE))
83
- target.write(data)
84
- end
85
- ensure
86
- target.close_write
87
- end
81
+ copy_data(source, target, close_target: true)
88
82
  end
89
83
  end
90
84
  end
@@ -94,12 +88,21 @@ class YleTf
94
88
  def self.io_output(target)
95
89
  lambda do |source, *|
96
90
  Thread.new do
97
- while (data = source.readpartial(BLOCK_SIZE))
98
- target.write(data)
99
- end
91
+ copy_data(source, target)
100
92
  end
101
93
  end
102
94
  end
95
+
96
+ # Reads all data from the source IO and writes it to the target IO
97
+ def self.copy_data(source, target, **opts)
98
+ while (data = source.readpartial(BLOCK_SIZE))
99
+ target.write(data)
100
+ end
101
+ rescue EOFError # rubocop:disable Lint/HandleExceptions
102
+ # All read
103
+ ensure
104
+ target.close_write if opts[:close_target]
105
+ end
103
106
  end
104
107
  end
105
108
  end
@@ -1,3 +1,3 @@
1
1
  class YleTf
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
@@ -32,6 +32,7 @@ module YleTfPlugins
32
32
  o.separator terraform_help
33
33
  end
34
34
  end
35
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
35
36
 
36
37
  def error?(env)
37
38
  env[:tf_env] == 'error'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yle_tf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yleisradio
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-09-19 00:00:00.000000000 Z
13
+ date: 2018-01-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  version: '0'
141
141
  requirements: []
142
142
  rubyforge_project:
143
- rubygems_version: 2.6.13
143
+ rubygems_version: 2.7.3
144
144
  signing_key:
145
145
  specification_version: 4
146
146
  summary: Tooling for Terraform