1- from ..lib .utils import perform_retries , run_stackql_command , catch_error_and_exit , run_stackql_query , export_vars , show_query , get_type
1+ from ..lib .utils import perform_retries , run_stackql_command , catch_error_and_exit , run_stackql_query , export_vars , show_query , get_type , check_all_dicts
22from ..lib .config import setup_environment , load_manifest , get_global_context_and_providers , get_full_context
33from ..lib .templating import get_queries
44
@@ -17,11 +17,24 @@ def __init__(self, stackql, vars, logger, stack_dir, stack_env):
1717 def process_exports (self , resource , exports_query , exports_retries , exports_retry_delay , dry_run , show_queries ,ignore_missing_exports = False ):
1818 expected_exports = resource .get ('exports' , [])
1919
20+ # Check if all items in expected_exports are dictionaries
21+ all_dicts = check_all_dicts (expected_exports , self .logger )
22+
2023 if len (expected_exports ) > 0 :
2124 protected_exports = resource .get ('protected' , [])
22-
2325 if dry_run :
24- export_data = {key : "<evaluated>" for key in expected_exports }
26+ export_data = {}
27+ if all_dicts :
28+ for item in expected_exports :
29+ for _ , val in item .items ():
30+ # when item is a dictionary,
31+ # val(expected_exports) is the key to be exported
32+ export_data [val ] = "<evaluated>"
33+ else :
34+ # when item is not a dictionary,
35+ # item is the key to be exported
36+ for item in expected_exports :
37+ export_data [item ] = "<evaluated>"
2538 export_vars (self , resource , export_data , expected_exports , protected_exports )
2639 self .logger .info (f"📦 dry run exports query for [{ resource ['name' ]} ]:\n \n /* exports query */\n { exports_query } \n " )
2740 else :
@@ -44,16 +57,31 @@ def process_exports(self, resource, exports_query, exports_retries, exports_retr
4457
4558 export = exports [0 ]
4659 if len (exports ) == 0 :
47- export = {key : '' for key in expected_exports }
60+ export_data = {}
61+ if all_dicts :
62+ for item in expected_exports :
63+ for key , val in item .items ():
64+ export_data [val ] = ''
65+ else :
66+ export_data [item ] = ''
4867 else :
4968 export_data = {}
50- for key in expected_exports :
51- if isinstance (export .get (key ), dict ) and 'String' in export [key ]:
52- export_data [key ] = export [key ]['String' ]
69+ for item in expected_exports :
70+ if all_dicts :
71+ for key , val in item .items ():
72+ # when item is a dictionary,
73+ # compare key(expected_exports) with key(export)
74+ # set val(expected_exports) as key and export[key] as value in export_data
75+ if isinstance (export .get (key ), dict ) and 'String' in export [key ]:
76+ export_data [val ] = export [key ]['String' ]
77+ else :
78+ export_data [val ] = export .get (key , '' )
5379 else :
54- export_data [key ] = export .get (key , '' )
55-
56- export_vars (self , resource , export_data , expected_exports , protected_exports )
80+ if isinstance (export .get (item ), dict ) and 'String' in export [item ]:
81+ export_data [item ] = export [item ]['String' ]
82+ else :
83+ export_data [item ] = export .get (item , '' )
84+ export_vars (self , resource , export_data , expected_exports , all_dicts , protected_exports )
5785
5886 def check_if_resource_exists (self , resource_exists , resource , exists_query , exists_retries , exists_retry_delay , dry_run , show_queries , delete_test = False ):
5987 check_type = 'exists'
0 commit comments