Method: CfnFlow::CLI#deploy

Defined in:
lib/cfn_flow/cli.rb

#deploy(environment) ⇒ Object



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
# File 'lib/cfn_flow/cli.rb', line 54

def deploy(environment)
  # Export environment as an env var so it can be interpolated in config
  ENV['CFN_FLOW_ENVIRONMENT'] = environment

  begin
    params = CfnFlow.stack_params(environment)
    stack = CfnFlow.cfn_resource.create_stack(params)
  rescue Aws::CloudFormation::Errors::ValidationError => e
    raise Thor::Error.new(e.message)
  end

  say "Launching stack #{stack.name}"

  # Invoke events
  say "Polling for events..."
  invoke :events, [stack.name], ['--poll']

  say "Stack Outputs:"
  invoke :show, [stack.name], ['--format=outputs-table']

  # Optionally cleanup other stacks in this environment
  if options[:cleanup]
    puts "Finding stacks to clean up"
    list_stacks_in_service.select {|s|
      s.name != stack.name && \
        s.tags.any? {|tag| tag.key == 'CfnFlowEnvironment' && tag.value == environment }
    }.map(&:name).each do |name|
      delete(name)
    end
  end
end