lono 6.1.11 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) hide show
  1. checksums.yaml +4 -4
  2. data/.cody/acceptance.sh +19 -3
  3. data/.gitignore +2 -2
  4. data/CHANGELOG.md +16 -1
  5. data/README.md +18 -20
  6. data/Rakefile +1 -0
  7. data/lib/lono.rb +7 -5
  8. data/lib/lono/abstract_base.rb +25 -0
  9. data/lib/lono/api/client.rb +30 -0
  10. data/lib/lono/api/proxy.rb +58 -0
  11. data/lib/lono/api/repos.rb +8 -0
  12. data/lib/lono/api/verify.rb +13 -0
  13. data/lib/lono/app_file/base.rb +4 -11
  14. data/lib/lono/app_file/build.rb +1 -1
  15. data/lib/lono/app_file/upload.rb +1 -4
  16. data/lib/lono/autoloader.rb +3 -1
  17. data/lib/lono/aws_services.rb +9 -9
  18. data/lib/lono/aws_services/helper.rb +14 -0
  19. data/lib/lono/aws_services/{util.rb → stack.rb} +1 -9
  20. data/lib/lono/aws_services/stack_set.rb +41 -0
  21. data/lib/lono/blueprint.rb +2 -2
  22. data/lib/lono/blueprint/configset/loader.rb +7 -0
  23. data/lib/lono/blueprint/helper.rb +8 -2
  24. data/lib/lono/blueprint/meta.rb +4 -12
  25. data/lib/lono/blueprint/new.rb +3 -3
  26. data/lib/lono/blueprint/root.rb +6 -26
  27. data/lib/lono/bundle.rb +54 -0
  28. data/lib/lono/cfn.rb +31 -75
  29. data/lib/lono/cfn/base.rb +39 -136
  30. data/lib/lono/cfn/cancel.rb +14 -9
  31. data/lib/lono/cfn/create.rb +15 -19
  32. data/lib/lono/cfn/delete.rb +9 -9
  33. data/lib/lono/cfn/deploy.rb +4 -4
  34. data/lib/lono/cfn/download.rb +27 -9
  35. data/lib/lono/cfn/opts.rb +80 -0
  36. data/lib/lono/cfn/preview/changeset.rb +23 -23
  37. data/lib/lono/cfn/preview/codediff.rb +5 -6
  38. data/lib/lono/cfn/preview/param.rb +10 -10
  39. data/lib/lono/cfn/rollback.rb +5 -5
  40. data/lib/lono/cfn/status.rb +0 -10
  41. data/lib/lono/cfn/update.rb +22 -27
  42. data/lib/lono/clean.rb +3 -3
  43. data/lib/lono/cli.rb +69 -34
  44. data/lib/lono/code.rb +22 -0
  45. data/lib/lono/command.rb +7 -0
  46. data/lib/lono/config_location.rb +6 -13
  47. data/lib/lono/configset.rb +9 -0
  48. data/lib/lono/configset/combiner.rb +128 -0
  49. data/lib/lono/configset/evaluate_file.rb +8 -0
  50. data/lib/lono/configset/list.rb +67 -0
  51. data/lib/lono/configset/loader.rb +98 -0
  52. data/lib/lono/configset/loader/dsl.rb +9 -0
  53. data/lib/lono/configset/materializer/final.rb +10 -0
  54. data/lib/lono/configset/materializer/gems_builder.rb +81 -0
  55. data/lib/lono/configset/materializer/jade.rb +15 -0
  56. data/lib/lono/configset/materializer/source.rb +54 -0
  57. data/lib/lono/configset/meta.rb +19 -0
  58. data/lib/lono/configset/meta/dsl.rb +12 -0
  59. data/lib/lono/configset/new.rb +84 -0
  60. data/lib/lono/configset/preparer.rb +44 -0
  61. data/lib/lono/configset/register/base.rb +121 -0
  62. data/lib/lono/configset/register/blueprint.rb +16 -0
  63. data/lib/lono/configset/register/dsl.rb +15 -0
  64. data/lib/lono/configset/register/project.rb +12 -0
  65. data/lib/lono/configset/registry.rb +34 -0
  66. data/lib/lono/configset/resolver.rb +42 -0
  67. data/lib/lono/conventions.rb +18 -7
  68. data/lib/lono/core.rb +16 -20
  69. data/lib/lono/default/settings.yml +2 -3
  70. data/lib/lono/ext/bundler.rb +7 -0
  71. data/lib/lono/file_uploader.rb +8 -5
  72. data/lib/lono/finder/base.rb +140 -0
  73. data/lib/lono/finder/blueprint.rb +11 -0
  74. data/lib/lono/finder/blueprint/configset.rb +17 -0
  75. data/lib/lono/finder/configset.rb +11 -0
  76. data/lib/lono/generate.rb +93 -0
  77. data/lib/lono/help/blueprint/new.md +0 -1
  78. data/lib/lono/help/cfn/delete.md +1 -1
  79. data/lib/lono/help/cfn/deploy.md +5 -76
  80. data/lib/lono/help/cfn/status.md +0 -4
  81. data/lib/lono/help/cfn/update.md +1 -1
  82. data/lib/lono/help/code/convert.md +51 -0
  83. data/lib/lono/help/code/import.md +30 -0
  84. data/lib/lono/help/configsets.md +24 -0
  85. data/lib/lono/help/generate.md +4 -4
  86. data/lib/lono/help/new.md +1 -2
  87. data/lib/lono/help/sets/delete.md +8 -0
  88. data/lib/lono/help/sets/deploy.md +76 -0
  89. data/lib/lono/help/sets/instances/delete.md +21 -0
  90. data/lib/lono/help/sets/instances/list.md +14 -0
  91. data/lib/lono/help/sets/instances/status.md +15 -0
  92. data/lib/lono/help/sets/instances/sync.md +88 -0
  93. data/lib/lono/help/sets/status.md +23 -0
  94. data/lib/lono/help/upgrade.md +1 -0
  95. data/lib/lono/importer.rb +22 -0
  96. data/lib/lono/importer/base.rb +59 -0
  97. data/lib/lono/importer/converter.rb +19 -0
  98. data/lib/lono/importer/download.rb +46 -0
  99. data/lib/lono/importer/dsl.rb +36 -0
  100. data/lib/lono/importer/erb.rb +31 -0
  101. data/lib/lono/importer/params.rb +56 -0
  102. data/lib/lono/importer/service/coder.rb +81 -0
  103. data/lib/lono/inspector/base.rb +12 -22
  104. data/lib/lono/inspector/graph.rb +1 -1
  105. data/lib/lono/inspector/summary.rb +41 -17
  106. data/lib/lono/jade.rb +103 -0
  107. data/lib/lono/jade/circular.rb +26 -0
  108. data/lib/lono/jadespec.rb +41 -0
  109. data/lib/lono/new.rb +2 -2
  110. data/lib/lono/opts.rb +43 -0
  111. data/lib/lono/output/template.rb +48 -0
  112. data/lib/lono/param.rb +3 -5
  113. data/lib/lono/param/generator.rb +13 -33
  114. data/lib/lono/pro.rb +15 -0
  115. data/lib/lono/pro/base.rb +16 -0
  116. data/lib/lono/pro/repo.rb +27 -0
  117. data/lib/lono/project_checker.rb +4 -29
  118. data/lib/lono/registration.rb +15 -0
  119. data/lib/lono/registration/base.rb +37 -0
  120. data/lib/lono/registration/check.rb +15 -0
  121. data/lib/lono/registration/temp.rb +60 -0
  122. data/lib/lono/registration/user.rb +54 -0
  123. data/lib/lono/script/base.rb +1 -10
  124. data/lib/lono/script/upload.rb +2 -12
  125. data/lib/lono/seed.rb +2 -11
  126. data/lib/lono/seed/base.rb +55 -110
  127. data/lib/lono/sets.rb +38 -0
  128. data/lib/lono/sets/base.rb +45 -0
  129. data/lib/lono/sets/create.rb +30 -0
  130. data/lib/lono/sets/delete.rb +47 -0
  131. data/lib/lono/sets/deploy.rb +11 -0
  132. data/lib/lono/sets/instances.rb +33 -0
  133. data/lib/lono/sets/instances/base.rb +30 -0
  134. data/lib/lono/sets/instances/delete.rb +69 -0
  135. data/lib/lono/sets/instances/list.rb +13 -0
  136. data/lib/lono/sets/instances/opts.rb +29 -0
  137. data/lib/lono/sets/instances/status.rb +12 -0
  138. data/lib/lono/sets/instances/sync.rb +182 -0
  139. data/lib/lono/sets/list.rb +35 -0
  140. data/lib/lono/sets/opts.rb +18 -0
  141. data/lib/lono/sets/preview/codediff.rb +35 -0
  142. data/lib/lono/sets/preview/param.rb +32 -0
  143. data/lib/lono/sets/status.rb +116 -0
  144. data/lib/lono/sets/status/instance.rb +20 -0
  145. data/lib/lono/sets/status/instance/base.rb +120 -0
  146. data/lib/lono/sets/status/instance/completed.rb +35 -0
  147. data/lib/lono/sets/status/instance/deleted.rb +32 -0
  148. data/lib/lono/sets/status/instance/show.rb +7 -0
  149. data/lib/lono/sets/status/instances.rb +111 -0
  150. data/lib/lono/sets/summarize.rb +20 -0
  151. data/lib/lono/sets/time_spent.rb +11 -0
  152. data/lib/lono/sets/update.rb +81 -0
  153. data/lib/lono/template.rb +5 -7
  154. data/lib/lono/template/configset_injector.rb +50 -0
  155. data/lib/lono/template/context.rb +4 -4
  156. data/lib/lono/template/context/loader.rb +4 -16
  157. data/lib/lono/template/evaluate.rb +2 -1
  158. data/lib/lono/template/generator.rb +17 -15
  159. data/lib/lono/template/helper.rb +7 -7
  160. data/lib/lono/template/post_processor.rb +2 -12
  161. data/lib/lono/template/strategy/base.rb +4 -0
  162. data/lib/lono/template/{dsl.rb → strategy/dsl.rb} +4 -6
  163. data/lib/lono/template/{dsl → strategy/dsl}/builder.rb +11 -15
  164. data/lib/lono/template/{dsl → strategy/dsl}/builder/fn.rb +1 -1
  165. data/lib/lono/template/strategy/dsl/builder/helpers.rb +11 -0
  166. data/lib/lono/template/strategy/dsl/builder/helpers/core_helper.rb +14 -0
  167. data/lib/lono/template/strategy/dsl/builder/helpers/file_helper.rb +48 -0
  168. data/lib/lono/template/strategy/dsl/builder/helpers/lookup_helper.rb +27 -0
  169. data/lib/lono/template/strategy/dsl/builder/helpers/s3_helper.rb +13 -0
  170. data/lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb +39 -0
  171. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/base.rb +6 -17
  172. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/condition.rb +1 -1
  173. data/lib/lono/template/strategy/dsl/builder/section/extensions.rb +9 -0
  174. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/mapping.rb +1 -1
  175. data/lib/lono/template/{dsl/builder/section_methods.rb → strategy/dsl/builder/section/methods.rb} +9 -2
  176. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/output.rb +1 -1
  177. data/lib/lono/template/strategy/dsl/builder/section/parameter.rb +69 -0
  178. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/resource.rb +1 -1
  179. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/resource/property_mover.rb +1 -1
  180. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/section.rb +1 -1
  181. data/lib/lono/template/{dsl → strategy/dsl}/builder/squeezer.rb +1 -1
  182. data/lib/lono/template/strategy/dsl/builder/stringify.rb +15 -0
  183. data/lib/lono/template/{dsl → strategy/dsl}/builder/syntax.rb +3 -2
  184. data/lib/lono/template/strategy/dsl/finalizer.rb +12 -0
  185. data/lib/lono/template/strategy/dsl/finalizer/parameter_groups.rb +56 -0
  186. data/lib/lono/template/{erb.rb → strategy/erb.rb} +5 -5
  187. data/lib/lono/template/strategy/source.rb +8 -0
  188. data/lib/lono/template/template.rb +1 -1
  189. data/lib/lono/template/upload.rb +4 -9
  190. data/lib/lono/template/util.rb +0 -40
  191. data/lib/lono/upgrade.rb +12 -10
  192. data/lib/lono/user_data.rb +4 -4
  193. data/lib/lono/utils/pretty_time.rb +14 -0
  194. data/lib/lono/utils/sure.rb +23 -0
  195. data/lib/lono/version.rb +1 -1
  196. data/lib/lono/yamler/loader.rb +52 -0
  197. data/lib/lono/yamler/validator.rb +51 -0
  198. data/lib/templates/blueprint/%blueprint_name%.gemspec.tt +4 -0
  199. data/lib/templates/blueprint/README.md.tt +1 -1
  200. data/lib/templates/blueprint/seed/configs.rb +2 -2
  201. data/lib/templates/blueprint_types/dsl/app/templates/%blueprint_name%.rb +17 -18
  202. data/lib/templates/blueprint_types/erb/app/templates/%blueprint_name%.yml +63 -4
  203. data/lib/templates/configset/%configset_name%.gemspec.tt +41 -0
  204. data/lib/templates/configset/.gitignore +11 -0
  205. data/lib/templates/configset/CHANGELOG.md +7 -0
  206. data/lib/templates/configset/Gemfile +4 -0
  207. data/lib/templates/configset/README.md.tt +3 -0
  208. data/lib/templates/configset/Rakefile.tt +9 -0
  209. data/lib/templates/configset/lib/configset.yml +20 -0
  210. data/lib/templates/skeleton/.gitignore +1 -0
  211. data/lib/templates/skeleton/Gemfile +0 -1
  212. data/lib/templates/skeleton/README.md +4 -4
  213. data/lib/templates/skeleton/configs/settings.yml +1 -1
  214. data/lono.gemspec +1 -4
  215. metadata +146 -79
  216. data/Guardfile +0 -19
  217. data/lib/lono/app_file.rb +0 -5
  218. data/lib/lono/blueprint/find.rb +0 -90
  219. data/lib/lono/blueprint/info.rb +0 -10
  220. data/lib/lono/blueprint/list.rb +0 -14
  221. data/lib/lono/cfn/current.rb +0 -95
  222. data/lib/lono/cfn/preview.rb +0 -4
  223. data/lib/lono/cfn/suffix.rb +0 -67
  224. data/lib/lono/cfn/util.rb +0 -27
  225. data/lib/lono/help/cfn/current.md +0 -18
  226. data/lib/lono/help/upgrade4.md +0 -25
  227. data/lib/lono/inspector.rb +0 -4
  228. data/lib/lono/output_template.rb +0 -35
  229. data/lib/lono/template/base.rb +0 -13
  230. data/lib/lono/template/dsl/builder/helpers.rb +0 -8
  231. data/lib/lono/template/dsl/builder/helpers/core_helper.rb +0 -107
  232. data/lib/lono/template/dsl/builder/helpers/param_helper.rb +0 -61
  233. data/lib/lono/template/dsl/builder/parameter.rb +0 -39
  234. data/lib/lono/upgrade/upgrade4.rb +0 -175
  235. data/lib/lono/upgrade/upgrade42.rb +0 -36
  236. data/lib/lono/upgrade/upgrade5.rb +0 -55
  237. data/lib/templates/blueprint/.meta/config.yml.tt +0 -4
  238. data/lib/templates/skeleton/Guardfile +0 -12
  239. data/lib/templates/upgrade5/blueprints/main/.lono/config.yml +0 -3
  240. data/lib/templates/upgrade5/blueprints/main/.meta/config.yml +0 -3
@@ -1,27 +1,32 @@
1
1
  class Lono::Cfn
2
2
  class Cancel
3
3
  include Lono::AwsServices
4
- include Util
4
+ include Lono::Utils::Sure
5
5
 
6
- def initialize(stack_name, options={})
7
- @stack_name = switch_current(stack_name)
6
+ def initialize(options={})
8
7
  @options = options
8
+ @stack = options[:stack]
9
9
  end
10
10
 
11
11
  def run
12
- stack = find_stack(@stack_name)
12
+ if @options[:noop]
13
+ puts "NOOP Canceling #{@stack} stack"
14
+ return
15
+ end
16
+
17
+ stack = find_stack(@stack)
13
18
  unless stack
14
- puts "The '#{@stack_name}' stack does not exist. Unable to cancel"
19
+ puts "The '#{@stack}' stack does not exist. Unable to cancel"
15
20
  exit 1
16
21
  end
17
22
 
18
- puts "Canceling updates to #{@stack_name}."
23
+ puts "Canceling updates to #{@stack}."
19
24
  puts "Current stack status: #{stack.stack_status}"
20
25
  if stack.stack_status == "CREATE_IN_PROGRESS"
21
- cfn.delete_stack(stack_name: @stack_name)
26
+ cfn.delete_stack(stack_name: @stack)
22
27
  puts "Canceling stack creation."
23
28
  elsif stack.stack_status == "UPDATE_IN_PROGRESS"
24
- cfn.cancel_update_stack(stack_name: @stack_name)
29
+ cfn.cancel_update_stack(stack_name: @stack)
25
30
  puts "Canceling stack update."
26
31
  status.wait if @options[:wait]
27
32
  else
@@ -30,7 +35,7 @@ class Lono::Cfn
30
35
  end
31
36
 
32
37
  def status
33
- @status ||= Status.new(@stack_name)
38
+ @status ||= Status.new(@stack)
34
39
  end
35
40
  end
36
41
  end
@@ -2,14 +2,10 @@ require "yaml"
2
2
 
3
3
  class Lono::Cfn
4
4
  class Create < Base
5
- # save_stack is the interface method
6
- def save_stack(params)
7
- create_stack(params)
8
- end
9
-
5
+ # save is the interface method
10
6
  # aws cloudformation create-stack --stack-name prod-hi-123456789 --parameters file://output/params/prod-hi-123456789.json --template-body file://output/prod-hi.json
11
- def create_stack(params)
12
- message = "Creating #{@stack_name.color(:green)} stack."
7
+ def save(parameters)
8
+ message = "Creating #{@stack.color(:green)} stack."
13
9
  if @options[:noop]
