22from pathlib import Path
33from configparser import NoSectionError , NoOptionError
44
5- import hcl2
65import boto3
7- from configupdater import ConfigUpdater
86from botocore .exceptions import ClientError
7+ from configupdater import ConfigUpdater
98
109from leverage import logger
11- from leverage ._utils import key_finder , ExitError , get_or_create_section
10+ from leverage ._utils import key_finder , ExitError , get_or_create_section , parse_tf_file
1211
1312
1413class SkipProfile (Exception ):
@@ -66,8 +65,7 @@ def get_profiles(cli):
6665 # these are files from the layer we are currently on
6766 for name in ("config.tf" , "locals.tf" ):
6867 try :
69- with open (name ) as tf_file :
70- tf_config = hcl2 .load (tf_file )
68+ tf_config = parse_tf_file (Path (name ))
7169 except FileNotFoundError :
7270 continue
7371
@@ -76,8 +74,7 @@ def get_profiles(cli):
7674 raw_profiles .update (set (key_finder (tf_config , "profile" , "lookup" )))
7775
7876 # the profile value from <layer>/config/backend.tfvars
79- with open (cli .paths .local_backend_tfvars ) as backend_config_file :
80- backend_config = hcl2 .load (backend_config_file )
77+ backend_config = parse_tf_file (cli .paths .local_backend_tfvars )
8178 tf_profile = backend_config ["profile" ]
8279
8380 return tf_profile , raw_profiles
0 commit comments