diff --git a/src/main/python/ddadevops/application/terraform_service.py b/src/main/python/ddadevops/application/terraform_service.py index 9dfc483..e500735 100644 --- a/src/main/python/ddadevops/application/terraform_service.py +++ b/src/main/python/ddadevops/application/terraform_service.py @@ -50,11 +50,15 @@ class TerraformService: # TODO: internal? def copy_local_state(self, devops: Devops): - self.file_api.cp("terraform.tfstate", devops.build_path(), check=False) + terraform_domain = devops.specialized_builds[BuildType.TERRAFORM] + if terraform_domain.is_local_state(): + self.file_api.cp("terraform.tfstate", devops.build_path(), check=False) # TODO: internal? def rescue_local_state(self, devops: Devops): - self.file_api.cp(f"{devops.build_path()}/terraform.tfstate", ".", check=False) + terraform_domain = devops.specialized_builds[BuildType.TERRAFORM] + if terraform_domain.is_local_state(): + self.file_api.cp(f"{devops.build_path()}/terraform.tfstate", ".", check=False) def initialize_build_dir(self, devops: Devops): terraform = devops.specialized_builds[BuildType.TERRAFORM] diff --git a/src/main/python/ddadevops/digitalocean_backend_properties_mixin.py b/src/main/python/ddadevops/digitalocean_backend_properties_mixin.py index 2cd33b9..de8128f 100644 --- a/src/main/python/ddadevops/digitalocean_backend_properties_mixin.py +++ b/src/main/python/ddadevops/digitalocean_backend_properties_mixin.py @@ -20,12 +20,6 @@ class DigitaloceanBackendPropertiesMixin(): ret.update({"region": self.region}) return ret - def copy_local_state(self): - pass - - def rescue_local_state(self): - pass - def init_client(self): terraform = Terraform( working_dir=self.build_path(), diff --git a/src/main/python/ddadevops/domain/provider_digitalocean.py b/src/main/python/ddadevops/domain/provider_digitalocean.py index e71d9af..6f3f633 100644 --- a/src/main/python/ddadevops/domain/provider_digitalocean.py +++ b/src/main/python/ddadevops/domain/provider_digitalocean.py @@ -63,6 +63,9 @@ class Digitalocean(Validateable, CredentialMappingDefault): "region": self.do_region, } return result + + def is_local_state(self): + return not self.do_as_backend @classmethod def get_mapping_default(cls) -> List[Dict[str, str]]: diff --git a/src/main/python/ddadevops/domain/provider_hetzner.py b/src/main/python/ddadevops/domain/provider_hetzner.py index 26018a9..078117e 100644 --- a/src/main/python/ddadevops/domain/provider_hetzner.py +++ b/src/main/python/ddadevops/domain/provider_hetzner.py @@ -20,6 +20,9 @@ class Hetzner(Validateable, CredentialMappingDefault): return { "hetzner_api_key": self.hetzner_api_key } + + def is_local_state(self): + return True @classmethod def get_mapping_default(cls) -> List[Dict[str, str]]: diff --git a/src/main/python/ddadevops/domain/terraform.py b/src/main/python/ddadevops/domain/terraform.py index 03fd5c9..f373a9e 100644 --- a/src/main/python/ddadevops/domain/terraform.py +++ b/src/main/python/ddadevops/domain/terraform.py @@ -77,6 +77,12 @@ class TerraformDomain(Validateable): result = result.union(self.tf_additional_resources_from_package) return result + def is_local_state(self): + result = True + for provider in self.providers.values(): + result = result and provider.is_local_state() + return result + @classmethod def parse_provider_types( cls, tf_provider_types: List[str] diff --git a/src/test/python/domain/test_terraform.py b/src/test/python/domain/test_terraform.py index b7dd38e..54b4655 100644 --- a/src/test/python/domain/test_terraform.py +++ b/src/test/python/domain/test_terraform.py @@ -153,4 +153,4 @@ def test_should_calculate_local_state_handling(): "tf_provider_types": ["DIGITALOCEAN"], "do_as_backend": True, })) - assert sut.is_local_state() + assert not sut.is_local_state()