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
|
||||
|
||||
|
||||
|
@ -18,8 +18,8 @@ class Digitalocean(Validateable, CredentialMappingDefault):
|
|||
result += self.__validate_is_not_empty__("do_spaces_secret_key")
|
||||
return result
|
||||
|
||||
def resources_from_package(self) -> List[str]:
|
||||
return ["provider_registry.tf", "do_provider.tf", "do_mixin_vars.tf"]
|
||||
def resources_from_package(self) -> Set[str]:
|
||||
return {"provider_registry.tf", "do_provider.tf", "do_mixin_vars.tf"}
|
||||
|
||||
def project_vars(self):
|
||||
return {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from typing import List, Dict
|
||||
from typing import List, Dict, Set
|
||||
from .common import Validateable, CredentialMappingDefault
|
||||
|
||||
class Hetzner(Validateable, CredentialMappingDefault):
|
||||
|
@ -13,8 +13,8 @@ class Hetzner(Validateable, CredentialMappingDefault):
|
|||
result += self.__validate_is_not_empty__("hetzner_api_key")
|
||||
return result
|
||||
|
||||
def resources_from_package(self) -> List[str]:
|
||||
return ["provider_registry.tf", "hetzner_provider.tf", "hetzner_mixin_vars.tf"]
|
||||
def resources_from_package(self) -> Set[str]:
|
||||
return {"provider_registry.tf", "hetzner_provider.tf", "hetzner_mixin_vars.tf"}
|
||||
|
||||
def project_vars(self):
|
||||
return {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from typing import List
|
||||
from typing import List, Set
|
||||
from pathlib import Path
|
||||
from .common import (
|
||||
Validateable,
|
||||
|
@ -18,7 +18,7 @@ class TerraformDomain(Validateable):
|
|||
self.tf_build_commons_path = inp.get("tf_build_commons_path")
|
||||
self.tf_provider_types = inp.get("tf_provider_types", [])
|
||||
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_use_workspace = inp.get("tf_use_workspace", True)
|
||||
|
@ -70,11 +70,11 @@ class TerraformDomain(Validateable):
|
|||
result.update(self.tf_additional_vars)
|
||||
return result
|
||||
|
||||
def resources_from_package(self) -> List[str]:
|
||||
result = ["versions.tf", "terraform_build_vars.tf"]
|
||||
def resources_from_package(self) -> Set[str]:
|
||||
result = {"versions.tf", "terraform_build_vars.tf"}
|
||||
for provider in self.providers.values():
|
||||
result += provider.resources_from_package()
|
||||
result += self.tf_additional_resources_from_package
|
||||
result = result.union(provider.resources_from_package())
|
||||
result = result.union(self.tf_additional_resources_from_package)
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -83,7 +83,7 @@ def test_should_calculate_resources_from_package():
|
|||
}
|
||||
)
|
||||
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(
|
||||
{
|
||||
|
@ -91,13 +91,13 @@ def test_should_calculate_resources_from_package():
|
|||
}
|
||||
)
|
||||
sut = TerraformDomain(config)
|
||||
assert [
|
||||
assert {
|
||||
"versions.tf",
|
||||
"terraform_build_vars.tf",
|
||||
"provider_registry.tf",
|
||||
"do_provider.tf",
|
||||
"do_mixin_vars.tf",
|
||||
] == sut.resources_from_package()
|
||||
} == sut.resources_from_package()
|
||||
|
||||
config = devops_config(
|
||||
{
|
||||
|
@ -105,17 +105,17 @@ def test_should_calculate_resources_from_package():
|
|||
}
|
||||
)
|
||||
sut = TerraformDomain(config)
|
||||
assert [
|
||||
assert {
|
||||
"versions.tf",
|
||||
"terraform_build_vars.tf",
|
||||
"provider_registry.tf",
|
||||
"hetzner_provider.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)
|
||||
assert [
|
||||
assert {
|
||||
"versions.tf",
|
||||
"terraform_build_vars.tf",
|
||||
"provider_registry.tf",
|
||||
|
@ -125,4 +125,4 @@ def test_should_calculate_resources_from_package():
|
|||
"hetzner_provider.tf",
|
||||
"hetzner_mixin_vars.tf",
|
||||
"my.file",
|
||||
] == sut.resources_from_package()
|
||||
} == sut.resources_from_package()
|
||||
|
|
Loading…
Reference in a new issue