Class: AwsCftTools::Template
- Inherits:
-
Object
- Object
- AwsCftTools::Template
- Includes:
- FileSystem, Metadata, Properties
- Defined in:
- lib/aws_cft_tools/template.rb,
lib/aws_cft_tools/template/metadata.rb,
lib/aws_cft_tools/template/properties.rb,
lib/aws_cft_tools/template/dsl_context.rb,
lib/aws_cft_tools/template/file_system.rb
Overview
Fetch templates from deployed stacks and consider them in the dependency tree for removing or deploying templates in the repo. Flag stacks with no local source to not be updated on deployment.
Add ability to init to fetch templates from stacks and put them in files.
Stacks should be removed (“retracted”) from AWS before they are removed from the set of templates. Otherwise, they won’t be considered in the set of available templates or stacks.
The AwsCftTools::Template class wraps a CloudFormation template source to provide support for various operations by the toolset.
CloudFormation Templates
As much as possible, this tool uses CloudFormation templates as-is and makes as many inferences as reasonable. However, some things aren’t captured in stock template information.
Allowed Environments
The environments in which a template should be deployed is provided by the AllowedValues
or the AllowedPattern
key of the Environment
template parameter.
Allowed Regions
A template can be pinned to a particular region or set of regions by providing a list of values for the Region
key in the template metadata. If no such key is present, then the template can be deployed or otherwise used in all regions.
Explicit Template Dependencies
As much as possible, dependencies between templates are inferred based on exported and imported values. However, some templates might depend on another template in a way that isn’t captured by these values. For those dependencies, the templates that should be run first can be listed under the DependesOn.Templates
metadata key.
Template Parameters
Rather than require mappings in templates to hold environment-specific values, a template has a corresponding parameters file that holds the value for the stack parameter for each environment. This parameters file is in YAML format and passed through ERB before parsing, so it can incorporate environment variables and other logic into specifying parameter values.
Defined Under Namespace
Modules: DSLContext, FileSystem, Metadata, Properties
Constant Summary
Constants included from Metadata
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
-
#initialize(filename, options = {}) ⇒ Template
constructor
A new instance of Template.
-
#stack_parameters ⇒ Hash
Parameters to provide to the AWS client to deploy the template.
-
#tags ⇒ Array<Hash>
Template tags suitable for use in deploying a stack.
Methods included from Properties
#allowed_environments, #allowed_environments_regex, #allowed_regions, #default_parameters, #environment?, #inputs, #outputs, #region?, #role, #role?, #template_dependencies
Methods included from Metadata
#name, #parameters, #template, #template?, #template_source_for_aws, #template_type
Methods included from FileSystem
#parameter_file, #parameters_source, #template_file, #template_source
Constructor Details
#initialize(filename, options = {}) ⇒ Template
Returns a new instance of Template.
101 102 103 104 |
# File 'lib/aws_cft_tools/template.rb', line 101 def initialize(filename, = {}) @options = @filename = filename end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
80 81 82 |
# File 'lib/aws_cft_tools/template.rb', line 80 def filename @filename end |
Instance Method Details
#stack_parameters ⇒ Hash
Returns parameters to provide to the AWS client to deploy the template.
119 120 121 122 123 124 125 126 |
# File 'lib/aws_cft_tools/template.rb', line 119 def stack_parameters { stack_name: name, template_body: template_source_for_aws, parameters: hash_to_param_list(parameters || {}), tags: } end |
#tags ⇒ Array<Hash>
Returns template tags suitable for use in deploying a stack.
109 110 111 112 113 114 |
# File 'lib/aws_cft_tools/template.rb', line 109 def [ { key: 'Environment', value: @options[:environment] }, { key: 'Source', value: ('/' + filename.to_s).gsub(%r{/+}, '/') } ] + role_tag end |