From 287c37abb204086ad5443cbf5ea065e305d090ba Mon Sep 17 00:00:00 2001 From: Jason Roelofs Date: Tue, 18 Oct 2011 10:06:35 -0400 Subject: [PATCH] Add CloudFormation UpdateStack call --- lib/fog/aws/cloud_formation.rb | 1 + .../parsers/cloud_formation/update_stack.rb | 19 ++++++ .../requests/cloud_formation/update_stack.rb | 62 +++++++++++++++++++ .../requests/cloud_formation/stack_tests.rb | 14 +++++ 4 files changed, 96 insertions(+) create mode 100644 lib/fog/aws/parsers/cloud_formation/update_stack.rb create mode 100644 lib/fog/aws/requests/cloud_formation/update_stack.rb diff --git a/lib/fog/aws/cloud_formation.rb b/lib/fog/aws/cloud_formation.rb index 061fe0602..78ecf4387 100644 --- a/lib/fog/aws/cloud_formation.rb +++ b/lib/fog/aws/cloud_formation.rb @@ -9,6 +9,7 @@ module Fog request_path 'fog/aws/requests/cloud_formation' request :create_stack + request :update_stack request :delete_stack request :describe_stack_events request :describe_stack_resources diff --git a/lib/fog/aws/parsers/cloud_formation/update_stack.rb b/lib/fog/aws/parsers/cloud_formation/update_stack.rb new file mode 100644 index 000000000..3e3f528ab --- /dev/null +++ b/lib/fog/aws/parsers/cloud_formation/update_stack.rb @@ -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 diff --git a/lib/fog/aws/requests/cloud_formation/update_stack.rb b/lib/fog/aws/requests/cloud_formation/update_stack.rb new file mode 100644 index 000000000..d54473cbb --- /dev/null +++ b/lib/fog/aws/requests/cloud_formation/update_stack.rb @@ -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 diff --git a/tests/aws/requests/cloud_formation/stack_tests.rb b/tests/aws/requests/cloud_formation/stack_tests.rb index 8ef8d3838..8ced99e75 100644 --- a/tests/aws/requests/cloud_formation/stack_tests.rb +++ b/tests/aws/requests/cloud_formation/stack_tests.rb @@ -18,6 +18,11 @@ Shindo.tests('AWS::CloudFormation | stack requests', ['aws', 'cloudformation']) 'StackId' => String } + @update_stack_format = { + 'RequestId' => String, + 'StackId' => String + } + @get_template_format = { 'RequestId' => String, 'TemplateBody' => String @@ -103,6 +108,15 @@ Shindo.tests('AWS::CloudFormation | stack requests', ['aws', 'cloudformation']) ).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