File: create_change_set.rb

package info (click to toggle)
ruby-fog-aws 3.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,816 kB
  • sloc: ruby: 68,587; makefile: 6
file content (75 lines) | stat: -rw-r--r-- 2,954 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
module Fog
  module AWS
    class CloudFormation
      class Real
        require 'fog/aws/parsers/cloud_formation/create_change_set'

        # Create a Change Set.
        #
        # * stack_name [String] Name of the stack to create.
        # * options [Hash]:
        #   * ChangeSetName [String] The name of the change set.
        #   * Description [String] A description to help you identify this change set.
        #   * 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.
        #   * UsePreviousTemplate [Boolean] Reuse the template that is associated with the stack to create the change set.
        #   * NotificationARNs [Array] List of SNS topics to publish events to.
        #   * 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.
        #
        # @return [Excon::Response]:
        #   * body [Hash:
        #     * Id [String] - The Amazon Resource Name (ARN) of the change set
        #
        # @see http://docs.amazonwebservices.com/AWSCloudFormation/latest/APIReference/API_CreateChangeSet.html

        def create_change_set(stack_name, options = {})
          params = {
            'StackName' => stack_name,
          }

          if options['ChangeSetName']
            params['ChangeSetName'] = options['ChangeSetName']
          end

          if options['Description']
            params['Description'] = options['Description']
          end
          if options['UsePreviousTemplate']
            params['UsePreviousTemplate'] = options['UsePreviousTemplate']
          end

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

          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'    => 'CreateChangeSet',
            :parser     => Fog::Parsers::AWS::CloudFormation::CreateChangeSet.new
          }.merge!(params))
        end
      end
    end
  end
end