Class: CloudFormationTagParser

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudformation_tag_parser.rb

Instance Method Summary collapse

Instance Method Details

#tags(cloudformation_json:, logical_resource_id:) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cloudformation_tag_parser.rb', line 5

def tags(cloudformation_json:,
         logical_resource_id:)

  cloudformation = JSON.load(cloudformation_json)
  if cloudformation['Resources'].nil?
    raise 'malformed json, must have Resources key at least'
  end

  resource = cloudformation['Resources'][logical_resource_id]
  if resource.nil?
    raise "logical resource id #{logical_resource_id} is not found"
  end

  # Properties isn't there is a blow error, but jsut ignore that... need a better all-round parser for cfn in the first place
  tags = resource['Properties']['Tags']
  tags.nil? ? [] : tags
end