Class: Stackit::Stack

Inherits:
Object
  • Object
show all
Defined in:
lib/stackit/stack.rb

Direct Known Subclasses

ManagedStack

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Stack

Returns a new instance of Stack.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/stackit/stack.rb', line 27

def initialize(options = {})
  options = options.to_h.symbolize_keys!
  self.cloudformation = options[:cloudformation] || Stackit.cloudformation
  self.stack_name = options[:stack_name]
  self.description = options[:description]
  self.parameters = options[:parameters]
  self.disable_rollback = options[:disable_rollback]
  self.notification_arns = options[:notification_arns]
  self.timeout_in_minutes = options[:timeout_in_minutes]
  self.capabilities = options[:capabilities]
  self.tags = options[:tags]
  self.on_failure = options[:on_failure]
  self.use_previous_template = options[:use_previous_template]
  self.retain_resources = options[:retain_resources]
  self.change_set_name = options[:change_set_name]
end

Instance Attribute Details

#capabilitiesObject

Returns the value of attribute capabilities.



20
21
22
# File 'lib/stackit/stack.rb', line 20

def capabilities
  @capabilities
end

#change_set_nameObject

Returns the value of attribute change_set_name.



25
26
27
# File 'lib/stackit/stack.rb', line 25

def change_set_name
  @change_set_name
end

#cloudformationObject

Returns the value of attribute cloudformation.



4
5
6
# File 'lib/stackit/stack.rb', line 4

def cloudformation
  @cloudformation
end

#creation_timeObject

Returns the value of attribute creation_time.



9
10
11
# File 'lib/stackit/stack.rb', line 9

def creation_time
  @creation_time
end

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/stackit/stack.rb', line 7

def description
  @description
end

#disable_rollbackObject

Returns the value of attribute disable_rollback.



13
14
15
# File 'lib/stackit/stack.rb', line 13

def disable_rollback
  @disable_rollback
end

#last_updated_timeObject

Returns the value of attribute last_updated_time.



10
11
12
# File 'lib/stackit/stack.rb', line 10

def last_updated_time
  @last_updated_time
end

#notification_arnsObject

Returns the value of attribute notification_arns.



19
20
21
# File 'lib/stackit/stack.rb', line 19

def notification_arns
  @notification_arns
end

#on_failureObject

Returns the value of attribute on_failure.



22
23
24
# File 'lib/stackit/stack.rb', line 22

def on_failure
  @on_failure
end

#parametersObject

Returns the value of attribute parameters.



8
9
10
# File 'lib/stackit/stack.rb', line 8

def parameters
  @parameters
end

#retain_resourcesObject

Returns the value of attribute retain_resources.



24
25
26
# File 'lib/stackit/stack.rb', line 24

def retain_resources
  @retain_resources
end

#stack_idObject

Returns the value of attribute stack_id.



5
6
7
# File 'lib/stackit/stack.rb', line 5

def stack_id
  @stack_id
end

#stack_nameObject

Returns the value of attribute stack_name.



6
7
8
# File 'lib/stackit/stack.rb', line 6

def stack_name
  @stack_name
end

#stack_policy_bodyObject

Returns the value of attribute stack_policy_body.



15
16
17
# File 'lib/stackit/stack.rb', line 15

def stack_policy_body
  @stack_policy_body
end

#stack_policy_during_update_bodyObject

Returns the value of attribute stack_policy_during_update_body.



17
18
19
# File 'lib/stackit/stack.rb', line 17

def stack_policy_during_update_body
  @stack_policy_during_update_body
end

#stack_policy_during_update_urlObject

Returns the value of attribute stack_policy_during_update_url.



18
19
20
# File 'lib/stackit/stack.rb', line 18

def stack_policy_during_update_url
  @stack_policy_during_update_url
end

#stack_policy_urlObject

Returns the value of attribute stack_policy_url.



16
17
18
# File 'lib/stackit/stack.rb', line 16

def stack_policy_url
  @stack_policy_url
end

#stack_statusObject

Returns the value of attribute stack_status.



11
12
13
# File 'lib/stackit/stack.rb', line 11

def stack_status
  @stack_status
end

#stack_status_reasonObject

Returns the value of attribute stack_status_reason.



12
13
14
# File 'lib/stackit/stack.rb', line 12

def stack_status_reason
  @stack_status_reason
end

#tagsObject

Returns the value of attribute tags.



21
22
23
# File 'lib/stackit/stack.rb', line 21

def tags
  @tags
end

#timeout_in_minutesObject

Returns the value of attribute timeout_in_minutes.



14
15
16
# File 'lib/stackit/stack.rb', line 14

def timeout_in_minutes
  @timeout_in_minutes
end

#use_previous_templateObject

Returns the value of attribute use_previous_template.



23
24
25
# File 'lib/stackit/stack.rb', line 23

def use_previous_template
  @use_previous_template
end

Instance Method Details

#[](key) ⇒ Object



44
45
46
# File 'lib/stackit/stack.rb', line 44

def [](key)
  parameters[key.to_sym] || outputs[key.to_sym] || resources[key.to_sym]
end

#change_set_request_paramsObject



148
149
150
151
152
153
154
155
156
157
# File 'lib/stackit/stack.rb', line 148

def change_set_request_params
{
  change_set_name: change_set_name || "#{stack_name}#{Time.now.strftime("%m%d%Y%H%M%S")}",
  stack_name: stack_name,
  use_previous_template: use_previous_template,
  parameters: to_request_parameters,
  notification_arns: notification_arns,
  tags: to_request_tags
}
end

#create_stack_request_paramsObject



114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/stackit/stack.rb', line 114

def create_stack_request_params
  {
    stack_name: stack_name,
    parameters: to_request_parameters,
    disable_rollback: disable_rollback,
    timeout_in_minutes: timeout_in_minutes,
    notification_arns: notification_arns,
    on_failure: on_failure,
    stack_policy_body: stack_policy_body,
    stack_policy_url: stack_policy_url,
    tags: to_request_tags
  }
end

#delete_stack_request_paramsObject



141
142
143
144
145
146
# File 'lib/stackit/stack.rb', line 141

def delete_stack_request_params
{
  stack_name: stack_name,
  retain_resources: retain_resources
}
end

#hydrate!Object



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/stackit/stack.rb', line 100

def hydrate!
  @stack_id = stack.stack_id
  @description = stack.description
  @creation_time = stack.creation_time
  @last_updated_time = stack.last_updated_time
  @stack_status = stack.stack_status
  @stack_status_reason = stack.stack_status_reason
  @disable_rollback = stack.disable_rollback
  @timeout_in_minutes = stack.timeout_in_minutes
  @stack_policy_body = stack.stack_policy_body if stack.respond_to?(:stack_policy_body)
  @stack_policy_url = stack.stack_policy_url if stack.respond_to?(:stack_policy_url)
  self
end

#outputsObject



58
59
60
61
62
63
64
65
66
# File 'lib/stackit/stack.rb', line 58

def outputs
  @outputs ||= begin
    stack.outputs.inject({}) do |hash, output|
      hash.merge(output[:output_key].to_sym => output[:output_value])
    end
  rescue ::Aws::CloudFormation::Errors::ValidationError => e
    [] if e.message =~ /Stack with id #{stack_name} does not exist/
  end
end

#resourcesObject



68
69
70
71
72
# File 'lib/stackit/stack.rb', line 68

def resources
  @resources ||= list_stack_resources.inject({}) do |hash, resource|
    hash.merge(resource[:logical_resource_id].to_sym => resource[:physical_resource_id])
  end
end

#update_stack_request_paramsObject



128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/stackit/stack.rb', line 128

def update_stack_request_params
  {
    stack_name: stack_name,
    use_previous_template: use_previous_template,
    stack_policy_during_update_body: stack_policy_during_update_body,
    stack_policy_during_update_url: stack_policy_during_update_url,
    parameters: to_request_parameters,
    stack_policy_body: stack_policy_body,
    stack_policy_url: stack_policy_url,
    tags: to_request_tags
  }
end