tfwrapper 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -4
- data/ChangeLog.md +5 -0
- data/README.md +7 -3
- data/lib/tfwrapper/helpers.rb +4 -1
- data/lib/tfwrapper/raketasks.rb +6 -1
- data/lib/tfwrapper/version.rb +1 -1
- data/spec/unit/helpers_spec.rb +29 -3
- data/spec/unit/raketasks_spec.rb +7 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68a638cd8db6246d0a17096f0b8bc125166772ea
|
4
|
+
data.tar.gz: 05301d7bfcc0a75562b8036e657cf610d4aa55a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23f2edc392399b115ad02465a1b3b9fad6d6c37b633e4bcc6ea8463799c3af4c641f00828b0eb6879e380abe48ca3c38a8ee21ce8bf96b677f069f0adede586d
|
7
|
+
data.tar.gz: 72af330049aab08bfb69c539985bb9dc0c2ef5b13c57b02ae682c77468410b4880672407d3b84e420d6858248c2f98cdd822fc0fa51d3a23fa77482a3ec0d66c
|
data/.travis.yml
CHANGED
@@ -50,13 +50,13 @@ matrix:
|
|
50
50
|
name: "ruby-2.3 acceptance TF 0.11.2"
|
51
51
|
- rvm: 2.3
|
52
52
|
install: bundle install
|
53
|
-
script: bundle exec rake spec:acceptance TF_VERSION=
|
54
|
-
name: "ruby-2.3 acceptance TF
|
53
|
+
script: bundle exec rake spec:acceptance TF_VERSION=0.11.14
|
54
|
+
name: "ruby-2.3 acceptance TF 0.11.14"
|
55
55
|
- rvm: 2.4
|
56
56
|
install: bundle install
|
57
57
|
script: bundle exec rake spec:unit
|
58
58
|
name: "ruby-2.4 unit"
|
59
59
|
- rvm: 2.4
|
60
60
|
install: bundle install
|
61
|
-
script: bundle exec rake spec:acceptance TF_VERSION=
|
62
|
-
name: "ruby-2.4 acceptance TF
|
61
|
+
script: bundle exec rake spec:acceptance TF_VERSION=0.11.14
|
62
|
+
name: "ruby-2.4 acceptance TF 0.11.14"
|
data/ChangeLog.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
Version 0.6.1
|
2
|
+
|
3
|
+
- Add ``allowed_empty_vars`` option.
|
4
|
+
- Only support terraform up to 0.11.14.
|
5
|
+
|
1
6
|
Version 0.6.0
|
2
7
|
|
3
8
|
- Include full terraform output when a terraform run fails with output including ``hrottling``, ``status code: 403``, or ``status code: 401``. Previously terraform output was suppressed in these cases, which causes confusion with providers other than "aws" that include these strings in their failure output.
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Build of master branch: [![TravisCI](https://api.travis-ci.org/manheim/tfwrapper
|
|
4
4
|
|
5
5
|
Documentation: [http://www.rubydoc.info/gems/tfwrapper/](http://www.rubydoc.info/gems/tfwrapper/)
|
6
6
|
|
7
|
-
tfwrapper provides Rake tasks for working with [Hashicorp Terraform](https://www.terraform.io/) 0.9
|
7
|
+
tfwrapper provides Rake tasks for working with [Hashicorp Terraform](https://www.terraform.io/) 0.9 through 0.11, ensuring proper initialization and passing in variables from the environment or Ruby, as well as optionally pushing some information to Consul. tfwrapper also attempts to detect and retry
|
8
8
|
failed runs due to AWS throttling or access denied errors.
|
9
9
|
|
10
10
|
## Overview
|
@@ -44,12 +44,12 @@ with 1.9.3 is simply too high to justify.
|
|
44
44
|
Add to your ``Gemfile``:
|
45
45
|
|
46
46
|
```ruby
|
47
|
-
gem 'tfwrapper', '~> 0.
|
47
|
+
gem 'tfwrapper', '~> 0.6.1'
|
48
48
|
```
|
49
49
|
|
50
50
|
### Supported Terraform Versions
|
51
51
|
|
52
|
-
tfwrapper only supports terraform 0.9
|
52
|
+
tfwrapper only supports terraform 0.9-0.11. It is tested against multiple versions from 0.9.2 to 0.11.14.
|
53
53
|
|
54
54
|
### Terraform Landscape
|
55
55
|
|
@@ -147,6 +147,10 @@ TFWrapper::RakeTasks.install_tasks(
|
|
147
147
|
)
|
148
148
|
```
|
149
149
|
|
150
|
+
These variables are tested to be set in the environment with a non-empty value, and will raise an error if any are
|
151
|
+
missing or empty. If some should be allowed to be missing or empty empty, pass a ``allowed_empty_vars`` list with
|
152
|
+
their environment variable names.
|
153
|
+
|
150
154
|
### Ruby Variables to Terraform Variables
|
151
155
|
|
152
156
|
If you wish to explicitly bind values from your Ruby code to terraform variables, you can do this with
|
data/lib/tfwrapper/helpers.rb
CHANGED
@@ -78,9 +78,12 @@ module TFWrapper
|
|
78
78
|
# non-empty. Raise StandardError if any aren't.
|
79
79
|
#
|
80
80
|
# @param required [Array] list of required environment variables
|
81
|
-
|
81
|
+
# @param allowed_missing [Array] list of environment variables to allow to
|
82
|
+
# be empty or missing.
|
83
|
+
def self.check_env_vars(required, allowed_missing)
|
82
84
|
missing = []
|
83
85
|
required.each do |name|
|
86
|
+
next if allowed_missing.include?(name)
|
84
87
|
if !ENV.include?(name)
|
85
88
|
puts "ERROR: Environment variable '#{name}' must be set."
|
86
89
|
missing << name
|
data/lib/tfwrapper/raketasks.rb
CHANGED
@@ -55,6 +55,8 @@ module TFWrapper
|
|
55
55
|
# configurations in the same Rakefile.
|
56
56
|
# @option opts [Hash] :tf_vars_from_env hash of Terraform variables to the
|
57
57
|
# (required) environment variables to populate their values from
|
58
|
+
# @option opts [Hash] :allowed_empty_vars array of environment variable
|
59
|
+
# names (specified in :tf_vars_from_env) to allow to be empty or missing.
|
58
60
|
# @option opts [Hash] :tf_extra_vars hash of Terraform variables to their
|
59
61
|
# values; overrides any same-named keys in ``tf_vars_from_env``
|
60
62
|
# @option opts [String] :consul_url URL to access Consul at, for the
|
@@ -96,6 +98,7 @@ module TFWrapper
|
|
96
98
|
@ns_prefix = opts.fetch(:namespace_prefix, nil)
|
97
99
|
@consul_env_vars_prefix = opts.fetch(:consul_env_vars_prefix, nil)
|
98
100
|
@tf_vars_from_env = opts.fetch(:tf_vars_from_env, {})
|
101
|
+
@allowed_empty_vars = opts.fetch(:allowed_empty_vars, [])
|
99
102
|
@tf_extra_vars = opts.fetch(:tf_extra_vars, {})
|
100
103
|
@backend_config = opts.fetch(:backend_config, {})
|
101
104
|
@consul_url = opts.fetch(:consul_url, nil)
|
@@ -162,7 +165,9 @@ module TFWrapper
|
|
162
165
|
desc 'Run terraform init with appropriate arguments'
|
163
166
|
task :init do |t|
|
164
167
|
@before_proc.call(t.name, @tf_dir) unless @before_proc.nil?
|
165
|
-
TFWrapper::Helpers.check_env_vars(
|
168
|
+
TFWrapper::Helpers.check_env_vars(
|
169
|
+
@tf_vars_from_env.values, @allowed_empty_vars
|
170
|
+
)
|
166
171
|
@tf_version = check_tf_version
|
167
172
|
cmd = [
|
168
173
|
'terraform',
|
data/lib/tfwrapper/version.rb
CHANGED
data/spec/unit/helpers_spec.rb
CHANGED
@@ -213,10 +213,16 @@ describe TFWrapper::Helpers do
|
|
213
213
|
it 'returns nil if vars present' do
|
214
214
|
ENV['foo'] = 'fooval'
|
215
215
|
ENV['bar'] = 'barval'
|
216
|
-
expect(TFWrapper::Helpers.check_env_vars(%w[foo bar])).to be_nil
|
216
|
+
expect(TFWrapper::Helpers.check_env_vars(%w[foo bar], [])).to be_nil
|
217
217
|
ENV.delete('foo')
|
218
218
|
ENV.delete('bar')
|
219
219
|
end
|
220
|
+
it 'returns nil if vars ignored' do
|
221
|
+
ENV['foo'] = ''
|
222
|
+
expect(TFWrapper::Helpers.check_env_vars(%w[foo bar], %w[foo bar]))
|
223
|
+
.to be_nil
|
224
|
+
ENV.delete('foo')
|
225
|
+
end
|
220
226
|
it 'exits if not present' do
|
221
227
|
ENV.delete('foo')
|
222
228
|
ENV.delete('bar')
|
@@ -224,7 +230,7 @@ describe TFWrapper::Helpers do
|
|
224
230
|
.with('ERROR: Environment variable \'foo\' must be set.')
|
225
231
|
expect(STDOUT).to receive(:puts)
|
226
232
|
.with('ERROR: Environment variable \'bar\' must be set.')
|
227
|
-
expect { TFWrapper::Helpers.check_env_vars(%w[foo bar]) }
|
233
|
+
expect { TFWrapper::Helpers.check_env_vars(%w[foo bar], %w[baz]) }
|
228
234
|
.to raise_error StandardError, 'Missing or empty environment ' \
|
229
235
|
'variables: ["foo", "bar"]'
|
230
236
|
end
|
@@ -235,11 +241,31 @@ describe TFWrapper::Helpers do
|
|
235
241
|
.with("ERROR: Environment variable 'foo' must not be empty.")
|
236
242
|
expect(STDOUT).to receive(:puts)
|
237
243
|
.with("ERROR: Environment variable 'bar' must not be empty.")
|
238
|
-
expect { TFWrapper::Helpers.check_env_vars(%w[foo bar]) }
|
244
|
+
expect { TFWrapper::Helpers.check_env_vars(%w[foo bar], %w[baz]) }
|
239
245
|
.to raise_error StandardError, 'Missing or empty environment ' \
|
240
246
|
'variables: ["foo", "bar"]'
|
241
247
|
ENV.delete('foo')
|
242
248
|
ENV.delete('bar')
|
243
249
|
end
|
250
|
+
it 'exits if not present and partially ignored' do
|
251
|
+
ENV.delete('foo')
|
252
|
+
ENV.delete('bar')
|
253
|
+
expect(STDOUT).to receive(:puts)
|
254
|
+
.with('ERROR: Environment variable \'foo\' must be set.')
|
255
|
+
expect { TFWrapper::Helpers.check_env_vars(%w[foo bar], %w[bar]) }
|
256
|
+
.to raise_error StandardError, 'Missing or empty environment ' \
|
257
|
+
'variables: ["foo"]'
|
258
|
+
end
|
259
|
+
it 'exits if empty and partially ignored' do
|
260
|
+
ENV['foo'] = ''
|
261
|
+
ENV['bar'] = ' '
|
262
|
+
expect(STDOUT).to receive(:puts)
|
263
|
+
.with("ERROR: Environment variable 'foo' must not be empty.")
|
264
|
+
expect { TFWrapper::Helpers.check_env_vars(%w[foo bar], %w[bar]) }
|
265
|
+
.to raise_error StandardError, 'Missing or empty environment ' \
|
266
|
+
'variables: ["foo"]'
|
267
|
+
ENV.delete('foo')
|
268
|
+
ENV.delete('bar')
|
269
|
+
end
|
244
270
|
end
|
245
271
|
end
|
data/spec/unit/raketasks_spec.rb
CHANGED
@@ -59,6 +59,7 @@ describe TFWrapper::RakeTasks do
|
|
59
59
|
expect(cls.instance_variable_get('@tf_dir')).to eq('/rake/dir/tfdir')
|
60
60
|
expect(cls.instance_variable_get('@consul_env_vars_prefix')).to eq(nil)
|
61
61
|
expect(cls.instance_variable_get('@tf_vars_from_env')).to eq({})
|
62
|
+
expect(cls.instance_variable_get('@allowed_empty_vars')).to eq([])
|
62
63
|
expect(cls.instance_variable_get('@tf_extra_vars')).to eq({})
|
63
64
|
expect(cls.instance_variable_get('@backend_config')).to eq({})
|
64
65
|
expect(cls.instance_variable_get('@consul_url')).to eq(nil)
|
@@ -87,6 +88,7 @@ describe TFWrapper::RakeTasks do
|
|
87
88
|
'tf/dir',
|
88
89
|
consul_env_vars_prefix: 'cvprefix',
|
89
90
|
tf_vars_from_env: { 'foo' => 'bar' },
|
91
|
+
allowed_empty_vars: %w[bar blam],
|
90
92
|
tf_extra_vars: { 'baz' => 'blam' },
|
91
93
|
consul_url: 'foobar',
|
92
94
|
before_proc: bproc,
|
@@ -100,6 +102,8 @@ describe TFWrapper::RakeTasks do
|
|
100
102
|
.to eq('cvprefix')
|
101
103
|
expect(cls.instance_variable_get('@tf_vars_from_env'))
|
102
104
|
.to eq('foo' => 'bar')
|
105
|
+
expect(cls.instance_variable_get('@allowed_empty_vars'))
|
106
|
+
.to eq(%w[bar blam])
|
103
107
|
expect(cls.instance_variable_get('@tf_extra_vars'))
|
104
108
|
.to eq('baz' => 'blam')
|
105
109
|
expect(cls.instance_variable_get('@backend_config')).to eq({})
|
@@ -317,6 +321,7 @@ describe TFWrapper::RakeTasks do
|
|
317
321
|
.to eq(Gem::Version.new('0.0.0'))
|
318
322
|
vars = { foo: 'bar', baz: 'blam' }
|
319
323
|
subject.instance_variable_set('@tf_vars_from_env', vars)
|
324
|
+
subject.instance_variable_set('@allowed_empty_vars', ['bar'])
|
320
325
|
allow(TFWrapper::Helpers).to receive(:check_env_vars)
|
321
326
|
allow(ENV).to receive(:[])
|
322
327
|
subject.instance_variable_set(
|
@@ -329,7 +334,7 @@ describe TFWrapper::RakeTasks do
|
|
329
334
|
allow(subject).to receive(:check_tf_version)
|
330
335
|
.and_return(Gem::Version.new('0.9.5'))
|
331
336
|
expect(TFWrapper::Helpers)
|
332
|
-
.to receive(:check_env_vars).once.ordered.with(vars.values)
|
337
|
+
.to receive(:check_env_vars).once.ordered.with(vars.values, ['bar'])
|
333
338
|
expect(subject).to receive(:check_tf_version).once.ordered
|
334
339
|
expect(subject).to receive(:terraform_runner).once.ordered
|
335
340
|
.with('terraform init -input=false '\
|
@@ -351,7 +356,7 @@ describe TFWrapper::RakeTasks do
|
|
351
356
|
allow(subject).to receive(:check_tf_version)
|
352
357
|
.and_return(Gem::Version.new('0.10.2'))
|
353
358
|
expect(TFWrapper::Helpers)
|
354
|
-
.to receive(:check_env_vars).once.ordered.with(vars.values)
|
359
|
+
.to receive(:check_env_vars).once.ordered.with(vars.values, [])
|
355
360
|
expect(subject).to receive(:check_tf_version).once.ordered
|
356
361
|
expect(subject).to receive(:terraform_runner).once.ordered
|
357
362
|
.with('terraform init -input=false')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tfwrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jantman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: retries
|
@@ -421,7 +421,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
421
421
|
version: '0'
|
422
422
|
requirements: []
|
423
423
|
rubyforge_project:
|
424
|
-
rubygems_version: 2.
|
424
|
+
rubygems_version: 2.6.14
|
425
425
|
signing_key:
|
426
426
|
specification_version: 4
|
427
427
|
summary: Rake tasks for running Hashicorp Terraform sanely
|