def __init__(self, path: str, variables: List[str]): """ :param path: The path to the Terraform configuration files to execute. :param variables: Any additional variables to set alongside the Terraform command. """ self.path = get_absolute_path(path=path) wrapper_config_files = find_wrapper_config_files(self.path) wrapper_config = parse_wrapper_configs(wrapper_config_files) self.envvars = resolve_envvars(wrapper_config.envvars) self.variables = variables
def test_resolve_envvars_from_wrapper_config(self, mock_ssm_cache): """Test envvars can be resolved correctly""" mock_ssm_cache.parameter.return_value = MagicMock(value="SSM_VALUE") wrapper_config = parse_wrapper_configs( wrapper_config_files=[ os.path.join(os.getcwd(), 'mock_directory/config/.tf_wrapper'), os.path.join(os.getcwd(), 'mock_directory/config/app4/.tf_wrapper'), ] ) actual_envvars = resolve_envvars(wrapper_config.envvars) self.assertEqual("OVERWRITTEN_VALUE", actual_envvars["OVERWRITTEN_KEY"]) self.assertEqual("HARDCODED_VALUE", actual_envvars["HARDCODED_KEY"]) self.assertEqual("SSM_VALUE", actual_envvars["SSM_KEY"]) mock_ssm_cache.parameter.assert_called_once_with("FAKE_SSM_PATH")