Implement additional resources as sets
Avoids duplicates when using multiple providers
This commit is contained in:
parent
b26cf9ff0a
commit
7ad5468a11
4 changed files with 20 additions and 20 deletions
|
@ -1,4 +1,4 @@
|
||||||
from typing import List, Dict
|
from typing import List, Dict, Set
|
||||||
from .common import Validateable, CredentialMappingDefault
|
from .common import Validateable, CredentialMappingDefault
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ class Digitalocean(Validateable, CredentialMappingDefault):
|
||||||
result += self.__validate_is_not_empty__("do_spaces_secret_key")
|
result += self.__validate_is_not_empty__("do_spaces_secret_key")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def resources_from_package(self) -> List[str]:
|
def resources_from_package(self) -> Set[str]:
|
||||||
return ["provider_registry.tf", "do_provider.tf", "do_mixin_vars.tf"]
|
return {"provider_registry.tf", "do_provider.tf", "do_mixin_vars.tf"}
|
||||||
|
|
||||||
def project_vars(self):
|
def project_vars(self):
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from typing import List, Dict
|
from typing import List, Dict, Set
|
||||||
from .common import Validateable, CredentialMappingDefault
|
from .common import Validateable, CredentialMappingDefault
|
||||||
|
|
||||||
class Hetzner(Validateable, CredentialMappingDefault):
|
class Hetzner(Validateable, CredentialMappingDefault):
|
||||||
|
@ -13,8 +13,8 @@ class Hetzner(Validateable, CredentialMappingDefault):
|
||||||
result += self.__validate_is_not_empty__("hetzner_api_key")
|
result += self.__validate_is_not_empty__("hetzner_api_key")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def resources_from_package(self) -> List[str]:
|
def resources_from_package(self) -> Set[str]:
|
||||||
return ["provider_registry.tf", "hetzner_provider.tf", "hetzner_mixin_vars.tf"]
|
return {"provider_registry.tf", "hetzner_provider.tf", "hetzner_mixin_vars.tf"}
|
||||||
|
|
||||||
def project_vars(self):
|
def project_vars(self):
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from typing import List
|
from typing import List, Set
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from .common import (
|
from .common import (
|
||||||
Validateable,
|
Validateable,
|
||||||
|
@ -18,7 +18,7 @@ class TerraformDomain(Validateable):
|
||||||
self.tf_build_commons_path = inp.get("tf_build_commons_path")
|
self.tf_build_commons_path = inp.get("tf_build_commons_path")
|
||||||
self.tf_provider_types = inp.get("tf_provider_types", [])
|
self.tf_provider_types = inp.get("tf_provider_types", [])
|
||||||
self.tf_additional_resources_from_package = inp.get(
|
self.tf_additional_resources_from_package = inp.get(
|
||||||
"tf_additional_resources_from_package", []
|
"tf_additional_resources_from_package", set()
|
||||||
)
|
)
|
||||||
self.tf_additional_tfvar_files = inp.get("tf_additional_tfvar_files", [])
|
self.tf_additional_tfvar_files = inp.get("tf_additional_tfvar_files", [])
|
||||||
self.tf_use_workspace = inp.get("tf_use_workspace", True)
|
self.tf_use_workspace = inp.get("tf_use_workspace", True)
|
||||||
|
@ -70,11 +70,11 @@ class TerraformDomain(Validateable):
|
||||||
result.update(self.tf_additional_vars)
|
result.update(self.tf_additional_vars)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def resources_from_package(self) -> List[str]:
|
def resources_from_package(self) -> Set[str]:
|
||||||
result = ["versions.tf", "terraform_build_vars.tf"]
|
result = {"versions.tf", "terraform_build_vars.tf"}
|
||||||
for provider in self.providers.values():
|
for provider in self.providers.values():
|
||||||
result += provider.resources_from_package()
|
result = result.union(provider.resources_from_package())
|
||||||
result += self.tf_additional_resources_from_package
|
result = result.union(self.tf_additional_resources_from_package)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -83,7 +83,7 @@ def test_should_calculate_resources_from_package():
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
sut = TerraformDomain(config)
|
sut = TerraformDomain(config)
|
||||||
assert ["versions.tf", "terraform_build_vars.tf"] == sut.resources_from_package()
|
assert {"versions.tf", "terraform_build_vars.tf"} == sut.resources_from_package()
|
||||||
|
|
||||||
config = devops_config(
|
config = devops_config(
|
||||||
{
|
{
|
||||||
|
@ -91,13 +91,13 @@ def test_should_calculate_resources_from_package():
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
sut = TerraformDomain(config)
|
sut = TerraformDomain(config)
|
||||||
assert [
|
assert {
|
||||||
"versions.tf",
|
"versions.tf",
|
||||||
"terraform_build_vars.tf",
|
"terraform_build_vars.tf",
|
||||||
"provider_registry.tf",
|
"provider_registry.tf",
|
||||||
"do_provider.tf",
|
"do_provider.tf",
|
||||||
"do_mixin_vars.tf",
|
"do_mixin_vars.tf",
|
||||||
] == sut.resources_from_package()
|
} == sut.resources_from_package()
|
||||||
|
|
||||||
config = devops_config(
|
config = devops_config(
|
||||||
{
|
{
|
||||||
|
@ -105,17 +105,17 @@ def test_should_calculate_resources_from_package():
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
sut = TerraformDomain(config)
|
sut = TerraformDomain(config)
|
||||||
assert [
|
assert {
|
||||||
"versions.tf",
|
"versions.tf",
|
||||||
"terraform_build_vars.tf",
|
"terraform_build_vars.tf",
|
||||||
"provider_registry.tf",
|
"provider_registry.tf",
|
||||||
"hetzner_provider.tf",
|
"hetzner_provider.tf",
|
||||||
"hetzner_mixin_vars.tf",
|
"hetzner_mixin_vars.tf",
|
||||||
] == sut.resources_from_package()
|
} == sut.resources_from_package()
|
||||||
|
|
||||||
config = devops_config({"tf_additional_resources_from_package": ["my.file"]})
|
config = devops_config({"tf_additional_resources_from_package": {"my.file"}})
|
||||||
sut = TerraformDomain(config)
|
sut = TerraformDomain(config)
|
||||||
assert [
|
assert {
|
||||||
"versions.tf",
|
"versions.tf",
|
||||||
"terraform_build_vars.tf",
|
"terraform_build_vars.tf",
|
||||||
"provider_registry.tf",
|
"provider_registry.tf",
|
||||||
|
@ -125,4 +125,4 @@ def test_should_calculate_resources_from_package():
|
||||||
"hetzner_provider.tf",
|
"hetzner_provider.tf",
|
||||||
"hetzner_mixin_vars.tf",
|
"hetzner_mixin_vars.tf",
|
||||||
"my.file",
|
"my.file",
|
||||||
] == sut.resources_from_package()
|
} == sut.resources_from_package()
|
||||||
|
|
Loading…
Reference in a new issue