diff --git a/src/main/python/ddadevops/domain/terraform.py b/src/main/python/ddadevops/domain/terraform.py index 95b29bb..acd1292 100644 --- a/src/main/python/ddadevops/domain/terraform.py +++ b/src/main/python/ddadevops/domain/terraform.py @@ -31,6 +31,7 @@ class Terraform(Validateable): def validate(self) -> List[str]: result = [] result += self.__validate_is_not_empty__("module") + result += self.__validate_is_not_empty__("stage") result += self.__validate_is_not_empty__("tf_build_commons_dir_name") return result @@ -43,3 +44,9 @@ class Terraform(Validateable): def terraform_build_commons_path(self) -> Path: mylist = [self.tf_build_commons_path, self.tf_build_commons_dir_name] return Path("/".join(filter_none(mylist)) + "/") + + def project_vars(self): + ret = {"stage": self.stage, "module": self.module} + if self.tf_additional_vars: + ret.update(self.tf_additional_vars) + return ret diff --git a/src/test/python/domain/test_terraform.py b/src/test/python/domain/test_terraform.py index d46457d..b042bf0 100644 --- a/src/test/python/domain/test_terraform.py +++ b/src/test/python/domain/test_terraform.py @@ -31,3 +31,8 @@ def test_should_calculate_terraform_build_commons_path(): config = devops_config({}) sut = Terraform(config) assert Path("build_commons_path/terraform") == sut.terraform_build_commons_path() + +def test_should_calculate_project_vars(): + config = devops_config({}) + sut = Terraform(config) + assert {'module': 'module', 'stage': 'test'} == sut.project_vars()