fix terraform issues

This commit is contained in:
Michael Jerger 2023-05-24 17:50:09 +02:00
parent 62464afb83
commit de29c1dad8
5 changed files with 22 additions and 19 deletions

View file

@ -28,7 +28,7 @@ use_plugin("python.distutils")
default_task = "publish" default_task = "publish"
name = "ddadevops" name = "ddadevops"
version = "4.0.0-dev48" version = "4.0.0-dev52"
summary = "tools to support builds combining gopass, terraform, dda-pallet, aws & hetzner-cloud" summary = "tools to support builds combining gopass, terraform, dda-pallet, aws & hetzner-cloud"
description = __doc__ description = __doc__
authors = [Author("meissa GmbH", "buero@meissa-gmbh.de")] authors = [Author("meissa GmbH", "buero@meissa-gmbh.de")]

View file

@ -1,2 +1,3 @@
from .image_build_service import ImageBuildService from .image_build_service import ImageBuildService
from .release_mixin_services import ReleaseService from .release_mixin_services import ReleaseService
from .terraform_service import TerraformService

View file

@ -50,12 +50,10 @@ class TerraformService:
print(output) print(output)
def copy_local_state(self, devops: Devops): def copy_local_state(self, devops: Devops):
# TODO: orignal was unchecked ... self.file_api.cp("terraform.tfstate", devops.build_path(), check=False)
self.file_api.cp("terraform.tfstate", devops.build_path())
def rescue_local_state(self, devops: Devops): def rescue_local_state(self, devops: Devops):
# TODO: orignal was unchecked ... self.file_api.cp(f"{devops.build_path()}/terraform.tfstate", ".", check=False)
self.file_api.cp(f"{devops.build_path()}/terraform.tfstate", ".")
def initialize_build_dir(self, devops: Devops): def initialize_build_dir(self, devops: Devops):
terraform = devops.specialized_builds[BuildType.TERRAFORM] terraform = devops.specialized_builds[BuildType.TERRAFORM]
@ -63,12 +61,11 @@ class TerraformService:
self.__copy_build_resources_from_package__(devops) self.__copy_build_resources_from_package__(devops)
else: else:
self.__copy_build_resources_from_dir__(devops) self.__copy_build_resources_from_dir__(devops)
# TODO: orignal was unchecked ...
self.copy_local_state(devops) self.copy_local_state(devops)
self.file_api.cp("*.tf", devops.build_path()) self.file_api.cp("*.tf", devops.build_path(), check=False)
self.file_api.cp("*.properties", devops.build_path()) self.file_api.cp("*.properties", devops.build_path(), check=False)
self.file_api.cp("*.tfvars", devops.build_path()) self.file_api.cp("*.tfvars", devops.build_path(), check=False)
self.file_api.cp_recursive("scripts", devops.build_path()) self.file_api.cp_recursive("scripts", devops.build_path(), check=False)
def init_client(self, devops: Devops): def init_client(self, devops: Devops):
terraform_domain = devops.specialized_builds[BuildType.TERRAFORM] terraform_domain = devops.specialized_builds[BuildType.TERRAFORM]

View file

@ -1,4 +1,5 @@
from .devops_build import DevopsBuild, create_devops_build_config from .devops_build import DevopsBuild, create_devops_build_config
from .application import TerraformService
def create_devops_terraform_build_config( def create_devops_terraform_build_config(
@ -48,7 +49,7 @@ class DevopsTerraformBuild(DevopsBuild):
inp["mixin_types"] = config.get("mixin_types", []) inp["mixin_types"] = config.get("mixin_types", [])
super().__init__(project, inp) super().__init__(project, inp)
project.build_depends_on("dda-python-terraform") project.build_depends_on("dda-python-terraform")
self.teraform_service = Terraform.prod() self.teraform_service = TerraformService.prod()
def initialize_build_dir(self): def initialize_build_dir(self):
super().initialize_build_dir() super().initialize_build_dir()

View file

@ -20,14 +20,14 @@ class FileApi:
self.execution_api.execute("rm -rf " + directory) self.execution_api.execute("rm -rf " + directory)
self.execution_api.execute("mkdir -p " + directory) self.execution_api.execute("mkdir -p " + directory)
def cp(self, src: str, target_dir: str): def cp(self, src: str, target_dir: str, check=True):
self.execution_api.execute(f"cp {src} {target_dir}") self.execution_api.execute(f"cp {src} {target_dir}", check=check)
def cp_force(self, src: str, target_dir: str): def cp_force(self, src: str, target_dir: str, check=True):
self.execution_api.execute("cp -f " + src + "* " + target_dir) self.execution_api.execute(f"cp -f {src}* {target_dir}", check=check)
def cp_recursive(self, src: str, target_dir: str): def cp_recursive(self, src: str, target_dir: str, check=True):
self.execution_api.execute("cp -r " + src + " " + target_dir) self.execution_api.execute(f"cp -r {src} {target_dir}", check=check)
def write_data_to_file(self, path: Path, data: bytes): def write_data_to_file(self, path: Path, data: bytes):
with open(path, "w", encoding="utf-8") as output_file: with open(path, "w", encoding="utf-8") as output_file:
@ -47,6 +47,7 @@ class FileApi:
with open(path, "r", encoding="utf-8") as input_file: with open(path, "r", encoding="utf-8") as input_file:
return load(input_file) return load(input_file)
class ImageApi: class ImageApi:
def image(self, name: str, path: Path): def image(self, name: str, path: Path):
run( run(
@ -101,12 +102,15 @@ class ImageApi:
class ExecutionApi: class ExecutionApi:
def execute(self, command: str, dry_run=False, shell=True): def execute(self, command: str, dry_run=False, shell=True, check=True):
output = "" output = ""
if dry_run: if dry_run:
print(command) print(command)
else: else:
output = check_output(command, encoding="UTF-8", shell=shell) # output = check_output(command, encoding="UTF-8", shell=shell)
output = run(
command, encoding="UTF-8", shell=shell, stdout=PIPE, check=check
).stdout
output = output.rstrip() output = output.rstrip()
return output return output