tfwrapper 0.2.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +54 -0
- data/.rubocop.yml +22 -0
- data/ChangeLog.md +3 -0
- data/Gemfile +4 -0
- data/Guardfile +21 -0
- data/LICENSE +21 -0
- data/README.md +320 -0
- data/Rakefile +60 -0
- data/circle.yml +24 -0
- data/lib/tfwrapper/helpers.rb +81 -0
- data/lib/tfwrapper/raketasks.rb +357 -0
- data/lib/tfwrapper/version.rb +6 -0
- data/lib/tfwrapper.rb +8 -0
- data/spec/acceptance/acceptance_helpers.rb +99 -0
- data/spec/acceptance/acceptance_spec.rb +461 -0
- data/spec/acceptance/consulserver.rb +34 -0
- data/spec/fixtures/Rakefile +7 -0
- data/spec/fixtures/testOne.tf +22 -0
- data/spec/fixtures/testThree/Rakefile +32 -0
- data/spec/fixtures/testThree/bar/testThreeBar.tf +28 -0
- data/spec/fixtures/testThree/baz/testThreeBaz.tf +22 -0
- data/spec/fixtures/testThree/foo/testThreeFoo.tf +27 -0
- data/spec/fixtures/testTwo/Rakefile +9 -0
- data/spec/fixtures/testTwo/foo/bar/testTwo.tf +28 -0
- data/spec/spec_helper.rb +58 -0
- data/spec/unit/helpers_spec.rb +143 -0
- data/spec/unit/raketasks_spec.rb +851 -0
- data/tfwrapper.gemspec +61 -0
- metadata +419 -0
@@ -0,0 +1,461 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'consulserver'
|
4
|
+
require_relative 'acceptance_helpers'
|
5
|
+
require 'open3'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
TF_VERSION = '0.9.2'
|
9
|
+
|
10
|
+
Diplomat.configure do |config|
|
11
|
+
config.url = 'http://127.0.0.1:8500'
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'tfwrapper' do
|
15
|
+
before(:all) do
|
16
|
+
tf_path = File.dirname(HashicorpFetcher.new('terraform', TF_VERSION).fetch)
|
17
|
+
ENV['PATH'] = "#{tf_path}:#{ENV['PATH']}"
|
18
|
+
@server = ConsulServer.new
|
19
|
+
end
|
20
|
+
after(:all) do
|
21
|
+
@server.stop
|
22
|
+
end
|
23
|
+
after(:each) { cleanup_tf }
|
24
|
+
context 'testOne - basic TF with remote state' do
|
25
|
+
before(:all) do
|
26
|
+
@fixturepath = File.absolute_path(
|
27
|
+
File.join(File.dirname(__FILE__), '..', 'fixtures')
|
28
|
+
)
|
29
|
+
end
|
30
|
+
describe 'rake -T' do
|
31
|
+
before(:all) do
|
32
|
+
@out_err, @ecode = Open3.capture2e(
|
33
|
+
'timeout -k 60 45 bundle exec rake -T',
|
34
|
+
chdir: @fixturepath
|
35
|
+
)
|
36
|
+
end
|
37
|
+
it 'does not time out' do
|
38
|
+
expect(@ecode.exitstatus).to_not eq(124)
|
39
|
+
expect(@ecode.exitstatus).to_not eq(137)
|
40
|
+
end
|
41
|
+
it 'exits zero' do
|
42
|
+
expect(@ecode.exitstatus).to eq(0)
|
43
|
+
end
|
44
|
+
it 'lists the 5 tasks' do
|
45
|
+
lines = @out_err.split("\n")
|
46
|
+
expect(lines.length).to eq(5)
|
47
|
+
end
|
48
|
+
it 'includes the apply task' do
|
49
|
+
expect(@out_err).to include('rake tf:apply[target]')
|
50
|
+
end
|
51
|
+
it 'includes the destroy task' do
|
52
|
+
expect(@out_err).to include('rake tf:destroy[target]')
|
53
|
+
end
|
54
|
+
it 'includes the init task' do
|
55
|
+
expect(@out_err).to include('rake tf:init')
|
56
|
+
end
|
57
|
+
it 'includes the plan task' do
|
58
|
+
expect(@out_err).to include('rake tf:plan[target]')
|
59
|
+
end
|
60
|
+
it 'includes the write_tf_vars task' do
|
61
|
+
expect(@out_err).to include('rake tf:write_tf_vars')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
describe 'tf:apply' do
|
65
|
+
before(:all) do
|
66
|
+
@out_err, @ecode = Open3.capture2e(
|
67
|
+
'timeout -k 60 45 bundle exec rake tf:apply',
|
68
|
+
chdir: @fixturepath
|
69
|
+
)
|
70
|
+
@varpath = File.join(@fixturepath, 'build.tfvars.json')
|
71
|
+
end
|
72
|
+
after(:all) do
|
73
|
+
File.delete(@varpath) if File.file?(@varpath)
|
74
|
+
end
|
75
|
+
it 'does not time out' do
|
76
|
+
expect(@ecode.exitstatus).to_not eq(124)
|
77
|
+
expect(@ecode.exitstatus).to_not eq(137)
|
78
|
+
end
|
79
|
+
it 'exits zero' do
|
80
|
+
expect(@ecode.exitstatus).to eq(0)
|
81
|
+
end
|
82
|
+
it 'uses the correct Terraform version' do
|
83
|
+
expect(@out_err).to include("Terraform v#{TF_VERSION}")
|
84
|
+
end
|
85
|
+
it 'runs apply correctly and succeeds' do
|
86
|
+
expect(@out_err)
|
87
|
+
.to include('terraform_runner command: \'terraform apply -var-file')
|
88
|
+
expect(@out_err).to include('consul_keys.testOne: Creating...')
|
89
|
+
expect(@out_err).to include(
|
90
|
+
'Apply complete! Resources: 1 added, 0 changed, 0 destroyed.'
|
91
|
+
)
|
92
|
+
expect(@out_err).to include("Outputs:\n\nfoo_variable = bar")
|
93
|
+
end
|
94
|
+
it 'writes the vars file' do
|
95
|
+
expect(File.file?(@varpath)).to be(true)
|
96
|
+
c = File.open(@varpath, 'r').read
|
97
|
+
expect(JSON.parse(c)).to eq({})
|
98
|
+
end
|
99
|
+
it 'sets the consul key' do
|
100
|
+
expect(Diplomat::Kv.get('testOne')).to eq('bar')
|
101
|
+
end
|
102
|
+
it 'writes remote state to consul' do
|
103
|
+
state = JSON.parse(Diplomat::Kv.get('terraform/testOne'))
|
104
|
+
expect(state['version']).to eq(3)
|
105
|
+
expect(state['terraform_version']).to eq(TF_VERSION)
|
106
|
+
expect(state['serial']).to eq(1)
|
107
|
+
expect(state['modules'].length).to eq(1)
|
108
|
+
expect(state['modules'][0]['outputs']['foo_variable']['value'])
|
109
|
+
.to eq('bar')
|
110
|
+
expect(state['modules'][0]['resources'])
|
111
|
+
.to include('consul_keys.testOne')
|
112
|
+
expect(state['modules'][0]['resources'].length).to eq(1)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
context 'testTwo - TF with vars, remote state and consul env var update' do
|
117
|
+
before(:all) do
|
118
|
+
@fixturepath = File.absolute_path(
|
119
|
+
File.join(File.dirname(__FILE__), '..', 'fixtures', 'testTwo')
|
120
|
+
)
|
121
|
+
ENV['FOO'] = 'fooval'
|
122
|
+
end
|
123
|
+
after(:all) { ENV.delete('FOO') }
|
124
|
+
describe 'rake -T' do
|
125
|
+
before(:all) do
|
126
|
+
@out_err, @ecode = Open3.capture2e(
|
127
|
+
'timeout -k 60 45 bundle exec rake -T',
|
128
|
+
chdir: @fixturepath
|
129
|
+
)
|
130
|
+
end
|
131
|
+
it 'does not time out' do
|
132
|
+
expect(@ecode.exitstatus).to_not eq(124)
|
133
|
+
expect(@ecode.exitstatus).to_not eq(137)
|
134
|
+
end
|
135
|
+
it 'exits zero' do
|
136
|
+
expect(@ecode.exitstatus).to eq(0)
|
137
|
+
end
|
138
|
+
it 'lists the 5 tasks' do
|
139
|
+
lines = @out_err.split("\n")
|
140
|
+
expect(lines.length).to eq(5)
|
141
|
+
end
|
142
|
+
it 'includes the apply task' do
|
143
|
+
expect(@out_err).to include('rake tf:apply[target]')
|
144
|
+
end
|
145
|
+
it 'includes the destroy task' do
|
146
|
+
expect(@out_err).to include('rake tf:destroy[target]')
|
147
|
+
end
|
148
|
+
it 'includes the init task' do
|
149
|
+
expect(@out_err).to include('rake tf:init')
|
150
|
+
end
|
151
|
+
it 'includes the plan task' do
|
152
|
+
expect(@out_err).to include('rake tf:plan[target]')
|
153
|
+
end
|
154
|
+
it 'includes the write_tf_vars task' do
|
155
|
+
expect(@out_err).to include('rake tf:write_tf_vars')
|
156
|
+
end
|
157
|
+
end
|
158
|
+
describe 'tf:apply' do
|
159
|
+
before(:all) do
|
160
|
+
@out_err, @ecode = Open3.capture2e(
|
161
|
+
'timeout -k 60 45 bundle exec rake tf:apply',
|
162
|
+
chdir: @fixturepath
|
163
|
+
)
|
164
|
+
@varpath = File.join(@fixturepath, 'build.tfvars.json')
|
165
|
+
end
|
166
|
+
after(:all) do
|
167
|
+
File.delete(@varpath) if File.file?(@varpath)
|
168
|
+
end
|
169
|
+
it 'does not time out' do
|
170
|
+
expect(@ecode.exitstatus).to_not eq(124)
|
171
|
+
expect(@ecode.exitstatus).to_not eq(137)
|
172
|
+
end
|
173
|
+
it 'exits zero' do
|
174
|
+
expect(@ecode.exitstatus).to eq(0)
|
175
|
+
end
|
176
|
+
it 'uses the correct Terraform version' do
|
177
|
+
expect(@out_err).to include("Terraform v#{TF_VERSION}")
|
178
|
+
end
|
179
|
+
it 'runs apply correctly and succeeds' do
|
180
|
+
expect(@out_err)
|
181
|
+
.to include('terraform_runner command: \'terraform apply -var-file')
|
182
|
+
expect(@out_err).to include('consul_keys.testTwo: Creating...')
|
183
|
+
expect(@out_err).to include(
|
184
|
+
'Apply complete! Resources: 1 added, 0 changed, 0 destroyed.'
|
185
|
+
)
|
186
|
+
expect(@out_err).to include(
|
187
|
+
"Outputs:\n\nbar_variable = barval\nfoo_variable = fooval"
|
188
|
+
)
|
189
|
+
end
|
190
|
+
it 'writes the vars file' do
|
191
|
+
expect(File.file?(@varpath)).to be(true)
|
192
|
+
c = File.open(@varpath, 'r').read
|
193
|
+
expect(JSON.parse(c))
|
194
|
+
.to eq('foo' => 'fooval', 'bar' => 'barval')
|
195
|
+
end
|
196
|
+
it 'sets the consul keys' do
|
197
|
+
expect(Diplomat::Kv.get('testTwo/foo')).to eq('fooval')
|
198
|
+
expect(Diplomat::Kv.get('testTwo/bar')).to eq('barval')
|
199
|
+
end
|
200
|
+
it 'writes remote state to consul' do
|
201
|
+
state = JSON.parse(Diplomat::Kv.get('terraform/testTwo'))
|
202
|
+
expect(state['version']).to eq(3)
|
203
|
+
expect(state['terraform_version']).to eq(TF_VERSION)
|
204
|
+
expect(state['serial']).to eq(1)
|
205
|
+
expect(state['modules'].length).to eq(1)
|
206
|
+
expect(state['modules'][0]['outputs']['foo_variable']['value'])
|
207
|
+
.to eq('fooval')
|
208
|
+
expect(state['modules'][0]['outputs']['bar_variable']['value'])
|
209
|
+
.to eq('barval')
|
210
|
+
expect(state['modules'][0]['resources'])
|
211
|
+
.to include('consul_keys.testTwo')
|
212
|
+
expect(state['modules'][0]['resources'].length).to eq(1)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
context 'testThree - TF with namespaces' do
|
217
|
+
before(:all) do
|
218
|
+
@fixturepath = File.absolute_path(
|
219
|
+
File.join(File.dirname(__FILE__), '..', 'fixtures', 'testThree')
|
220
|
+
)
|
221
|
+
ENV['FOO'] = 'fooval'
|
222
|
+
end
|
223
|
+
after(:all) { ENV.delete('FOO') }
|
224
|
+
describe 'rake -T' do
|
225
|
+
before(:all) do
|
226
|
+
@out_err, @ecode = Open3.capture2e(
|
227
|
+
'timeout -k 60 45 bundle exec rake -T',
|
228
|
+
chdir: @fixturepath
|
229
|
+
)
|
230
|
+
end
|
231
|
+
it 'does not time out' do
|
232
|
+
expect(@ecode.exitstatus).to_not eq(124)
|
233
|
+
expect(@ecode.exitstatus).to_not eq(137)
|
234
|
+
end
|
235
|
+
it 'exits zero' do
|
236
|
+
expect(@ecode.exitstatus).to eq(0)
|
237
|
+
end
|
238
|
+
it 'lists the 15 tasks' do
|
239
|
+
lines = @out_err.split("\n")
|
240
|
+
expect(lines.length).to eq(15)
|
241
|
+
end
|
242
|
+
it 'includes the non-namespaced apply task' do
|
243
|
+
expect(@out_err).to include('rake tf:apply[target]')
|
244
|
+
end
|
245
|
+
it 'includes the non-namespaced destroy task' do
|
246
|
+
expect(@out_err).to include('rake tf:destroy[target]')
|
247
|
+
end
|
248
|
+
it 'includes the non-namespaced init task' do
|
249
|
+
expect(@out_err).to include('rake tf:init')
|
250
|
+
end
|
251
|
+
it 'includes the non-namespaced plan task' do
|
252
|
+
expect(@out_err).to include('rake tf:plan[target]')
|
253
|
+
end
|
254
|
+
it 'includes the non-namespaced write_tf_vars task' do
|
255
|
+
expect(@out_err).to include('rake tf:write_tf_vars')
|
256
|
+
end
|
257
|
+
it 'includes the bar-namespaced apply task' do
|
258
|
+
expect(@out_err).to include('rake bar_tf:apply[target]')
|
259
|
+
end
|
260
|
+
it 'includes the bar-namespaced destroy task' do
|
261
|
+
expect(@out_err).to include('rake bar_tf:destroy[target]')
|
262
|
+
end
|
263
|
+
it 'includes the bar-namespaced init task' do
|
264
|
+
expect(@out_err).to include('rake bar_tf:init')
|
265
|
+
end
|
266
|
+
it 'includes the bar-namespaced plan task' do
|
267
|
+
expect(@out_err).to include('rake bar_tf:plan[target]')
|
268
|
+
end
|
269
|
+
it 'includes the bar-namespaced write_tf_vars task' do
|
270
|
+
expect(@out_err).to include('rake bar_tf:write_tf_vars')
|
271
|
+
end
|
272
|
+
it 'includes the baz-namespaced apply task' do
|
273
|
+
expect(@out_err).to include('rake baz_tf:apply[target]')
|
274
|
+
end
|
275
|
+
it 'includes the baz-namespaced destroy task' do
|
276
|
+
expect(@out_err).to include('rake baz_tf:destroy[target]')
|
277
|
+
end
|
278
|
+
it 'includes the baz-namespaced init task' do
|
279
|
+
expect(@out_err).to include('rake baz_tf:init')
|
280
|
+
end
|
281
|
+
it 'includes the baz-namespaced plan task' do
|
282
|
+
expect(@out_err).to include('rake baz_tf:plan[target]')
|
283
|
+
end
|
284
|
+
it 'includes the baz-namespaced write_tf_vars task' do
|
285
|
+
expect(@out_err).to include('rake baz_tf:write_tf_vars')
|
286
|
+
end
|
287
|
+
end
|
288
|
+
describe 'tf:apply' do
|
289
|
+
before(:all) do
|
290
|
+
@out_err, @ecode = Open3.capture2e(
|
291
|
+
'timeout -k 60 45 bundle exec rake tf:apply',
|
292
|
+
chdir: @fixturepath
|
293
|
+
)
|
294
|
+
@varpath = File.join(@fixturepath, 'build.tfvars.json')
|
295
|
+
end
|
296
|
+
after(:all) do
|
297
|
+
File.delete(@varpath) if File.file?(@varpath)
|
298
|
+
end
|
299
|
+
it 'does not time out' do
|
300
|
+
expect(@ecode.exitstatus).to_not eq(124)
|
301
|
+
expect(@ecode.exitstatus).to_not eq(137)
|
302
|
+
end
|
303
|
+
it 'exits zero' do
|
304
|
+
expect(@ecode.exitstatus).to eq(0)
|
305
|
+
end
|
306
|
+
it 'uses the correct Terraform version' do
|
307
|
+
expect(@out_err).to include("Terraform v#{TF_VERSION}")
|
308
|
+
end
|
309
|
+
it 'runs apply correctly and succeeds' do
|
310
|
+
expect(@out_err)
|
311
|
+
.to include('terraform_runner command: \'terraform apply -var-file')
|
312
|
+
expect(@out_err).to include('consul_keys.testThreeFoo: Creating...')
|
313
|
+
expect(@out_err).to include(
|
314
|
+
'Apply complete! Resources: 1 added, 0 changed, 0 destroyed.'
|
315
|
+
)
|
316
|
+
expect(@out_err).to include(
|
317
|
+
"Outputs:\n\nbar_variable = barval\nfoo_variable = fooval"
|
318
|
+
)
|
319
|
+
end
|
320
|
+
it 'writes the vars file' do
|
321
|
+
expect(File.file?(@varpath)).to be(true)
|
322
|
+
c = File.open(@varpath, 'r').read
|
323
|
+
expect(JSON.parse(c))
|
324
|
+
.to eq('foo' => 'fooval', 'bar' => 'barval')
|
325
|
+
end
|
326
|
+
it 'sets the consul keys' do
|
327
|
+
expect(Diplomat::Kv.get('testThreeFoo/foo')).to eq('fooval')
|
328
|
+
expect(Diplomat::Kv.get('testThreeFoo/bar')).to eq('barval')
|
329
|
+
end
|
330
|
+
it 'writes remote state to consul' do
|
331
|
+
state = JSON.parse(Diplomat::Kv.get('terraform/testThreeFoo'))
|
332
|
+
expect(state['version']).to eq(3)
|
333
|
+
expect(state['terraform_version']).to eq(TF_VERSION)
|
334
|
+
expect(state['serial']).to eq(1)
|
335
|
+
expect(state['modules'].length).to eq(1)
|
336
|
+
expect(state['modules'][0]['outputs']['foo_variable']['value'])
|
337
|
+
.to eq('fooval')
|
338
|
+
expect(state['modules'][0]['outputs']['bar_variable']['value'])
|
339
|
+
.to eq('barval')
|
340
|
+
expect(state['modules'][0]['resources'])
|
341
|
+
.to include('consul_keys.testThreeFoo')
|
342
|
+
expect(state['modules'][0]['resources'].length).to eq(1)
|
343
|
+
end
|
344
|
+
end
|
345
|
+
describe 'bar_tf:apply' do
|
346
|
+
before(:all) do
|
347
|
+
@out_err, @ecode = Open3.capture2e(
|
348
|
+
'timeout -k 60 45 bundle exec rake bar_tf:apply',
|
349
|
+
chdir: @fixturepath
|
350
|
+
)
|
351
|
+
@varpath = File.join(@fixturepath, 'bar_build.tfvars.json')
|
352
|
+
end
|
353
|
+
after(:all) do
|
354
|
+
File.delete(@varpath) if File.file?(@varpath)
|
355
|
+
end
|
356
|
+
it 'does not time out' do
|
357
|
+
expect(@ecode.exitstatus).to_not eq(124)
|
358
|
+
expect(@ecode.exitstatus).to_not eq(137)
|
359
|
+
end
|
360
|
+
it 'exits zero' do
|
361
|
+
expect(@ecode.exitstatus).to eq(0)
|
362
|
+
end
|
363
|
+
it 'uses the correct Terraform version' do
|
364
|
+
expect(@out_err).to include("Terraform v#{TF_VERSION}")
|
365
|
+
end
|
366
|
+
it 'runs apply correctly and succeeds' do
|
367
|
+
expect(@out_err)
|
368
|
+
.to include('terraform_runner command: \'terraform apply -var-file')
|
369
|
+
expect(@out_err).to include('consul_keys.testThreeBar: Creating...')
|
370
|
+
expect(@out_err).to include(
|
371
|
+
'Apply complete! Resources: 1 added, 0 changed, 0 destroyed.'
|
372
|
+
)
|
373
|
+
expect(@out_err).to include(
|
374
|
+
"Outputs:\n\nbar_variable = barval\nfoo_variable = fooval"
|
375
|
+
)
|
376
|
+
end
|
377
|
+
it 'writes the vars file' do
|
378
|
+
expect(File.file?(@varpath)).to be(true)
|
379
|
+
c = File.open(@varpath, 'r').read
|
380
|
+
expect(JSON.parse(c))
|
381
|
+
.to eq('foo' => 'fooval', 'bar' => 'barval')
|
382
|
+
end
|
383
|
+
it 'sets the consul keys' do
|
384
|
+
expect(Diplomat::Kv.get('testThreeBar/foo')).to eq('fooval')
|
385
|
+
expect(Diplomat::Kv.get('testThreeBar/bar')).to eq('barval')
|
386
|
+
end
|
387
|
+
it 'writes remote state to consul' do
|
388
|
+
state = JSON.parse(Diplomat::Kv.get('terraform/testThreeBar'))
|
389
|
+
expect(state['version']).to eq(3)
|
390
|
+
expect(state['terraform_version']).to eq(TF_VERSION)
|
391
|
+
expect(state['serial']).to eq(1)
|
392
|
+
expect(state['modules'].length).to eq(1)
|
393
|
+
expect(state['modules'][0]['outputs']['foo_variable']['value'])
|
394
|
+
.to eq('fooval')
|
395
|
+
expect(state['modules'][0]['outputs']['bar_variable']['value'])
|
396
|
+
.to eq('barval')
|
397
|
+
expect(state['modules'][0]['resources'])
|
398
|
+
.to include('consul_keys.testThreeBar')
|
399
|
+
expect(state['modules'][0]['resources'].length).to eq(1)
|
400
|
+
end
|
401
|
+
end
|
402
|
+
describe 'baz_tf:apply' do
|
403
|
+
before(:all) do
|
404
|
+
@out_err, @ecode = Open3.capture2e(
|
405
|
+
'timeout -k 60 45 bundle exec rake baz_tf:apply',
|
406
|
+
chdir: @fixturepath
|
407
|
+
)
|
408
|
+
@varpath = File.join(@fixturepath, 'baz_build.tfvars.json')
|
409
|
+
end
|
410
|
+
after(:all) do
|
411
|
+
File.delete(@varpath) if File.file?(@varpath)
|
412
|
+
end
|
413
|
+
it 'does not time out' do
|
414
|
+
expect(@ecode.exitstatus).to_not eq(124)
|
415
|
+
expect(@ecode.exitstatus).to_not eq(137)
|
416
|
+
end
|
417
|
+
it 'exits zero' do
|
418
|
+
expect(@ecode.exitstatus).to eq(0)
|
419
|
+
end
|
420
|
+
it 'uses the correct Terraform version' do
|
421
|
+
expect(@out_err).to include("Terraform v#{TF_VERSION}")
|
422
|
+
end
|
423
|
+
it 'runs apply correctly and succeeds' do
|
424
|
+
expect(@out_err)
|
425
|
+
.to include('terraform_runner command: \'terraform apply -var-file')
|
426
|
+
expect(@out_err).to include('consul_keys.testThreeBaz: Creating...')
|
427
|
+
expect(@out_err).to include(
|
428
|
+
'Apply complete! Resources: 1 added, 0 changed, 0 destroyed.'
|
429
|
+
)
|
430
|
+
expect(@out_err).to include(
|
431
|
+
"Outputs:\n\nfoo_variable = fooval"
|
432
|
+
)
|
433
|
+
end
|
434
|
+
it 'writes the vars file' do
|
435
|
+
expect(File.file?(@varpath)).to be(true)
|
436
|
+
c = File.open(@varpath, 'r').read
|
437
|
+
expect(JSON.parse(c))
|
438
|
+
.to eq('foo' => 'fooval')
|
439
|
+
end
|
440
|
+
it 'sets the consul keys' do
|
441
|
+
expect(Diplomat::Kv.get('testThreeBaz/foo')).to eq('fooval')
|
442
|
+
end
|
443
|
+
it 'writes remote state to consul' do
|
444
|
+
state = JSON.parse(Diplomat::Kv.get('terraform/testThreeBaz'))
|
445
|
+
expect(state['version']).to eq(3)
|
446
|
+
expect(state['terraform_version']).to eq(TF_VERSION)
|
447
|
+
expect(state['serial']).to eq(1)
|
448
|
+
expect(state['modules'].length).to eq(1)
|
449
|
+
expect(state['modules'][0]['outputs']['foo_variable']['value'])
|
450
|
+
.to eq('fooval')
|
451
|
+
expect(state['modules'][0]['resources'])
|
452
|
+
.to include('consul_keys.testThreeBaz')
|
453
|
+
expect(state['modules'][0]['resources'].length).to eq(1)
|
454
|
+
end
|
455
|
+
it 'writes the environment variables to Consul' do
|
456
|
+
cvars = JSON.parse(Diplomat::Kv.get('vars/testThreeBaz'))
|
457
|
+
expect(cvars).to eq('FOO' => 'fooval')
|
458
|
+
end
|
459
|
+
end
|
460
|
+
end
|
461
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'acceptance_helpers'
|
4
|
+
require 'diplomat'
|
5
|
+
require 'retries'
|
6
|
+
|
7
|
+
# Run a Consul server process in the background, for acceptance tests
|
8
|
+
class ConsulServer
|
9
|
+
def initialize(version = '0.7.5')
|
10
|
+
bin_path = HashicorpFetcher.new('consul', version).fetch
|
11
|
+
@process = Process.spawn(
|
12
|
+
"#{bin_path} agent -server -dev",
|
13
|
+
out: '/dev/null',
|
14
|
+
err: '/dev/null'
|
15
|
+
)
|
16
|
+
Diplomat.configure do |config|
|
17
|
+
config.url = 'http://127.0.0.1:8500'
|
18
|
+
end
|
19
|
+
with_retries(
|
20
|
+
max_tries: 40,
|
21
|
+
base_sleep_seconds: 0.25,
|
22
|
+
max_sleep_seconds: 0.25,
|
23
|
+
rescue: [Faraday::ConnectionFailed, Diplomat::UnknownStatus]
|
24
|
+
) do
|
25
|
+
Diplomat::Kv.get('/', keys: true)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def stop
|
30
|
+
return if @process.nil?
|
31
|
+
Process.kill('TERM', @process)
|
32
|
+
Process.wait
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
terraform {
|
2
|
+
required_version = "> 0.9.0"
|
3
|
+
backend "consul" {
|
4
|
+
address = "127.0.0.1:8500"
|
5
|
+
path = "terraform/testOne"
|
6
|
+
}
|
7
|
+
}
|
8
|
+
|
9
|
+
provider "consul" {
|
10
|
+
address = "127.0.0.1:8500"
|
11
|
+
}
|
12
|
+
|
13
|
+
variable "foo" { default = "bar" }
|
14
|
+
|
15
|
+
resource "consul_keys" "testOne" {
|
16
|
+
key {
|
17
|
+
path = "testOne"
|
18
|
+
value = "${var.foo}"
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
output "foo_variable" { value = "${var.foo}" }
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tfwrapper/raketasks'
|
4
|
+
|
5
|
+
# @option opts [String] :consul_url URL to access Consul at, for the
|
6
|
+
# ``:consul_env_vars_prefix`` option.
|
7
|
+
# @option opts [String] :consul_env_vars_prefix if specified and not nil,
|
8
|
+
# write the environment variables used from ``tf_vars_from_env``
|
9
|
+
# and their values to JSON at this path in Consul. This should have
|
10
|
+
# the same naming constraints as ``consul_prefix``.
|
11
|
+
|
12
|
+
TFWrapper::RakeTasks.install_tasks(
|
13
|
+
'foo',
|
14
|
+
backend_config: { 'path' => 'terraform/testThreeFoo' },
|
15
|
+
tf_vars_from_env: { 'foo' => 'FOO' },
|
16
|
+
tf_extra_vars: { 'bar' => 'barval' }
|
17
|
+
)
|
18
|
+
|
19
|
+
TFWrapper::RakeTasks.install_tasks(
|
20
|
+
'bar',
|
21
|
+
namespace_prefix: 'bar',
|
22
|
+
tf_vars_from_env: { 'foo' => 'FOO' },
|
23
|
+
tf_extra_vars: { 'bar' => 'barval' }
|
24
|
+
)
|
25
|
+
|
26
|
+
TFWrapper::RakeTasks.install_tasks(
|
27
|
+
'baz',
|
28
|
+
namespace_prefix: 'baz',
|
29
|
+
tf_vars_from_env: { 'foo' => 'FOO' },
|
30
|
+
consul_url: 'http://127.0.0.1:8500',
|
31
|
+
consul_env_vars_prefix: 'vars/testThreeBaz'
|
32
|
+
)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
terraform {
|
2
|
+
required_version = "> 0.9.0"
|
3
|
+
backend "consul" {
|
4
|
+
address = "127.0.0.1:8500"
|
5
|
+
path = "terraform/testThreeBar"
|
6
|
+
}
|
7
|
+
}
|
8
|
+
|
9
|
+
provider "consul" {
|
10
|
+
address = "127.0.0.1:8500"
|
11
|
+
}
|
12
|
+
|
13
|
+
variable "foo" {}
|
14
|
+
variable "bar" { default = "bar" }
|
15
|
+
|
16
|
+
resource "consul_keys" "testThreeBar" {
|
17
|
+
key {
|
18
|
+
path = "testThreeBar/foo"
|
19
|
+
value = "${var.foo}"
|
20
|
+
}
|
21
|
+
key {
|
22
|
+
path = "testThreeBar/bar"
|
23
|
+
value = "${var.bar}"
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
output "foo_variable" { value = "${var.foo}" }
|
28
|
+
output "bar_variable" { value = "${var.bar}" }
|
@@ -0,0 +1,22 @@
|
|
1
|
+
terraform {
|
2
|
+
required_version = "> 0.9.0"
|
3
|
+
backend "consul" {
|
4
|
+
address = "127.0.0.1:8500"
|
5
|
+
path = "terraform/testThreeBaz"
|
6
|
+
}
|
7
|
+
}
|
8
|
+
|
9
|
+
provider "consul" {
|
10
|
+
address = "127.0.0.1:8500"
|
11
|
+
}
|
12
|
+
|
13
|
+
variable "foo" {}
|
14
|
+
|
15
|
+
resource "consul_keys" "testThreeBaz" {
|
16
|
+
key {
|
17
|
+
path = "testThreeBaz/foo"
|
18
|
+
value = "${var.foo}"
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
output "foo_variable" { value = "${var.foo}" }
|
@@ -0,0 +1,27 @@
|
|
1
|
+
terraform {
|
2
|
+
required_version = "> 0.9.0"
|
3
|
+
backend "consul" {
|
4
|
+
address = "127.0.0.1:8500"
|
5
|
+
}
|
6
|
+
}
|
7
|
+
|
8
|
+
provider "consul" {
|
9
|
+
address = "127.0.0.1:8500"
|
10
|
+
}
|
11
|
+
|
12
|
+
variable "foo" {}
|
13
|
+
variable "bar" { default = "bar" }
|
14
|
+
|
15
|
+
resource "consul_keys" "testThreeFoo" {
|
16
|
+
key {
|
17
|
+
path = "testThreeFoo/foo"
|
18
|
+
value = "${var.foo}"
|
19
|
+
}
|
20
|
+
key {
|
21
|
+
path = "testThreeFoo/bar"
|
22
|
+
value = "${var.bar}"
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
output "foo_variable" { value = "${var.foo}" }
|
27
|
+
output "bar_variable" { value = "${var.bar}" }
|
@@ -0,0 +1,28 @@
|
|
1
|
+
terraform {
|
2
|
+
required_version = "> 0.9.0"
|
3
|
+
backend "consul" {
|
4
|
+
address = "127.0.0.1:8500"
|
5
|
+
path = "terraform/testTwo"
|
6
|
+
}
|
7
|
+
}
|
8
|
+
|
9
|
+
provider "consul" {
|
10
|
+
address = "127.0.0.1:8500"
|
11
|
+
}
|
12
|
+
|
13
|
+
variable "foo" {}
|
14
|
+
variable "bar" { default = "bar" }
|
15
|
+
|
16
|
+
resource "consul_keys" "testTwo" {
|
17
|
+
key {
|
18
|
+
path = "testTwo/foo"
|
19
|
+
value = "${var.foo}"
|
20
|
+
}
|
21
|
+
key {
|
22
|
+
path = "testTwo/bar"
|
23
|
+
value = "${var.bar}"
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
output "foo_variable" { value = "${var.foo}" }
|
28
|
+
output "bar_variable" { value = "${var.bar}" }
|