Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix multi #120

Merged
merged 2 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion modules/graphmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,11 @@ def add_number_suffix(i: int, check_multiple_resource: str, tfdata: dict):
):
return list()
# Loop through each connection for this target resource

new_list = list(tfdata["graphdict"][check_multiple_resource])
for resource in list(tfdata["graphdict"][check_multiple_resource]):
matching_resource_list = helpers.list_of_dictkeys_containing(
tfdata["meta_data"], resource
tfdata["graphdict"], resource
)
for res in matching_resource_list:
if (
Expand Down Expand Up @@ -693,6 +694,7 @@ def handle_count_resources(multi_resources: list, tfdata: dict):
return tfdata


# Handle cases where a connection to only one of n numbered node exists
def handle_singular_references(tfdata: dict) -> dict:
for node, connections in dict(tfdata["graphdict"]).items():
for c in list(connections):
Expand Down
3 changes: 2 additions & 1 deletion modules/resource_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ def aws_handle_lb(tfdata: dict):
tfdata["graphdict"][renamed_node] = list()
tfdata["graphdict"][renamed_node].append(connection)
if (
tfdata["meta_data"][connection].get("count")
tfdata["meta_data"].get(connection)
and tfdata["meta_data"][connection].get("count")
or tfdata["meta_data"][connection].get("desired_count")
) and connection.split(".")[0] not in SHARED_SERVICES:
tfdata["meta_data"][renamed_node] = dict(
Expand Down
68 changes: 38 additions & 30 deletions modules/tfwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,36 +217,44 @@ def tf_makegraph(tfdata: dict):
else:
nodename = helpers.remove_brackets_and_numbers(nodename)
node_id = gvid_table.index(nodename)
for connection in tfdata["tfgraph"]["edges"]:
head = connection["head"]
tail = connection["tail"]
# Check that the connection is part of the nodes that will be created (exists in graphdict)
if (
node_id == head
and len(
[k for k in tfdata["graphdict"] if k.startswith(gvid_table[tail])]
)
> 0
):
conn = gvid_table[tail]
conn_type = gvid_table[tail].split(".")[0]
# Find out the actual nodes with ~ suffix where link is not specific to a numbered node
matched_connections = [
k for k in tfdata["graphdict"] if k.startswith(gvid_table[tail])
]
matched_nodes = [
k for k in tfdata["graphdict"] if k.startswith(gvid_table[head])
]
if not node in tfdata["graphdict"] and len(matched_nodes) == 1:
node = matched_nodes[0]
if not conn in tfdata["graphdict"] and len(matched_connections) == 1:
conn = matched_connections[0]
if conn_type in REVERSE_ARROW_LIST:
if not conn in tfdata["graphdict"].keys():
tfdata["graphdict"][conn] = list()
tfdata["graphdict"][conn].append(node)
else:
tfdata["graphdict"][node].append(conn)
if tfdata["tfgraph"].get("edges"):
for connection in tfdata["tfgraph"]["edges"]:
head = connection["head"]
tail = connection["tail"]
# Check that the connection is part of the nodes that will be created (exists in graphdict)
if (
node_id == head
and len(
[
k
for k in tfdata["graphdict"]
if k.startswith(gvid_table[tail])
]
)
> 0
):
conn = gvid_table[tail]
conn_type = gvid_table[tail].split(".")[0]
# Find out the actual nodes with ~ suffix where link is not specific to a numbered node
matched_connections = [
k for k in tfdata["graphdict"] if k.startswith(gvid_table[tail])
]
matched_nodes = [
k for k in tfdata["graphdict"] if k.startswith(gvid_table[head])
]
if not node in tfdata["graphdict"] and len(matched_nodes) == 1:
node = matched_nodes[0]
if (
not conn in tfdata["graphdict"]
and len(matched_connections) == 1
):
conn = matched_connections[0]
if conn_type in REVERSE_ARROW_LIST:
if not conn in tfdata["graphdict"].keys():
tfdata["graphdict"][conn] = list()
tfdata["graphdict"][conn].append(node)
else:
tfdata["graphdict"][node].append(conn)
tfdata = add_vpc_implied_relations(tfdata)
tfdata["original_graphdict"] = dict(tfdata["graphdict"])
tfdata["original_metadata"] = dict(tfdata["meta_data"])
Expand Down
9 changes: 3 additions & 6 deletions tests/testcase-wordpress.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,15 @@
"module.vpc.aws_route.public_internet_gateway[0]~1": [],
"module.vpc.aws_route_table.private[0]~1": [
"module.vpc.aws_route.private_nat_gateway",
"module.vpc.aws_route_table_association.private",
"aws_appautoscaling_target.this~1"
"module.vpc.aws_route_table_association.private"
],
"module.vpc.aws_route_table.private[1]~2": [
"module.vpc.aws_route.private_nat_gateway",
"module.vpc.aws_route_table_association.private",
"aws_appautoscaling_target.this~2"
"module.vpc.aws_route_table_association.private"
],
"module.vpc.aws_route_table.private[2]~3": [
"module.vpc.aws_route.private_nat_gateway",
"module.vpc.aws_route_table_association.private",
"aws_appautoscaling_target.this~3"
"module.vpc.aws_route_table_association.private"
],
"module.vpc.aws_route_table.public[0]~1": [
"module.vpc.aws_route.public_internet_gateway[0]~1",
Expand Down
Loading