Class: StackMaster::TestDriver::CloudFormation

Inherits:
Object
  • Object
show all
Defined in:
lib/stack_master/test_driver/cloud_formation.rb

Instance Method Summary collapse

Constructor Details

#initializeCloudFormation

Returns a new instance of CloudFormation.



49
50
51
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 49

def initialize
  reset
end

Instance Method Details

#add_stack(stack) ⇒ Object



119
120
121
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 119

def add_stack(stack)
  @stacks[stack.fetch(:stack_name)] = Stack.new(stack)
end

#add_stack_event(event) ⇒ Object



132
133
134
135
136
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 132

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



123
124
125
126
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 123

def add_stack_resource(options)
  @stack_resources[options.fetch(:stack_name)] ||= []
  @stack_resources[options.fetch(:stack_name)] << StackResource.new(options)
end

#create_stack(options) ⇒ Object



104
105
106
107
108
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 104

def create_stack(options)
  stack_name = options.fetch(:stack_name)
  add_stack(options)
  @stack_policies[stack_name] = options[:stack_policy_body]
end

#delete_stack(options) ⇒ Object



110
111
112
113
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 110

def delete_stack(options)
  stack_name = options.fetch(:stack_name)
  @stacks.delete(stack_name)
end

#describe_stack_events(options) ⇒ Object



93
94
95
96
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 93

def describe_stack_events(options)
  events = @stack_events[options.fetch(:stack_name)] || []
  OpenStruct.new(stack_events: events, next_token: nil)
end

#describe_stack_resources(options = {}) ⇒ Object



79
80
81
82
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 79

def describe_stack_resources(options = {})
  @stacks.fetch(options.fetch(:stack_name)) { raise Aws::CloudFormation::Errors::ValidationError.new('', 'Stack does not exist') }
  OpenStruct.new(stack_resources: @stack_resources[options.fetch(:stack_name)])
end

#describe_stacks(options = {}) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 65

def describe_stacks(options = {})
  stack_name = options[: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

#get_stack_policy(options) ⇒ Object



89
90
91
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 89

def get_stack_policy(options)
  OpenStruct.new(stack_policy_body: @stack_policies[options.fetch(:stack_name)])
end

#get_template(options) ⇒ Object



84
85
86
87
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 84

def get_template(options)
  template_body = @templates[options[:stack_name]] || nil
  OpenStruct.new(template_body: template_body)
end

#resetObject



57
58
59
60
61
62
63
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 57

def reset
  @stacks = {}
  @templates = {}
  @stack_events = {}
  @stack_resources = {}
  @stack_policies = {}
end

#set_region(region) ⇒ Object



53
54
55
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 53

def set_region(region)
  @region = region
end

#set_template(stack_name, template) ⇒ Object



128
129
130
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 128

def set_template(stack_name, template)
  @templates[stack_name] = template
end

#update_stack(options) ⇒ Object



98
99
100
101
102
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 98

def update_stack(options)
  stack_name = options.fetch(:stack_name)
  @stacks[stack_name].attributes = options
  @stack_policies[stack_name] = options[:stack_policy_body]
end

#validate_template(options) ⇒ Object



115
116
117
# File 'lib/stack_master/test_driver/cloud_formation.rb', line 115

def validate_template(options)
  true
end