yle_tf 1.0.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/bin/tf +1 -0
  3. data/lib/yle_tf.rb +4 -0
  4. data/lib/yle_tf/action.rb +4 -0
  5. data/lib/yle_tf/action/builder.rb +2 -0
  6. data/lib/yle_tf/action/command.rb +4 -2
  7. data/lib/yle_tf/action/copy_root_module.rb +2 -0
  8. data/lib/yle_tf/action/generate_vars_file.rb +2 -0
  9. data/lib/yle_tf/action/load_config.rb +9 -1
  10. data/lib/yle_tf/action/terraform_init.rb +63 -32
  11. data/lib/yle_tf/action/tf_hooks.rb +9 -5
  12. data/lib/yle_tf/action/tmpdir.rb +3 -1
  13. data/lib/yle_tf/action/verify_terraform_version.rb +19 -6
  14. data/lib/yle_tf/action/verify_tf_env.rb +2 -0
  15. data/lib/yle_tf/action/verify_yle_tf_version.rb +36 -0
  16. data/lib/yle_tf/action/write_terraformrc_defaults.rb +34 -17
  17. data/lib/yle_tf/backend.rb +47 -0
  18. data/lib/yle_tf/cli.rb +3 -1
  19. data/lib/yle_tf/config.rb +25 -9
  20. data/lib/yle_tf/config/defaults.rb +25 -11
  21. data/lib/yle_tf/config/erb.rb +2 -0
  22. data/lib/yle_tf/config/file.rb +2 -0
  23. data/lib/yle_tf/config/loader.rb +89 -59
  24. data/lib/yle_tf/config/migration.rb +117 -0
  25. data/lib/yle_tf/error.rb +2 -0
  26. data/lib/yle_tf/helpers/hash.rb +22 -0
  27. data/lib/yle_tf/logger.rb +2 -10
  28. data/lib/yle_tf/logger/colorize.rb +2 -0
  29. data/lib/yle_tf/plugin.rb +6 -2
  30. data/lib/yle_tf/plugin/action_hook.rb +2 -0
  31. data/lib/yle_tf/plugin/loader.rb +8 -1
  32. data/lib/yle_tf/plugin/manager.rb +3 -0
  33. data/lib/yle_tf/system.rb +5 -2
  34. data/lib/yle_tf/system/io_handlers.rb +5 -1
  35. data/lib/yle_tf/system/output_logger.rb +2 -0
  36. data/lib/yle_tf/system/tf_hook_output_logger.rb +2 -0
  37. data/lib/yle_tf/tf_hook.rb +11 -9
  38. data/lib/yle_tf/tf_hook/runner.rb +2 -0
  39. data/lib/yle_tf/vars_file.rb +16 -3
  40. data/lib/yle_tf/version.rb +3 -1
  41. data/lib/yle_tf/version_requirement.rb +2 -5
  42. data/lib/yle_tf_plugins/backends/{s3 → __default}/plugin.rb +6 -4
  43. data/lib/yle_tf_plugins/backends/file/backend.rb +89 -0
  44. data/lib/yle_tf_plugins/backends/file/plugin.rb +4 -2
  45. data/lib/yle_tf_plugins/commands/__default/command.rb +2 -0
  46. data/lib/yle_tf_plugins/commands/__default/plugin.rb +2 -0
  47. data/lib/yle_tf_plugins/commands/_config/command.rb +2 -0
  48. data/lib/yle_tf_plugins/commands/_config/plugin.rb +2 -0
  49. data/lib/yle_tf_plugins/commands/_shell/command.rb +2 -0
  50. data/lib/yle_tf_plugins/commands/_shell/plugin.rb +2 -0
  51. data/lib/yle_tf_plugins/commands/help/command.rb +9 -20
  52. data/lib/yle_tf_plugins/commands/help/plugin.rb +2 -0
  53. data/lib/yle_tf_plugins/commands/version/command.rb +2 -0
  54. data/lib/yle_tf_plugins/commands/version/plugin.rb +2 -0
  55. metadata +61 -22
  56. data/lib/yle_tf/backend_config.rb +0 -41
  57. data/lib/yle_tf_plugins/backends/file/command.rb +0 -31
  58. data/lib/yle_tf_plugins/backends/file/config.rb +0 -17
  59. data/lib/yle_tf_plugins/backends/s3/command.rb +0 -19
  60. data/lib/yle_tf_plugins/backends/swift/command.rb +0 -18
  61. data/lib/yle_tf_plugins/backends/swift/plugin.rb +0 -16
  62. data/vendor/logger_level_patch.rb +0 -29
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yle_tf'
2
4
 
