diff --git a/src/main/python/ddadevops/aws_backend_properties_mixin.py b/src/main/python/ddadevops/aws_backend_properties_mixin.py index 841b519..ef6cebe 100644 --- a/src/main/python/ddadevops/aws_backend_properties_mixin.py +++ b/src/main/python/ddadevops/aws_backend_properties_mixin.py @@ -1,33 +1,33 @@ from dda_python_terraform import Terraform from .devops_terraform_build import DevopsTerraformBuild + def add_aws_backend_properties_mixin_config(config, account_name): - config.update({'AwsBackendPropertiesMixin': - {'account_name': account_name}}) + config.update({"AwsBackendPropertiesMixin": {"account_name": account_name}}) return config -class AwsBackendPropertiesMixin(DevopsTerraformBuild): +class AwsBackendPropertiesMixin(DevopsTerraformBuild): def __init__(self, project, config): super().__init__(project, config) - aws_mixin_config = config['AwsBackendPropertiesMixin'] - self.account_name = aws_mixin_config['account_name'] - self.backend_config = "backend." + self.account_name + "." + self.stage + ".properties" + aws_mixin_config = config["AwsBackendPropertiesMixin"] + self.account_name = aws_mixin_config["account_name"] + self.backend_config = ( + "backend." + self.account_name + "." + self.stage + ".properties" + ) self.additional_tfvar_files.append(self.backend_config) def project_vars(self): ret = super().project_vars() - ret.update({'account_name': self.account_name}) + ret.update({"account_name": self.account_name}) return ret def copy_build_resources_from_package(self): super().copy_build_resources_from_package() - self.copy_build_resource_file_from_package('provider_registry.tf') - self.copy_build_resource_file_from_package('aws_provider.tf') - self.copy_build_resource_file_from_package( - 'aws_backend_properties_vars.tf') - self.copy_build_resource_file_from_package( - 'aws_backend_with_properties.tf') + self.copy_build_resource_file_from_package("provider_registry.tf") + self.copy_build_resource_file_from_package("aws_provider.tf") + self.copy_build_resource_file_from_package("aws_backend_properties_vars.tf") + self.copy_build_resource_file_from_package("aws_backend_with_properties.tf") def copy_local_state(self): pass @@ -36,14 +36,17 @@ class AwsBackendPropertiesMixin(DevopsTerraformBuild): pass def init_client(self): - terraform = Terraform(working_dir=self.build_path(), terraform_semantic_version=self.terraform_semantic_version) + terraform = Terraform( + working_dir=self.build_path(), + terraform_semantic_version=self.terraform_semantic_version, + ) terraform.init(backend_config=self.backend_config) self.print_terraform_command(terraform) if self.use_workspace: try: - terraform.workspace('select', self.stage) + terraform.workspace("select", self.stage) self.print_terraform_command(terraform) except: - terraform.workspace('new', self.stage) + terraform.workspace("new", self.stage) self.print_terraform_command(terraform) return terraform diff --git a/src/main/python/ddadevops/c4k_build.py b/src/main/python/ddadevops/c4k_build.py index c2f9685..4b95c63 100644 --- a/src/main/python/ddadevops/c4k_build.py +++ b/src/main/python/ddadevops/c4k_build.py @@ -43,6 +43,7 @@ def add_c4k_mixin_config( ) return config + class C4kBuild(DevopsBuild): def __init__(self, project, config): super().__init__(project, config) diff --git a/src/main/python/ddadevops/digitalocean_backend_properties_mixin.py b/src/main/python/ddadevops/digitalocean_backend_properties_mixin.py index 47526f3..49ac57b 100644 --- a/src/main/python/ddadevops/digitalocean_backend_properties_mixin.py +++ b/src/main/python/ddadevops/digitalocean_backend_properties_mixin.py @@ -1,55 +1,55 @@ from dda_python_terraform import Terraform from .digitalocean_terraform_build import DigitaloceanTerraformBuild -def add_digitalocean_backend_properties_mixin_config(config, - account_name, - endpoint, - bucket, - key, - region='eu-central-1'): - config.update({'DigitaloceanBackendPropertiesMixin': - {'account_name': account_name, - 'endpoint': endpoint, - 'bucket': bucket, - 'key': key, - 'region': region}}) + +def add_digitalocean_backend_properties_mixin_config( + config, account_name, endpoint, bucket, key, region="eu-central-1" +): + config.update( + { + "DigitaloceanBackendPropertiesMixin": { + "account_name": account_name, + "endpoint": endpoint, + "bucket": bucket, + "key": key, + "region": region, + } + } + ) return config class DigitaloceanBackendPropertiesMixin(DigitaloceanTerraformBuild): - def __init__(self, project, config): super().__init__(project, config) - do_mixin_config = config['DigitaloceanBackendPropertiesMixin'] - self.account_name = do_mixin_config['account_name'] - self.endpoint = do_mixin_config['endpoint'] - self.bucket = do_mixin_config['bucket'] - self.key = do_mixin_config['account_name'] + \ - '/' + do_mixin_config['key'] - self.region = do_mixin_config['region'] + do_mixin_config = config["DigitaloceanBackendPropertiesMixin"] + self.account_name = do_mixin_config["account_name"] + self.endpoint = do_mixin_config["endpoint"] + self.bucket = do_mixin_config["bucket"] + self.key = do_mixin_config["account_name"] + "/" + do_mixin_config["key"] + self.region = do_mixin_config["region"] self.backend_config = { - 'access_key': self.do_spaces_access_id, - 'secret_key': self.do_spaces_secret_key, - 'endpoint': self.endpoint, - 'bucket': self.bucket, - 'key': self.key, - 'region': self.region} + "access_key": self.do_spaces_access_id, + "secret_key": self.do_spaces_secret_key, + "endpoint": self.endpoint, + "bucket": self.bucket, + "key": self.key, + "region": self.region, + } def project_vars(self): ret = super().project_vars() - ret.update({'account_name': self.account_name}) - ret.update({'endpoint': self.endpoint}) - ret.update({'bucket': self.bucket}) - ret.update({'key': self.key}) - ret.update({'region': self.region}) + ret.update({"account_name": self.account_name}) + ret.update({"endpoint": self.endpoint}) + ret.update({"bucket": self.bucket}) + ret.update({"key": self.key}) + ret.update({"region": self.region}) return ret def copy_build_resources_from_package(self): super().copy_build_resources_from_package() - self.copy_build_resource_file_from_package( - 'do_backend_properties_vars.tf') - self.copy_build_resource_file_from_package( - 'do_backend_with_properties.tf') + self.copy_build_resource_file_from_package("do_backend_properties_vars.tf") + self.copy_build_resource_file_from_package("do_backend_with_properties.tf") def copy_local_state(self): pass @@ -58,15 +58,17 @@ class DigitaloceanBackendPropertiesMixin(DigitaloceanTerraformBuild): pass def init_client(self): - terraform = Terraform(working_dir=self.build_path(), - terraform_semantic_version=self.terraform_semantic_version) + terraform = Terraform( + working_dir=self.build_path(), + terraform_semantic_version=self.terraform_semantic_version, + ) terraform.init(backend_config=self.backend_config) self.print_terraform_command(terraform) if self.use_workspace: try: - terraform.workspace('select', self.stage) + terraform.workspace("select", self.stage) self.print_terraform_command(terraform) except: - terraform.workspace('new', self.stage) + terraform.workspace("new", self.stage) self.print_terraform_command(terraform) return terraform diff --git a/src/main/python/ddadevops/infrastructure/infrastructure.py b/src/main/python/ddadevops/infrastructure/infrastructure.py index 7e1df4b..814660e 100644 --- a/src/main/python/ddadevops/infrastructure/infrastructure.py +++ b/src/main/python/ddadevops/infrastructure/infrastructure.py @@ -98,12 +98,15 @@ class ExecutionApi: output = output.rstrip() return output - def execute_live(self, command): - process = Popen(command, stdout=PIPE) - for line in iter(process.stdout.readline, b""): - print(line.decode("utf-8"), end="") - process.stdout.close() - process.wait() + def execute_live(self, command, dry_run=False): + if dry_run: + print(command) + else: + process = Popen(command, stdout=PIPE) + for line in iter(process.stdout.readline, b""): + print(line.decode("utf-8"), end="") + process.stdout.close() + process.wait() class EnvironmentApi: diff --git a/src/main/python/ddadevops/provs_k3s_build.py b/src/main/python/ddadevops/provs_k3s_build.py index 190434a..a6baabb 100644 --- a/src/main/python/ddadevops/provs_k3s_build.py +++ b/src/main/python/ddadevops/provs_k3s_build.py @@ -1,7 +1,8 @@ -from .domain import DnsRecord +from .domain import DnsRecord, BuildType from .infrastructure import ExecutionApi from .devops_build import DevopsBuild + class ProvsK3sBuild(DevopsBuild): def __init__(self, project, config): inp = config.copy()