tfwrapper 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +5 -5
- data/ChangeLog.md +5 -0
- data/Gemfile +4 -0
- data/README.md +21 -2
- data/circle.yml +9 -5
- data/lib/tfwrapper/helpers.rb +21 -2
- data/lib/tfwrapper/raketasks.rb +72 -3
- data/lib/tfwrapper/version.rb +1 -1
- data/spec/acceptance/acceptance_helpers.rb +12 -0
- data/spec/acceptance/acceptance_spec.rb +190 -0
- data/spec/fixtures/landscapeTest/Rakefile +32 -0
- data/spec/fixtures/landscapeTest/main.tf +32 -0
- data/spec/fixtures/landscapeTest/state.json +43 -0
- data/spec/fixtures/landscapeTest/with_landscape_default.out +45 -0
- data/spec/fixtures/landscapeTest/with_landscape_dots.out +46 -0
- data/spec/fixtures/landscapeTest/with_landscape_lines.out +71 -0
- data/spec/fixtures/landscapeTest/with_landscape_stream.out +71 -0
- data/spec/fixtures/landscapeTest/without_landscape.out +62 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/unit/helpers_spec.rb +102 -0
- data/spec/unit/raketasks_spec.rb +205 -16
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73a99a40047a490174b186e5bf5c6b58dedea114
|
4
|
+
data.tar.gz: f64131d4e1a68fae63dc3b86465b64480a3edae3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e3d6202be5a238dc9a358ed190aa6debbef62e5f56cac5b365935afe407a700e46a3166e24af34640f00a21667dd34adec292bb1c7125fe82129da98eefeeed
|
7
|
+
data.tar.gz: 1b4b83ca1147ae1955d3e571e087467f792db7107b76c2d9f421ff9fd37dd4512860ca719b32a7fd8b56e8861b1785ff45b439eea01faa454e4169b0dd1b040c
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -2,10 +2,10 @@ AllCops:
|
|
2
2
|
TargetRubyVersion: 2.0
|
3
3
|
|
4
4
|
Metrics/AbcSize:
|
5
|
-
Max:
|
5
|
+
Max: 50
|
6
6
|
|
7
7
|
Metrics/BlockLength:
|
8
|
-
Max:
|
8
|
+
Max: 1400
|
9
9
|
|
10
10
|
Metrics/ClassLength:
|
11
11
|
Max: 500
|
@@ -14,10 +14,10 @@ Metrics/MethodLength:
|
|
14
14
|
Max: 100
|
15
15
|
|
16
16
|
Metrics/PerceivedComplexity:
|
17
|
-
Max:
|
17
|
+
Max: 10
|
18
18
|
|
19
19
|
Metrics/CyclomaticComplexity:
|
20
|
-
Max:
|
20
|
+
Max: 10
|
21
21
|
|
22
22
|
# These are to compensate for some warnings that differ by
|
23
23
|
# rubocop/ruby version
|
@@ -30,7 +30,7 @@ Style/MutableConstant:
|
|
30
30
|
- 'lib/tfwrapper/version.rb'
|
31
31
|
- 'spec/acceptance/acceptance_spec.rb'
|
32
32
|
|
33
|
-
|
33
|
+
Layout/MultilineMethodCallIndentation:
|
34
34
|
Exclude:
|
35
35
|
- 'spec/unit/raketasks_spec.rb'
|
36
36
|
|
data/ChangeLog.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
Version 0.5.0
|
2
|
+
|
3
|
+
- Add support for using terraform_landscape gem, if present, to reformat plan output; see README for usage.
|
4
|
+
- Add CircleCI testing under ruby 2.4.1, and acceptance tests for terraform 0.11.2.
|
5
|
+
|
1
6
|
Version 0.4.1
|
2
7
|
|
3
8
|
- Upgrade rubocop, yard and diplomat development dependency versions
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -18,7 +18,9 @@ This Gem provides the following Rake tasks:
|
|
18
18
|
one or more optional [resource address](https://www.terraform.io/docs/internals/resource-addressing.html) targets to pass to
|
19
19
|
terraform with the ``-target`` flag as Rake task arguments, i.e. ``bundle exec rake tf:plan[aws_instance.foo[1]]`` or
|
20
20
|
``bundle exec rake tf:plan[aws_instance.foo[1],aws_instance.bar[2]]``; see the
|
21
|
-
[plan documentation](https://www.terraform.io/docs/commands/plan.html) for more information.
|
21
|
+
[plan documentation](https://www.terraform.io/docs/commands/plan.html) for more information. By default this will use
|
22
|
+
[terraform_landscape](https://github.com/coinbase/terraform-landscape/blob/master/README.md) for formatting the plan
|
23
|
+
output if the ``terraform_landscape`` gem is installed; see the [section below](#terraform-landscape) for more information.
|
22
24
|
* __tf:apply__ - run ``terraform apply`` with all variables and configuration, and TF variables written to disk. You can specify
|
23
25
|
one or more optional [resource address](https://www.terraform.io/docs/internals/resource-addressing.html) targets to pass to
|
24
26
|
terraform with the ``-target`` flag as Rake task arguments, i.e. ``bundle exec rake tf:apply[aws_instance.foo[1]]`` or
|
@@ -42,13 +44,30 @@ with 1.9.3 is simply too high to justify.
|
|
42
44
|
Add to your ``Gemfile``:
|
43
45
|
|
44
46
|
```ruby
|
45
|
-
gem 'tfwrapper', '~> 0.
|
47
|
+
gem 'tfwrapper', '~> 0.5.0'
|
46
48
|
```
|
47
49
|
|
48
50
|
### Supported Terraform Versions
|
49
51
|
|
50
52
|
tfwrapper only supports terraform 0.9+. It is tested against multiple versions from 0.9.2 to 0.10.2 and the current release.
|
51
53
|
|
54
|
+
### Terraform Landscape
|
55
|
+
|
56
|
+
The [terraform_landscape](https://github.com/coinbase/terraform-landscape/blob/master/README.md) gem provides enhanced formatting of ``terraform plan`` output including colorization of changes and human-friendly diffs (i.e. diffs of JSON rendered with pretty-printing). By default ``plan`` output will be passed through terraform_landscape if the ``terraform_landscape`` gem is available. To enable this, add ``gem 'terraform_landscape', '~> 0.1.17'`` to your ``Gemfile``. __Note__ that we rely on an undocumented internal API of terraform_landscape to achieve this; the formatting code will fall back to unformatted output in case of an error.
|
57
|
+
|
58
|
+
If you wish to disable terraform_landscape output even when the gem is installed, pass ``disable_landscape: true`` as an option to ``install_tasks()``:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
TFWrapper::RakeTasks.install_tasks('.', disable_landscape: true)
|
62
|
+
```
|
63
|
+
|
64
|
+
In previous versions or when terraform_landscape is not installed, the output of all terraform commands is streamed in realtime. Since terraform_landscape requires the full and complete ``plan`` output in order to reformat it, this is no longer the case. By default when terraform_landscape is installed and not disabled the ``plan`` task will not produce any output until complete, at which point it will print the landscape-formatted output all at once. This behavior can be controlled with the ``:landscape_progress`` option of ``install_tasks()``, which takes one of the following values:
|
65
|
+
|
66
|
+
* ``nil``, the default, to not produce any output until the command is complete at which point the landscape-formatted output will be shown.
|
67
|
+
* ``:dots`` to print a dot to STDOUT for every line of ``terraform plan`` output and then print the landscape-formatted output when complete.
|
68
|
+
* ``:lines`` to print a dot followed by a newline to STDOUT for every line of ``terraform plan`` output and then print the landscape-formatted output when complete. This is useful for systems like Jenkins that line-buffer output (and don't display anything until a newline is encountered).
|
69
|
+
* ``:stream`` to stream the ``terraform plan`` output in realtime (as was the previous behavior) and then print the landscape-formatted output when complete. Note that this will result in the output containing the complete unformatted ``terraform plan`` output, followed by the landscape-formatted output.
|
70
|
+
|
52
71
|
## Usage
|
53
72
|
|
54
73
|
To use the Terraform rake tasks, require the module in your Rakefile and use the
|
data/circle.yml
CHANGED
@@ -5,11 +5,12 @@ dependencies:
|
|
5
5
|
pre:
|
6
6
|
- sudo add-apt-repository -y ppa:git-core/ppa && sudo apt-get update && sudo apt-get install git
|
7
7
|
override:
|
8
|
-
- 'bundle install'
|
9
|
-
- 'rvm 2.0.0-p598 exec bundle install'
|
10
|
-
- 'rvm 2.1.8 exec bundle install'
|
11
|
-
- 'rvm 2.2.5 exec bundle install'
|
12
|
-
- 'rvm 2.3.1 exec bundle install'
|
8
|
+
- 'bundle install --without landscape'
|
9
|
+
- 'rvm 2.0.0-p598 exec bundle install --without landscape'
|
10
|
+
- 'rvm 2.1.8 exec bundle install --without landscape'
|
11
|
+
- 'rvm 2.2.5 exec bundle install --without landscape'
|
12
|
+
- 'rvm 2.3.1 exec bundle install --without landscape'
|
13
|
+
- 'rvm 2.4.1 exec bundle install'
|
13
14
|
|
14
15
|
test:
|
15
16
|
override:
|
@@ -20,9 +21,12 @@ test:
|
|
20
21
|
- 'rvm 2.1.8 exec bundle exec rake spec:unit'
|
21
22
|
- 'rvm 2.2.5 exec bundle exec rake spec:unit'
|
22
23
|
- 'rvm 2.3.1 exec bundle exec rake spec:unit'
|
24
|
+
- 'rvm 2.4.1 exec bundle exec rake spec:unit'
|
23
25
|
- 'rvm 2.3.1 exec bundle exec rake spec:acceptance TF_VERSION=0.9.2'
|
24
26
|
- 'rvm 2.3.1 exec bundle exec rake spec:acceptance TF_VERSION=0.9.7'
|
25
27
|
- 'rvm 2.3.1 exec bundle exec rake spec:acceptance TF_VERSION=0.10.0'
|
26
28
|
- 'rvm 2.3.1 exec bundle exec rake spec:acceptance TF_VERSION=0.10.2'
|
29
|
+
- 'rvm 2.3.1 exec bundle exec rake spec:acceptance TF_VERSION=0.11.2'
|
27
30
|
- 'rvm 2.3.1 exec bundle exec rake spec:acceptance TF_VERSION=latest'
|
31
|
+
- 'rvm 2.4.1 exec bundle exec rake spec:acceptance TF_VERSION=0.11.2'
|
28
32
|
- 'bundle exec rake yard:generate'
|
data/lib/tfwrapper/helpers.rb
CHANGED
@@ -31,8 +31,20 @@ module TFWrapper
|
|
31
31
|
#
|
32
32
|
# @param cmd [String] command to run
|
33
33
|
# @param pwd [String] directory/path to run command in
|
34
|
+
# @option opts [Hash] :progress How to handle streaming output. Possible
|
35
|
+
# values are ``:stream`` (default) to stream each line in STDOUT/STDERR
|
36
|
+
# to STDOUT, ``:dots`` to print a dot for each line, ``:lines`` to print
|
37
|
+
# a dot followed by a newline for each line, or ``nil`` to not stream any
|
38
|
+
# output at all.
|
34
39
|
# @return [Array] - out_err [String], exit code [Fixnum]
|
35
|
-
def self.run_cmd_stream_output(cmd, pwd)
|
40
|
+
def self.run_cmd_stream_output(cmd, pwd, opts = {})
|
41
|
+
stream_type = opts.fetch(:progress, :stream)
|
42
|
+
unless [:dots, :lines, :stream, nil].include?(stream_type)
|
43
|
+
raise(
|
44
|
+
ArgumentError,
|
45
|
+
'progress option must be one of: [:dots, :lines, :stream, nil]'
|
46
|
+
)
|
47
|
+
end
|
36
48
|
old_sync = $stdout.sync
|
37
49
|
$stdout.sync = true
|
38
50
|
all_out_err = ''.dup
|
@@ -41,7 +53,13 @@ module TFWrapper
|
|
41
53
|
stdin.close_write
|
42
54
|
begin
|
43
55
|
while (line = stdout_and_err.gets)
|
44
|
-
|
56
|
+
if stream_type == :stream
|
57
|
+
puts line
|
58
|
+
elsif stream_type == :dots
|
59
|
+
STDOUT.print '.'
|
60
|
+
elsif stream_type == :lines
|
61
|
+
puts '.'
|
62
|
+
end
|
45
63
|
all_out_err << line
|
46
64
|
end
|
47
65
|
rescue IOError => e
|
@@ -51,6 +69,7 @@ module TFWrapper
|
|
51
69
|
end
|
52
70
|
# rubocop:disable Style/RedundantReturn
|
53
71
|
$stdout.sync = old_sync
|
72
|
+
puts '' if stream_type == :dots
|
54
73
|
return all_out_err, exit_status
|
55
74
|
# rubocop:enable Style/RedundantReturn
|
56
75
|
end
|
data/lib/tfwrapper/raketasks.rb
CHANGED
@@ -6,6 +6,15 @@ require 'rake'
|
|
6
6
|
require 'rubygems'
|
7
7
|
require 'tfwrapper/version'
|
8
8
|
|
9
|
+
# :nocov:
|
10
|
+
begin
|
11
|
+
require 'terraform_landscape'
|
12
|
+
HAVE_LANDSCAPE = true
|
13
|
+
rescue LoadError
|
14
|
+
HAVE_LANDSCAPE = false
|
15
|
+
end
|
16
|
+
# :nocov:
|
17
|
+
|
9
18
|
module TFWrapper
|
10
19
|
# Generates Rake tasks for working with Terraform.
|
11
20
|
class RakeTasks
|
@@ -63,6 +72,22 @@ module TFWrapper
|
|
63
72
|
# the body of each task. Called with two arguments, the String full
|
64
73
|
# (namespaced) name of the task being executed, and ``tf_dir``. This will
|
65
74
|
# not execute if the body of the task fails.
|
75
|
+
# @option opts [Bool] :disable_landscape By default, if the
|
76
|
+
# ``terraform_landscape`` gem can be loaded, it will be used to reformat
|
77
|
+
# the output of ``terraform plan``. If this is not desired, set to
|
78
|
+
# ``true`` to disable landscale. Default: ``false``.
|
79
|
+
# @option opts [Symbol, nil] :landscape_progress The ``terraform_landscape``
|
80
|
+
# code used to reformat plan output requires the full output of the
|
81
|
+
# complete ``plan`` execution. By default, this means that when landscape
|
82
|
+
# is used, no output will appear from the time ``terraform plan`` begins
|
83
|
+
# until the command is complete. If progress output is desired, this option
|
84
|
+
# can be set to one of the following: ``:dots`` to print a dot to STDOUT
|
85
|
+
# for every line of ``terraform plan`` output, ``:lines`` to print a dot
|
86
|
+
# followed by a newline (e.g. for systems like Jenkins that line buffer)
|
87
|
+
# for every line of ``terraform plan`` output, or ``:stream`` to stream
|
88
|
+
# the raw ``terraform plan`` output (which will then be followed by the
|
89
|
+
# reformatted landscape output). Default is ``nil`` to show no progress
|
90
|
+
# output.
|
66
91
|
def initialize(tf_dir, opts = {})
|
67
92
|
# find the directory that contains the Rakefile
|
68
93
|
rakedir = File.realpath(Rake.application.rakefile)
|
@@ -74,6 +99,15 @@ module TFWrapper
|
|
74
99
|
@tf_extra_vars = opts.fetch(:tf_extra_vars, {})
|
75
100
|
@backend_config = opts.fetch(:backend_config, {})
|
76
101
|
@consul_url = opts.fetch(:consul_url, nil)
|
102
|
+
@disable_landscape = opts.fetch(:disable_landscape, false)
|
103
|
+
@landscape_progress = opts.fetch(:landscape_progress, nil)
|
104
|
+
unless [:dots, :lines, :stream, nil].include?(@landscape_progress)
|
105
|
+
raise(
|
106
|
+
ArgumentError,
|
107
|
+
'landscape_progress option must be one of: ' \
|
108
|
+
'[:dots, :lines, :stream, nil]'
|
109
|
+
)
|
110
|
+
end
|
77
111
|
@before_proc = opts.fetch(:before_proc, nil)
|
78
112
|
if !@before_proc.nil? && !@before_proc.is_a?(Proc)
|
79
113
|
raise(
|
@@ -160,7 +194,13 @@ module TFWrapper
|
|
160
194
|
args.extras
|
161
195
|
)
|
162
196
|
|
163
|
-
|
197
|
+
stream_type = if HAVE_LANDSCAPE && !@disable_landscape
|
198
|
+
@landscape_progress
|
199
|
+
else
|
200
|
+
:stream
|
201
|
+
end
|
202
|
+
outerr = terraform_runner(cmd, progress: stream_type)
|
203
|
+
landscape_format(outerr) if HAVE_LANDSCAPE && !@disable_landscape
|
164
204
|
@after_proc.call(t.name, @tf_dir) unless @after_proc.nil?
|
165
205
|
end
|
166
206
|
end
|
@@ -296,13 +336,39 @@ module TFWrapper
|
|
296
336
|
res
|
297
337
|
end
|
298
338
|
|
339
|
+
# Given a string of terraform plan output, format it with
|
340
|
+
# terraform_landscape and print the result to STDOUT.
|
341
|
+
def landscape_format(output)
|
342
|
+
p = TerraformLandscape::Printer.new(
|
343
|
+
TerraformLandscape::Output.new(STDOUT)
|
344
|
+
)
|
345
|
+
p.process_string(output)
|
346
|
+
rescue StandardError, ScriptError => ex
|
347
|
+
STDERR.puts 'Exception calling terraform_landscape to reformat ' \
|
348
|
+
"output: #{ex.class.name}: #{ex}"
|
349
|
+
puts output unless @landscape_progress == :stream
|
350
|
+
end
|
351
|
+
|
299
352
|
# Run a Terraform command, providing some useful output and handling AWS
|
300
353
|
# API rate limiting gracefully. Raises StandardError on failure. The command
|
301
354
|
# is run in @tf_dir.
|
302
355
|
#
|
303
356
|
# @param cmd [String] Terraform command to run
|
357
|
+
# @option opts [Hash] :progress How to handle streaming output. Possible
|
358
|
+
# values are ``:stream`` (default) to stream each line in STDOUT/STDERR
|
359
|
+
# to STDOUT, ``:dots`` to print a dot for each line, ``:lines`` to print
|
360
|
+
# a dot followed by a newline for each line, or ``nil`` to not stream any
|
361
|
+
# output at all.
|
362
|
+
# @return [String] combined STDOUT and STDERR
|
304
363
|
# rubocop:disable Metrics/PerceivedComplexity
|
305
|
-
def terraform_runner(cmd)
|
364
|
+
def terraform_runner(cmd, opts = {})
|
365
|
+
stream_type = opts.fetch(:progress, :stream)
|
366
|
+
unless [:dots, :lines, :stream, nil].include?(stream_type)
|
367
|
+
raise(
|
368
|
+
ArgumentError,
|
369
|
+
'progress option must be one of: [:dots, :lines, :stream, nil]'
|
370
|
+
)
|
371
|
+
end
|
306
372
|
require 'retries'
|
307
373
|
STDERR.puts "terraform_runner command: '#{cmd}' (in #{@tf_dir})"
|
308
374
|
out_err = nil
|
@@ -321,7 +387,9 @@ module TFWrapper
|
|
321
387
|
) do
|
322
388
|
# this streams STDOUT and STDERR as a combined stream,
|
323
389
|
# and also captures them as a combined string
|
324
|
-
out_err, status = TFWrapper::Helpers.run_cmd_stream_output(
|
390
|
+
out_err, status = TFWrapper::Helpers.run_cmd_stream_output(
|
391
|
+
cmd, @tf_dir, progress: stream_type
|
392
|
+
)
|
325
393
|
if status != 0 && out_err.include?('hrottling')
|
326
394
|
raise StandardError, 'Terraform hit AWS API rate limiting'
|
327
395
|
end
|
@@ -340,6 +408,7 @@ module TFWrapper
|
|
340
408
|
"(exited #{status})"
|
341
409
|
end
|
342
410
|
STDERR.puts "terraform_runner command '#{cmd}' finished and exited 0"
|
411
|
+
out_err
|
343
412
|
end
|
344
413
|
# rubocop:enable Metrics/PerceivedComplexity
|
345
414
|
|
data/lib/tfwrapper/version.rb
CHANGED
@@ -24,12 +24,24 @@ def desired_tf_version
|
|
24
24
|
return ENV['TF_VERSION']
|
25
25
|
end
|
26
26
|
# else get the latest release from GitHub
|
27
|
+
latest_tf_version
|
28
|
+
end
|
29
|
+
|
30
|
+
def latest_tf_version
|
27
31
|
resp = Faraday.get('https://api.github.com/repos/hashicorp/terraform/releases/latest')
|
28
32
|
rel = JSON.parse(resp.body)['tag_name'].sub(/^v/, '')
|
29
33
|
puts "Found latest terraform release on GitHub: #{rel}"
|
30
34
|
rel
|
31
35
|
end
|
32
36
|
|
37
|
+
# Given the example terraform plan output with placeholders for the
|
38
|
+
# latest terraform version and fixtures path, return the interpolated string.
|
39
|
+
def clean_tf_plan_output(raw_out, latest_ver, fixture_path)
|
40
|
+
raw_out
|
41
|
+
.gsub('%%TF_LATEST_VER%%', latest_ver)
|
42
|
+
.gsub('%%FIXTUREPATH%%', fixture_path)
|
43
|
+
end
|
44
|
+
|
33
45
|
class HashicorpFetcher
|
34
46
|
def initialize(program, version)
|
35
47
|
@program = program
|
@@ -18,6 +18,10 @@ else
|
|
18
18
|
APPLY_CMD = 'terraform apply'
|
19
19
|
end
|
20
20
|
|
21
|
+
without_landscape = !HAVE_LANDSCAPE && TF_VERSION == '0.11.2'
|
22
|
+
with_landscape = HAVE_LANDSCAPE && TF_VERSION == '0.11.2'
|
23
|
+
latest_tf_ver = latest_tf_version
|
24
|
+
|
21
25
|
Diplomat.configure do |config|
|
22
26
|
config.url = 'http://127.0.0.1:8500'
|
23
27
|
end
|
@@ -734,4 +738,190 @@ describe 'tfwrapper' do
|
|
734
738
|
end
|
735
739
|
end
|
736
740
|
end
|
741
|
+
context 'landscapeTest', order: :defined do
|
742
|
+
before(:all) do
|
743
|
+
@fixturepath = File.absolute_path(
|
744
|
+
File.join(File.dirname(__FILE__), '..', 'fixtures', 'landscapeTest')
|
745
|
+
)
|
746
|
+
end
|
747
|
+
before(:each) do
|
748
|
+
Diplomat::Kv.put(
|
749
|
+
'landscapeTest/foo', '{"bar":"barval","baz":"bazval","foo":"fooval"}'
|
750
|
+
)
|
751
|
+
Diplomat::Kv.put(
|
752
|
+
'terraform/landscapeTest',
|
753
|
+
File.read(File.join(@fixturepath, 'state.json'))
|
754
|
+
)
|
755
|
+
end
|
756
|
+
context 'without landscape installed', if: without_landscape do
|
757
|
+
describe 'default_tf:plan' do
|
758
|
+
before(:all) do
|
759
|
+
@out_err, @ecode = Open3.capture2e(
|
760
|
+
'timeout -k 60 45 bundle exec rake default_tf:plan',
|
761
|
+
chdir: @fixturepath
|
762
|
+
)
|
763
|
+
@varpath = File.join(@fixturepath, 'default_build.tfvars.json')
|
764
|
+
end
|
765
|
+
after(:all) do
|
766
|
+
File.delete(@varpath) if File.file?(@varpath)
|
767
|
+
end
|
768
|
+
it 'does not time out' do
|
769
|
+
expect(@ecode.exitstatus).to_not eq(124)
|
770
|
+
expect(@ecode.exitstatus).to_not eq(137)
|
771
|
+
end
|
772
|
+
it 'exits zero' do
|
773
|
+
expect(@ecode.exitstatus).to eq(0)
|
774
|
+
end
|
775
|
+
it 'returns unmodified terraform output' do
|
776
|
+
expected = clean_tf_plan_output(
|
777
|
+
File.read(File.join(@fixturepath, 'without_landscape.out')),
|
778
|
+
latest_tf_ver, @fixturepath
|
779
|
+
)
|
780
|
+
expect(@out_err.strip).to eq(expected.strip)
|
781
|
+
end
|
782
|
+
end
|
783
|
+
end
|
784
|
+
context 'with landscape installed', if: with_landscape do
|
785
|
+
context 'and disabled' do
|
786
|
+
describe 'disabled_tf:plan' do
|
787
|
+
before(:all) do
|
788
|
+
@out_err, @ecode = Open3.capture2e(
|
789
|
+
'timeout -k 60 45 bundle exec rake disabled_tf:plan',
|
790
|
+
chdir: @fixturepath
|
791
|
+
)
|
792
|
+
@varpath = File.join(@fixturepath, 'disabled_build.tfvars.json')
|
793
|
+
end
|
794
|
+
after(:all) do
|
795
|
+
File.delete(@varpath) if File.file?(@varpath)
|
796
|
+
end
|
797
|
+
it 'does not time out' do
|
798
|
+
expect(@ecode.exitstatus).to_not eq(124)
|
799
|
+
expect(@ecode.exitstatus).to_not eq(137)
|
800
|
+
end
|
801
|
+
it 'exits zero' do
|
802
|
+
expect(@ecode.exitstatus).to eq(0)
|
803
|
+
end
|
804
|
+
it 'returns unmodified terraform output' do
|
805
|
+
expected = clean_tf_plan_output(
|
806
|
+
File.read(File.join(@fixturepath, 'without_landscape.out')),
|
807
|
+
latest_tf_ver, @fixturepath
|
808
|
+
).gsub('default_build.tfvars.json', 'disabled_build.tfvars.json')
|
809
|
+
expect(@out_err.strip).to eq(expected.strip)
|
810
|
+
end
|
811
|
+
end
|
812
|
+
end
|
813
|
+
context 'and default progress' do
|
814
|
+
describe 'default_tf:plan' do
|
815
|
+
before(:all) do
|
816
|
+
@out_err, @ecode = Open3.capture2e(
|
817
|
+
'timeout -k 60 45 bundle exec rake default_tf:plan',
|
818
|
+
chdir: @fixturepath
|
819
|
+
)
|
820
|
+
@varpath = File.join(@fixturepath, 'default_build.tfvars.json')
|
821
|
+
end
|
822
|
+
after(:all) do
|
823
|
+
File.delete(@varpath) if File.file?(@varpath)
|
824
|
+
end
|
825
|
+
it 'does not time out' do
|
826
|
+
expect(@ecode.exitstatus).to_not eq(124)
|
827
|
+
expect(@ecode.exitstatus).to_not eq(137)
|
828
|
+
end
|
829
|
+
it 'exits zero' do
|
830
|
+
expect(@ecode.exitstatus).to eq(0)
|
831
|
+
end
|
832
|
+
it 'returns landscape output and no plan output' do
|
833
|
+
expected = clean_tf_plan_output(
|
834
|
+
File.read(File.join(@fixturepath, 'with_landscape_default.out')),
|
835
|
+
latest_tf_ver, @fixturepath
|
836
|
+
)
|
837
|
+
expect(@out_err.strip).to eq(expected.strip)
|
838
|
+
end
|
839
|
+
end
|
840
|
+
end
|
841
|
+
context 'and dots progress' do
|
842
|
+
describe 'dots_tf:plan' do
|
843
|
+
before(:all) do
|
844
|
+
@out_err, @ecode = Open3.capture2e(
|
845
|
+
'timeout -k 60 45 bundle exec rake dots_tf:plan',
|
846
|
+
chdir: @fixturepath
|
847
|
+
)
|
848
|
+
@varpath = File.join(@fixturepath, 'dots_build.tfvars.json')
|
849
|
+
end
|
850
|
+
after(:all) do
|
851
|
+
File.delete(@varpath) if File.file?(@varpath)
|
852
|
+
end
|
853
|
+
it 'does not time out' do
|
854
|
+
expect(@ecode.exitstatus).to_not eq(124)
|
855
|
+
expect(@ecode.exitstatus).to_not eq(137)
|
856
|
+
end
|
857
|
+
it 'exits zero' do
|
858
|
+
expect(@ecode.exitstatus).to eq(0)
|
859
|
+
end
|
860
|
+
it 'returns progress dots for plan output and landscape output' do
|
861
|
+
expected = clean_tf_plan_output(
|
862
|
+
File.read(File.join(@fixturepath, 'with_landscape_dots.out')),
|
863
|
+
latest_tf_ver, @fixturepath
|
864
|
+
)
|
865
|
+
expect(@out_err.strip).to eq(expected.strip)
|
866
|
+
end
|
867
|
+
end
|
868
|
+
end
|
869
|
+
context 'and lines progress' do
|
870
|
+
describe 'lines_tf:plan' do
|
871
|
+
before(:all) do
|
872
|
+
@out_err, @ecode = Open3.capture2e(
|
873
|
+
'timeout -k 60 45 bundle exec rake lines_tf:plan',
|
874
|
+
chdir: @fixturepath
|
875
|
+
)
|
876
|
+
@varpath = File.join(@fixturepath, 'lines_build.tfvars.json')
|
877
|
+
end
|
878
|
+
after(:all) do
|
879
|
+
File.delete(@varpath) if File.file?(@varpath)
|
880
|
+
end
|
881
|
+
it 'does not time out' do
|
882
|
+
expect(@ecode.exitstatus).to_not eq(124)
|
883
|
+
expect(@ecode.exitstatus).to_not eq(137)
|
884
|
+
end
|
885
|
+
it 'exits zero' do
|
886
|
+
expect(@ecode.exitstatus).to eq(0)
|
887
|
+
end
|
888
|
+
it 'returns progress lines for plan output and landscape output' do
|
889
|
+
expected = clean_tf_plan_output(
|
890
|
+
File.read(File.join(@fixturepath, 'with_landscape_lines.out')),
|
891
|
+
latest_tf_ver, @fixturepath
|
892
|
+
)
|
893
|
+
expect(@out_err.strip).to eq(expected.strip)
|
894
|
+
end
|
895
|
+
end
|
896
|
+
end
|
897
|
+
context 'and stream progress' do
|
898
|
+
describe 'stream_tf:plan' do
|
899
|
+
before(:all) do
|
900
|
+
@out_err, @ecode = Open3.capture2e(
|
901
|
+
'timeout -k 60 45 bundle exec rake stream_tf:plan',
|
902
|
+
chdir: @fixturepath
|
903
|
+
)
|
904
|
+
@varpath = File.join(@fixturepath, 'stream_build.tfvars.json')
|
905
|
+
end
|
906
|
+
after(:all) do
|
907
|
+
File.delete(@varpath) if File.file?(@varpath)
|
908
|
+
end
|
909
|
+
it 'does not time out' do
|
910
|
+
expect(@ecode.exitstatus).to_not eq(124)
|
911
|
+
expect(@ecode.exitstatus).to_not eq(137)
|
912
|
+
end
|
913
|
+
it 'exits zero' do
|
914
|
+
expect(@ecode.exitstatus).to eq(0)
|
915
|
+
end
|
916
|
+
it 'returns streaming plan output and landscape output' do
|
917
|
+
expected = clean_tf_plan_output(
|
918
|
+
File.read(File.join(@fixturepath, 'with_landscape_stream.out')),
|
919
|
+
latest_tf_ver, @fixturepath
|
920
|
+
)
|
921
|
+
expect(@out_err.strip).to eq(expected.strip)
|
922
|
+
end
|
923
|
+
end
|
924
|
+
end
|
925
|
+
end
|
926
|
+
end
|
737
927
|
end
|