fix aws_backend wo kms

This commit is contained in:
Michael Jerger 2023-07-05 08:58:53 +02:00
parent 1c08952a86
commit 2fa5e94cb6
5 changed files with 25 additions and 7 deletions

View file

@ -29,7 +29,6 @@ class Aws(Validateable, CredentialMappingDefault):
if self.aws_as_backend:
result += self.__validate_is_not_empty__("aws_bucket")
result += self.__validate_is_not_empty__("aws_bucket_key")
result += self.__validate_is_not_empty__("aws_bucket_kms_key_id")
result += self.__validate_is_not_empty__("aws_region")
return result
@ -48,9 +47,20 @@ class Aws(Validateable, CredentialMappingDefault):
def resources_from_package(self) -> Set[str]:
result = {"provider_registry.tf", "aws_provider.tf", "aws_provider_vars.tf"}
if self.aws_as_backend:
result.update(
{"aws_backend_properties_vars.tf", "aws_backend_with_properties.tf"}
)
if self.aws_bucket_kms_key_id:
result.update(
{
"aws_backend_wkms_vars.tf",
"aws_backend.tf",
}
)
else:
result.update(
{
"aws_backend_wokms_vars.tf",
"aws_backend.tf",
}
)
return result
def project_vars(self):
@ -65,9 +75,14 @@ class Aws(Validateable, CredentialMappingDefault):
"account_name": self.aws_account_name,
"bucket": self.aws_bucket,
"key": self.__bucket_key__(),
"kms_key_id": self.aws_bucket_kms_key_id,
}
)
if self.aws_bucket_kms_key_id:
result.update(
{
"kms_key_id": self.aws_bucket_kms_key_id,
}
)
return result
def is_local_state(self):

View file

@ -0,0 +1,3 @@
variable "account_name" {}
variable "bucket" {}
variable "key" {}

View file

@ -161,10 +161,10 @@ def test_should_calculate_resources_from_package():
"provider_registry.tf",
"hetzner_provider.tf",
"hetzner_provider_vars.tf",
"aws_backend_with_properties.tf",
"aws_backend.tf",
"aws_provider.tf",
"aws_provider_vars.tf",
"aws_backend_properties_vars.tf",
"aws_backend_wkms_vars.tf",
"my.file",
} == sut.resources_from_package()