lib/cfer.rb
# Creates or updates a CloudFormation stack
# @param stack_name [String] The name of the stack to update
# @param options [Hash]
Creates or updates a CloudFormation stack
Creates or updates a CloudFormation stack
def converge!(stack_name, options = {})
      config(options)
      options[:on_failure].upcase! if options[:on_failure]
      tmpl = options[:template] || "#{stack_name}.rb"
      cfn = options[:aws_options] || {}
      cfn_stack = options[:cfer_client] || Cfer::Cfn::Client.new(cfn.merge(stack_name: stack_name))
      raise Cfer::Util::CferError, "No such template file: #{tmpl}" unless File.exist?(tmpl) || options[:cfer_stack]
      stack =
        options[:cfer_stack] ||
          Cfer::stack_from_file(tmpl,
            options.merge(
              client: cfn_stack,
              parameters: generate_final_parameters(options)
            )
          )
      begin
        operation = stack.converge!(options)
        if options[:follow] && !options[:change]
          begin
            tail! stack_name, options.merge(cfer_client: cfn_stack)
          rescue Interrupt
            puts "Caught interrupt. What would you like to do?"
            case HighLine.new($stdin, $stderr).choose('Continue', 'Quit', 'Rollback')
            when 'Continue'
              retry
            when 'Rollback'
              rollback_opts = {
                stack_name: stack_name
              }
              case operation
              when :created
                rollback_opts[:role_arn] = options[:role_arn] if options[:role_arn]
                cfn_stack.delete_stack rollback_opts
              when :updated
                cfn_stack.cancel_update_stack rollback_opts
              end
              retry
            end
          end
        end
        describe! stack_name, options rescue nil
      rescue Aws::CloudFormation::Errors::ValidationError => e
        Cfer::LOGGER.info "CFN validation error: #{e.message}"
      end
      stack
    end
def converge! ( stack_name , options = { } ) config ( options ) options [ :on_failure ] . upcase! if options [ :on_failure ] tmpl = options [ :template ] || "#{stack_name}.rb" cfn = options [ :aws_options ] || { } cfn_stack = options [ :cfer_client ] || Cfer :: Cfn :: Client . new ( cfn . merge ( stack_name : stack_name ) ) raise Cfer :: Util :: CferError , "No such template file: #{tmpl}" unless File . exist? ( tmpl ) || options [ :cfer_stack ] stack = options [ :cfer_stack ] || Cfer :: stack_from_file ( tmpl , options . merge ( client : cfn_stack , parameters : generate_final_parameters ( options ) ) ) begin operation = stack . converge! ( options ) if options [ :follow ] && ! options [ :change ] begin tail! stack_name , options . merge ( cfer_client : cfn_stack ) rescue Interrupt puts "Caught interrupt. What would you like to do?" case HighLine . new ( $stdin , $stderr ) . choose ( 'Continue' , 'Quit' , 'Rollback' ) when 'Continue' retry when 'Rollback' rollback_opts = { stack_name : stack_name } case operation when :created rollback_opts [ :role_arn ] = options [ :role_arn ] if options [ :role_arn ] cfn_stack . delete_stack rollback_opts when :updated cfn_stack . cancel_update_stack rollback_opts end retry end end end describe! stack_name , options rescue nil rescue Aws :: CloudFormation :: Errors :: ValidationError => e Cfer :: LOGGER . info "CFN validation error: #{e.message}" end stack end
Creates or updates a CloudFormation stack
Creates or updates a CloudFormation stack
# This is allowed to fail, particularly if we decided to roll back
stack_name
The name of the stack to update
The name of the stack to update
options
<not_specific>
<not_specific>
None