Class: StackMaster::TestDriver::CloudFormation
- Inherits:
-
Object
- Object
- StackMaster::TestDriver::CloudFormation
- Defined in:
- lib/stack_master/test_driver/cloud_formation.rb
Instance Method Summary collapse
- #add_stack(stack) ⇒ Object
- #add_stack_event(event) ⇒ Object
- #add_stack_resource(options) ⇒ Object
- #create_change_set(options) ⇒ Object
- #create_stack(options) ⇒ Object
- #delete_change_set(options) ⇒ Object
- #delete_stack(options) ⇒ Object
- #describe_change_set(options) ⇒ Object
- #describe_stack_events(options) ⇒ Object
- #describe_stack_resources(options = {}) ⇒ Object
- #describe_stacks(options = {}) ⇒ Object
- #execute_change_set(options) ⇒ Object
- #get_stack_policy(options) ⇒ Object
- #get_template(options) ⇒ Object
-
#initialize ⇒ CloudFormation
constructor
A new instance of CloudFormation.
- #region ⇒ Object
- #reset ⇒ Object
- #set_region(region) ⇒ Object
- #set_stack_policy(options) ⇒ Object
- #set_template(stack_name, template) ⇒ Object
- #validate_template(options) ⇒ Object
Constructor Details
#initialize ⇒ CloudFormation
Returns a new instance of CloudFormation.
66 67 68 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 66 def initialize reset end |
Instance Method Details
#add_stack(stack) ⇒ Object
173 174 175 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 173 def add_stack(stack) @stacks[stack.fetch(:stack_name)] = Stack.new(stack) end |
#add_stack_event(event) ⇒ Object
186 187 188 189 190 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 186 def add_stack_event(event) stack_name = event.fetch(:stack_name) @stack_events[stack_name] ||= [] @stack_events[stack_name] << StackEvent.new(event) end |
#add_stack_resource(options) ⇒ Object
177 178 179 180 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 177 def add_stack_resource() @stack_resources[.fetch(:stack_name)] ||= [] @stack_resources[.fetch(:stack_name)] << StackResource.new() end |
#create_change_set(options) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 87 def create_change_set() id = SecureRandom.uuid .merge!(change_set_id: id) @change_sets[id] = @change_sets[.fetch(:change_set_name)] = stack_name = .fetch(:stack_name) add_stack(stack_name: stack_name, stack_status: 'REVIEW_IN_PROGRESS') unless @stacks[stack_name] OpenStruct.new(id: id) end |
#create_stack(options) ⇒ Object
158 159 160 161 162 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 158 def create_stack() stack_name = .fetch(:stack_name) add_stack() @stack_policies[stack_name] = [:stack_policy_body] end |
#delete_change_set(options) ⇒ Object
116 117 118 119 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 116 def delete_change_set() change_set_id = .fetch(:change_set_name) @change_sets.delete(change_set_id) end |
#delete_stack(options) ⇒ Object
164 165 166 167 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 164 def delete_stack() stack_name = .fetch(:stack_name) @stacks.delete(stack_name) end |
#describe_change_set(options) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 97 def describe_change_set() change_set_id = .fetch(:change_set_name) change_set = @change_sets.fetch(change_set_id) change_details = [ OpenStruct.new(evaluation: 'Static', change_source: 'ResourceReference', target: OpenStruct.new(attribute: 'Properties', requires_recreation: 'Always', name: 'blah')) ] change = OpenStruct.new(action: 'Modify', replacement: 'True', scope: ['Properties'], details: change_details) changes = [ OpenStruct.new(type: 'AWS::Resource', resource_change: change) ] OpenStruct.new(change_set.merge(changes: changes, status: 'CREATE_COMPLETE')) end |
#describe_stack_events(options) ⇒ Object
153 154 155 156 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 153 def describe_stack_events() events = @stack_events[.fetch(:stack_name)] || [] OpenStruct.new(stack_events: events, next_token: nil) end |
#describe_stack_resources(options = {}) ⇒ Object
135 136 137 138 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 135 def describe_stack_resources( = {}) @stacks.fetch(.fetch(:stack_name)) { raise Aws::CloudFormation::Errors::ValidationError.new('', 'Stack does not exist') } OpenStruct.new(stack_resources: @stack_resources[.fetch(:stack_name)]) end |
#describe_stacks(options = {}) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 121 def describe_stacks( = {}) stack_name = [:stack_name] stacks = if stack_name if @stacks[stack_name] [@stacks[stack_name]] else raise Aws::CloudFormation::Errors::ValidationError.new('', 'Stack does not exist') end else @stacks.values end OpenStruct.new(stacks: stacks, next_token: nil) end |
#execute_change_set(options) ⇒ Object
110 111 112 113 114 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 110 def execute_change_set() change_set_id = .fetch(:change_set_name) change_set = @change_sets.fetch(change_set_id) @stacks[change_set.fetch(:stack_name)].attributes = change_set end |
#get_stack_policy(options) ⇒ Object
145 146 147 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 145 def get_stack_policy() OpenStruct.new(stack_policy_body: @stack_policies[.fetch(:stack_name)]) end |
#get_template(options) ⇒ Object
140 141 142 143 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 140 def get_template() template_body = @templates[[:stack_name]] || nil OpenStruct.new(template_body: template_body) end |
#region ⇒ Object
70 71 72 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 70 def region @region ||= ENV['AWS_REGION'] || Aws.config[:region] || Aws.shared_config.region end |
#reset ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 78 def reset @stacks = {} @templates = {} @stack_events = {} @stack_resources = {} @stack_policies = {} @change_sets = {} end |
#set_region(region) ⇒ Object
74 75 76 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 74 def set_region(region) @region = region end |
#set_stack_policy(options) ⇒ Object
149 150 151 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 149 def set_stack_policy() @stack_policies[.fetch(:stack_name)] = [:stack_policy_body] end |
#set_template(stack_name, template) ⇒ Object
182 183 184 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 182 def set_template(stack_name, template) @templates[stack_name] = template end |
#validate_template(options) ⇒ Object
169 170 171 |
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 169 def validate_template() true end |