14
10
  puts "NOOP #{message}"
15
11
  return
@@ -17,28 +13,28 @@ class Lono::Cfn
17
13
 
18
14
  delete_rollback_stack
19
15
 
20
- if stack_exists?(@stack_name)
21
- puts "Cannot create #{@stack_name.color(:green)} stack because it already exists.".color(:red)
16
+ if stack_exists?(@stack)
17
+ puts "Cannot create #{@stack.color(:green)} stack because it already exists.".color(:red)
22
18
  return
23
19
  end
24
20
 
25
- unless File.exist?(@template_path)
26
- puts "Cannot create #{@stack_name.color(:green)} template not found: #{@template_path}."
21
+ unless File.exist?(template_path)
22
+ puts "Cannot create #{@stack.color(:green)} template not found: #{template_path}."
27
23
  return
28
24
  end
29
25
 
30
- params = {
31
- stack_name: @stack_name,
32
- parameters: params,
26
+ options = {
27
+ stack_name: @stack,
28
+ parameters: parameters,
33
29
  capabilities: capabilities, # ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"]
34
30
  disable_rollback: !@options[:rollback],
35
31
  }
36
- params[:tags] = tags unless tags.empty?
37
- set_template_body!(params)
32
+ options[:tags] = tags unless tags.empty?
33
+ set_template_url!(options)
38
34
 
39
- show_parameters(params, "cfn.create_stack")
40
- cfn.create_stack(params) # TODO: COMMENT OUT FOR TESTING
35
+ show_options(options, "cfn.create_stack")
36
+ cfn.create_stack(options) # TODO: COMMENT OUT FOR TESTING
41
37
  puts message unless @options[:mute]
42
38
  end
43
39
  end
44
- end
40
+ end
@@ -1,25 +1,25 @@
1
1
  class Lono::Cfn
2
2
  class Delete
3
3
  include Lono::AwsServices
4
- include Util
4
+ include Lono::Utils::Sure
5
5
 
6
- def initialize(stack_name, options={})
7
- @stack_name = switch_current(stack_name)
6
+ def initialize(options={})
8
7
  @options = options
8
+ @stack = options.delete(:stack)
9
9
  end
10
10
 
11
11
  def run
12
- message = "Deleting #{@stack_name} stack."
12
+ message = "Deleting #{@stack} stack."
13
13
  if @options[:noop]
14
14
  puts "NOOP #{message}"
15
15
  else
16
- are_you_sure?(@stack_name, :delete)
16
+ sure?("Are you sure you want to delete the #{@stack} stack?")
17
17
 
18
- if stack_exists?(@stack_name)
19
- cfn.delete_stack(stack_name: @stack_name)
18
+ if stack_exists?(@stack)
19
+ cfn.delete_stack(stack_name: @stack)
20
20
  puts message
21
21
  else
22
- puts "#{@stack_name.inspect} stack does not exist".color(:red)
22
+ puts "#{@stack.inspect} stack does not exist".color(:red)
23
23
  return
24
24
  end
25
25
  end
@@ -32,7 +32,7 @@ class Lono::Cfn
32
32
  end
33
33
 
34
34
  def status
35
- @status ||= Status.new(@stack_name)
35
+ @status ||= Status.new(@stack)
36
36
  end
37
37
  end
38
38
  end
@@ -1,10 +1,10 @@
1
1
  class Lono::Cfn
2
2
  class Deploy < Base
3
- def save_stack(params)
4
- if stack_exists?(@stack_name)
5
- Update.new(@stack_name, @options).update_stack(params)
3
+ def save(parameters)
4
+ if stack_exists?(@stack)
5
+ Update.new(@options).save(parameters)
6
6
  else
7
- Create.new(@stack_name, @options).create_stack(params)
7
+ Create.new(@options).save(parameters)
8
8
  end
9
9
  end
10
10
  end
@@ -1,22 +1,37 @@
1
1
  require 'json'
2
+ require 'open-uri'
2
3
 
3
4
  class Lono::Cfn
4
- class Download < Base
5
+ class Download < Lono::AbstractBase
6
+ include Lono::AwsServices
7
+
5
8
  def run
6
- puts "Download existing template to: #{download_path}"
9
+ pretty_path = download_path.sub("#{Lono.root}/", '')
10
+ puts "Downloading template to: #{pretty_path}"
7
11
  return if @options[:noop]
8
12
  download_template
9
13
  end
10
14
 
11
15
  def download_template
12
- resp = cfn.get_template(
13
- stack_name: @stack_name,
14
- template_stage: "Original"
15
- )
16
- body = convert_to_yaml(resp.template_body)
16
+ body = download_stack
17
+ body = convert_to_yaml(body)
18
+ FileUtils.mkdir_p(File.dirname(download_path))
17
19
  IO.write(download_path, body)
18
20
  end
19
21
 
22
+ def download_stack
23
+ source = @options[:source]
24
+ if source
25
+ open(source).read # url or file
26
+ else
27
+ resp = cfn.get_template(
28
+ stack_name: @stack,
29
+ template_stage: "Original"
30
+ )
31
+ resp.template_body
32
+ end
33
+ end
34
+
20
35
  def convert_to_yaml(body)
21
36
  json?(body) ? YAML.dump(JSON.parse(body)) : body
22
37
  end
@@ -26,8 +41,11 @@ class Lono::Cfn
26
41
  end
27
42
 
28
43
  def download_path
29
- name = @options[:name] || @stack_name
30
- "/tmp/#{name}.yml"
44
+ "#{Lono.config.output_path}/#{@blueprint}/templates/#{@blueprint}.yml"
45
+ end
46
+
47
+ def name
48
+ @options[:name] || @stack
31
49
  end
32
50
  end
33
51
  end
@@ -0,0 +1,80 @@
1
+ class Lono::Cfn
2
+ class Opts < Lono::Opts
3
+ def create
4
+ base_options
5
+ wait_options
6
+ end
7
+
8
+ def update
9
+ base_options
10
+ update_options
11
+ wait_options
12
+ end
13
+
14
+ def deploy
15
+ update
16
+ end
17
+
18
+ def delete
19
+ wait_options
20
+ end
21
+
22
+ def cancel
23
+ wait_options
24
+ end
25
+
26
+ def preview
27
+ base_options
28
+ update_options
29
+ with_cli_scope do
30
+ option :keep, type: :boolean, desc: "keep the changeset instead of deleting it afterwards"
31
+ end
32
+ end
33
+
34
+ def download
35
+ base_options
36
+ with_cli_scope do
37
+ option :name, desc: "Name you want to save the template as. Default: existing stack name."
38
+ option :source, desc: "url or path to file with template"
39
+ end
40
+ end
41
+
42
+ # Lono::Cfn and Lono::Sets
43
+ def base_options(rollback: true)
44
+ with_cli_scope do
45
+ if rollback
46
+ option :rollback, type: :boolean, desc: "rollback", default: true
47
+ end
48
+ # common to Lono::Cfn and Lono::Sets
49
+ option :source, desc: "url or path to file with template"
50
+ option :blueprint, desc: "override convention and specify the template file to use"
51
+ option :capabilities, type: :array, desc: "iam capabilities. Ex: CAPABILITY_IAM, CAPABILITY_NAMED_IAM"
52
+ option :config, aliases: "c", desc: "override convention and specify both the param and variable file to use"
53
+ option :iam, type: :boolean, desc: "Shortcut for common IAM capabilities: CAPABILITY_IAM, CAPABILITY_NAMED_IAM"
54
+ option :param, aliases: "p", desc: "override convention and specify the param file to use"
55
+ option :tags, type: :hash, desc: "Tags for the stack. IE: Name:api-web Owner:bob"
56
+ option :template, desc: "override convention and specify the template file to use"
57
+ option :variable, aliases: "v", desc: "override convention and specify the variable file to use"
58
+ end
59
+ end
60
+
61
+ def wait_options
62
+ with_cli_scope do
63
+ option :wait, type: :boolean, desc: "Wait for stack operation to complete.", default: true
64
+ option :sure, type: :boolean, desc: "Skip are you sure prompt" # moved to base but used by commands like `lono cfn delete` also. Just keep here.
65
+ end
66
+ end
67
+
68
+ def update_options(change_set: true)
69
+ with_cli_scope do
70
+ if change_set
71
+ option :change_set, type: :boolean, default: true, desc: "Uses generated change set to update the stack. If false, will perform normal update-stack."
72
+ option :changeset_preview, type: :boolean, default: true, desc: "Show ChangeSet changes preview."
73
+ end
74
+ # common to Lono::Cfn and Lono::Sets
75
+ option :codediff_preview, type: :boolean, default: true, desc: "Show codediff changes preview."
76
+ option :param_preview, type: :boolean, default: true, desc: "Show parameter diff preview."
77
+ end
78
+ end
79
+ end
80
+ end
@@ -5,39 +5,39 @@ module Lono::Cfn::Preview
5
5
  puts "Changeset Preview:".color(:green)
6
6
 
7
7
  if @options[:noop]
8
- puts "NOOP CloudFormation preview for #{@stack_name} update"
8
+ puts "NOOP CloudFormation preview for #{@stack} update"
9
9
  return
10
10
  end
11
11
 
12
- params = generate_all
13
- success = preview_change_set(params)
12
+ parameters = generate_all
13
+ success = preview_change_set(parameters)
14
14
  delete_change_set if success && !@options[:keep] # Clean up and delete the change set
15
15
  end
16
16
 
17
- def preview_change_set(params)
18
- success = create_change_set(params)
17
+ def preview_change_set(parameters)
18
+ success = create_change_set(parameters)
19
19
  display_change_set if success
20
20
  end
21
21
 
22
- def create_change_set(params)
23
- unless stack_exists?(@stack_name)
24
- puts "WARN: Cannot create a change set for the stack because the #{@stack_name} does not exists.".color(:yellow)
22
+ def create_change_set(parameters)
23
+ unless stack_exists?(@stack)
24
+ puts "WARN: Cannot create a change set for the stack because the #{@stack} does not exists.".color(:yellow)
25
25
  return false
26
26
  end
27
- exit_unless_updatable!(stack_status(@stack_name))
27
+ exit_unless_updatable!
28
28
 
29
- params = {
29
+ options = {
30
30
  change_set_name: change_set_name,
31
- stack_name: @stack_name,
32
- parameters: params,
31
+ stack_name: @stack,
32
+ parameters: parameters,
33
33
  }
34
- params[:tags] = tags unless tags.empty?
35
- set_template_body!(params)
36
- show_parameters(params, "cfn.create_change_set")
34
+ options[:tags] = tags unless tags.empty?
35
+ set_template_url!(options)
36
+ show_options(options, "cfn.create_change_set")
37
37
  begin
38
- # Tricky for preview need to set capabilities so that it gets updated. For Base#run save_stack within the begin block already.
39
- params[:capabilities] = capabilities # ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"]
40
- cfn.create_change_set(params)
38
+ # Tricky for preview need to set capabilities so that it gets updated. For Base#run save within the begin block already.
39
+ options[:capabilities] = capabilities # ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"]
40
+ cfn.create_change_set(options)
41
41
  rescue Aws::CloudFormation::Errors::InsufficientCapabilitiesException => e
42
42
  # If coming from cfn_preview_command automatically add iam capabilities
43
43
  cfn_preview_command = ARGV.join(" ").include?("cfn preview")
@@ -83,7 +83,7 @@ module Lono::Cfn::Preview
83
83
 
84
84
  case change_set.status
85
85
  when "CREATE_COMPLETE"
86
- puts "CloudFormation preview for '#{@stack_name}' stack update. Changes:"
86
+ puts "CloudFormation preview for '#{@stack}' stack update. Changes:"
87
87
  changes = change_set.changes.sort_by do |change|
88
88
  change["resource_change"]["action"]
89
89
  end
@@ -91,7 +91,7 @@ module Lono::Cfn::Preview
91
91
  display_change(change)
92
92
  end
93
93
  when "FAILED"
94
- puts "WARN: Fail to create a CloudFormation preview for '#{@stack_name}' stack update. Reason:".color(:yellow)
94
+ puts "WARN: Fail to create a CloudFormation preview for '#{@stack}' stack update. Reason:".color(:yellow)
95
95
  puts change_set.status_reason
96
96
  quit(0)
97
97
  else
@@ -102,14 +102,14 @@ module Lono::Cfn::Preview
102
102
  def delete_change_set
103
103
  cfn.delete_change_set(
104
104
  change_set_name: change_set_name,
105
- stack_name: @stack_name
105
+ stack_name: @stack
106
106
  )
107
107
  end
108
108
 
109
109
  def execute_change_set
110
110
  cfn.execute_change_set(
111
111
  change_set_name: change_set_name,
112
- stack_name: @stack_name
112
+ stack_name: @stack
113
113
  )
114
114
  end
115
115
 
@@ -160,7 +160,7 @@ module Lono::Cfn::Preview
160
160
  def describe_change_set
161
161
  cfn.describe_change_set(
162
162
  change_set_name: change_set_name,
163
- stack_name: @stack_name
163
+ stack_name: @stack
164
164
  )
165
165
  end
166
166
  end
@@ -6,8 +6,8 @@ module Lono::Cfn::Preview
6
6
  def run
7
7
  puts "Code Diff Preview:".color(:green)
8
8
 
9
- unless stack_exists?(@stack_name)
10
- puts "WARN: Cannot create a diff for the stack because the #{@stack_name} does not exists.".color(:yellow)
9
+ unless stack_exists?(@stack)
10
+ puts "WARN: Cannot create a diff for the stack because the #{@stack} does not exists.".color(:yellow)
11
11
  return
12
12
  end
13
13
 
@@ -23,20 +23,19 @@ module Lono::Cfn::Preview
23
23
 
24
24
  def download_existing_cfn_template
25
25
  resp = cfn.get_template(
26
- stack_name: @stack_name,
26
+ stack_name: @stack,
27
27
  template_stage: "Original"
28
28
  )
29
- resp.template_body
30
29
  IO.write(existing_template_path, resp.template_body)
31
30
  end
32
31
 
33
32
  # for clarity
34
33
  def new_cfn_template
35
- @template_path
34
+ template_path
36
35
  end
37
36
 
38
37
  def existing_template_path
39
- "/tmp/existing_cfn_template.yml"
38
+ "/tmp/existing_stack.yml"
40
39
  end
41
40
  end
42
41
  end
@@ -7,12 +7,12 @@ module Lono::Cfn::Preview
7
7
  include Lono::AwsServices
8
8
 
9
9
  def run
10
- return unless stack_exists?(@stack_name)
10
+ return unless stack_exists?(@stack)
11
11
 
12
- generated_params # eager call generated_params so its output is above Parameter Diff Preview
12
+ generated_parameters # eager call generated_parameters so its output is above Parameter Diff Preview
13
13
  puts "Parameter Diff Preview:".color(:green)
14
14
  if @options[:noop]
15
- puts "NOOP CloudFormation parameters preview for #{@stack_name} update"
15
+ puts "NOOP CloudFormation parameters preview for #{@stack} update"
16
16
  return
17
17
  end
18
18
 
@@ -30,7 +30,7 @@ module Lono::Cfn::Preview
30
30
  memoize :existing_params
31
31
 
32
32
  def new_params
33
- params = optional_params.merge(generated_params)
33
+ params = optional_params.merge(generated_parameters)
34
34
  subtract(params, noecho_params)
35
35
  end
36
36
 
@@ -42,11 +42,11 @@ module Lono::Cfn::Preview
42
42
  Hash[hash.sort_by {|k,v| k}]
43
43
  end
44
44
 
45
- def generated_params
46
- params = generate_all
47
- normalize(params)
45
+ def generated_parameters
46
+ parameters = generate_all
47
+ normalize(parameters)
48
48
  end
49
- memoize :generated_params
49
+ memoize :generated_parameters
50
50
 
51
51
  def optional_params
52
52
  # normalizing to simple Hash
@@ -62,7 +62,7 @@ module Lono::Cfn::Preview
62
62
  memoize :noecho_params
63
63
 
64
64
  def stack_parameters
65
- resp = cfn.describe_stacks(stack_name: @stack_name)
65
+ resp = cfn.describe_stacks(stack_name: @stack)
66
66
  stack = resp.stacks.first
67
67
  stack.parameters
68
68
  end
@@ -70,7 +70,7 @@ module Lono::Cfn::Preview
70
70
 
71
71
  private
72
72
  def output_template
73
- Lono::OutputTemplate.new(@blueprint, @template)
73
+ Lono::Output::Template.new(@blueprint, @template)
74
74
  end
75
75
  memoize :output_template
76
76