enhance terraform class

This commit is contained in:
Michael Jerger 2023-05-25 15:21:13 +02:00
parent b24288976e
commit 4cf3ec8460
3 changed files with 20 additions and 0 deletions

View file

@ -39,6 +39,7 @@ classDiagram
class TerraformDomain {
tf_additional_vars
tf_additional_resources_from_package
tf_output_json_name
tf_use_workspace
tf_use_package_common_files

View file

@ -15,6 +15,9 @@ class TerraformDomain(Validateable):
self.tf_additional_vars = inp.get("tf_additional_vars")
self.tf_output_json_name = inp.get("tf_output_json_name")
self.tf_build_commons_path = inp.get("tf_build_commons_path")
self.tf_additional_resources_from_package = inp.get(
"tf_additional_resources_from_package", []
)
self.tf_additional_tfvar_files = inp.get("tf_additional_tfvar_files", [])
self.tf_use_workspace = inp.get("tf_use_workspace", True)
self.tf_debug_print_terraform_command = inp.get(
@ -33,6 +36,8 @@ class TerraformDomain(Validateable):
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")
result += self.__validate_is_not_none__("tf_additional_resources_from_package")
result += self.__validate_is_not_none__("tf_additional_tfvar_files")
return result
def output_json_name(self) -> str:
@ -50,3 +55,8 @@ class TerraformDomain(Validateable):
if self.tf_additional_vars:
ret.update(self.tf_additional_vars)
return ret
def resources_from_package(self) -> List[str]:
result = ["version.tf", "terraform_build_vars.tf"]
result += self.tf_additional_resources_from_package
return result

View file

@ -36,3 +36,12 @@ def test_should_calculate_project_vars():
config = devops_config({})
sut = TerraformDomain(config)
assert {'module': 'module', 'stage': 'test'} == sut.project_vars()
def test_should_calculate_resources_from_package():
config = devops_config({})
sut = TerraformDomain(config)
assert ["version.tf", "terraform_build_vars.tf"] == sut.resources_from_package()
config = devops_config({"tf_additional_resources_from_package": ["my.file"]})
sut = TerraformDomain(config)
assert ["version.tf", "terraform_build_vars.tf", "my.file"] == sut.resources_from_package()