terragov 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a6a1b21ce61bd33cbe176f659736df43d5b675e
4
- data.tar.gz: f795a6e0a83173b5c324a19f8e849442128a111a
3
+ metadata.gz: 7b370d90ba03ce0099a9971f81f4fbc7b1b52e73
4
+ data.tar.gz: ff3d7bd9b1053b301cf20f670c3eca8038f8a81c
5
5
  SHA512:
6
- metadata.gz: 4aece8878211d2e6a066a90e811d0284ddfe844ec4785d7b04abee636f5126d96a417a1f26f274aea757e431cf489e22fec64565b88b649671b2f90177e06f5a
7
- data.tar.gz: e670688f84d0966ba605341927626a1ebc26abf42d7bea949eaca980f9d2dd7b4b64b1e28621c302aea7f8784a25e416c31af651983397a8c9cb5c75c3501c59
6
+ metadata.gz: 76887d22c0ec35ce3274f26b6e120ad6558c7efb7c7a79a652a4582255be95958a4f9ca2143e925c059cc891dc40cc1a7e1f6899040cbb7d998688bf70c80c00
7
+ data.tar.gz: '092fb3626be1b16143ed90098939207bfd4d9e293b2251b63033c6990aaae3c6ca42a31c9dad9caefa9e1498541d0f640091f35b1b01dff9bd3cbfd82196c700'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.3.1 (2017-12-28)
2
+
3
+ - Added a "deploy" command to allow deploying multiple projects in order as defined
4
+ a "deployment" file
5
+
1
6
  ## 0.3.0 (2017-11-26)
2
7
 
3
8
  - Updated configuration file to allow default values and project specific values
data/README.md CHANGED
@@ -26,7 +26,8 @@ Command | Description
26
26
  --- | ---
27
27
  `plan` | Plan Terraform resources
28
28
  `apply` | Apply Terraform changes
29
- `delete` | Delete Terraform resources
29
+ `destroy` | Delete Terraform resources
30
+ `deploy` | Deploy multiple projects as defined by a deployment file
30
31
  `clean` | Delete any files that have been left by Terraform
31
32
 
32
33
  There are several **required** arguments to pass when running `apply`, `plan` or `destroy`:
@@ -87,6 +88,32 @@ Argument | Description
87
88
  `dryrun` | CLI option is `--dry-run`, but config file and env var is `dryrun` and `TERRAGOV_DRYRUN` respectively
88
89
  `skip_git_check` | Do not compare branches between the repo and data directories
89
90
 
91
+ ## Deployment
92
+
93
+ You can run multiple projects using the `deploy` command. Create a deployment file with the following:
94
+
95
+ ```
96
+ ---
97
+ default:
98
+ - 'app-one'
99
+ - 'app-two'
100
+ - 'app-three'
101
+
102
+ development:
103
+ - 'app-foo'
104
+ - 'app-bar'
105
+ ```
106
+
107
+ It will use whatever is defined in the `default` configuration:
108
+
109
+ `terragov deploy --file integration.yaml --command plan`
110
+
111
+ Define a specific group to deploy:
112
+
113
+ `terragov deploy --file integration.yaml --command plan --group development`
114
+
115
+ This will use the configuration set by all the methods described previously.
116
+
90
117
  ## Development
91
118
 
92
119
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/terragov/cli.rb CHANGED
@@ -170,16 +170,21 @@ module Terragov
170
170
  end
171
171
  end
172
172
 
173
- def cmd_options
174
- {
175
- # Always load the project name first
176
- 'project' => config('project'),
173
+ def cmd_options(deployment = false)
174
+ cmd_hash = {}
175
+
176
+ # Always load the project name first
177
+ unless deployment
178
+ cmd_hash = { 'project' => config('project') }
179
+ end
180
+
181
+ cmd_hash.merge({
177
182
  'environment' => config('environment'),
178
183
  'data_dir' => config('data_dir', true),
179
184
  'stack' => config('stack'),
180
185
  'repo_dir' => config('repo_dir', true),
181
186
  'extra' => extra
182
- }
187
+ })
183
188
  end
