diff --git a/build.py b/build.py index 06c0dc9..8b23190 100644 --- a/build.py +++ b/build.py @@ -28,7 +28,7 @@ use_plugin("python.distutils") default_task = "publish" name = "ddadevops" -version = "4.0.0-dev52" +version = "4.0.0-dev57" summary = "tools to support builds combining gopass, terraform, dda-pallet, aws & hetzner-cloud" description = __doc__ authors = [Author("meissa GmbH", "buero@meissa-gmbh.de")] diff --git a/src/main/python/ddadevops/application/terraform_service.py b/src/main/python/ddadevops/application/terraform_service.py index de7d68d..9dfc483 100644 --- a/src/main/python/ddadevops/application/terraform_service.py +++ b/src/main/python/ddadevops/application/terraform_service.py @@ -2,7 +2,7 @@ from pathlib import Path from dda_python_terraform import Terraform, IsFlagged from packaging import version -from ..domain import Devops, BuildType, TerraformDomain +from ..domain import Devops, BuildType from ..infrastructure import FileApi, ResourceApi, TerraformApi @@ -79,10 +79,10 @@ class TerraformService: self.__print_terraform_command__(terraform, devops) if terraform_domain.tf_use_workspace: try: - terraform.workspace("select", self.stage) + terraform.workspace("select", devops.stage) self.__print_terraform_command__(terraform, devops) except: - terraform.workspace("new", self.stage) + terraform.workspace("new", devops.stage) self.__print_terraform_command__(terraform, devops) return terraform @@ -115,7 +115,7 @@ class TerraformService: var=terraform_domain.project_vars(), var_file=terraform_domain.tf_additional_tfvar_files, ) - self.__print_terraform_command__(terraform) + self.__print_terraform_command__(terraform, devops) if return_code not in (0, 2): raise RuntimeError(return_code, "terraform error:", stderr) if return_code == 2: @@ -199,6 +199,7 @@ class TerraformService: tf_import_resource, ): terraform_domain = devops.specialized_builds[BuildType.TERRAFORM] + terraform = self.init_client(devops) return_code, _, stderr = terraform.import_cmd( tf_import_name, tf_import_resource, @@ -207,6 +208,6 @@ class TerraformService: var=terraform_domain.project_vars(), var_file=terraform_domain.tf_additional_tfvar_files, ) - self.print_terraform_command(terraform, devops) + self.__print_terraform_command__(terraform, devops) if return_code > 0: raise RuntimeError(return_code, "terraform error:", stderr) diff --git a/src/main/python/ddadevops/devops_terraform_build.py b/src/main/python/ddadevops/devops_terraform_build.py index 6b0f8ce..b475358 100644 --- a/src/main/python/ddadevops/devops_terraform_build.py +++ b/src/main/python/ddadevops/devops_terraform_build.py @@ -86,7 +86,7 @@ class DevopsTerraformBuild(DevopsBuild): def destroy(self, auto_approve=False): devops = self.devops_repo.get_devops(self.project) - self.teraform_service.refresh(devops) + self.teraform_service.destroy(devops, auto_approve=auto_approve) self.post_build() def tf_import( diff --git a/src/main/python/ddadevops/digitalocean_terraform_build.py b/src/main/python/ddadevops/digitalocean_terraform_build.py index 685de23..8a285d3 100644 --- a/src/main/python/ddadevops/digitalocean_terraform_build.py +++ b/src/main/python/ddadevops/digitalocean_terraform_build.py @@ -1,6 +1,5 @@ from .devops_terraform_build import ( DevopsTerraformBuild, - create_devops_terraform_build_config, ) diff --git a/src/main/python/ddadevops/domain/c4k.py b/src/main/python/ddadevops/domain/c4k.py index 635d770..ffca857 100644 --- a/src/main/python/ddadevops/domain/c4k.py +++ b/src/main/python/ddadevops/domain/c4k.py @@ -1,4 +1,4 @@ -from typing import List, Optional +from typing import List, Dict, Optional from .common import ( Validateable, CredentialMappingDefault, @@ -66,7 +66,7 @@ class C4k(Validateable, CredentialMappingDefault): return f"c4k-{self.c4k_executable_name}-standalone.jar {config_path} {auth_path} > {output_path}" @classmethod - def get_mapping_default(cls) -> List[map]: + def get_mapping_default(cls) -> List[Dict[str, str]]: return [ { "gopass_path": "server/meissa/grafana-cloud", diff --git a/src/main/python/ddadevops/domain/common.py b/src/main/python/ddadevops/domain/common.py index 6eba93f..3533b04 100644 --- a/src/main/python/ddadevops/domain/common.py +++ b/src/main/python/ddadevops/domain/common.py @@ -1,5 +1,5 @@ from enum import Enum -from typing import List +from typing import List, Dict def filter_none(list_to_filter): @@ -59,9 +59,10 @@ class Validateable: class CredentialMappingDefault: @classmethod - def get_mapping_default(cls) -> List[map]: + def get_mapping_default(cls) -> List[Dict[str, str]]: return [] + class DnsRecord(Validateable): def __init__(self, fqdn, ipv4=None, ipv6=None): self.fqdn = fqdn diff --git a/src/main/python/ddadevops/domain/image.py b/src/main/python/ddadevops/domain/image.py index 5a1a5f6..d24b59b 100644 --- a/src/main/python/ddadevops/domain/image.py +++ b/src/main/python/ddadevops/domain/image.py @@ -1,4 +1,4 @@ -from typing import List +from typing import List, Dict from .common import ( filter_none, Validateable, @@ -38,7 +38,7 @@ class Image(Validateable): return "/".join(filter_none(commons_path)) + "/" @classmethod - def get_mapping_default(cls) -> List[map]: + def get_mapping_default(cls) -> List[Dict[str, str]]: return [ { "gopass_path": "meissa/web/docker.com", diff --git a/src/main/python/ddadevops/domain/init_service.py b/src/main/python/ddadevops/domain/init_service.py index d44046b..0adbaa1 100644 --- a/src/main/python/ddadevops/domain/init_service.py +++ b/src/main/python/ddadevops/domain/init_service.py @@ -37,9 +37,9 @@ class InitService: ) def initialize(self, inp: dict) -> Devops: - build_types = self.devops_factory.__parse_build_types__(inp["build_types"]) - mixin_types = self.devops_factory.__parse_mixin_types__(inp["mixin_types"]) - provider_types = TerraformDomain.parse_provider_types(inp["tf_provider_types"]) + build_types = self.devops_factory.__parse_build_types__(inp.get("build_types", [])) + mixin_types = self.devops_factory.__parse_mixin_types__(inp.get("mixin_types", [])) + provider_types = TerraformDomain.parse_provider_types(inp.get("tf_provider_types", [])) version = None default_mappings = [] diff --git a/src/main/python/ddadevops/domain/provider_digitalocean.py b/src/main/python/ddadevops/domain/provider_digitalocean.py index 3325567..aeded28 100644 --- a/src/main/python/ddadevops/domain/provider_digitalocean.py +++ b/src/main/python/ddadevops/domain/provider_digitalocean.py @@ -1,4 +1,4 @@ -from typing import List +from typing import List, Dict from .common import Validateable, CredentialMappingDefault @@ -29,7 +29,7 @@ class Digitalocean(Validateable, CredentialMappingDefault): } @classmethod - def get_mapping_default(cls) -> List[map]: + def get_mapping_default(cls) -> List[Dict[str, str]]: return [ { "gopass_path": "server/devops/digitalocean/s3", diff --git a/src/main/python/ddadevops/domain/terraform.py b/src/main/python/ddadevops/domain/terraform.py index 4f5ba89..ddce425 100644 --- a/src/main/python/ddadevops/domain/terraform.py +++ b/src/main/python/ddadevops/domain/terraform.py @@ -1,10 +1,8 @@ -from typing import List, Optional +from typing import List from pathlib import Path from .common import ( Validateable, ProviderType, - DnsRecord, - Devops, filter_none, ) from .provider_digitalocean import Digitalocean @@ -70,7 +68,7 @@ class TerraformDomain(Validateable): return result def resources_from_package(self) -> List[str]: - result = ["version.tf", "terraform_build_vars.tf"] + 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 diff --git a/src/main/python/ddadevops/domain/version.py b/src/main/python/ddadevops/domain/version.py index 22d2566..7fd8b73 100644 --- a/src/main/python/ddadevops/domain/version.py +++ b/src/main/python/ddadevops/domain/version.py @@ -36,7 +36,7 @@ class Version(Validateable): return self.to_string().__hash__() def is_snapshot(self): - return not self.snapshot_suffix is None + return self.snapshot_suffix is not None def to_string(self) -> str: version_no = ".".join([str(x) for x in self.version_list]) diff --git a/src/main/python/ddadevops/infrastructure/infrastructure.py b/src/main/python/ddadevops/infrastructure/infrastructure.py index 80224ca..18edca1 100644 --- a/src/main/python/ddadevops/infrastructure/infrastructure.py +++ b/src/main/python/ddadevops/infrastructure/infrastructure.py @@ -1,10 +1,10 @@ -from subprocess import check_output, Popen, PIPE, run +from subprocess import Popen, PIPE, run from pathlib import Path from sys import stdout from os import chmod, environ -from pkg_resources import resource_string from json import load, dumps import yaml +from pkg_resources import resource_string class ResourceApi: