bolt 1.28.0 → 1.29.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bolt might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2d33a034fb69edd25b761aec5e21075aa9ad9f0ccce67122994a2e24dda01f4
4
- data.tar.gz: '0348c1d2ed663a0c3556795017c219a88c4e432788fe10e8d75bb1f03f0eed89'
3
+ metadata.gz: 8594a6349cae9dc7c45446a40f0f15c7093a2b706361f48a938b6a21471a7ae4
4
+ data.tar.gz: 0a4954a8df306277da739d1ae33849719f0071db2ef9ba337ca3a7e045a2861f
5
5
  SHA512:
6
- metadata.gz: b842c4a35c334729e47f361ea5be9a0467934d1afc718cec50d117f6573f1a2024eac84e4049730c02bd6cc97158dadc7c4ce1d6adff207efbdc103ffc4f0560
7
- data.tar.gz: 470115a05e6edd058de12934e48e77441105cd83baeadca192d7bf7591b2e5f2bef998164614bee9cbebe0b511fe7507a8dcd61b0fbb19810e75e59bb55c7900
6
+ metadata.gz: 63d35051226313b40df680787dd026922fc829480e5cc7e73e34f882ab494a0a7bfb746a2cb561c34ad63f35d382226fd165c45783c2249f23e15763065ba07d
7
+ data.tar.gz: 9702e0fe3b12e5f7b7b5531d4dee87a5bd12a39070946c7ea9da678aa8db5d018195c34a1b7f4109c470ef34d98ec6831167cd254c50375df89a8d6dd0a51cb0
@@ -5,6 +5,10 @@ require 'json'
5
5
  module Bolt
6
6
  class Plugin
7
7
  class Terraform
8
+ KNOWN_KEYS = Set['_plugin', 'dir', 'resource_type', 'uri', 'name', 'statefile',
9
+ 'config', 'backend']
10
+ REQ_KEYS = Set['dir', 'resource_type']
11
+
8
12
  def initialize
9
13
  @logger = Logging.logger[self]
10
14
  end
@@ -21,7 +25,25 @@ module Bolt
21
25
  @logger.warn("Could not find property #{property} of terraform resource #{name}")
22
26
  end
23
27
 
28
+ # Make sure no unexpected keys are in the inventory config and
29
+ # that required keys are present
30
+ def validate_options(opts)
31
+ opt_keys = opts.keys.to_set
32
+
33
+ unless KNOWN_KEYS.superset?(opt_keys)
34
+ keys = opt_keys - KNOWN_KEYS
35
+ raise Bolt::ValidationError, "Unexpected key(s) in inventory config: #{keys.to_a.inspect}"
36
+ end
37
+
38
+ unless opt_keys.superset?(REQ_KEYS)
39
+ keys = REQ_KEYS - opt_keys
40
+ raise Bolt::ValidationError, "Expected key(s) in inventory config: #{keys.to_a.inspect}"
41
+ end
42
+ end
43
+
24
44
  def inventory_targets(opts)
45
+ validate_options(opts)
46
+
25
47
  state = load_statefile(opts)
26
48
 
27
49
  resources = extract_resources(state)
@@ -49,11 +71,43 @@ module Bolt
49
71
  end
50
72
 
51
73
  def load_statefile(opts)
74
+ statefile = if opts['backend'] == 'remote'
75
+ load_remote_statefile(opts)
76
+ else
77
+ load_local_statefile(opts)
78
+ end
79
+
80
+ JSON.parse(statefile)
81
+ end
82
+
83
+ # Uses the Terraform CLI to pull remote state files
84
+ def load_remote_statefile(opts)
85
+ dir = File.expand_path(opts['dir'])
86
+
87
+ begin
88
+ stdout_str, stderr_str, status = Open3.capture3('terraform state pull', chdir: dir)
89
+ rescue Errno::ENOENT
90
+ reason = if File.directory?(dir)
91
+ "Could not find executable 'terraform'"
92
+ else
93
+ "Could not find directory '#{dir}'"
94
+ end
95
+ raise Bolt::Error.new(reason, 'FILE_ERROR')
96
+ end
97
+
98
+ unless status.success?
99
+ err = stdout_str + stderr_str
100
+ msg = "Could not pull Terraform remote state file for #{opts['dir']}:\n#{err}"
101
+ raise Bolt::Error.new(msg, 'bolt/terraform-state-error')
102
+ end
103
+
104
+ stdout_str
105
+ end
106
+
107
+ def load_local_statefile(opts)
52
108
  dir = opts['dir']
53
109
  filename = opts.fetch('statefile', 'terraform.tfstate')
54
- statefile = File.expand_path(File.join(dir, filename))
55
-
56
- JSON.parse(File.read(statefile))
110
+ File.read(File.expand_path(File.join(dir, filename)))
57
111
  rescue StandardError => e
58
112
  raise Bolt::FileError.new("Could not load Terraform state file #{filename}: #{e}", filename)
59
113
  end
@@ -68,8 +122,10 @@ module Bolt
68
122
  resource_set['instances'].map do |resource|
69
123
  instance_name = prefix
70
124
  instance_name += ".#{resource['index_key']}" if resource['index_key']
71
-
72
- [instance_name, resource['attributes']]
125
+ # When using `terraform state pull` with terraform >= 0.12 version 3 statefiles
126
+ # Will be converted to version 4. When converted attributes is converted to attributes_flat
127
+ attributes = resource['attributes'] || resource['attributes_flat']
128
+ [instance_name, attributes]
73
129
  end
74
130
  end
75
131
  else
@@ -12,8 +12,7 @@ module Bolt
12
12
  end
13
13
 
14
14
  def self.validate(options)
15
- logger = Logging.logger[self]
16
- validate_sudo_options(options, logger)
15
+ validate_sudo_options(options)
17
16
  end
18
17
 
19
18
  def with_connection(target, *_args)
@@ -28,8 +28,7 @@ module Bolt
28
28
  end
29
29
 
30
30
  def self.validate(options)
31
- logger = Logging.logger[self]
32
- validate_sudo_options(options, logger)
31
+ validate_sudo_options(options)
33
32
 
34
33
  host_key = options['host-key-check']
35
34
  unless !!host_key == host_key
@@ -6,12 +6,7 @@ require 'bolt/transport/base'
6
6
  module Bolt
7
7
  module Transport
8
8
  class Sudoable < Base
9
- def self.validate_sudo_options(options, logger)
10
- if options['sudo-password'] && options['run-as'].nil?
11
- logger.warn("--sudo-password will not be used without specifying a " \
12
- "user to escalate to with --run-as")
13
- end
14
-
9
+ def self.validate_sudo_options(options)
15
10
  run_as_cmd = options['run-as-command']
16
11
  if run_as_cmd && (!run_as_cmd.is_a?(Array) || run_as_cmd.any? { |n| !n.is_a?(String) })
17
12
  raise Bolt::ValidationError, "run-as-command must be an Array of Strings, received #{run_as_cmd}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bolt
4
- VERSION = '1.28.0'
4
+ VERSION = '1.29.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bolt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.28.0
4
+ version: 1.29.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-08 00:00:00.000000000 Z
11
+ date: 2019-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable