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_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>)


51
52
53
# File 'lib/aws_cft_tools/template/properties.rb', line 51

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

#default_parametersObject

Returns the parameter defaults for the template.



25
26
27
28
29
# File 'lib/aws_cft_tools/template/properties.rb', line 25

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

#environment?(value) ⇒ Boolean

Returns:

  • (Boolean)


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

def environment?(value)
  allowed_environments.include?(value)
end

#inputsArray<String>

lists the imports expected by the template

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

Returns:

  • (Array<String>)


88
89
90
91
92
93
94
# File 'lib/aws_cft_tools/template/properties.rb', line 88

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>)


75
76
77
78
79
# File 'lib/aws_cft_tools/template/properties.rb', line 75

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

#region?(region) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/aws_cft_tools/template/properties.rb', line 55

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)


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

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

#role?(value) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/aws_cft_tools/template/properties.rb', line 40

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.



64
65
66
# File 'lib/aws_cft_tools/template/properties.rb', line 64

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