Skip to content

Commit

Permalink
Merge pull request fog#568 from jameskilton/update_stack
Browse files Browse the repository at this point in the history
Add CloudFormation UpdateStack API
  • Loading branch information
geemus committed Oct 18, 2011
2 parents a61be10 + 287c37a commit 6535e9e
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/fog/aws/cloud_formation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class CloudFormation < Fog::Service

request_path 'fog/aws/requests/cloud_formation'
request :create_stack
request :update_stack
request :delete_stack
request :describe_stack_events
request :describe_stack_resources
Expand Down
19 changes: 19 additions & 0 deletions lib/fog/aws/parsers/cloud_formation/update_stack.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Fog
module Parsers
module AWS
module CloudFormation

class UpdateStack < Fog::Parsers::Base

def end_element(name)
case name
when 'RequestId', 'StackId'
@response[name] = value
end
end

end
end
end
end
end
62 changes: 62 additions & 0 deletions lib/fog/aws/requests/cloud_formation/update_stack.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module Fog
module AWS
class CloudFormation
class Real

require 'fog/aws/parsers/cloud_formation/update_stack'

# Update a stack
#
# ==== Parameters
# * stack_name<~String>: name of the stack to update
# * options<~Hash>:
# * TemplateBody<~String>: structure containing the template body
# or (one of the two Template parameters is required)
# * TemplateURL<~String>: URL of file containing the template body
# * Parameters<~Hash>: Hash of providers to supply to template
# * Capabilities<~Array>: List of capabilties the stack is granted. Currently CAPABILITY_IAM
# for allowing the creation of IAM resources
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'StackId'<~String> - Id of the stack being updated
#
# ==== See Also
# http://docs.amazonwebservices.com/AWSCloudFormation/latest/APIReference/API_UpdateStack.html
#
def update_stack(stack_name, options = {})
params = {
'StackName' => stack_name,
}

if options['Parameters']
options['Parameters'].keys.each_with_index do |key, index|
index += 1 # params are 1-indexed
params.merge!({
"Parameters.member.#{index}.ParameterKey" => key,
"Parameters.member.#{index}.ParameterValue" => options['Parameters'][key]
})
end
end

if options['TemplateBody']
params['TemplateBody'] = options['TemplateBody']
elsif options['TemplateURL']
params['TemplateURL'] = options['TemplateURL']
end

if options['Capabilities']
params.merge!(Fog::AWS.indexed_param("Capabilities.member", [*options['Capabilities']]))
end

request({
'Action' => 'UpdateStack',
:parser => Fog::Parsers::AWS::CloudFormation::UpdateStack.new
}.merge!(params))
end

end
end
end
end
14 changes: 14 additions & 0 deletions tests/aws/requests/cloud_formation/stack_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
'StackId' => String
}

@update_stack_format = {
'RequestId' => String,
'StackId' => String
}

@get_template_format = {
'RequestId' => String,
'TemplateBody' => String
Expand Down Expand Up @@ -103,6 +108,15 @@
).body
end

tests("update_stack('#{@stack_name}', 'TemplateURL' => '#{@template_url}', Parameters => {'KeyName' => 'cloudformation'})").formats(@update_stack_format) do
pending if Fog.mocking?
Fog::AWS[:cloud_formation].update_stack(
@stack_name,
'TemplateURL' => @template_url,
'Parameters' => {'KeyName' => 'cloudformation'}
).body
end

tests("get_template('#{@stack_name})").formats(@get_template_format) do
pending if Fog.mocking?
Fog::AWS[:cloud_formation].get_template(@stack_name).body
Expand Down

0 comments on commit 6535e9e

Please sign in to comment.