Class: Shelter::CLI::Stack::CloudFormation

Inherits:
Thor
  • Object
show all
Defined in:
lib/cli/stack/cloud_formation.rb

Overview

CloudFormation based stack base

Instance Method Summary collapse

Instance Method Details

#createObject



34
35
36
37
38
39
40
41
42
# File 'lib/cli/stack/cloud_formation.rb', line 34

def create
  cf_client.create_stack(
    stack_name: get_attr(:stack_name),
    capabilities: get_attr(:capabilities),
    template_body: File.open(get_attr(:template_file)).read,
    tags: meta, parameters: stack_params(get_attr(:parameters))
  )
  wait_until(:stack_create_complete, get_attr(:stack_name))
end

#deleteObject



58
59
60
61
62
# File 'lib/cli/stack/cloud_formation.rb', line 58

def delete
  raise 'Stack is not deletable!!!' unless get_attr(:deletable)
  cf_client.delete_stack(stack_name: get_attr(:stack_name))
  wait_until(:stack_delete_complete, get_attr(:stack_name))
end

#outputObject



25
26
27
28
29
30
31
# File 'lib/cli/stack/cloud_formation.rb', line 25

def output
  stack = cf_client.describe_stacks(
    stack_name: get_attr(:stack_name)
  ).stacks.first

  stack.outputs.each { |out| display_stack_output(out) }
end

#statusObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cli/stack/cloud_formation.rb', line 12

def status
  stack = cf_client.describe_stacks(
    stack_name: get_attr(:stack_name)
  ).stacks.first

  cf_client.describe_stack_resources(
    stack_name: stack.stack_name
  ).stack_resources.each { |r| display_stack_resource(r) }
rescue Aws::CloudFormation::Errors::ValidationError
  puts "#{get_attr(:stack_name)} does not exist"
end

#updateObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cli/stack/cloud_formation.rb', line 45

def update
  cf_client.update_stack(
    stack_name: get_attr(:stack_name),
    capabilities: get_attr(:capabilities),
    template_body: File.open(get_attr(:template_file)).read,
    tags: meta, parameters: stack_params(get_attr(:parameters))
  )
  wait_until(:stack_update_complete, get_attr(:stack_name))
rescue Aws::CloudFormation::Errors::ValidationError => e
  puts e.message
end