Class: RenderCFN::MainStack

Inherits:
Stack show all
Defined in:
lib/renderCFN/mainStack.rb

Instance Method Summary collapse

Methods inherited from Stack

#add, #render, #uploadTemplate

Methods inherited from AwsObject

#get, #name

Constructor Details

#initialize(arguments) ⇒ MainStack

Returns a new instance of MainStack.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/renderCFN/mainStack.rb', line 8

def initialize( arguments)
  
  super( arguments)
  
  @stackID = String.new()
  @templateName = 'main.yml'
  @templateURL = "https://s3.amazonaws.com/#{@@bucket}/stacks/#{@@stackName}/#{@templateName}"
  
  @awsObject = { 
    'AWSTemplateFormatVersion' => '2010-09-09',
    'Description' => arguments[:description] ? "#{arguments[:description]} [renderCFN]" : 'Made with renderCFN',
    'Resources' => {} 
  }

end

Instance Method Details

#createStackObject



30
31
32
33
34
35
# File 'lib/renderCFN/mainStack.rb', line 30

def createStack()
  uploadTemplate()
  cfn = Aws::CloudFormation::Client.new( )
  cfn.create_stack( stack_name: @@stackName, template_url: @templateURL, capabilities: ["CAPABILITY_IAM"])
  @@stackID = getAWSStackID()
end

#deleteStackObject



43
44
45
46
# File 'lib/renderCFN/mainStack.rb', line 43

def deleteStack()
  cfn = Aws::CloudFormation::Client.new( )
  cfn.delete_stack( stack_name: @@stackName)
end

#executeObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/renderCFN/mainStack.rb', line 53

def execute()
  case @@action
  when 'create'
    createStack()
  when 'delete'
    deleteStack()
  when 'update'
    updateStack()
  when 'validate'
    validateStack()
  when 'print'
    render()
  end
end

#getAWSStackIDObject



24
25
26
27
28
# File 'lib/renderCFN/mainStack.rb', line 24

def getAWSStackID( )
  cfn = Aws::CloudFormation::Client.new( )
  stackCall = cfn.describe_stacks(stack_name: @@stackName )
  stackCall['stacks'][0]['stack_id']
end

#updateStackObject



37
38
39
40
41
# File 'lib/renderCFN/mainStack.rb', line 37

def updateStack()
  uploadTemplate()
  cfn = Aws::CloudFormation::Client.new( )
  cfn.update_stack( stack_name: @@stackID, template_url: @templateURL, capabilities: ["CAPABILITY_IAM"] )
end

#validateStackObject



48
49
50
51
# File 'lib/renderCFN/mainStack.rb', line 48

def validateStack()
  cfn = Aws::CloudFormation::Client.new( )
  cfn.validate_template( template_url: @templateURL)
end