Class: Sfn::Command::Create

Inherits:
Sfn::Command
  • Object
show all
Includes:
Sfn::CommandModule::Base, Sfn::CommandModule::Stack, Sfn::CommandModule::Template
Defined in:
lib/sfn/command/create.rb

Overview

Create command

Constant Summary

Constants included from Sfn::CommandModule::Template

Sfn::CommandModule::Template::DEFAULT_PROVIDER_NAME, Sfn::CommandModule::Template::MAX_PARAMETER_ATTEMPTS, Sfn::CommandModule::Template::TEMPLATE_IGNORE_DIRECTORIES

Constants inherited from Sfn::Command

CONFIG_BASE_NAME, VALID_CONFIG_EXTENSIONS

Instance Method Summary collapse

Methods included from Sfn::CommandModule::Stack

included

Methods included from Sfn::CommandModule::Template

included

Methods included from Sfn::CommandModule::Base

included

Methods inherited from Sfn::Command

#config, #initialize

Methods included from Sfn::CommandModule::Callbacks

#api_action!, #callbacks_for, #run_callbacks_for

Constructor Details

This class inherits a constructor from Sfn::Command

Instance Method Details

#execute!Object

Run the stack creation command



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/sfn/command/create.rb', line 13

def execute!
  name_required!
  name = name_args.first

  # NOTE: Always disable plans on create
  config[:plan] = false

  if config[:template]
    file = config[:template]
  else
    file = load_template_file
  end

  unless config[:print_only]
    ui.info "#{ui.color("SparkleFormation:", :bold)} #{ui.color("create", :green)}"
  end

  stack_info = "#{ui.color("Name:", :bold)} #{name}"
  if config[:path]
    stack_info << " #{ui.color("Path:", :bold)} #{config[:file]}"
  end

  if config[:print_only]
    ui.puts format_json(parameter_scrub!(template_content(file)))
    return
  else
    ui.info "  -> #{stack_info}"
  end

  stack = provider.connection.stacks.build(
    config.fetch(:options, Smash.new).dup.merge(
      :name => name,
      :template => template_content(file),
      :parameters => Smash.new,
    )
  )

  apply_stacks!(stack)
  populate_parameters!(file, :current_parameters => stack.parameters)

  stack.parameters = config_root_parameters

  if config[:upload_root_template]
    upload_result = store_template(name, file, Smash.new)
    stack.template_url = upload_result[:url]
  else
    stack.template = parameter_scrub!(template_content(file, :scrub))
  end

  api_action!(:api_stack => stack) do
    stack.save
    if config[:poll]
      poll_stack(stack.name)
      stack = provider.stack(name)

      if stack.reload.state == :create_complete
        ui.info "Stack create complete: #{ui.color("SUCCESS", :green)}"
        namespace.const_get(:Describe).new({:outputs => true}, [name]).execute!
      else
        ui.fatal "Create of new stack #{ui.color(name, :bold)}: #{ui.color("FAILED", :red, :bold)}"
        raise "Stack did not reach a successful completion state."
      end
    else
      ui.warn "Stack state polling has been disabled."
      ui.info "Stack creation initialized for #{ui.color(name, :green)}"
    end
  end
end