Class: AwsCftTools::Stack

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/aws_cft_tools/stack.rb

Overview

Provides a unified interface for accessing information about deployed CloudFormation templates.

Instance Method Summary collapse

Constructor Details

#initialize(aws_stack, aws_client) ⇒ Stack

Returns a new instance of Stack.



10
11
12
13
# File 'lib/aws_cft_tools/stack.rb', line 10

def initialize(aws_stack, aws_client)
  @aws_client = aws_client
  @aws_stack = aws_stack
end

Instance Method Details

#environmentString

Returns the environment of the stack.

Returns:

  • (String)

    the environment of the stack



56
57
58
# File 'lib/aws_cft_tools/stack.rb', line 56

def environment
  tags['Environment']
end

#filenameString

Returns the filename of the stack’s template source.

Returns:

  • (String)

    the filename of the stack’s template source



70
71
72
73
74
75
# File 'lib/aws_cft_tools/stack.rb', line 70

def filename
  @filename ||= begin
    source = tags['Source']
    source ? source.sub(%r{^/+}, '') : nil
  end
end

#outputsHash

Returns mapping of output name with output definition.

Returns:

  • (Hash)

    mapping of output name with output definition



42
43
44
# File 'lib/aws_cft_tools/stack.rb', line 42

def outputs
  @outputs ||= build_hashes(@aws_stack.outputs || [], &:output_key)
end

#parametersHash

Returns mapping of parameter name to parameter definition.

Returns:

  • (Hash)

    mapping of parameter name to parameter definition



49
50
51
# File 'lib/aws_cft_tools/stack.rb', line 49

def parameters
  @parameters ||= build_hashes(@aws_stack.parameters || [], &:parameter_key)
end

#roleString

Returns the role of the stack.

Returns:

  • (String)

    the role of the stack



63
64
65
# File 'lib/aws_cft_tools/stack.rb', line 63

def role
  tags['Role']
end

#tagsHash

Returns dictionary of tag names and values for the stack.

Returns:

  • (Hash)

    dictionary of tag names and values for the stack



36
37
38
# File 'lib/aws_cft_tools/stack.rb', line 36

def tags
  @tags ||= @aws_stack.tags.each_with_object({}) { |tag, hash| hash[tag.key] = tag.value }
end

#template_sourceString

Returns the unparsed body of the template definition.

Returns:

  • (String)

    the unparsed body of the template definition



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

def template_source
  @template ||= begin
    resp = @aws_client.get_template(stack_name: name,
                                    template_stage: 'Original')
    resp.template_body
  end
end