3
5
  module YleTfPlugins
@@ -7,8 +9,8 @@ module YleTfPlugins
7
9
  register
8
10
 
9
11
  backend('file') do
10
- require_relative 'command'
11
- Command
12
+ require_relative 'backend'
13
+ Backend
12
14
  end
13
15
  end
14
16
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yle_tf/logger'
2
4
  require 'yle_tf/system'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yle_tf'
2
4
 
3
5
  module YleTfPlugins
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yle_tf/logger'
2
4
 
3
5
  module YleTfPlugins
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yle_tf'
2
4
 
3
5
  module YleTfPlugins
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module YleTfPlugins
2
4
  module CommandShell
3
5
  class Command
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yle_tf'
2
4
 
3
5
  module YleTfPlugins
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'optparse'
2
4
 
3
- require 'yle_tf/system'
4
5
  require 'yle_tf/plugin'
5
6
 
6
7
  module YleTfPlugins
@@ -18,18 +19,17 @@ module YleTfPlugins
18
19
  o.banner = 'Usage: tf <environment> <command> [<args>]'
19
20
  o.separator ''
20
21
  o.separator 'YleTf options:'
21
- o.on('-h', '--help', 'Prints this help')
22
+ o.on('-h', '--help', 'Prints this help')
22
23
  o.on('-v', '--version', 'Prints the version information')
23
- o.on('--debug', 'Print debug information')
24
- o.on('--no-color', 'Do not output with colors')
25
- o.on('--no-hooks', 'Do not run any hooks')
26
- o.on('--only-hooks', 'Only run the hooks')
24
+ o.on('--debug', 'Print debug information')
25
+ o.on('--no-color', 'Do not output with colors')
26
+ o.on('--no-hooks', 'Do not run any hooks')
27
+ o.on('--only-hooks', 'Only run the hooks')
27
28
  o.separator ''
28
- o.separator 'Special tf commands:'
29
+ o.separator 'Special YleTf commands:'
29
30
  o.separator tf_command_help
30
31
  o.separator ''
31
- o.separator 'Terraform commands:'
32
- o.separator terraform_help
32
+ o.separator 'Run `terraform -help` to get list of all Terraform commands.'
33
33
  end
34
34
  end
35
35
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
@@ -47,17 +47,6 @@ module YleTfPlugins
47
47
  " #{command.ljust(18)} #{data[:synopsis]}"
48
48
  end
49
49
  end
50
-
51
- def terraform_help
52
- on_error = proc do |exit_code|
53
- # exit_code is nil if the command was not found
54
- # Ignore other exit codes, as older Terraform versions return
55
- # non-zero exit codes for the help.
56
- return ' [Terraform not found]' if exit_code.nil?
57
- end
58
- help = YleTf::System.read_cmd('terraform', '--help', error_handler: on_error)
59
- help.lines.grep(/^ /)
60
- end
61
50
  end
62
51
  end
63
52
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yle_tf'
2
4
 
3
5
  module YleTfPlugins
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yle_tf/system'
2
4
  require 'yle_tf/version'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yle_tf'
2
4
 
3
5
  module YleTfPlugins
metadata CHANGED
@@ -1,59 +1,101 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yle_tf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yleisradio
8
8
  - Teemu Matilainen
9
9
  - Antti Forsell
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-09-10 00:00:00.000000000 Z
13
+ date: 2021-01-27 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thwait
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: 0.2.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: 0.2.0
15
29
  - !ruby/object:Gem::Dependency
16
30
  name: bundler
17
31
  requirement: !ruby/object:Gem::Requirement
18
32
  requirements:
19
33
  - - "~>"
20
34
  - !ruby/object:Gem::Version
21
- version: '1.13'
35
+ version: '2.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '2.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: guard-rspec
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '4.7'
22
50
  type: :development
23
51
  prerelease: false
24
52
  version_requirements: !ruby/object:Gem::Requirement
25
53
  requirements:
26
54
  - - "~>"
27
55
  - !ruby/object:Gem::Version
28
- version: '1.13'
56
+ version: '4.7'
29
57
  - !ruby/object:Gem::Dependency
30
58
  name: rake
31
59
  requirement: !ruby/object:Gem::Requirement
