sceptre.diffing package

Submodules

sceptre.diffing.stack_differ module

class sceptre.diffing.stack_differ.DeepDiffStackDiffer(show_no_echo=False, *, universal_template_loader=<function load>)[source]

Bases: StackDiffer[DeepDiff]

A StackDiffer that relies upon the DeepDiff library to produce the difference between the stack as it has been deployed onto CloudFormation and as it exists locally within Sceptre.

This differ relies upon a recursive key/value comparison of Python data structures, indicating specific keys or values that have been added, removed, or altered between the two. Templates are read in as dictionaries and compared this way, so json or yaml formatting changes will not be reflected, only changes in value.

VERBOSITY_LEVEL_TO_INDICATE_CHANGED_VALUES = 2
compare_stack_configurations(deployed, generated)[source]

Implement this method to return the diff for the stack configurations.

Parameters
  • deployed (Optional[StackConfiguration]) – The StackConfiguration as it has been deployed. This MIGHT be None, if the stack has not been deployed.

  • generated (StackConfiguration) – The StackConfiguration as it exists locally within Sceptre

Return type

DeepDiff

Returns

The generated diff between the two

compare_templates(deployed, generated)[source]

Implement this method to return the diff for the templates

Parameters
  • deployed (str) – The stack template as it has been deployed

  • generated (str) – The stack template as it exists locally within Sceptre

Return type

DeepDiff

Returns

The generated diff between the two

class sceptre.diffing.stack_differ.DifflibStackDiffer(show_no_echo=False, *, universal_template_loader=<function load>)[source]

Bases: StackDiffer[List[str]]

A StackDiffer that uses difflib to produce a diff between the stack as it exists on AWS and the stack as it exists locally within Sceptre.

Because difflib generates diffs off of lists of strings, both StackConfigurations and

compare_stack_configurations(deployed, generated)[source]

Implement this method to return the diff for the stack configurations.

Parameters
  • deployed (Optional[StackConfiguration]) – The StackConfiguration as it has been deployed. This MIGHT be None, if the stack has not been deployed.

  • generated (StackConfiguration) – The StackConfiguration as it exists locally within Sceptre

Return type

List[str]

Returns

The generated diff between the two

compare_templates(deployed, generated)[source]

Implement this method to return the diff for the templates

Parameters
  • deployed (str) – The stack template as it has been deployed

  • generated (str) – The stack template as it exists locally within Sceptre

Return type

List[str]

Returns

The generated diff between the two

class sceptre.diffing.stack_differ.StackConfiguration(stack_name: str, parameters: Dict[str, Union[str, List[str]]], stack_tags: Dict[str, str], notifications: List[str], cloudformation_service_role: Optional[str])[source]

Bases: NamedTuple

A data container to represent the comparable parts of a Stack.

cloudformation_service_role: Optional[str]

Alias for field number 4

notifications: List[str]

Alias for field number 3

parameters: Dict[str, Union[str, List[str]]]

Alias for field number 1

stack_name: str

Alias for field number 0

stack_tags: Dict[str, str]

Alias for field number 2

class sceptre.diffing.stack_differ.StackDiff(stack_name: str, template_diff: DiffType, config_diff: DiffType, is_deployed: bool, generated_config: StackConfiguration, generated_template: str)[source]

Bases: NamedTuple

A data container to represent the full difference between a deployed stack and the stack as it exists locally within Sceptre.

config_diff: DiffType

Alias for field number 2

generated_config: StackConfiguration

Alias for field number 4

generated_template: str

Alias for field number 5

is_deployed: bool

Alias for field number 3

stack_name: str

Alias for field number 0

template_diff: DiffType

Alias for field number 1

class sceptre.diffing.stack_differ.StackDiffer(show_no_echo=False)[source]

Bases: Generic[DiffType]

A utility for producing a StackDiff that indicates the full difference between a given stack as it is currently DEPLOYED on CloudFormation and the stack as it exists in the local Sceptre configurations.

This utility compares both the stack configuration (specifically those attributes that CAN be compared) as well as the stack template.

As an abstract base class, the two comparison methods need to be implemented so that the StackDiff can be generated.

NO_ECHO_REPLACEMENT = '***HIDDEN***'
STACK_STATUSES_INDICATING_NOT_DEPLOYED = ['CREATE_FAILED', 'ROLLBACK_COMPLETE', 'DELETE_COMPLETE']
abstract compare_stack_configurations(deployed, generated)[source]