184
189
 
185
190
  def git_compare_repo_and_data(skip = false)
@@ -211,7 +216,7 @@ module Terragov
211
216
  end
212
217
  end
213
218
 
214
- def run_terraform_cmd(cmd, opt = nil)
219
+ def run_terraform_cmd(cmd, opt = nil, deployment = false)
215
220
  paths = Terragov::BuildPaths.new.base(cmd_options)
216
221
  varfiles = Terragov::BuildPaths.new.build_command(cmd_options)
217
222
  backend = paths[:backend_file]
@@ -221,8 +226,10 @@ module Terragov
221
226
 
222
227
  do_dryrun = config('dryrun', false, false)
223
228
 
224
- skip_check = config('skip_git_check', false, false)
225
- git_compare_repo_and_data(skip_check)
229
+ unless deployment
230
+ skip_check = config('skip_git_check', false, false)
231
+ git_compare_repo_and_data(skip_check)
232
+ end
226
233
 
227
234
  puts cmd_options.to_yaml if be_verbose
228
235
 
@@ -230,6 +237,33 @@ module Terragov
230
237
  Terragov::Terraform.new.execute(cmd, varfiles, backend, project_dir, do_dryrun, be_verbose)
231
238
  end
232
239
 
240
+ def run_deployment(file, group, command)
241
+ abort("Must set deployment file: --file") unless file
242
+ abort("Must set command to run: --command") unless command
243
+ abort("Cannot find deployment file: #{file}") unless File.exist?(file)
244
+
245
+ deployment_file = YAML.load_file(file)
246
+ deployment_config = deployment_file[group]
247
+
248
+ if deployment_config.nil?
249
+ abort("Deployment configuration must be an array of projects to run")
250
+ end
251
+
252
+ if command == 'plan' || command == 'apply'
253
+ deployment_config.each do |proj|
254
+ $project = proj
255
+ run_terraform_cmd(command, nil, true)
256
+ end
257
+ elsif command == 'destroy'
258
+ deployment_config.reverse.each do |proj|
259
+ $project = proj
260
+ run_terraform_cmd(command, nil, true)
261
+ end
262
+ else
263
+ abort("Command must be apply, plan or destroy")
264
+ end
265
+ end
266
+
233
267
  def run
234
268
  command :plan do |c|
235
269
  c.syntax = 'terragov plan'
@@ -260,6 +294,20 @@ module Terragov
260
294
  end
261
295
  end
262
296
 
297
+ command :deploy do |c|
298
+ c.syntax = 'terragov deploy -f <deployment file>'
299
+ c.description = 'Deploy a group of projects as specified in a deployment configuration'
300
+ c.option '-f', '--file STRING', 'Specify deployment file'
301
+ c.option '-g', '--group STRING', 'Specify group that you wish to deploy'
302
+ c.option '-c', '--command STRING', 'What command to run: apply, plan or destroy.'
303
+ c.action do |_args, options|
304
+
305
+ group = options.group.nil? ? 'default' : options.group
306
+
307
+ run_deployment(options.file, group, options.command)
308
+ end
309
+ end
310
+
263
311
  command :clean do |c|
264
312
  c.syntax = 'terragov clean'
265
313
  c.description = 'Clean your directory of any files terraform may have left lying around'
@@ -1,3 +1,3 @@
1
1
  module Terragov
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.3.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terragov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laura Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-26 00:00:00.000000000 Z
11
+ date: 2017-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
201
  version: '0'
202
202
  requirements: []
203
203
  rubyforge_project:
204
- rubygems_version: 2.6.11
204
+ rubygems_version: 2.6.8
205
205
  signing_key:
206
206
  specification_version: 4
207
207
  summary: Wrapper for GOV.UK Terraform deployments.