simplygenius-atmos 0.11.2 → 0.11.3

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
  SHA256:
3
- metadata.gz: cb1186c014f0d9ae9001d66ca5594ec089cd4aef594f231e996866668eb268bb
4
- data.tar.gz: 47310dea764cc5efb7a2163383464cfb8b80ddc5b07cb73f7403ce54a093d38e
3
+ metadata.gz: 04d15a018baaae4374130fb1128992a038334e7f15669f2444b76b4e235d1175
4
+ data.tar.gz: 6ef9631e9148dbee317857276ade4be8ce832dbe4321521a03f048067cd4b8b3
5
5
  SHA512:
6
- metadata.gz: ad9ffd6c76d3f8a3a0231d769b949e2c93184ee079e85d9ca8992d423058577c1d5957444759daf464bd3628f2daa0e53efc639a22d825f8b774e07d6101cf1a
7
- data.tar.gz: 3b3540a55ab7b27c99e1caf23fde8feb4c0765d3aad67e576002d8249ee6b8daabfc629994f982ba91170b702e891c8585506531c284cca3ab51de253211dced
6
+ metadata.gz: 7c08a8603f993acc6d7eae4e60fdda61620cfe57f8bb1317bb7cb8cf84ac2eefbe0b63b59629f45f168d548b694e9f94e4f034628de8f822ffc824114d6318d0
7
+ data.tar.gz: e926bfa00c22e54cafcabd80f0174eb0178bab25a1cbcfb8632aea1d5f607ba0300dbf59d082d462453a7b7923cb066deb9e49760c5ef65e37d68f16c03010d6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ 0.11.3 (11/12/2019)
2
+ -------------------
3
+
4
+ * add a compat mode for running with terraform 0.11 [30052a1](https://github.com/simplygenius/atmos/commit/30052a1)
5
+ * handle deleting a secret that doesn't exist [224c926](https://github.com/simplygenius/atmos/commit/224c926)
6
+ * update rubyzip to avoid vulnerability [d46d817](https://github.com/simplygenius/atmos/commit/d46d817)
7
+
8
+
1
9
  0.11.2 (10/18/2019)
2
10
  -------------------
3
11
 
@@ -7,9 +7,7 @@ module SimplyGenius
7
7
 
8
8
  class Secret < BaseCommand
9
9
 
10
- def self.description
11
- "Manages application secrets"
12
- end
10
+ banner "Manages application secrets"
13
11
 
14
12
  subcommand "get", "Gets the secret value" do
15
13
 
@@ -80,8 +78,12 @@ module SimplyGenius
80
78
  Atmos.config.provider.auth_manager.authenticate(ENV) do |auth_env|
81
79
  ClimateControl.modify(auth_env) do
82
80
  value = Atmos.config.provider.secret_manager.get(key)
83
- Atmos.config.provider.secret_manager.delete(key)
84
- logger.info "Deleted secret: #{key}=#{value}"
81
+ if value
82
+ Atmos.config.provider.secret_manager.delete(key)
83
+ logger.info "Deleted secret: #{key}=#{value}"
84
+ else
85
+ logger.warn "Key does not exist: #{key}"
86
+ end
85
87
  end
86
88
  end
87
89
 
@@ -23,6 +23,7 @@ module SimplyGenius
23
23
  if @recipes.blank?
24
24
  logger.warn("Check your configuration, there are no recipes in '#{recipe_config_path}'")
25
25
  end
26
+ @compat11 = Atmos.config['atmos.terraform.compat11'].to_s == "true"
26
27
  end
27
28
 
28
29
  def run(*terraform_args, skip_backend: false, skip_secrets: false, get_modules: false, output_io: nil)
@@ -172,10 +173,19 @@ module SimplyGenius
172
173
  end
173
174
  end
174
175
 
175
- # terraform currently (v0.11.7) doesn't handle maps with nested maps or
176
- # lists well, so flatten them - nested maps get expanded into the top level
177
- # one, with their keys being appended with underscores, and lists get
178
- # joined with "," so we end up with a single hash with homogenous types
176
+ def homogenize_encode(v)
177
+ case v
178
+ when nil
179
+ @compat11 ? "" : v
180
+ else
181
+ v
182
+ end
183
+ end
184
+
185
+ # terraform requires all values within a map to have the same type, so
186
+ # flatten the map - nested maps get expanded into the top level one, with
187
+ # their keys being appended with underscores, and lists get joined with
188
+ # "," so we end up with a single hash with homogenous types
179
189
  #
180
190
  def homogenize_for_terraform(obj, prefix="")
181
191
  if obj.is_a? Hash
@@ -185,7 +195,7 @@ module SimplyGenius
185
195
  if ho.is_a? Hash
186
196
  result = result.merge(ho)
187
197
  else
188
- result["#{prefix}#{k}"] = ho
198
+ result["#{prefix}#{k}"] = homogenize_encode(ho)
189
199
  end
190
200
  end
191
201
  return result
@@ -194,15 +204,41 @@ module SimplyGenius
194
204
  obj.each do |o|
195
205
  ho = homogenize_for_terraform(o, prefix)
196
206
  if ho.is_a? Hash
197
- result << ho.collect {|k, v| "#{k}=#{v}"}.join(";")
207
+ result << ho.collect {|k, v| "#{k}=#{homogenize_encode(v)}"}.join(";")
198
208
  else
199
- result << ho
209
+ result << homogenize_encode(ho)
200
210
  end
201
211
  end
202
212
  return result.join(",")
203
213
  else
204
- return obj
214
+ return homogenize_encode(obj)
215
+ end
216
+ end
217
+
218
+ def encode_tf_env_value(v)
219
+ case v
220
+ when nil
221
+ @compat11 ? "" : JSON.generate(v)
222
+ when Numeric, String, TrueClass, FalseClass
223
+ v.to_s
224
+ when Hash
225
+ if @compat11
226
+ hcl_hash =v.collect {|k, v| %Q("#{k.to_s}"="#{encode_tf_env_value(v)}") }.join(",")
227
+ "{#{hcl_hash}}"
228
+ else
229
+ JSON.generate(v)
230
+ end
231
+ else
232
+ JSON.generate(v)
233
+ end
234
+ end
235
+
236
+ def encode_tf_env(hash)
237
+ result = {}
238
+ hash.each do |k, v|
239
+ result["TF_VAR_#{k}"] = encode_tf_env_value(v)
205
240
  end
241
+ return result
206
242
  end
207
243
 
208
244
  def tf_recipes_dir
@@ -221,34 +257,30 @@ module SimplyGenius
221
257
  # ENV, so kinda clunk to have to do both CC and pass the env in
222
258
  ClimateControl.modify(@process_env) do
223
259
  secrets = Atmos.config.provider.secret_manager.to_h
224
- env_secrets = Hash[secrets.collect { |k, v| ["TF_VAR_#{k}", v] }]
260
+ env_secrets = encode_tf_env(secrets)
225
261
  return env_secrets
226
262
  end
227
263
  end
228
264
 
265
+ # TODO: Add ability to declare variables as well as set them. May need to
266
+ # inspect existing tf to find all declared vars so we don't double declare
229
267
  def atmos_env
230
268
  # A var value in the env is ignored if a variable declaration doesn't exist for it in a tf file. Thus,
231
269
  # as a convenience to allow everything from atmos to be referenceable, we put everything from the atmos_config
232
270
  # in a homogenized hash named atmos_config which is declared by the atmos scaffolding. For variables which are
233
- # declared, we also merge in atmos config with only the values homogenized (vs the entire map) so that hash
271
+ # declared, we also merge in atmos config with only the hash values homogenized (vs the entire map) so that hash
234
272
  # variables if declared in terraform can be managed from yml, set here and accessed from terraform
235
273
  #
236
274
  homogenized_config = homogenize_for_terraform(Atmos.config.to_h)
275
+ homogenized_values = Hash[Atmos.config.to_h.collect {|k, v| [k, v.is_a?(Hash) ? homogenize_for_terraform(v) : v]}]
237
276
  var_hash = {
238
277
  all_env_names: Atmos.config.all_env_names,
239
278
  account_ids: Atmos.config.account_hash,
240
279
  atmos_config: homogenized_config
241
280
  }
242
- var_hash = var_hash.merge(Atmos.config.to_h)
243
- env_hash = Hash[var_hash.collect do |k, v|
244
- encoded_val = case v
245
- when Numeric, String, TrueClass, FalseClass
246
- v.to_s
247
- else
248
- JSON.generate(v)
249
- end
250
- ["TF_VAR_#{k}", encoded_val]
251
- end]
281
+ var_hash = var_hash.merge(homogenized_values)
282
+
283
+ env_hash = encode_tf_env(var_hash)
252
284
 
253
285
  # write out a file so users have some visibility into vars passed in -
254
286
  # mostly useful for debugging
@@ -269,8 +301,9 @@ module SimplyGenius
269
301
  end
270
302
 
271
303
  def link_support_dirs
272
- ['modules', 'templates'].each do |subdir|
273
- ln_sf(File.join(Atmos.config.root_dir, subdir), Atmos.config.tf_working_dir)
304
+ ['modules', 'templates', '.terraform-version'].each do |subdir|
305
+ source = File.join(Atmos.config.root_dir, subdir)
306
+ ln_sf(source, Atmos.config.tf_working_dir) if File.exist?(source)
274
307
  end
275
308
  end
276
309
 
@@ -1,5 +1,5 @@
1
1
  module SimplyGenius
2
2
  module Atmos
3
- VERSION = "0.11.2"
3
+ VERSION = "0.11.3"
4
4
  end
5
5
  end
@@ -75,3 +75,5 @@ atmos:
75
75
  # env/group combination will be independent and download all plugins for
76
76
  # itself only
77
77
  disable_shared_plugins: false
78
+ # Set true if running terraform version < 0.11.x
79
+ compat11: false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplygenius-atmos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
4
+ version: 0.11.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Conway
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-18 00:00:00.000000000 Z
11
+ date: 2019-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -282,14 +282,14 @@ dependencies:
282
282
  requirements:
283
283
  - - "~>"
284
284
  - !ruby/object:Gem::Version
285
- version: 1.2.2
285
+ version: 1.3.0
286
286
  type: :runtime
287
287
  prerelease: false
288
288
  version_requirements: !ruby/object:Gem::Requirement
289
289
  requirements:
290
290
  - - "~>"
291
291
  - !ruby/object:Gem::Version
292
- version: 1.2.2
292
+ version: 1.3.0
293
293
  - !ruby/object:Gem::Dependency
294
294
  name: hashie
295
295
  requirement: !ruby/object:Gem::Requirement