32
60
  requirements:
33
61
  - - "~>"
34
62
  - !ruby/object:Gem::Version
35
- version: '12.0'
63
+ version: '13.0'
36
64
  type: :development
37
65
  prerelease: false
38
66
  version_requirements: !ruby/object:Gem::Requirement
39
67
  requirements:
40
68
  - - "~>"
41
69
  - !ruby/object:Gem::Version
42
- version: '12.0'
70
+ version: '13.0'
43
71
  - !ruby/object:Gem::Dependency
44
72
  name: rspec
45
73
  requirement: !ruby/object:Gem::Requirement
46
74
  requirements:
47
75
  - - "~>"
48
76
  - !ruby/object:Gem::Version
49
- version: '3.5'
77
+ version: '3.8'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '3.8'
85
+ - !ruby/object:Gem::Dependency
86
+ name: serverspec
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '2.41'
50
92
  type: :development
51
93
  prerelease: false
52
94
  version_requirements: !ruby/object:Gem::Requirement
53
95
  requirements:
54
96
  - - "~>"
55
97
  - !ruby/object:Gem::Version
56
- version: '3.5'
98
+ version: '2.41'
57
99
  description: Tooling for Terraform to support environments, hooks, etc.
58
100
  email:
59
101
  - devops@yle.fi
@@ -77,15 +119,18 @@ files:
77
119
  - lib/yle_tf/action/tmpdir.rb
78
120
  - lib/yle_tf/action/verify_terraform_version.rb
79
121
  - lib/yle_tf/action/verify_tf_env.rb
122
+ - lib/yle_tf/action/verify_yle_tf_version.rb
80
123
  - lib/yle_tf/action/write_terraformrc_defaults.rb
81
- - lib/yle_tf/backend_config.rb
124
+ - lib/yle_tf/backend.rb
82
125
  - lib/yle_tf/cli.rb
83
126
  - lib/yle_tf/config.rb
84
127
  - lib/yle_tf/config/defaults.rb
85
128
  - lib/yle_tf/config/erb.rb
86
129
  - lib/yle_tf/config/file.rb
87
130
  - lib/yle_tf/config/loader.rb
131
+ - lib/yle_tf/config/migration.rb
88
132
  - lib/yle_tf/error.rb
133
+ - lib/yle_tf/helpers/hash.rb
89
134
  - lib/yle_tf/logger.rb
90
135
  - lib/yle_tf/logger/colorize.rb
91
136
  - lib/yle_tf/plugin.rb
@@ -101,13 +146,9 @@ files:
101
146
  - lib/yle_tf/vars_file.rb
102
147
  - lib/yle_tf/version.rb
103
148
  - lib/yle_tf/version_requirement.rb
104
- - lib/yle_tf_plugins/backends/file/command.rb
105
- - lib/yle_tf_plugins/backends/file/config.rb
149
+ - lib/yle_tf_plugins/backends/__default/plugin.rb
150
+ - lib/yle_tf_plugins/backends/file/backend.rb
106
151
  - lib/yle_tf_plugins/backends/file/plugin.rb
107
- - lib/yle_tf_plugins/backends/s3/command.rb
108
- - lib/yle_tf_plugins/backends/s3/plugin.rb
109
- - lib/yle_tf_plugins/backends/swift/command.rb
110
- - lib/yle_tf_plugins/backends/swift/plugin.rb
111
152
  - lib/yle_tf_plugins/commands/__default/command.rb
112
153
  - lib/yle_tf_plugins/commands/__default/plugin.rb
113
154
  - lib/yle_tf_plugins/commands/_config/command.rb
@@ -119,7 +160,6 @@ files:
119
160
  - lib/yle_tf_plugins/commands/version/command.rb
120
161
  - lib/yle_tf_plugins/commands/version/plugin.rb
121
162
  - vendor/hash_deep_merge.rb
122
- - vendor/logger_level_patch.rb
123
163
  - vendor/middleware/LICENSE
124
164
  - vendor/middleware/builder.rb
125
165
  - vendor/middleware/runner.rb
@@ -127,7 +167,7 @@ homepage: https://github.com/Yleisradio/yle_tf
127
167
  licenses:
128
168
  - MIT
129
169
  metadata: {}
130
- post_install_message:
170
+ post_install_message:
131
171
  rdoc_options: []
132
172
  require_paths:
133
173
  - lib
@@ -135,16 +175,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
175
  requirements:
