Sha256: 6e4171f0bd8c2b5d317a99bf7195e321363cc476a8438b96ee20d748231f8e29

Contents?: true

Size: 1.75 KB

Versions: 12

Compression:

Stored size: 1.75 KB

Contents

class Lono::Cfn::Create < Lono::Cfn::Base
  # save_stack is the interface method
  def save_stack(params)
    create_stack(params)
  end

  # aws cloudformation create-stack --stack-name prod-hi-123456789 --parameters file://output/params/prod-hi-123456789.json --template-body file://output/prod-hi.json
  def create_stack(params)
    message = "Creating #{@stack_name} stack."
    if @options[:noop]
      puts "NOOP #{message}"
      return
    end

    if stack_exists?(@stack_name)
      puts "Cannot create '#{@stack_name}' stack because it already exists.".colorize(:red)
      return
    end

    unless File.exist?(@template_path)
      puts "Cannot create '#{@stack_name}' template not found: #{@template_path}."
      return
    end

    template_body = IO.read(@template_path)
    cfn.create_stack(
      stack_name: @stack_name,
      template_body: template_body,
      parameters: params,
      capabilities: capabilities, # ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"]
      disable_rollback: !@options[:rollback],
    )
    puts message unless @options[:mute]
  end

  # Appends a short random string at the end of a stack name.
  # Later we will strip this same random string from the template name.
  # Very makes it convenient.  We can just type:
  #
  #   lono cfn create main --randomize-stack-name
  #
  # instead of:
  #
  #   lono cfn create main-[RANDOM] --template main
  #
  # The randomize_stack_name can be specified at the CLI but can also be saved as a
  # preference.
  #
  # It is not a default setting because it might confuse new lono users.
  def randomize(stack_name)
    if randomize_stack_name?
      random = (0...3).map { (65 + rand(26)).chr }.join.downcase # Ex: jhx
      [stack_name, random].join('-')
    else
      stack_name
    end
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
lono-3.5.0 lib/lono/cfn/create.rb
lono-3.4.1 lib/lono/cfn/create.rb
lono-3.4.0 lib/lono/cfn/create.rb
lono-3.3.4 lib/lono/cfn/create.rb
lono-3.3.2 lib/lono/cfn/create.rb
lono-3.3.0 lib/lono/cfn/create.rb
lono-3.2.1 lib/lono/cfn/create.rb
lono-3.2.0 lib/lono/cfn/create.rb
lono-3.1.3 lib/lono/cfn/create.rb
lono-3.1.2 lib/lono/cfn/create.rb
lono-3.1.1 lib/lono/cfn/create.rb
lono-3.0.1 lib/lono/cfn/create.rb