stacker.blueprints package

Submodules

stacker.blueprints.base module

class stacker.blueprints.base.Blueprint(name, context, mappings=None, description=None)[source]

Bases: future.types.newobject.newobject

Base implementation for rendering a troposphere template.

Parameters:
  • name (str) – A name for the blueprint.
  • context (stacker.context.Context) – the context the blueprint is being executed under.
  • mappings (dict, optional) – Cloudformation Mappings to be used in the template.
add_output(name, value)[source]

Simple helper for adding outputs.

Parameters:
  • name (str) – The name of the output to create.
  • value (str) – The value to put in the output.
create_template()[source]
defined_variables()[source]

Return a dictionary of variables defined by the blueprint.

By default, this will just return the values from VARIABLES, but this makes it easy for subclasses to add variables.

Returns:variables defined by the blueprint
Return type:dict
get_cfn_parameters()[source]

Return a dictionary of variables with type CFNType.

Returns:
variables that need to be submitted as CloudFormation
Parameters.
Return type:dict
get_parameter_definitions()[source]

Get the parameter definitions to submit to CloudFormation.

Any variable definition whose type is an instance of CFNType will be returned as a CloudFormation Parameter.

Returns:
parameter definitions. Keys are parameter names, the values
are dicts containing key/values for various parameter properties.
Return type:dict
get_parameter_values()[source]

Return a dictionary of variables with type CFNType.

Returns:
variables that need to be submitted as CloudFormation
Parameters. Will be a dictionary of <parameter name>: <parameter value>.
Return type:dict
get_required_parameter_definitions()[source]

Returns all template parameters that do not have a default value.

Returns:
dict of required CloudFormation Parameters for the blueprint.
Will be a dictionary of <parameter name>: <parameter attributes>.
Return type:dict
get_variables()[source]

Return a dictionary of variables available to the template.

These variables will have been defined within VARIABLES or self.defined_variables. Any variable value that contains a lookup will have been resolved.

Returns:variables available to the template
Return type:dict

Raises:

import_mappings()[source]
read_user_data(user_data_path)[source]

Reads and parses a user_data file.

Parameters:user_data_path (str) – path to the userdata file
Returns:the parsed user data file
Return type:str
render_template()[source]

Render the Blueprint to a CloudFormation template

rendered
requires_change_set

Returns true if the underlying template has transforms.

reset_template()[source]
resolve_variables(provided_variables)[source]

Resolve the values of the blueprint variables.

This will resolve the values of the VARIABLES with values from the env file, the config, and any lookups resolved.

Parameters:provided_variables (list of stacker.variables.Variable) – list of provided variables
set_template_description(description)[source]

Adds a description to the Template

Parameters:description (str) – A description to be added to the resulting template.
setup_parameters()[source]

Add any CloudFormation parameters to the template

to_json(variables=None)[source]

Render the blueprint and return the template in json form.

Parameters:variables (dict) – Optional dictionary providing/overriding variable values.
Returns:the rendered CFN JSON template
Return type:str
version
class stacker.blueprints.base.CFNParameter(name, value)[source]

Bases: future.types.newobject.newobject

ref
to_parameter_value()[source]

Return the value to be submitted to CloudFormation

stacker.blueprints.base.build_parameter(name, properties)[source]

Builds a troposphere Parameter with the given properties.

Parameters:
Returns:

The created parameter object.

Return type:

troposphere.Parameter

stacker.blueprints.base.parse_user_data(variables, raw_user_data, blueprint_name)[source]

Parse the given user data and renders it as a template

It supports referencing template variables to create userdata that’s supplemented with information from the stack, as commonly required when creating EC2 userdata files.

For example:
Given a raw_user_data string: ‘open file ${file}’ And a variables dictionary with: {‘file’: ‘test.txt’} parse_user_data would output: open file test.txt
Parameters:
  • variables (dict) – variables available to the template
  • raw_user_data (str) – the user_data to be parsed
  • blueprint_name (str) – the name of the blueprint
