tfwrapper 0.4.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,45 @@
1
+ Terraform v0.11.2
2
+
3
+ Your version of Terraform is out of date! The latest version
4
+ is %%TF_LATEST_VER%%. You can update by downloading from www.terraform.io/downloads.html
5
+ terraform_runner command: 'terraform init -input=false' (in %%FIXTUREPATH%%)
6
+ Running with: Terraform v0.11.2
7
+
8
+ Your version of Terraform is out of date! The latest version
9
+ is %%TF_LATEST_VER%%. You can update by downloading from www.terraform.io/downloads.html
10
+
11
+ Initializing the backend...
12
+ 
13
+ Successfully configured the backend "consul"! Terraform will automatically
14
+ use this backend unless the backend configuration changes.
15
+
16
+ Initializing provider plugins...
17
+ - Checking for available provider plugins on https://releases.hashicorp.com...
18
+ - Downloading plugin for provider "consul" (1.0.0)...
19
+
20
+ Terraform has been successfully initialized!
21
+ 
22
+ You may now begin working with Terraform. Try running "terraform plan" to see
23
+ any changes that are required for your infrastructure. All Terraform commands
24
+ should now work.
25
+
26
+ If you ever set or change modules or backend configuration for Terraform,
27
+ rerun this command to reinitialize your working directory. If you forget, other
28
+ commands will detect it and remind you to do so if necessary.
29
+ terraform_runner command 'terraform init -input=false' finished and exited 0
30
+ Terraform vars written to: %%FIXTUREPATH%%/dots_build.tfvars.json
31
+ terraform_runner command: 'terraform plan -var-file %%FIXTUREPATH%%/dots_build.tfvars.json' (in %%FIXTUREPATH%%)
32
+ Terraform vars:
33
+ ..........................terraform_runner command 'terraform plan -var-file %%FIXTUREPATH%%/dots_build.tfvars.json' finished and exited 0
34
+
35
+ ~ consul_key_prefix.landscapeTest
36
+  subkeys.foo: {
37
+ - "bar": "barval",
38
+ - "baz": "bazval",
39
+ - "foo": "fooval"
40
+ + "bar": "bar2val",
41
+ + "baz": "baz2val",
42
+ + "foo": "foo2val"
43
+ }
44
+
45
+ Plan: 0 to add, 1 to change, 0 to destroy.
@@ -0,0 +1,70 @@
1
+ Terraform v0.11.2
2
+
3
+ Your version of Terraform is out of date! The latest version
4
+ is %%TF_LATEST_VER%%. You can update by downloading from www.terraform.io/downloads.html
5
+ terraform_runner command: 'terraform init -input=false' (in %%FIXTUREPATH%%)
6
+ Running with: Terraform v0.11.2
7
+
8
+ Your version of Terraform is out of date! The latest version
9
+ is %%TF_LATEST_VER%%. You can update by downloading from www.terraform.io/downloads.html
10
+
11
+ Initializing the backend...
12
+ 
13
+ Successfully configured the backend "consul"! Terraform will automatically
14
+ use this backend unless the backend configuration changes.
15
+
16
+ Initializing provider plugins...
17
+ - Checking for available provider plugins on https://releases.hashicorp.com...
18
+ - Downloading plugin for provider "consul" (1.0.0)...
19
+
20
+ Terraform has been successfully initialized!
21
+ 
22
+ You may now begin working with Terraform. Try running "terraform plan" to see
23
+ any changes that are required for your infrastructure. All Terraform commands
24
+ should now work.
25
+
26
+ If you ever set or change modules or backend configuration for Terraform,
27
+ rerun this command to reinitialize your working directory. If you forget, other
28
+ commands will detect it and remind you to do so if necessary.
29
+ terraform_runner command 'terraform init -input=false' finished and exited 0
30
+ Terraform vars written to: %%FIXTUREPATH%%/lines_build.tfvars.json
31
+ terraform_runner command: 'terraform plan -var-file %%FIXTUREPATH%%/lines_build.tfvars.json' (in %%FIXTUREPATH%%)
32
+ Terraform vars:
33
+ .
34
+ .
35
+ .
36
+ .
37
+ .
38
+ .
39
+ .
40
+ .
41
+ .
42
+ .
43
+ .
44
+ .
45
+ .
46
+ .
47
+ .
48
+ .
49
+ .
50
+ .
51
+ .
52
+ .
53
+ .
54
+ .
55
+ .
56
+ .
57
+ .
58
+ .
59
+ terraform_runner command 'terraform plan -var-file %%FIXTUREPATH%%/lines_build.tfvars.json' finished and exited 0
60
+ ~ consul_key_prefix.landscapeTest
61
+  subkeys.foo: {
62
+ - "bar": "barval",
63
+ - "baz": "bazval",
64
+ - "foo": "fooval"
65
+ + "bar": "bar2val",
66
+ + "baz": "baz2val",
67
+ + "foo": "foo2val"
68
+ }
69
+
70
+ Plan: 0 to add, 1 to change, 0 to destroy.
@@ -0,0 +1,71 @@
1
+ Terraform v0.11.2
2
+
3
+ Your version of Terraform is out of date! The latest version
4
+ is %%TF_LATEST_VER%%. You can update by downloading from www.terraform.io/downloads.html
5
+ terraform_runner command: 'terraform init -input=false' (in %%FIXTUREPATH%%)
6
+ Running with: Terraform v0.11.2
7
+
8
+ Your version of Terraform is out of date! The latest version
9
+ is %%TF_LATEST_VER%%. You can update by downloading from www.terraform.io/downloads.html
10
+
11
+ Initializing the backend...
12
+ 
13
+ Successfully configured the backend "consul"! Terraform will automatically
14
+ use this backend unless the backend configuration changes.
15
+
16
+ Initializing provider plugins...
17
+ - Checking for available provider plugins on https://releases.hashicorp.com...
18
+ - Downloading plugin for provider "consul" (1.0.0)...
19
+
20
+ Terraform has been successfully initialized!
21
+ 
22
+ You may now begin working with Terraform. Try running "terraform plan" to see
23
+ any changes that are required for your infrastructure. All Terraform commands
24
+ should now work.
25
+
26
+ If you ever set or change modules or backend configuration for Terraform,
27
+ rerun this command to reinitialize your working directory. If you forget, other
28
+ commands will detect it and remind you to do so if necessary.
29
+ terraform_runner command 'terraform init -input=false' finished and exited 0
30
+ Terraform vars written to: %%FIXTUREPATH%%/stream_build.tfvars.json
31
+ terraform_runner command: 'terraform plan -var-file %%FIXTUREPATH%%/stream_build.tfvars.json' (in %%FIXTUREPATH%%)
32
+ Terraform vars:
33
+ Refreshing Terraform state in-memory prior to plan...
34
+ The refreshed state will be used to calculate this plan, but will not be
35
+ persisted to local or remote state storage.
36
+ 
37
+ consul_key_prefix.landscapeTest: Refreshing state... (ID: landscapeTest/)
38
+
39
+ ------------------------------------------------------------------------
40
+
41
+ An execution plan has been generated and is shown below.
42
+ Resource actions are indicated with the following symbols:
43
+ ~ update in-place
44
+ 
45
+ Terraform will perform the following actions:
46
+
47
+  ~ consul_key_prefix.landscapeTest
48
+  subkeys.foo: "{\"bar\":\"barval\",\"baz\":\"bazval\",\"foo\":\"fooval\"}" => "{\"bar\":\"bar2val\",\"baz\":\"baz2val\",\"foo\":\"foo2val\"}"
49
+ 
50
+ 
51
+ Plan: 0 to add, 1 to change, 0 to destroy.
52
+
53
+ ------------------------------------------------------------------------
54
+
55
+ Note: You didn't specify an "-out" parameter to save this plan, so Terraform
56
+ can't guarantee that exactly these actions will be performed if
57
+ "terraform apply" is subsequently run.
58
+
59
+ terraform_runner command 'terraform plan -var-file %%FIXTUREPATH%%/stream_build.tfvars.json' finished and exited 0
60
+ ~ consul_key_prefix.landscapeTest
61
+  subkeys.foo: {
62
+ - "bar": "barval",
63
+ - "baz": "bazval",
64
+ - "foo": "fooval"
65
+ + "bar": "bar2val",
66
+ + "baz": "baz2val",
67
+ + "foo": "foo2val"
68
+ }
69
+
70
+ Plan: 0 to add, 1 to change, 0 to destroy.
71
+
@@ -0,0 +1,62 @@
1
+ Terraform v0.11.2
2
+
3
+ Your version of Terraform is out of date! The latest version
4
+ is %%TF_LATEST_VER%%. You can update by downloading from www.terraform.io/downloads.html
5
+ terraform_runner command: 'terraform init -input=false' (in %%FIXTUREPATH%%)
6
+ Running with: Terraform v0.11.2
7
+
8
+ Your version of Terraform is out of date! The latest version
9
+ is %%TF_LATEST_VER%%. You can update by downloading from www.terraform.io/downloads.html
10
+
11
+ Initializing the backend...
12
+ 
13
+ Successfully configured the backend "consul"! Terraform will automatically
14
+ use this backend unless the backend configuration changes.
15
+
16
+ Initializing provider plugins...
17
+ - Checking for available provider plugins on https://releases.hashicorp.com...
18
+ - Downloading plugin for provider "consul" (1.0.0)...
19
+
20
+ Terraform has been successfully initialized!
21
+ 
22
+ You may now begin working with Terraform. Try running "terraform plan" to see
23
+ any changes that are required for your infrastructure. All Terraform commands
24
+ should now work.
25
+
26
+ If you ever set or change modules or backend configuration for Terraform,
27
+ rerun this command to reinitialize your working directory. If you forget, other
28
+ commands will detect it and remind you to do so if necessary.
29
+ terraform_runner command 'terraform init -input=false' finished and exited 0
30
+ Terraform vars written to: %%FIXTUREPATH%%/default_build.tfvars.json
31
+ terraform_runner command: 'terraform plan -var-file %%FIXTUREPATH%%/default_build.tfvars.json' (in %%FIXTUREPATH%%)
32
+ Terraform vars:
33
+ Refreshing Terraform state in-memory prior to plan...
34
+ The refreshed state will be used to calculate this plan, but will not be
35
+ persisted to local or remote state storage.
36
+ 
37
+
38
+ ------------------------------------------------------------------------
39
+
40
+ An execution plan has been generated and is shown below.
41
+ Resource actions are indicated with the following symbols:
42
+ + create
43
+ 
44
+ Terraform will perform the following actions:
45
+
46
+  + consul_key_prefix.landscapeTest
47
+  id: <computed>
48
+ datacenter: <computed>
49
+ path_prefix: "landscapeTest/"
50
+ subkeys.%: "1"
51
+ subkeys.foo: "{\"bar\":\"bar2val\",\"baz\":\"baz2val\",\"foo\":\"foo2val\"}"
52
+ 
53
+ 
54
+ Plan: 1 to add, 0 to change, 0 to destroy.
55
+
56
+ ------------------------------------------------------------------------
57
+
58
+ Note: You didn't specify an "-out" parameter to save this plan, so Terraform
59
+ can't guarantee that exactly these actions will be performed if
60
+ "terraform apply" is subsequently run.
61
+
62
+ terraform_runner command 'terraform plan -var-file %%FIXTUREPATH%%/default_build.tfvars.json' finished and exited 0
@@ -8,6 +8,7 @@ terraform {
8
8
 
9
9
  provider "consul" {
10
10
  address = "127.0.0.1:8500"
11
+ version = "1.0.0"
11
12
  }
12
13
 
13
14
  variable "foo" { default = "bar" }
@@ -8,6 +8,7 @@ terraform {
8
8
 
9
9
  provider "consul" {
10
10
  address = "127.0.0.1:8500"
11
+ version = "1.0.0"
11
12
  }
12
13
 
13
14
  variable "foo" {}
@@ -8,6 +8,7 @@ terraform {
8
8
 
9
9
  provider "consul" {
10
10
  address = "127.0.0.1:8500"
11
+ version = "1.0.0"
11
12
  }
12
13
 
13
14
  variable "foo" {}
@@ -7,6 +7,7 @@ terraform {
7
7
 
8
8
  provider "consul" {
9
9
  address = "127.0.0.1:8500"
10
+ version = "1.0.0"
10
11
  }
11
12
 
12
13
  variable "foo" {}
@@ -7,6 +7,7 @@ terraform {
7
7
 
8
8
  provider "consul" {
9
9
  address = "127.0.0.1:8500"
10
+ version = "1.0.0"
10
11
  }
11
12
 
12
13
  variable "foo" {}
@@ -4,6 +4,13 @@ require 'simplecov'
4
4
  require 'simplecov-console'
5
5
  require 'rspec_junit_formatter'
6
6
 
7
+ begin
8
+ require 'terraform_landscape'
9
+ HAVE_LANDSCAPE = true
10
+ rescue LoadError
11
+ HAVE_LANDSCAPE = false
12
+ end
13
+
7
14
  ENV['CONSUL_ADDR'] ||= '127.0.0.1:8500'
8
15
  ENV['CONSUL_URL'] ||= "http://#{ENV['CONSUL_ADDR']}"
9
16
 
@@ -54,12 +54,91 @@ describe TFWrapper::Helpers do
54
54
  expect(Open3).to receive(:popen2e)
55
55
  .once.with('foo bar', chdir: '/foo')
56
56
  expect(STDOUT).to receive(:puts).once.with('mystdout')
57
+ expect(STDOUT).to_not receive(:print)
57
58
  expect($stdout).to receive(:sync=).once.with(true)
58
59
  expect($stdout).to receive(:sync=).once.with(false)
59
60
  expect(TFWrapper::Helpers.run_cmd_stream_output('foo bar', '/foo'))
60
61
  .to eq(['mystdout', 0])
61
62
  end
62
63
  end
64
+ context 'progress dots' do
65
+ it 'prints dots and returns output' do
66
+ dbl_wait_thread = double(Thread)
67
+ @outerrpipe_w.write('mystdout')
68
+ @outerrpipe_w.close
69
+ es = double('exitstatus', exitstatus: 0)
70
+ allow(dbl_wait_thread).to receive(:value).and_return(es)
71
+ allow($stdout).to receive(:sync).and_return(false)
72
+ allow($stdout).to receive(:sync=).with(true)
73
+ allow(Open3).to receive(:popen2e).and_yield(
74
+ @inpipe_w, @outerrpipe_r, dbl_wait_thread
75
+ )
76
+
77
+ expect(Open3).to receive(:popen2e)
78
+ .once.with('foo bar', chdir: '/foo')
79
+ expect(STDOUT).to receive(:puts).once.with('')
80
+ expect(STDOUT).to receive(:print).once.with('.')
81
+ expect($stdout).to receive(:sync=).once.with(true)
82
+ expect($stdout).to receive(:sync=).once.with(false)
83
+ expect(
84
+ TFWrapper::Helpers.run_cmd_stream_output(
85
+ 'foo bar', '/foo', progress: :dots
86
+ )
87
+ ).to eq(['mystdout', 0])
88
+ end
89
+ end
90
+ context 'progress lines' do
91
+ it 'prints a dot per line and returns output' do
92
+ dbl_wait_thread = double(Thread)
93
+ @outerrpipe_w.write('mystdout')
94
+ @outerrpipe_w.close
95
+ es = double('exitstatus', exitstatus: 0)
96
+ allow(dbl_wait_thread).to receive(:value).and_return(es)
97
+ allow($stdout).to receive(:sync).and_return(false)
98
+ allow($stdout).to receive(:sync=).with(true)
99
+ allow(Open3).to receive(:popen2e).and_yield(
100
+ @inpipe_w, @outerrpipe_r, dbl_wait_thread
101
+ )
102
+
103
+ expect(Open3).to receive(:popen2e)
104
+ .once.with('foo bar', chdir: '/foo')
105
+ expect(STDOUT).to receive(:puts).once.with('.')
106
+ expect(STDOUT).to_not receive(:print)
107
+ expect($stdout).to receive(:sync=).once.with(true)
108
+ expect($stdout).to receive(:sync=).once.with(false)
109
+ expect(
110
+ TFWrapper::Helpers.run_cmd_stream_output(
111
+ 'foo bar', '/foo', progress: :lines
112
+ )
113
+ ).to eq(['mystdout', 0])
114
+ end
115
+ end
116
+ context 'progress nil' do
117
+ it 'does not print anything but returns output' do
118
+ dbl_wait_thread = double(Thread)
119
+ @outerrpipe_w.write('mystdout')
120
+ @outerrpipe_w.close
121
+ es = double('exitstatus', exitstatus: 0)
122
+ allow(dbl_wait_thread).to receive(:value).and_return(es)
123
+ allow($stdout).to receive(:sync).and_return(false)
124
+ allow($stdout).to receive(:sync=).with(true)
125
+ allow(Open3).to receive(:popen2e).and_yield(
126
+ @inpipe_w, @outerrpipe_r, dbl_wait_thread
127
+ )
128
+
129
+ expect(Open3).to receive(:popen2e)
130
+ .once.with('foo bar', chdir: '/foo')
131
+ expect(STDOUT).to_not receive(:puts)
132
+ expect(STDOUT).to_not receive(:print)
133
+ expect($stdout).to receive(:sync=).once.with(true)
134
+ expect($stdout).to receive(:sync=).once.with(false)
135
+ expect(
136
+ TFWrapper::Helpers.run_cmd_stream_output(
137
+ 'foo bar', '/foo', progress: nil
138
+ )
139
+ ).to eq(['mystdout', 0])
140
+ end
141
+ end
63
142
  context 'IOError' do
64
143
  it 'handles IOErrors gracefully' do
65
144
  dbl_wait_thread = double(Thread)
@@ -106,15 +185,44 @@ describe TFWrapper::Helpers do
106
185
  .to eq(["mystdout\nSTDERR\n", 23])
107
186
  end
108
187
  end
188
+ context 'invalid :progress option' do
189
+ it 'raises an error' do
190
+ dbl_wait_thread = double(Thread)
191
+ @outerrpipe_w.write('mystdout')
192
+ @outerrpipe_w.close
193
+ es = double('exitstatus', exitstatus: 0)
194
+ allow(dbl_wait_thread).to receive(:value).and_return(es)
195
+ allow($stdout).to receive(:sync).and_return(false)
196
+ allow($stdout).to receive(:sync=).with(true)
197
+ allow(Open3).to receive(:popen2e).and_yield(
198
+ @inpipe_w, @outerrpipe_r, dbl_wait_thread
199
+ )
200
+
201
+ expect(Open3).to_not receive(:popen2e)
202
+ expect(STDOUT).to_not receive(:puts)
203
+ expect($stdout).to_not receive(:sync=)
204
+ expect do
205
+ TFWrapper::Helpers.run_cmd_stream_output(
206
+ 'foo bar', '/foo', progress: :foo
207
+ )
208
+ end.to raise_error(ArgumentError, /progress option must be one of/)
209
+ end
210
+ end
109
211
  end
110
212
  describe '#check_env_vars' do
111
213
  it 'returns nil if vars present' do
112
214
  ENV['foo'] = 'fooval'
113
215
  ENV['bar'] = 'barval'
114
- 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
115
217
  ENV.delete('foo')
116
218
  ENV.delete('bar')
117
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
118
226
  it 'exits if not present' do
119
227
  ENV.delete('foo')
120
228
  ENV.delete('bar')
@@ -122,7 +230,7 @@ describe TFWrapper::Helpers do
122
230
  .with('ERROR: Environment variable \'foo\' must be set.')
123
231
  expect(STDOUT).to receive(:puts)
124
232
  .with('ERROR: Environment variable \'bar\' must be set.')
125
- expect { TFWrapper::Helpers.check_env_vars(%w[foo bar]) }
233
+ expect { TFWrapper::Helpers.check_env_vars(%w[foo bar], %w[baz]) }
126
234
  .to raise_error StandardError, 'Missing or empty environment ' \
127
235
  'variables: ["foo", "bar"]'
128
236
  end
@@ -133,11 +241,31 @@ describe TFWrapper::Helpers do
133
241
  .with("ERROR: Environment variable 'foo' must not be empty.")
134
242
  expect(STDOUT).to receive(:puts)
135
243
  .with("ERROR: Environment variable 'bar' must not be empty.")
136
- expect { TFWrapper::Helpers.check_env_vars(%w[foo bar]) }
244
+ expect { TFWrapper::Helpers.check_env_vars(%w[foo bar], %w[baz]) }
137
245
  .to raise_error StandardError, 'Missing or empty environment ' \
138
246
  'variables: ["foo", "bar"]'
139
247
  ENV.delete('foo')
140
248
  ENV.delete('bar')
141
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
142
270
  end
143
271
  end