terragov 0.2.5.2 → 0.3.0

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: 34fec7129f031849a422749f2d0d9a9f54c3c6a4
4
- data.tar.gz: f14943b68ac8e627bb12873a43a941ff7c682a41
3
+ metadata.gz: 7a6a1b21ce61bd33cbe176f659736df43d5b675e
4
+ data.tar.gz: f795a6e0a83173b5c324a19f8e849442128a111a
5
5
  SHA512:
6
- metadata.gz: bf982e8c0e14e751ad7646940b29c2fbf70b5667ee335abf79daf0c17ec3eef9a4fb83acc423685b123d96b86d7c69cdc6b20fae7fc023f02d2e851e3e711ac5
7
- data.tar.gz: 539b16c5019e21402f4bf975e048bb1f05dfae3be5dd18d5a84cd6a8ce495e073d52aa931d7208aa4b75986b381a9974c2419963a513b70f832885ba079e19fa
6
+ metadata.gz: 4aece8878211d2e6a066a90e811d0284ddfe844ec4785d7b04abee636f5126d96a417a1f26f274aea757e431cf489e22fec64565b88b649671b2f90177e06f5a
7
+ data.tar.gz: e670688f84d0966ba605341927626a1ebc26abf42d7bea949eaca980f9d2dd7b4b64b1e28621c302aea7f8784a25e416c31af651983397a8c9cb5c75c3501c59
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.3.0 (2017-11-26)
2
+
3
+ - Updated configuration file to allow default values and project specific values
4
+ - Uses `-detailed-exitcode` by default, and warns user if there are changes pending
5
+ - Small code tidy
6
+
1
7
  ## 0.2.4 (2017-10-15)
2
8
 
3
9
  - Updated cleaner method to check for both ".terraform" and "terraform.tfstate.backup"
data/README.md CHANGED
@@ -63,12 +63,20 @@ The contents should be YAML, and look like the following:
63
63
 
64
64
  ```
65
65
  ---
66
- environment: 'integration'
67
- stack: 'blue'
68
- repo_dir: '~/govuk/govuk-aws'
69
- data_dir: '~/govuk/govuk-aws-data/data'
66
+ default:
67
+ environment: 'integration'
68
+ stack: 'blue'
69
+ repo_dir: '~/govuk/govuk-aws'
70
+ data_dir: '~/govuk/govuk-aws-data/data'
71
+
72
+ app-some-project:
73
+ stack: 'green'
70
74
  ```
71
75
 
76
+ Specify default values under the "default" block, and if you need any project specific values, add them under the key of the same name of that project.
77
+
78
+ Project specific values will take precedence over default values.
79
+
72
80
  ## Optional global arguments
73
81
 
74
82
  These may be set in the same way as described above, with the same precedence, but they are not required.
data/lib/terragov/cli.rb CHANGED
@@ -96,59 +96,90 @@ module Terragov
96
96
  def load_config_file
97
97
  if $config_file || ENV['TERRAGOV_CONFIG_FILE']
98
98
  file = $config_file || ENV['TERRAGOV_CONFIG_FILE']
99
- $values = YAML.load_file(File.expand_path(file))
100
- $values
99
+ YAML.load_file(File.expand_path(file))
100
+ end
101
+ end
102
+
103
+ def config_file_default
104
+ if load_config_file['default'].nil?
105
+ return nil
106
+ else
107
+ return load_config_file['default']
108
+ end
109
+ end
110
+
111
+ def config_file_specific_project(project_name)
112
+ load_config_file[project_name]
113
+ end
114
+
115
+ def config_file(option)
116
+ # This has to be loaded in seperately to avoid any cyclic dependencies
117
+ project_name = $project || ENV['TERRAGOV_PROJECT']
118
+
119
+ if project_name.nil?
120
+ if config_file_default.nil?
121
+ return nil
122
+ else
123
+ return config_file_default[option]
124
+ end
125
+ else
126
+ project_config = config_file_specific_project(project_name)
127
+ if project_config.nil? or project_config[option].nil?
128
+ return config_file_default[option]
129
+ else
130
+ return project_config[option]
131
+ end
101
132
  end
102
133
  end
103
134
 
104
135
  def config(option, file = false, required = true)
105
136
  env_var = "TERRAGOV_#{option.upcase}"
106
137
  error_message = "Must set #{option}. Use --help for details."
138
+
139
+ # Load from CLI option
107
140
  if public_send(option)
108
141
  if file
109
142
  return File.expand_path(public_send(option))
110
143
  else
111
144
  return public_send(option)
112
145
  end
146
+
147
+ # Load from environment variable
113
148
  elsif ENV[env_var]
114
149
  if file
115
150
  return File.expand_path(ENV[env_var])
116
151
  else
117
152
  return ENV[env_var]
118
153
  end
154
+
155
+ # Load from config file
119
156
  elsif !load_config_file.nil?
120
- if load_config_file[option].nil?
121
- if required
122
- abort(error_message)
123
- else
124
- return false
125
- end
157
+ if config_file(option).nil?
158
+ abort(error_message) if required
159
+ return false
126
160
  else
127
161
  if file
128
- return File.expand_path(load_config_file[option])
162
+ return File.expand_path(config_file(option))
129
163
  else
130
- return load_config_file[option]
164
+ return config_file(option)
131
165
  end
132
166
  end
133
167
  else
134
- if required
135
- abort(error_message)
136
- else
137
- return false
138
- end
168
+ abort(error_message) if required
169
+ return false
139
170
  end
140
171
  end
141
172
 
142
173
  def cmd_options
143
- cmd_options_hash = {
174
+ {
175
+ # Always load the project name first
176
+ 'project' => config('project'),
144
177
  'environment' => config('environment'),
145
178
  'data_dir' => config('data_dir', true),
146
- 'project' => config('project'),
147
179
  'stack' => config('stack'),
148
180
  'repo_dir' => config('repo_dir', true),
149
181
  'extra' => extra
150
182
  }
151
- cmd_options_hash
152
183
  end
153
184
 
154
185
  def git_compare_repo_and_data(skip = false)
@@ -26,6 +26,10 @@ module Terragov
26
26
  Dir.chdir directory
27
27
  init(backend, dryrun, verbose)
28
28
 
29
+ if command == 'plan'
30
+ command = 'plan -detailed-exitcode'
31
+ end
32
+
29
33
  full_command = "bash -c 'terraform #{command} #{vars}'"
30
34
 
31
35
  run(full_command, dryrun, verbose)
@@ -41,7 +45,15 @@ module Terragov
41
45
  puts command
42
46
  else
43
47
  puts command if verbose
44
- abort("There was an issue running the command: #{command}") unless system(command)
48
+ system(command)
49
+
50
+ # Catch the output of "-detailed-exitcode"
51
+ if $?.exitstatus == 2
52
+ puts "Command completed successfully, but with updates available to apply"
53
+ exit 2
54
+ elsif $?.exitstatus != (0 or 2)
55
+ abort("There was an issue running command: #{command}")
56
+ end
45
57
  end
46
58
  end
47
59
  end
@@ -1,3 +1,3 @@
1
1
  module Terragov
2
- VERSION = '0.2.5.2'.freeze
2
+ VERSION = '0.3.0'.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.2.5.2
4
+ version: 0.3.0
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-05 00:00:00.000000000 Z
11
+ date: 2017-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander