Class: Stackup::ChangeSet

Inherits:
Object
  • Object
show all
Includes:
ErrorHandling
Defined in:
lib/stackup/change_set.rb

Overview

An abstraction of a CloudFormation change-set.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ErrorHandling

#handling_cf_errors

Constructor Details

#initialize(name, stack) ⇒ ChangeSet



9
10
11
12
# File 'lib/stackup/change_set.rb', line 9

def initialize(name, stack)
  @name = name
  @stack = stack
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/stackup/change_set.rb', line 14

def name
  @name
end

#stackObject (readonly)

Returns the value of attribute stack.



15
16
17
# File 'lib/stackup/change_set.rb', line 15

def stack
  @stack
end

Instance Method Details

#create(options = {}) ⇒ String

Create the change-set.

Refer Aws::CloudFormation::Client#create_change_set

(see http://docs.aws.amazon.com/sdkforruby/api/Aws/CloudFormation/Client.html#create_change_set-instance_method)

Options Hash (options):

  • :capabilities (Array<String>) — default: CAPABILITY_NAMED_IAM

    list of capabilities required for stack template

  • :description (String)

    change-set description

  • :notification_arns (String)

    ARNs for the Amazon SNS topics associated with this stack

  • :parameters (Hash, Array<Hash>)

    stack parameters, either as a Hash, or an Array of Aws::CloudFormation::Types::Parameter structures

  • :tags (Hash, Array<Hash>)

    stack tags, either as a Hash, or an Array of Aws::CloudFormation::Types::Tag structures

  • :resource_types (Array<String>)

    resource types that you have permissions to work with

  • :template (Hash)

    stack template, as Ruby data

  • :template_body (String)

    stack template, as JSON or YAML

  • :template_url (String)

    location of stack template

  • :use_previous_template (boolean)

    if true, reuse the existing template

  • :force (boolean)

    if true, delete any existing change-set of the same name

Raises:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/stackup/change_set.rb', line 53

def create(options = {})
  options = options.dup
  options[:stack_name] = stack.name
  options[:change_set_name] = name
  options[:change_set_type] = stack.exists? ? "UPDATE" : "CREATE"
  force = options.delete(:force)
  if (template_data = options.delete(:template))
    options[:template_body] = MultiJson.dump(template_data)
  end
  if (parameters = options[:parameters])
    options[:parameters] = Parameters.new(parameters).to_a
  end
  if (tags = options[:tags])
    options[:tags] = normalize_tags(tags)
  end
  options[:capabilities] ||= ["CAPABILITY_NAMED_IAM"]
  delete if force
  handling_cf_errors do
    cf_client.create_change_set(options)
    loop do
      current = describe
      logger.debug("change_set_status=#{current.status}")
      case current.status
      when /COMPLETE/
        return current.status
      when "FAILED"
        logger.error(current.status_reason)
        fail StackUpdateError, "change-set creation failed" if status == "FAILED"
      end
      sleep(wait_poll_interval)
    end
    status
  end
end

#deleteObject

Delete a change-set.

Raises:



105
106
107
108
109
110
# File 'lib/stackup/change_set.rb', line 105

def delete
  handling_cf_errors do
    cf_client.delete_change_set(:stack_name => stack.name, :change_set_name => name)
  end
  nil
end

#describeObject

Describe the change-set.

Refer Aws::CloudFormation::Client#describe_change_set

(http://docs.aws.amazon.com/sdkforruby/api/Aws/CloudFormation/Client.html#describe_change_set-instance_method)


123
124
125
126
127
# File 'lib/stackup/change_set.rb', line 123

def describe
  handling_cf_errors do
    cf_client.describe_change_set(:stack_name => stack.name, :change_set_name => name)
  end
end

#executeString

Execute the change-set.

Raises:



95
96
97
98
99
# File 'lib/stackup/change_set.rb', line 95

def execute
  modify_stack("UPDATE_COMPLETE", "update failed") do
    cf_client.execute_change_set(:stack_name => stack.name, :change_set_name => name)
  end
end

#statusObject



112
113
114
# File 'lib/stackup/change_set.rb', line 112

def status
  describe.status
end