sceptre.diffing package

Submodules

sceptre.diffing.diff_writer module

class sceptre.diffing.diff_writer.DeepDiffWriter(stack_diff: sceptre.diffing.stack_differ.StackDiff, output_stream: TextIO, output_format: str)[source]

Bases: sceptre.diffing.diff_writer.DiffWriter[deepdiff.diff.DeepDiff]

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

dump_diff(diff: deepdiff.diff.DeepDiff) str[source]

“Implement this method to write the DiffType to string

property has_config_difference: bool

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

property has_template_difference: bool

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

class sceptre.diffing.diff_writer.DiffLibWriter(stack_diff: sceptre.diffing.stack_differ.StackDiff, output_stream: TextIO, output_format: str)[source]

Bases: sceptre.diffing.diff_writer.DiffWriter[List[str]]

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

dump_diff(diff: List[str]) str[source]

“Implement this method to write the DiffType to string

property has_config_difference: bool

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

property has_template_difference: bool

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

class sceptre.diffing.diff_writer.DiffWriter(stack_diff: sceptre.diffing.stack_differ.StackDiff, output_stream: TextIO, output_format: str)[source]

Bases: Generic[sceptre.diffing.stack_differ.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: sceptre.diffing.stack_differ.DiffType) str[source]

“Implement this method to write the DiffType to string

abstract property has_config_difference: bool

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

property has_difference: bool
abstract property has_template_difference: bool

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

write()[source]

Writes the diff to the output stream.

sceptre.diffing.stack_differ module

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

Bases: sceptre.diffing.stack_differ.StackDiffer[deepdiff.diff.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: Optional[sceptre.diffing.stack_differ.StackConfiguration], generated: sceptre.diffing.stack_differ.StackConfiguration) deepdiff.diff.DeepDiff[source]

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

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

  • generated – The StackConfiguration as it exists locally within Sceptre

Returns

The generated diff between the two

compare_templates(deployed: str, generated: str) deepdiff.diff.DeepDiff[source]

Implement this method to return the diff for the templates

Parameters
  • deployed – The stack template as it has been deployed

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

Returns

The generated diff between the two

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

Bases: sceptre.diffing.stack_differ.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: Optional[sceptre.diffing.stack_differ.StackConfiguration], generated: sceptre.diffing.stack_differ.StackConfiguration) List[str][source]

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

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

  • generated – The StackConfiguration as it exists locally within Sceptre

Returns

The generated diff between the two

compare_templates(deployed: str, generated: str) List[str][source]

Implement this method to return the diff for the templates

Parameters
  • deployed – The stack template as it has been deployed

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

Returns

The generated diff between the two

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

Bases: tuple

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

notifications: List[str]

Alias for field number 3

parameters: Dict[str, str]

Alias for field number 1

role_arn: Optional[str]

Alias for field number 4

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: sceptre.diffing.stack_differ.DiffType, config_diff: sceptre.diffing.stack_differ.DiffType, is_deployed: bool, generated_config: sceptre.diffing.stack_differ.StackConfiguration, generated_template: str)[source]

Bases: tuple

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

config_diff: sceptre.diffing.stack_differ.DiffType

Alias for field number 2

generated_config: sceptre.diffing.stack_differ.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: sceptre.diffing.stack_differ.DiffType

Alias for field number 1

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

Bases: Generic[sceptre.diffing.stack_differ.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: Optional[sceptre.diffing.stack_differ.StackConfiguration], generated: sceptre.diffing.stack_differ.StackConfiguration) sceptre.diffing.stack_differ.DiffType[source]

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

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

  • generated – The StackConfiguration as it exists locally within Sceptre

Returns

The generated diff between the two

abstract compare_templates(deployed: str, generated: str) sceptre.diffing.stack_differ.DiffType[source]

Implement this method to return the diff for the templates

Parameters
  • deployed – The stack template as it has been deployed

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

Returns

The generated diff between the two

diff(stack_actions: sceptre.plan.actions.StackActions) sceptre.diffing.stack_differ.StackDiff[source]

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

Parameters

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

Returns

The StackDiff that expresses the difference.

sceptre.diffing.stack_differ.repr_odict(dumper: yaml.dumper.Dumper, data: cfn_tools.odict.ODict) str[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 – The Dumper that is being used to serialize this object

  • data – The ODict object to serialize

Returns

The serialized ODict

sceptre.diffing.stack_differ.repr_str(dumper: yaml.dumper.Dumper, data: str) str[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 – The Dumper that is being used to serialize this object

  • data – The string to serialize

Returns

The represented string