Class: SimpleDeploy::AWS::CloudFormation

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

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Methods included from Helpers

#connection_args

Constructor Details

#initializeCloudFormation

Returns a new instance of CloudFormation.



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

def initialize
  @config  = SimpleDeploy.config
  @logger  = SimpleDeploy.logger
  @connect = Fog::AWS::CloudFormation.new connection_args
end

Instance Method Details

#create(args) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/simple_deploy/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(:exception => e).process
end

#describe_stack(name) ⇒ Object



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

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

#destroy(name) ⇒ Object



35
36
37
38
39
40
# File 'lib/simple_deploy/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(:exception => e).process
end

#stack_events(name, limit) ⇒ Object



54
55
56
57
58
# File 'lib/simple_deploy/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(:exception => e).process
end

#stack_outputs(name) ⇒ Object



64
65
66
# File 'lib/simple_deploy/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/simple_deploy/aws/cloud_formation.rb', line 48

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

#stack_status(name) ⇒ Object



60
61
62
# File 'lib/simple_deploy/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/simple_deploy/aws/cloud_formation.rb', line 68

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

#update(args) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/simple_deploy/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(:exception => e).process
end