use enhanced terraform structure
This commit is contained in:
parent
4cf3ec8460
commit
85aa41b2a8
4 changed files with 85 additions and 52 deletions
|
@ -32,10 +32,9 @@ class TerraformService:
|
|||
)
|
||||
|
||||
def __copy_build_resources_from_package__(self, devops: Devops):
|
||||
self.__copy_build_resource_file_from_package__("versions.tf", devops)
|
||||
self.__copy_build_resource_file_from_package__(
|
||||
"terraform_build_vars.tf", devops
|
||||
)
|
||||
terraform_domain = devops.specialized_builds[BuildType.TERRAFORM]
|
||||
for resource in terraform_domain.resources_from_package():
|
||||
self.__copy_build_resource_file_from_package__(resource, devops)
|
||||
|
||||
def __copy_build_resources_from_dir__(self, devops: Devops):
|
||||
terraform = devops.specialized_builds[BuildType.TERRAFORM]
|
||||
|
|
|
@ -1,26 +1,31 @@
|
|||
from .devops_terraform_build import DevopsTerraformBuild, create_devops_terraform_build_config
|
||||
from .devops_terraform_build import (
|
||||
DevopsTerraformBuild,
|
||||
create_devops_terraform_build_config,
|
||||
)
|
||||
|
||||
|
||||
def create_digitalocean_terraform_build_config(stage,
|
||||
def create_digitalocean_terraform_build_config(
|
||||
stage,
|
||||
project_root_path,
|
||||
module,
|
||||
additional_vars,
|
||||
do_api_key,
|
||||
do_spaces_access_id,
|
||||
do_spaces_secret_key,
|
||||
build_dir_name='target',
|
||||
build_dir_name="target",
|
||||
output_json_name=None,
|
||||
use_workspace=True,
|
||||
use_package_common_files=True,
|
||||
build_commons_path=None,
|
||||
terraform_build_commons_dir_name='terraform',
|
||||
terraform_build_commons_dir_name="terraform",
|
||||
debug_print_terraform_command=False,
|
||||
additional_tfvar_files=None,
|
||||
terraform_semantic_version="1.0.8",
|
||||
):
|
||||
):
|
||||
if not additional_tfvar_files:
|
||||
additional_tfvar_files = []
|
||||
config = create_devops_terraform_build_config(stage,
|
||||
config = create_devops_terraform_build_config(
|
||||
stage,
|
||||
project_root_path,
|
||||
module,
|
||||
additional_vars,
|
||||
|
@ -32,32 +37,48 @@ def create_digitalocean_terraform_build_config(stage,
|
|||
terraform_build_commons_dir_name,
|
||||
debug_print_terraform_command,
|
||||
additional_tfvar_files,
|
||||
terraform_semantic_version)
|
||||
config.update({'DigitaloceanTerraformBuild':
|
||||
{'do_api_key': do_api_key,
|
||||
'do_spaces_access_id': do_spaces_access_id,
|
||||
'do_spaces_secret_key': do_spaces_secret_key}})
|
||||
terraform_semantic_version,
|
||||
)
|
||||
config.update(
|
||||
{
|
||||
"DigitaloceanTerraformBuild": {
|
||||
"do_api_key": do_api_key,
|
||||
"do_spaces_access_id": do_spaces_access_id,
|
||||
"do_spaces_secret_key": do_spaces_secret_key,
|
||||
}
|
||||
}
|
||||
)
|
||||
return config
|
||||
|
||||
|
||||
class DigitaloceanTerraformBuild(DevopsTerraformBuild):
|
||||
|
||||
def __init__(self, project, config):
|
||||
additional_resources = config.get("tf_additional_resources_from_package", [])
|
||||
additional_resources += [
|
||||
"provider_registry.tf",
|
||||
"do_provider.tf",
|
||||
"do_mixin_vars.tf",
|
||||
]
|
||||
config["tf_additional_resources_from_package"] = additional_resources
|
||||
|
||||
additional_vars = config.get("tf_additional_vars", {})
|
||||
additional_vars.update(
|
||||
{
|
||||
"do_api_key": config.get("do_api_key"),
|
||||
"do_spaces_access_id": config.get("do_spaces_access_id"),
|
||||
"do_spaces_secret_key": config.get("do_spaces_secret_key"),
|
||||
}
|
||||
)
|
||||
super().__init__(project, config)
|
||||
do_mixin_config = config['DigitaloceanTerraformBuild']
|
||||
self.do_api_key = do_mixin_config['do_api_key']
|
||||
self.do_spaces_access_id = do_mixin_config['do_spaces_access_id']
|
||||
self.do_spaces_secret_key = do_mixin_config['do_spaces_secret_key']
|
||||
|
||||
self.terraform_service = TerraformService.prod()
|
||||
|
||||
def project_vars(self):
|
||||
ret = super().project_vars()
|
||||
ret['do_api_key'] = self.do_api_key
|
||||
ret['do_spaces_access_id'] = self.do_spaces_access_id
|
||||
ret['do_spaces_secret_key'] = self.do_spaces_secret_key
|
||||
ret["do_api_key"] = self.do_api_key
|
||||
ret["do_spaces_access_id"] = self.do_spaces_access_id
|
||||
ret["do_spaces_secret_key"] = self.do_spaces_secret_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')
|
||||
|
|
|
@ -63,6 +63,19 @@ class InitService:
|
|||
"name": "image_dockerhub_password",
|
||||
},
|
||||
]
|
||||
if BuildType.DIGITALOCEAN_TERRAFORM in build_types:
|
||||
default_mappings += [
|
||||
{
|
||||
"gopass_path": "server/devops/digitalocean/s3",
|
||||
"gopass_field": "id",
|
||||
"name": "do_spaces_access_id",
|
||||
},
|
||||
{
|
||||
"gopass_path": "server/devops/digitalocean/s3",
|
||||
"gopass_field": "secret",
|
||||
"name": "do_spaces_secret_key",
|
||||
},
|
||||
]
|
||||
|
||||
if MixinType.RELEASE in mixin_types:
|
||||
primary_build_file_id = inp.get(
|
||||
|
|
|
@ -24,14 +24,14 @@ def devops_config(overrides: dict) -> dict:
|
|||
"k3s_letsencrypt_endpoint": "k3s_letsencrypt_endpoint",
|
||||
"k3s_enable_echo": "false",
|
||||
"k3s_app_filename_to_provision": "k3s_app.yaml",
|
||||
"tf_additional_vars": None,
|
||||
"tf_additional_vars": [],
|
||||
"tf_output_json_name": "the_out.json",
|
||||
"tf_use_workspace": None,
|
||||
"tf_use_package_common_files": None,
|
||||
"tf_build_commons_path": "build_commons_path",
|
||||
"tf_build_commons_dir_name": "terraform",
|
||||
"tf_debug_print_terraform_command": None,
|
||||
"tf_additional_tfvar_files": None,
|
||||
"tf_additional_tfvar_files": [],
|
||||
"tf_terraform_semantic_version": None,
|
||||
"do_api_key": "api_key",
|
||||
"do_spaces_access_id": "spaces_id",
|
||||
|
|
Loading…
Reference in a new issue