diff --git a/src/main/python/ddadevops/domain/provider_aws.py b/src/main/python/ddadevops/domain/provider_aws.py index f90a18a..870cd79 100644 --- a/src/main/python/ddadevops/domain/provider_aws.py +++ b/src/main/python/ddadevops/domain/provider_aws.py @@ -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): diff --git a/src/main/resources/terraform/aws_backend_with_properties.tf b/src/main/resources/terraform/aws_backend.tf similarity index 100% rename from src/main/resources/terraform/aws_backend_with_properties.tf rename to src/main/resources/terraform/aws_backend.tf diff --git a/src/main/resources/terraform/aws_backend_properties_vars.tf b/src/main/resources/terraform/aws_backend_wkms_vars.tf similarity index 100% rename from src/main/resources/terraform/aws_backend_properties_vars.tf rename to src/main/resources/terraform/aws_backend_wkms_vars.tf diff --git a/src/main/resources/terraform/aws_backend_wokms_vars.tf b/src/main/resources/terraform/aws_backend_wokms_vars.tf new file mode 100644 index 0000000..3fc147f --- /dev/null +++ b/src/main/resources/terraform/aws_backend_wokms_vars.tf @@ -0,0 +1,3 @@ +variable "account_name" {} +variable "bucket" {} +variable "key" {} \ No newline at end of file diff --git a/src/test/python/domain/test_terraform.py b/src/test/python/domain/test_terraform.py index 4759135..4ef412e 100644 --- a/src/test/python/domain/test_terraform.py +++ b/src/test/python/domain/test_terraform.py @@ -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()