Module: AwsCftTools::Template::Properties

Included in:
AwsCftTools::Template
Defined in:
lib/aws_cft_tools/template/properties.rb

Overview

Simple properties of templates.

Instance Method Summary collapse

Instance Method Details

#allowed_environmentsArray<String>

Returns the list of environments allowed for the Environment parameter.

Returns:

  • (Array<String>)


14
15
16
# File 'lib/aws_cft_tools/template/properties.rb', line 14

def allowed_environments
  template.dig('Parameters', 'Environment', 'AllowedValues') || []
end

#allowed_environments_regexObject



18
19
20
21
# File 'lib/aws_cft_tools/template/properties.rb', line 18

def allowed_environments_regex
  source = template.dig('Parameters', 'Environment', 'AllowedPattern')
  Regexp.compile(source) if source
end

#allowed_regionsArray<String>

Note:

The region in which a template is deployed is available as the AWS::Region pseudo-parameter.

Returns the list of regions in which the template is allowed.

Returns:

  • (Array<String>)


58
59
60
# File 'lib/aws_cft_tools/template/properties.rb', line 58

def allowed_regions
  template.dig('Metadata', 'Region') || []
end

#default_parametersObject

Returns the parameter defaults for the template.



32
33
34
35
36
# File 'lib/aws_cft_tools/template/properties.rb', line 32

def default_parameters
  (template['Parameters'] || []).each_with_object({}) do |param, hash|
    hash[param.first] = param.last['Default']
  end
end

#environment?(value) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/aws_cft_tools/template/properties.rb', line 23

def environment?(value)
  return allowed_environments.include?(value) if allowed_environments.any?
  regex = allowed_environments_regex
  return regex.match?(value) if regex
end

#inputsArray<String>

lists the imports expected by the template

Note that this does substitutions of any references to template parameters.

Returns:

  • (Array<String>)


95
96
97
98
99
100
101
# File 'lib/aws_cft_tools/template/properties.rb', line 95

def inputs
  (template['Resources'] || {})
    .values
    .flat_map { |resource| pull_imports(resource['Properties'] || {}) }
    .uniq
    .map(&method(:with_substitutions))
end

#outputsArray<String>

lists the exported values from the template

Note that this does substitutions of any references to template parameters.

Returns:

  • (Array<String>)


82
83
84
85
86
# File 'lib/aws_cft_tools/template/properties.rb', line 82

def outputs
  (template['Outputs'] || []).map do |_, output|
    with_substitutions(output_name(output.dig('Export', 'Name')))
  end
end

#region?(region) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/aws_cft_tools/template/properties.rb', line 62

def region?(region)
  !region || allowed_regions.empty? || allowed_regions.include?(region)
end

#roleString

Returns the role of the template as specified in the template metadata.

Returns:

  • (String)


43
44
45
# File 'lib/aws_cft_tools/template/properties.rb', line 43

def role
  template.dig('Metadata', 'Role')
end

#role?(value) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/aws_cft_tools/template/properties.rb', line 47

def role?(value)
  !value || role == value
end

#template_dependenciesObject

Returns any templates on which this template has an explicit dependency.

These explicit dependencies are combined with any dependencies implied by imported values.



71
72
73
# File 'lib/aws_cft_tools/template/properties.rb', line 71

def template_dependencies
  template.dig('Metadata', 'DependsOn', 'Templates') || []
end