Implement this method to return the diff for the stack configurations.

Parameters
  • deployed (Optional[StackConfiguration]) – The StackConfiguration as it has been deployed. This MIGHT be None, if the stack has not been deployed.

  • generated (StackConfiguration) – The StackConfiguration as it exists locally within Sceptre

Return type

TypeVar(DiffType)

Returns

The generated diff between the two

abstract compare_templates(deployed, generated)[source]

Implement this method to return the diff for the templates

Parameters
  • deployed (str) – The stack template as it has been deployed

  • generated (str) – The stack template as it exists locally within Sceptre

Return type

TypeVar(DiffType)

Returns

The generated diff between the two

diff(stack_actions)[source]

Produces a StackDiff between the currently deployed stack (if it exists) and the stack as it exists locally in Sceptre.

Parameters

stack_actions (StackActions) – The StackActions object to use for generating and fetching templates as well as providing other details about the stack.

Return type

StackDiff

Returns

The StackDiff that expresses the difference.

sceptre.diffing.stack_differ.repr_odict(dumper, data)[source]

A YAML Representer for cfn-flip’s ODict objects.

ODicts are a variation on OrderedDicts for that library. Since the Diff command makes extensive use of ODicts, they can end up in diff output and the PyYaml library doesn’t otherwise calls the dicts like !!ODict, which looks weird. We can just treat them like normal dicts when we serialize them, though.

Parameters
  • dumper (Dumper) – The Dumper that is being used to serialize this object

  • data (ODict) – The ODict object to serialize

Return type

str

Returns

The serialized ODict

sceptre.diffing.stack_differ.repr_str(dumper, data)[source]

A YAML Representer that handles strings, breaking multi-line strings into something a lot more readable in the yaml output. This is useful for representing long, multiline strings in templates or in stack parameters.

Parameters
  • dumper (Dumper) – The Dumper that is being used to serialize this object

  • data (str) – The string to serialize

Return type

str

Returns

The represented string

sceptre.diffing.diff_writer module

class sceptre.diffing.diff_writer.ColouredDiffLibWriter(stack_diff, output_stream, output_format)[source]

Bases: DiffLibWriter

A DiffWriter for StackDiffs where the DiffType is a a list of strings with coloured diffs.

dump_diff(diff)[source]

“Implement this method to write the DiffType to string

Return type

str

class sceptre.diffing.diff_writer.DeepDiffWriter(stack_diff, output_stream, output_format)[source]

Bases: DiffWriter[DeepDiff]

A DiffWriter for StackDiffs where the DiffType is a DeepDiff object.

dump_diff(diff)[source]

“Implement this method to write the DiffType to string

Return type

str

property has_config_difference: bool

Implement this to indicate whether or not there is a config difference

Return type

bool

property has_template_difference: bool

Implement this to indicate whether or not there is a template difference

Return type

bool

class sceptre.diffing.diff_writer.DiffLibWriter(stack_diff, output_stream, output_format)[source]

Bases: DiffWriter[List[str]]

A DiffWriter for StackDiffs where the DiffType is a a list of strings.

dump_diff(diff)[source]

“Implement this method to write the DiffType to string

Return type

str

property has_config_difference: bool

Implement this to indicate whether or not there is a config difference

Return type

bool

property has_template_difference: bool

Implement this to indicate whether or not there is a template difference

Return type

bool

class sceptre.diffing.diff_writer.DiffWriter(stack_diff, output_stream, output_format)[source]

Bases: Generic[DiffType]

A component responsible for taking a StackDiff and writing it in a way that is useful and readable. This is an abstract base class, so the abstract methods need to be implemented to create a DiffWriter for a given DiffType.

LINE_BAR = '--------------------------------------------------------------------------------'
STAR_BAR = '********************************************************************************'
abstract dump_diff(diff)[source]

“Implement this method to write the DiffType to string

Return type

str

abstract property has_config_difference: bool

Implement this to indicate whether or not there is a config difference

Return type

bool

property has_difference: bool
Return type

bool

abstract property has_template_difference: bool

Implement this to indicate whether or not there is a template difference

Return type

bool

write()[source]

Writes the diff to the output stream.