136
176
  - - ">="
137
177
  - !ruby/object:Gem::Version
138
- version: '2.2'
178
+ version: '2.3'
139
179
  required_rubygems_version: !ruby/object:Gem::Requirement
140
180
  requirements:
141
181
  - - ">="
142
182
  - !ruby/object:Gem::Version
143
183
  version: '0'
144
184
  requirements: []
145
- rubyforge_project:
146
- rubygems_version: 2.7.3
147
- signing_key:
185
+ rubygems_version: 3.2.3
186
+ signing_key:
148
187
  specification_version: 4
149
188
  summary: Tooling for Terraform
150
189
  test_files: []
@@ -1,41 +0,0 @@
1
- require 'json'
2
-
3
- class YleTf
4
- class BackendConfig
5
- BACKEND_CONFIG_FILE = '_backend.tf.json'.freeze
6
-
7
- attr_reader :type, :config
8
-
9
- def initialize(type, config)
10
- @type = type
11
- @config = config
12
- end
13
-
14
- # Returns an `Array` of CLI args for Terraform pre 0.9 `init` command
15
- def cli_args
16
- args = ["-backend=#{type}"]
17
- config.each do |key, value|
18
- args << "-backend-config=#{key}=#{value}"
19
- end
20
- args
21
- end
22
-
23
- # Generate backend configuration file for Terraform v0.9+
24
- def generate_config
25
- data = {
26
- terraform: [{
27
- backend: [to_h]
28
- }]
29
- }
30
- File.write(BACKEND_CONFIG_FILE, JSON.pretty_generate(data))
31
- yield if block_given?
32
- end
33
-
34
- # Returns the backend configuration as a `Hash` for Terraform v0.9+
35
- def to_h
36
- { type => config }
37
- end
38
-
39
- alias to_s to_h
40
- end
41
- end
@@ -1,31 +0,0 @@
1
- require_relative 'config'
2
-
3
- module YleTfPlugins
4
- module Backends
5
- module File
6
- class Command
7
- def backend_config(config)
8
- local_path = Pathname.pwd.join('terraform.tfstate')
9
- tfstate_path = tfstate_path(config)
10
-
11
- YleTf::Logger.info("Symlinking state to '#{tfstate_path}'")
12
- local_path.make_symlink(tfstate_path)
13
- tfstate_path.write(tfstate_template, perm: 0o644) if !tfstate_path.exist?
14
-
15
- Config.new(
16
- 'file',
17
- 'file' => tfstate_path.to_s
18
- )
19
- end
20
-
21
- def tfstate_path(config)
22
- config.module_dir.join(config.fetch('backend', 'file'))
23
- end
24
-
25
- def tfstate_template
26
- '{"version": 1}'
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,17 +0,0 @@
1
- require 'yle_tf/backend_config'
2
-
3
- module YleTfPlugins
4
- module Backends
5
- module File
6
- class Config < YleTf::BackendConfig
7
- def generate_config
8
- yield if block_given?
9
- end
10
-
11
- def cli_args
12
- nil
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,19 +0,0 @@
1
- require 'yle_tf/backend_config'
2
-
3
- module YleTfPlugins
4
- module Backends
5
- module S3
6
- class Command
7
- def backend_config(config)
8
- YleTf::BackendConfig.new(
9
- 's3',
10
- 'region' => config.fetch('backend', 'region'),
11
- 'bucket' => config.fetch('backend', 'bucket'),
12
- 'key' => config.fetch('backend', 'file'),
13
- 'encrypt' => config.fetch('backend', 'encrypt')
14
- )
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,18 +0,0 @@
1
- require 'yle_tf/backend_config'
2
-
3
- module YleTfPlugins
4
- module Backends
5
- module Swift
6
- class Command
7
- def backend_config(config)
8
- YleTf::BackendConfig.new(
9
- 'swift',
10
- 'region_name' => config.fetch('backend', 'region'),
11
- 'container' => config.fetch('backend', 'container'),
12
- 'archive_container' => config.fetch('backend', 'archive_container') { nil }
13
- )
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,16 +0,0 @@
1
- require 'yle_tf'
2
-
3
- module YleTfPlugins
4
- module Backends
5
- module Swift
6
- class Plugin < YleTf::Plugin
7
- register
8
-
9
- backend('swift') do
10
- require_relative 'command'
11
- Command
12
- end
13
- end
14
- end
15
- end
16
- end