add do-backend-mixin

This commit is contained in:
jerger 2022-12-10 15:29:29 +01:00
parent bec4d01063
commit d244214242
5 changed files with 65 additions and 3 deletions

View file

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

View file

@ -9,12 +9,12 @@ from .devops_build import DevopsBuild, create_devops_build_config, get_devops_bu
from .devops_terraform_build import DevopsTerraformBuild, create_devops_terraform_build_config
from .devops_docker_build import DevopsDockerBuild, create_devops_docker_build_config
from .hetzner_mixin import HetznerMixin, add_hetzner_mixin_config
from .digitalocean_mixin import DigitaloceanMixin, add_digitalocean_mixin_config
from .digitalocean_terraform_build import DigitaloceanTerraformBuild, create_digitalocean_terraform_build_config
from .digitalocean_backend_properties_mixin import DigitaloceanBackendPropertiesMixin, add_digitalocean_backend_properties_mixin_config
from .exoscale_mixin import ExoscaleMixin, add_exoscale_mixin_config
from .aws_backend_properties_mixin import AwsBackendPropertiesMixin, add_aws_backend_properties_mixin_config
from .aws_mfa_mixin import AwsMfaMixin, add_aws_mfa_mixin_config
from .aws_rds_pg_mixin import AwsRdsPgMixin, add_aws_rds_pg_mixin_config
from .dda_simple_mixin import DdaSimpleMixin, add_dda_simple_mixin_config
from .provs_k3s_mixin import ProvsK3sMixin, add_provs_k3s_mixin_config
from .python_util import execute

View file

@ -0,0 +1,49 @@
from dda_python_terraform import *
from .devops_terraform_build import DevopsTerraformBuild
def add_digitalocean_backend_properties_mixin_config(config, account_name):
config.update({'DigitaloceanBackendPropertiesMixin':
{'account_name': account_name}})
return config
class DigitaloceanBackendPropertiesMixin(DigitaloceanTerraformBuild):
def __init__(self, project, config):
super().__init__(project, config)
aws_mixin_config = config['DigitaloceanBackendPropertiesMixin']
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})
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')
def copy_local_state(self):
pass
def rescue_local_state(self):
pass
def init_client(self):
tf = Terraform(working_dir=self.build_path(), terraform_semantic_version=self.terraform_semantic_version)
tf.init(backend_config=self.backend_config)
self.print_terraform_command(tf)
if self.use_workspace:
try:
tf.workspace('select', self.stage)
self.print_terraform_command(tf)
except:
tf.workspace('new', self.stage)
self.print_terraform_command(tf)
return tf

View file

@ -0,0 +1,5 @@
variable "bucket" {}
variable "key" {}
variable "kms_key_id" {}
variable "region" {}
variable "account_name" {}

View file

@ -0,0 +1,8 @@
terraform {
backend "s3" {
skip_requesting_account_id = true
skip_credentials_validation = true
skip_get_ec2_platforms = true
skip_metadata_api_check = true
}
}