add terraform_build_commons_path()
This commit is contained in:
parent
15335ae73f
commit
74a95c8c59
3 changed files with 34 additions and 11 deletions
|
@ -1,8 +1,10 @@
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
from pathlib import Path
|
||||||
from .common import (
|
from .common import (
|
||||||
Validateable,
|
Validateable,
|
||||||
DnsRecord,
|
DnsRecord,
|
||||||
Devops,
|
Devops,
|
||||||
|
filter_none,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +20,9 @@ class Terraform(Validateable):
|
||||||
self.tf_debug_print_terraform_command = inp.get(
|
self.tf_debug_print_terraform_command = inp.get(
|
||||||
"tf_debug_print_terraform_command", False
|
"tf_debug_print_terraform_command", False
|
||||||
)
|
)
|
||||||
self.tf_commons_dir_name = inp.get("tf_commons_dir_name", "terraform")
|
self.tf_build_commons_dir_name = inp.get(
|
||||||
|
"tf_build_commons_dir_name", "terraform"
|
||||||
|
)
|
||||||
self.tf_terraform_semantic_version = inp.get(
|
self.tf_terraform_semantic_version = inp.get(
|
||||||
"tf_terraform_semantic_version", "1.0.8"
|
"tf_terraform_semantic_version", "1.0.8"
|
||||||
)
|
)
|
||||||
|
@ -27,6 +31,7 @@ class Terraform(Validateable):
|
||||||
def validate(self) -> List[str]:
|
def validate(self) -> List[str]:
|
||||||
result = []
|
result = []
|
||||||
result += self.__validate_is_not_empty__("module")
|
result += self.__validate_is_not_empty__("module")
|
||||||
|
result += self.__validate_is_not_empty__("tf_build_commons_dir_name")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def output_json_name(self) -> str:
|
def output_json_name(self) -> str:
|
||||||
|
@ -34,3 +39,7 @@ class Terraform(Validateable):
|
||||||
return self.tf_output_json_name
|
return self.tf_output_json_name
|
||||||
else:
|
else:
|
||||||
return f"out_{self.module}.json"
|
return f"out_{self.module}.json"
|
||||||
|
|
||||||
|
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)) + "/")
|
||||||
|
|
|
@ -28,8 +28,8 @@ def devops_config(overrides: dict) -> dict:
|
||||||
"tf_output_json_name": "the_out.json",
|
"tf_output_json_name": "the_out.json",
|
||||||
"tf_use_workspace": None,
|
"tf_use_workspace": None,
|
||||||
"tf_use_package_common_files": None,
|
"tf_use_package_common_files": None,
|
||||||
"tf_build_commons_path": None,
|
"tf_build_commons_path": "build_commons_path",
|
||||||
"tf_commons_dir_name": None,
|
"tf_build_commons_dir_name": "terraform",
|
||||||
"tf_debug_print_terraform_command": None,
|
"tf_debug_print_terraform_command": None,
|
||||||
"tf_additional_tfvar_files": None,
|
"tf_additional_tfvar_files": None,
|
||||||
"tf_terraform_semantic_version": None,
|
"tf_terraform_semantic_version": None,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import pytest
|
import pytest
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from src.main.python.ddadevops.domain import DnsRecord, BuildType, Terraform
|
from src.main.python.ddadevops.domain import DnsRecord, BuildType, Terraform
|
||||||
from .helper import build_devops
|
from .helper import build_devops, devops_config
|
||||||
|
|
||||||
|
|
||||||
def test_creation():
|
def test_creation():
|
||||||
|
@ -9,11 +9,25 @@ def test_creation():
|
||||||
assert BuildType.TERRAFORM in sut.specialized_builds
|
assert BuildType.TERRAFORM in sut.specialized_builds
|
||||||
assert sut.specialized_builds[BuildType.TERRAFORM]
|
assert sut.specialized_builds[BuildType.TERRAFORM]
|
||||||
|
|
||||||
def test_should_calculate_output_json_name():
|
|
||||||
devops = build_devops({})
|
|
||||||
sut = devops.specialized_builds[BuildType.TERRAFORM]
|
|
||||||
assert 'the_out.json' == sut.output_json_name()
|
|
||||||
|
|
||||||
devops = build_devops({"tf_output_json_name": None,})
|
def test_should_calculate_output_json_name():
|
||||||
sut = devops.specialized_builds[BuildType.TERRAFORM]
|
config = devops_config({})
|
||||||
assert 'out_module.json' == sut.output_json_name()
|
sut = Terraform(config)
|
||||||
|
assert "the_out.json" == sut.output_json_name()
|
||||||
|
|
||||||
|
config = devops_config({})
|
||||||
|
del config["tf_output_json_name"]
|
||||||
|
sut = Terraform(config)
|
||||||
|
assert "out_module.json" == sut.output_json_name()
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_calculate_terraform_build_commons_path():
|
||||||
|
config = devops_config({})
|
||||||
|
del config["tf_build_commons_path"]
|
||||||
|
del config["tf_build_commons_dir_name"]
|
||||||
|
sut = Terraform(config)
|
||||||
|
assert Path("terraform") == sut.terraform_build_commons_path()
|
||||||
|
|
||||||
|
config = devops_config({})
|
||||||
|
sut = Terraform(config)
|
||||||
|
assert Path("build_commons_path/terraform") == sut.terraform_build_commons_path()
|
||||||
|
|
Loading…
Reference in a new issue