yle_tf 0.3.0 → 0.4.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
2
  SHA256:
3
- metadata.gz: 95dbeb71fae7b996332d0392c7e1c0710e8cfce4898be87574817308626ca9cf
4
- data.tar.gz: 90b6c63351a1e30f6bee26825274cbca0aaeb8d5cd05d1a256bef8f9d8408c81
3
+ metadata.gz: fef8984348903ca788037c6d3562009f2499d513375aca7b8a6e93d14e9cf7cb
4
+ data.tar.gz: adf1e1f5a27f03c420cde1d49496956a224a88a5fa434cbd0eb4dcf90fa00810
5
5
  SHA512:
6
- metadata.gz: 7a00736661dba53738ab1c44ac48f990264c955c0747c50795a01c893bf9ac1e69da9c82e66a62edbe0a3464d0c42a6ceb84e1f41a40da98e22a15231c7e54cb
7
- data.tar.gz: a97abc8c99fb34b8db0881ef3c972f706a03667759aeca420b38dda4f3c549724b0125f3909ff9b77346d1e4119f99ec07e208820a1acfc38cfbe87714cff6ae
6
+ metadata.gz: 834703a380e72cd8ccd7c8c3dd4f5013042f6fa39f230da61fa3859a860d02102415a48a1cd7065021439b5b506a13c6a184f39241aef7f4e719b2af9a42164e
7
+ data.tar.gz: c432b0981046afd428eb2110dd45becfa810952c2d4e4d7263b117da82d5dd3da8c0a01713c8fff01ff5abe29c269dcfb99927d80a3941e8114dd6f573e9dc60
@@ -8,14 +8,16 @@ class YleTf
8
8
  autoload :TerraformInit, 'yle_tf/action/terraform_init'
9
9
  autoload :TfHooks, 'yle_tf/action/tf_hooks'
10
10
  autoload :TmpDir, 'yle_tf/action/tmpdir'
11
- autoload :VerifyTfEnv, 'yle_tf/action/verify_tf_env'
12
11
  autoload :VerifyTerraformVersion, 'yle_tf/action/verify_terraform_version'
12
+ autoload :VerifyTfEnv, 'yle_tf/action/verify_tf_env'
13
+ autoload :WriteTerraformrcDefaults, 'yle_tf/action/write_terraformrc_defaults'
13
14
 
14
15
  def self.default_action_stack(command_class = nil)
15
16
  Builder.new do
16
17
  use LoadConfig
17
18
  use VerifyTfEnv
18
19
  use TmpDir
20
+ use WriteTerraformrcDefaults
19
21
  use VerifyTerraformVersion
20
22
  use CopyRootModule
21
23
  use GenerateVarsFile
@@ -0,0 +1,59 @@
1
+ require 'fileutils'
2
+ require 'yle_tf/logger'
3
+
4
+ class YleTf
5
+ module Action
6
+ class WriteTerraformrcDefaults
7
+ # Path of the Terraform CLI configuration file
8
+ RC_PATH = '~/.terraformrc'.freeze
9
+
10
+ # Path of the plugin cache directory
11
+ DEFAULT_PLUGIN_CACHE_PATH = '~/.terraform.d/plugin-cache'.freeze
12
+
13
+ def initialize(app)
14
+ @app = app
15
+ end
16
+
17
+ def call(env)
18
+ Logger.debug("Writing default configuration to '#{RC_PATH}'")
19
+ open_rc_file do |rc_file|
20
+ keys = existing_keys(rc_file)
21
+
22
+ configure_checkpoint(rc_file) if !keys.include?('disable_checkpoint')
23
+ configure_plugin_cache_dir(rc_file) if !keys.include?('plugin_cache_dir')
24
+ end
25
+
26
+ @app.call(env)
27
+ end
28
+
29
+ def open_rc_file(&block)
30
+ File.open(File.expand_path(RC_PATH), 'a+', &block)
31
+ end
32
+
33
+ def existing_keys(rc_file)
34
+ [].tap do |keys|
35
+ rc_file.each_line do |line|
36
+ keys << Regexp.last_match(1) if line =~ /^(.+?)[ \t]*=/
37
+ end
38
+ end
39
+ end
40
+
41
+ def configure_checkpoint(rc_file)
42
+ Logger.info("Disabling Terraform upgrade and security bulletin checks by '#{RC_PATH}'")
43
+
44
+ rc_file.puts('disable_checkpoint = true')
45
+ end
46
+
47
+ def configure_plugin_cache_dir(rc_file)
48
+ Logger.info("Configuring global Terraform plugin cache by '#{RC_PATH}'")
49
+ rc_file.puts("plugin_cache_dir = \"#{DEFAULT_PLUGIN_CACHE_PATH}\"")
50
+
51
+ dir = File.expand_path(DEFAULT_PLUGIN_CACHE_PATH)
52
+ return if File.directory?(dir)
53
+
54
+ Logger.debug("Creating the plugin cache dir '#{dir}'")
55
+ FileUtils.mkdir_p(dir)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -1,3 +1,5 @@
1
+ require 'yle_tf/error'
2
+ require 'yle_tf/logger'
1
3
  require 'yle_tf/system/output_logger'
2
4
 
3
5
  class YleTf
@@ -69,7 +71,11 @@ class YleTf
69
71
  def self.dev_null_output
70
72
  lambda do |io, *|
71
73
  Thread.new do
72
- while io.read; end
74
+ begin
75
+ while io.read; end
76
+ rescue IOError => e
77
+ YleTf::Logger.debug e.full_message
78
+ end
73
79
  end
74
80
  end
75
81
  end
@@ -100,6 +106,8 @@ class YleTf
100
106
  end
101
107
  rescue EOFError # rubocop:disable Lint/HandleExceptions
102
108
  # All read
109
+ rescue IOError => e
110
+ YleTf::Logger.debug e.full_message
103
111
  ensure
104
112
  target.close_write if opts[:close_target]
105
113
  end
@@ -13,7 +13,11 @@ class YleTf
13
13
 
14
14
  def call(io, progname)
15
15
  Thread.new do
16
- io.each { |line| log(progname, line.chomp) }
16
+ begin
17
+ io.each { |line| log(progname, line.chomp) }
18
+ rescue IOError => e
19
+ YleTf::Logger.debug e.full_message
20
+ end
17
21
  end
18
22
  end
19
23
 
@@ -1,3 +1,3 @@
1
1
  class YleTf
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
@@ -10,6 +10,7 @@ module YleTfPlugins
10
10
 
11
11
  YleTf::Action::Builder.new do
12
12
  use YleTf::Action::TmpDir
13
+ use YleTf::Action::WriteTerraformrcDefaults
13
14
  use YleTf::Action::Command, Command
14
15
  end
15
16
  end
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.3.0
4
+ version: 0.4.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: 2018-01-26 00:00:00.000000000 Z
13
+ date: 2018-03-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -77,6 +77,7 @@ files:
77
77
  - lib/yle_tf/action/tmpdir.rb
78
78
  - lib/yle_tf/action/verify_terraform_version.rb
79
79
  - lib/yle_tf/action/verify_tf_env.rb
80
+ - lib/yle_tf/action/write_terraformrc_defaults.rb
80
81
  - lib/yle_tf/backend_config.rb
81
82
  - lib/yle_tf/cli.rb
82
83
  - lib/yle_tf/config.rb