Returns:

The parsed user data, with all the variables values and

refs replaced with their resolved values.

Return type:

str

Raises:
  • InvalidUserdataPlaceholder – Raised when a placeholder name in raw_user_data is not valid. E.g ${100} would raise this.
  • MissingVariable – Raised when a variable is in the raw_user_data that is not given in the blueprint
stacker.blueprints.base.resolve_variable(var_name, var_def, provided_variable, blueprint_name)[source]

Resolve a provided variable value against the variable definition.

Parameters:
  • var_name (str) – The name of the defined variable on a blueprint.
  • var_def (dict) – A dictionary representing the defined variables attributes.
  • provided_variable (stacker.variables.Variable) – The variable value provided to the blueprint.
  • blueprint_name (str) – The name of the blueprint that the variable is being applied to.
Returns:

The resolved variable value, could be any python object.

Return type:

object

Raises:
  • MissingVariable – Raised when a variable with no default is not provided a value.
  • UnresolvedVariable – Raised when the provided variable is not already resolved.
  • ValueError – Raised when the value is not the right type and cannot be cast as the correct type. Raised by stacker.blueprints.base.validate_variable_type()
  • ValidatorError – Raised when a validator raises an exception. Wraps the original exception.
stacker.blueprints.base.validate_allowed_values(allowed_values, value)[source]

Support a variable defining which values it allows.

Parameters:
  • allowed_values (Optional[list]) – A list of allowed values from the variable definition
  • value (obj) – The object representing the value provided for the variable
Returns:

Boolean for whether or not the value is valid.

Return type:

bool

stacker.blueprints.base.validate_variable_type(var_name, var_type, value)[source]

Ensures the value is the correct variable type.

Parameters:
  • var_name (str) – The name of the defined variable on a blueprint.
  • var_type (type) – The type that the value should be.
  • value (obj) – The object representing the value provided for the variable
Returns:

Returns the appropriate value object. If the original value

was of CFNType, the returned value will be wrapped in CFNParameter.

Return type:

object

Raises:

ValueError – If the value isn’t of var_type and can’t be cast as that type, this is raised.

stacker.blueprints.testutil module

class stacker.blueprints.testutil.BlueprintTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

OUTPUT_PATH = 'tests/fixtures/blueprints'
assertRenderedBlueprint(blueprint)[source]
class stacker.blueprints.testutil.YamlDirTestGenerator[source]

Bases: object

Generate blueprint tests from yaml config files.

This class creates blueprint tests from yaml files with a syntax similar to stackers’ configuration syntax. For example,

— namespace: test stacks:

  • name: test_sample class_path: stacker_blueprints.test.Sample variables:

    var1: value1

will create a test for the specified blueprint, passing that variable as part of the test.

The test will generate a .json file for this blueprint, and compare it with the stored result.

By default, the generator looks for files named ‘test_*.yaml’ in its same directory. In order to use it, subclass it in a directory containing such tests, and name the class with a pattern that will include it in nosetests’ tests (for example, TestGenerator).

The subclass may override some properties:

@property base_class: by default, the generated tests are subclasses of stacker.blueprints.testutil.BlueprintTestCase. In order to change this, set this property to the desired base class.

@property yaml_dirs: by default, the directory where the generator is subclassed is searched for test files. Override this array for specifying more directories. These must be relative to the directory in which the subclass lives in. Globs may be used.

Default: [ ‘.’ ]. Example override: [ ‘.’, ‘tests/*/’ ]

@property yaml_filename: by default, the generator looks for files named ‘test_*.yaml’. Use this to change this pattern. Globs may be used.

There’s an example of this use in the tests/ subdir of stacker_blueprints.

base_class
test_generator()[source]
yaml_dirs
yaml_filename
stacker.blueprints.testutil.diff(a, b)[source]

A human readable differ.

Module contents