require 'fog' module Stackster class AWS class CloudFormation def initialize(args) @config = args[:config] @logger = @config.logger @connect = Fog::AWS::CloudFormation.new :aws_access_key_id => @config.access_key, :aws_secret_access_key => @config.secret_key, :region => @config.region end def create(args) parameters = { 'Parameters' => args[:parameters] } data = { 'Capabilities' => ['CAPABILITY_IAM'], 'TemplateBody' => args[:template] }.merge parameters begin @connect.create_stack(args[:name], data) rescue Exception => e Error.new(:config => @config, :exception => e).process end @logger.info "Cloud Formation stack creation completed." end def update(args) parameters = { 'Parameters' => args[:parameters] } data = { 'Capabilities' => ['CAPABILITY_IAM'], 'TemplateBody' => args[:template] }.merge parameters begin @connect.update_stack(args[:name], data) rescue Exception => e Error.new(:config => @config, :exception => e).process end @logger.info "Cloud Formation stack update completed." end def destroy(name) begin @connect.delete_stack name rescue Exception => e Error.new(:config => @config, :exception => e).process end @logger.info "Cloud Formation stack destroy completed." end def describe_stack(name) @connect.describe_stacks('StackName' => name).body['Stacks'] end def stack_resources(name) @connect.describe_stack_resources('StackName' => name).body['StackResources'] end def stack_events(name, limit) @connect.describe_stack_events(name).body['StackEvents'] [0..limit-1] end def stack_status(name) describe_stack(name).first['StackStatus'] end def stack_outputs(name) describe_stack(name).last['Outputs'] end def template(name) @connect.get_template(name).body['TemplateBody'] end end end end