Esempio n. 1
0
 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
Esempio n. 2
0
    def test_parse_wrapper_config(self):
        """Test parse wrapper configs and merge correctly"""
        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'),
            ]
        )

        self.assertEqual("OVERWRITTEN_VALUE", wrapper_config.envvars["OVERWRITTEN_KEY"].value)
        self.assertEqual("HARDCODED_VALUE", wrapper_config.envvars["HARDCODED_KEY"].value)
        self.assertEqual("FAKE_SSM_PATH", wrapper_config.envvars["SSM_KEY"].path)
Esempio n. 3
0
    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")