handle the case of non local state
This commit is contained in:
parent
8f61e286ae
commit
f399d1e637
6 changed files with 19 additions and 9 deletions
|
@ -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]
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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]]:
|
||||
|
|
|
@ -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]]:
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue