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::MAX_PARAMETER_ATTEMPTS, Sfn::CommandModule::Template::TEMPLATE_IGNORE_DIRECTORIES

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



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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/sfn/command/create.rb', line 14

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
    nested_stacks_unpack = file.delete('sfn_nested_stack')
  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

  unless(config[:print_only])
    ui.info "  -> #{stack_info}"
  end

  if(nested_stacks_unpack)
    unpack_nesting(name, file, :create)
  else

    if(config[:print_only] && !config[:apply_stacks])
      ui.puts _format_json(
        translate_template(
          Sfn::Utils::StackParameterScrubber.scrub!(file)
        )
      )
      return
    end

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

    apply_stacks!(stack)
    stack.template = Sfn::Utils::StackParameterScrubber.scrub!(stack.template)

    if(config[:print_only])
      ui.puts _format_json(translate_template(stack.template))
      return
    end

    populate_parameters!(stack.template)
    stack.parameters = config_root_parameters

    stack.template = translate_template(stack.template)

    api_action!(:api_stack => stack) do
      stack.save
      if(config[:poll])
        poll_stack(stack.name)
        stack = provider.connection.stacks.get(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

end