Class: Stackster::AWS::CloudFormation

Inherits:
Object
  • Object
show all
Defined in:
lib/stackster/aws/cloud_formation.rb,
lib/stackster/aws/cloud_formation/error.rb

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CloudFormation

Returns a new instance of CloudFormation.



7
8
9
10
11
12
13
# File 'lib/stackster/aws/cloud_formation.rb', line 7

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

Instance Method Details

#create(args) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/stackster/aws/cloud_formation.rb', line 15

def create(args)
  parameters = { 'Parameters' => args[:parameters] }
  data = { 'Capabilities' => ['CAPABILITY_IAM'],
           'TemplateBody' => args[:template] }.merge parameters
  @connect.create_stack(args[:name], data)
  @logger.info "Cloud Formation stack creation completed."
rescue Exception => e  
  Error.new(:config => @config, :exception => e).process
end

#describe_stack(name) ⇒ Object



42
43
44
45
46
# File 'lib/stackster/aws/cloud_formation.rb', line 42

def describe_stack(name)
  @connect.describe_stacks('StackName' => name).body['Stacks']
rescue Exception => e  
  Error.new(:config => @config, :exception => e).process
end

#destroy(name) ⇒ Object



35
36
37
38
39
40
# File 'lib/stackster/aws/cloud_formation.rb', line 35

def destroy(name)
  @connect.delete_stack name
  @logger.info "Cloud Formation stack destroy completed."
rescue Exception => e  
  Error.new(:config => @config, :exception => e).process
end

#stack_events(name, limit) ⇒ Object



54
55
56
57
58
# File 'lib/stackster/aws/cloud_formation.rb', line 54

def stack_events(name, limit)
  @connect.describe_stack_events(name).body['StackEvents'] [0..limit-1]
rescue Exception => e  
  Error.new(:config => @config, :exception => e).process
end

#stack_outputs(name) ⇒ Object



64
65
66
# File 'lib/stackster/aws/cloud_formation.rb', line 64

def stack_outputs(name)
  describe_stack(name).last['Outputs']
end

#stack_resources(name) ⇒ Object



48
49
50
51
52
# File 'lib/stackster/aws/cloud_formation.rb', line 48

def stack_resources(name)
  @connect.describe_stack_resources('StackName' => name).body['StackResources']
rescue Exception => e  
  Error.new(:config => @config, :exception => e).process
end

#stack_status(name) ⇒ Object



60
61
62
# File 'lib/stackster/aws/cloud_formation.rb', line 60

def stack_status(name)
  describe_stack(name).first['StackStatus']
end

#template(name) ⇒ Object



68
69
70
71
72
# File 'lib/stackster/aws/cloud_formation.rb', line 68

def template(name)
  @connect.get_template(name).body['TemplateBody']
rescue Exception => e  
  Error.new(:config => @config, :exception => e).process
end

#update(args) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/stackster/aws/cloud_formation.rb', line 25

def update(args)
  parameters = { 'Parameters' => args[:parameters] }
  data = { 'Capabilities' => ['CAPABILITY_IAM'],
           'TemplateBody' => args[:template] }.merge parameters
  @connect.update_stack(args[:name], data)
  @logger.info "Cloud Formation stack update completed."
rescue Exception => e  
  Error.new(:config => @config, :exception => e).process
end