From 8cb3da6d927276483141f441aaad97887c4be94b Mon Sep 17 00:00:00 2001 From: jerger Date: Fri, 9 Dec 2022 14:53:54 +0100 Subject: [PATCH] add do mixin --- build.py | 2 +- .../python/ddadevops/digiatlocean_mixin.py | 27 +++++++++++++++++++ src/main/resources/terraform/do_mixin_vars.tf | 2 ++ src/main/resources/terraform/do_provider.tf | 3 +++ .../resources/terraform/provider_registry.tf | 5 ++++ 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/main/python/ddadevops/digiatlocean_mixin.py create mode 100644 src/main/resources/terraform/do_mixin_vars.tf create mode 100644 src/main/resources/terraform/do_provider.tf diff --git a/build.py b/build.py index a65c6a4..111c8eb 100644 --- a/build.py +++ b/build.py @@ -28,7 +28,7 @@ use_plugin("python.distutils") default_task = "publish" name = "ddadevops" -version = "1.1.0-dev" +version = "2.0.0-dev" 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/digiatlocean_mixin.py b/src/main/python/ddadevops/digiatlocean_mixin.py new file mode 100644 index 0000000..cd881ae --- /dev/null +++ b/src/main/python/ddadevops/digiatlocean_mixin.py @@ -0,0 +1,27 @@ +from .devops_terraform_build import DevopsTerraformBuild + + +def add_digitalocean_mixin_config(config, do_api_key): + config.update({'DigitaloceanMixin': + {'do_api_key': do_api_key}}) + return config + + +class DigitaloceanMixin(DevopsTerraformBuild): + + def __init__(self, project, config): + super().__init__(project, config) + do_mixin_config = config['DigitaloceanMixin'] + self.do_api_key = do_mixin_config['do_api_key'] + + def project_vars(self): + ret = super().project_vars() + if self.do_api_key: + ret['do_api_key'] = self.do_api_key + 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('do_provider.tf') + self.copy_build_resource_file_from_package('do_mixin_vars.tf') diff --git a/src/main/resources/terraform/do_mixin_vars.tf b/src/main/resources/terraform/do_mixin_vars.tf new file mode 100644 index 0000000..fecefd8 --- /dev/null +++ b/src/main/resources/terraform/do_mixin_vars.tf @@ -0,0 +1,2 @@ +variable "do_api_key" { +} diff --git a/src/main/resources/terraform/do_provider.tf b/src/main/resources/terraform/do_provider.tf new file mode 100644 index 0000000..13ccad7 --- /dev/null +++ b/src/main/resources/terraform/do_provider.tf @@ -0,0 +1,3 @@ +provider "digitalocean" { + token = var.do_api_key +} diff --git a/src/main/resources/terraform/provider_registry.tf b/src/main/resources/terraform/provider_registry.tf index 56275f1..eb53c21 100644 --- a/src/main/resources/terraform/provider_registry.tf +++ b/src/main/resources/terraform/provider_registry.tf @@ -20,5 +20,10 @@ terraform { source = "timohirt/hetznerdns" version = ">= 1.1.0" } + + digitalocean = { + source = "digitalocean/digitalocean" + version = "~> 2.0" + } } } \ No newline at end of file