Terragraph.core
The core of the terragraph module
- class terragraph.core.HighlightingMode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
EnumAn Enum for managing the highlighting modes for edges
- ALL = 'all'
- PRECEDING = 'preceding'
- SUCCESSOR = 'successor'
- class terragraph.core.Terragraph(dot_data: str, subgraph_name: str = '"root"', highlighting_mode: HighlightingMode = HighlightingMode.PRECEDING)[source]
Bases:
objectA class that will parse the output from a terraform graph command and can highlight a node and its associated edges. It can highlight preceeding edges, or succesor edges. It can also highlight both allowing the full dependency tree top and bottom for a given node.
- DEFAULT_HIGHLIGHTING_MODE = 'preceding'
- get_edges() list[Edge][source]
Gets a list of all edges in the terraform sub graph :return: A list of pydot.Edge
- get_highlighted_edges() list[Edge][source]
Gets a list of nodes which have a color attribute :return: A list of pydot.Node objects which have a color attribute
- get_highlighted_nodes() list[Node][source]
Gets a list of nodes which have a color attribute :return: A list of pydot.Node objects which have a color attribute
- get_node_names() list[str][source]
Gets a list of all the nodes in the terraform_graph :return: list of node names
- get_nodes() list[Node][source]
Gets a list of all nodes in the terraform sub graph :return: a list of pydot.Node objects
- static highlight_edges(edges: list[Edge], color: str = 'red') None[source]
highlights a list of edges with the color name :param edges: A list of edge objects to be highlighted :param color: The color to highlight the edges :return: None
- highlight_node(node_name: str, color: str = 'red') None[source]
Highlights a node and its given edges :param node_name: The name of the node to highlight from :param color: The color to highlight the node :return: None :raises ValueError: If the node_name is not a node in the graph
- highlight_node_edges(node_name: str) None[source]
Takes a node name and will highlight the node and its edges based on the self.highlight_mode value :param node_name: The name of the node to highlight and the edges from it. :return: None :raises ValueError: Raises a ValueError when the node name passed is not a node in the graph.
- terragraph.core.create_highlighted_svg(dot_file_name: str, highlighted_node_name: str, mode: HighlightingMode = HighlightingMode.PRECEDING, filtered: bool = False) None[source]
Will create a highlighted representation of the graph under the same path as the dot_file_name but suffixed with .svg
- Parameters:
filtered – A boolean that indicates if only the highlighted nodes should be shown
dot_file_name – The name/path to a file containing a terraform graph output
highlighted_node_name – The node name to highlight in the graph and its edges.
mode – An Enum indicating which highlighting mode to use
- Returns:
This does not return anything as it will create the SVG in the file system.
- terragraph.core.from_file(filename: str, mode: HighlightingMode = HighlightingMode.PRECEDING) Terragraph[source]
Takes a file name containing a ‘terraform graph’ output and returns a Terragraph object of it