mirror of
https://gitea.fenix-dev.com/fenix-gitea-admin/iac-opentofu-private.git
synced 2025-10-27 15:53:06 +00:00
36 lines
1011 B
Python
36 lines
1011 B
Python
|
|
#!/usr/bin/env python3
|
|
import yaml
|
|
import sys
|
|
import json
|
|
from collections.abc import Mapping
|
|
|
|
def deep_merge_yaml(dict1, dict2):
|
|
result = dict1.copy()
|
|
for key, value in dict2.items():
|
|
if key in result:
|
|
if isinstance(result[key], list) and isinstance(value, list):
|
|
result[key] = result[key] + value
|
|
elif isinstance(result[key], Mapping) and isinstance(value, Mapping):
|
|
result[key] = deep_merge_yaml(result[key], value)
|
|
else:
|
|
result[key] = value
|
|
else:
|
|
result[key] = value
|
|
return result
|
|
|
|
def main():
|
|
input_data = json.load(sys.stdin)
|
|
file1 = input_data["file1"]
|
|
file2 = input_data["file2"]
|
|
|
|
with open(file1, "r") as f1, open(file2, "r") as f2:
|
|
yaml1 = yaml.safe_load(f1)
|
|
yaml2 = yaml.safe_load(f2)
|
|
|
|
merged = deep_merge_yaml(yaml1, yaml2)
|
|
print(json.dumps({"merged_yaml": yaml.dump(merged, sort_keys=False)}))
|
|
|
|
if __name__ == "__main__":
|
|
main()
|