Module: Shelter::CLI::Helpers::CloudFormation

Defined in:
lib/cli/helpers/cloudformation_helper.rb

Overview

Mixin module for CloudFormation

Instance Method Summary collapse

Instance Method Details

#cf_clientObject



8
9
10
11
12
13
14
15
# File 'lib/cli/helpers/cloudformation_helper.rb', line 8

def cf_client
  @cf_client ||= Aws::CloudFormation::Client.new(
    credentials: Aws::Credentials.new(
      ENV.fetch('AWS_ACCESS_KEY_ID'),
      ENV.fetch('AWS_SECRET_ACCESS_KEY')
    )
  )
end

#display_stack_output(out) ⇒ Object



31
32
33
34
# File 'lib/cli/helpers/cloudformation_helper.rb', line 31

def display_stack_output(out)
  puts out.description unless out.description.nil?
  puts "#{out.output_key}: #{out.output_value}"
end

#display_stack_resource(r) ⇒ Object



25
26
27
28
29
# File 'lib/cli/helpers/cloudformation_helper.rb', line 25

def display_stack_resource(r)
  puts "Resource ID: #{r.physical_resource_id}"
  puts "  Resource Type: #{r.resource_type}"
  puts "  Resource Status: #{r.resource_status}"
end

#stack_meta(res, type: 'resource') ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cli/helpers/cloudformation_helper.rb', line 36

def stack_meta(res, type: 'resource')
  tags = []

  res.each do |key, value|
    tags << { key: key.to_s, value: value.to_s }
  end

  tags << { key: 'type', value: type }

  tags
end

#stack_params(res) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/cli/helpers/cloudformation_helper.rb', line 48

def stack_params(res)
  params = []

  res.each do |key, value|
    params << { parameter_key: key.to_s, parameter_value: value.to_s }
  end

  params
end

#wait_until(status, stack_name) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/cli/helpers/cloudformation_helper.rb', line 17

def wait_until(status, stack_name)
  puts "Waiting for '#{status}' on '#{stack_name}'..."
  cf_client.wait_until(
    status,
    stack_name: stack_name
  )
end