From f881698320b2b4d5883fae8ef294aa6507ff91ee Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Tue, 13 Jun 2023 09:18:13 +0200 Subject: [PATCH] add provider doc --- doc/DevopsImageBuild.md | 2 +- doc/DevopsTerraformBuild.md | 6 +- doc/DevopsTerraformBuildWithAwsProvider.md | 90 +++++++++++++++ ...sTerraformBuildWithDigitaloceanProvider.md | 106 ++++++++++++++++++ ...DevopsTerraformBuildWithHetznerProvider.md | 89 +++++++++++++++ .../ddadevops/domain/provider_digitalocean.py | 2 +- src/test/python/domain/helper.py | 3 - 7 files changed, 288 insertions(+), 10 deletions(-) create mode 100644 doc/DevopsTerraformBuildWithAwsProvider.md create mode 100644 doc/DevopsTerraformBuildWithDigitaloceanProvider.md create mode 100644 doc/DevopsTerraformBuildWithHetznerProvider.md diff --git a/doc/DevopsImageBuild.md b/doc/DevopsImageBuild.md index 2480e06..381b671 100644 --- a/doc/DevopsImageBuild.md +++ b/doc/DevopsImageBuild.md @@ -52,7 +52,7 @@ classDiagram ### build.py ```python -from subprocess import run +from os import environ from pybuilder.core import task, init from ddadevops import * diff --git a/doc/DevopsTerraformBuild.md b/doc/DevopsTerraformBuild.md index 3c4fbac..7070c27 100644 --- a/doc/DevopsTerraformBuild.md +++ b/doc/DevopsTerraformBuild.md @@ -52,7 +52,7 @@ classDiagram ### build.py ```python -from subprocess import run +from os import environ from pybuilder.core import task, init from ddadevops import * @@ -113,7 +113,3 @@ def tf_import(project): ```bash pyb image plan apply destroy ``` - -### full example - -... can be found [here](../infrastructure/devops-build) diff --git a/doc/DevopsTerraformBuildWithAwsProvider.md b/doc/DevopsTerraformBuildWithAwsProvider.md new file mode 100644 index 0000000..1dca96b --- /dev/null +++ b/doc/DevopsTerraformBuildWithAwsProvider.md @@ -0,0 +1,90 @@ +# Aws Provider + +## Input + +| name | description | default | +| --------------------- | ------------------------------------------------------------------------------------------------------------------------------ | -------------- | +| aws_as_backend | you can use aws s3 as backend state storage | False | +| aws_region | in case of backend usage | "eu-central-1" | +| aws_bucket | in case of backend usage, the bucket your state is stored in. the url is S3://{aws_bucket}/{aws_bucket_key}/{aws_account_name} | | +| aws_bucket_key | | {module} | +| aws_account_name | | {stage} | +| aws_bucket_kms_key_id | in case of backend usage, kms key for encrypting your state | | + +### Credentials Mapping defaults +#### without a defined provider + +```python +[ +] +``` + +## Example Usage +### build.py + +```python +from os import environ +from pybuilder.core import task, init +from ddadevops import * + +name = 'my-project' +MODULE = 'my-module' +PROJECT_ROOT_PATH = '..' + +@init +def initialize(project): + project.build_depends_on("ddadevops>=4.0.0") + + input = { + "credentials_mapping": [], + "name": name, + "module": MODULE, + "name": name, + "module": MODULE, + "stage": environ["STAGE"], + "project_root_path": PROJECT_ROOT_PATH, + "build_types": ["TERRAFORM"], + "mixin_types": [], + "tf_provider_types": ["AWS"], + "tf_use_workspace": False, + "tf_terraform_semantic_version": "1.4.2", + "aws_as_backend": True, + "aws_bucket": "your-configuration", + "aws_bucket_kms_key_id": "your-kms-key-id", + } + + build = DevopsTerraformBuild(project, config) + build.initialize_build_dir() + + +@task +def plan(project): + build = get_devops_build(project) + build.plan() + + +@task +def apply(project): + build = get_devops_build(project) + build.apply(True) + + +@task +def destroy(project): + build = get_devops_build(project) + build.destroy() + + +@task +def tf_import(project): + build = get_devops_build(project) + build.tf_import( + "terraform.resource", "providers id" + ) +``` + +### call the build + +```bash +pyb image plan apply destroy +``` diff --git a/doc/DevopsTerraformBuildWithDigitaloceanProvider.md b/doc/DevopsTerraformBuildWithDigitaloceanProvider.md new file mode 100644 index 0000000..b5b4054 --- /dev/null +++ b/doc/DevopsTerraformBuildWithDigitaloceanProvider.md @@ -0,0 +1,106 @@ +# Digitalocean Provider + +## Input + +| name | description | default | +| -------------------- | --------------------------------------------------------------------------------------------------------------------------- | ----------------------------- | +| do_api_key | the do api key | | +| do_as_backend | you can use do s3 as backend state storage | False | +| do_spaces_access_id | in case of backend usage | | +| do_spaces_secret_key | in case of backend usage | | +| do_endpoint | in case of backend usage | "fra1.digitaloceanspaces.com" | +| do_region | in case of backend usage | "eu-central-1" | +| do_bucket | in case of backend usage, the bucket your state is stored in. the url is S3://{do_bucket}/{do_bucket_key}/{do_account_name} | | +| do_bucket_key | | {module} | +| do_account_name | | {stage} | + +### Credentials Mapping defaults + +```python +[ + { + "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", + }, +] +``` + +## Example Usage +### build.py + +```python +from os import environ +from pybuilder.core import task, init +from ddadevops import * + +name = 'my-project' +MODULE = 'my-module' +PROJECT_ROOT_PATH = '..' + +@init +def initialize(project): + project.build_depends_on("ddadevops>=4.0.0") + + input = { + "credentials_mapping": [ + { + "gopass_path": environ.get("DIGITALOCEAN_TOKEN_KEY_PATH", None), + "name": "do_api_key", + }, + ], + "name": name, + "module": MODULE, + "name": name, + "module": MODULE, + "stage": environ["STAGE"], + "project_root_path": PROJECT_ROOT_PATH, + "build_types": ["TERRAFORM"], + "mixin_types": [], + "tf_provider_types": ["DIGITALOCEAN"], + "tf_use_workspace": False, + "tf_terraform_semantic_version": "1.4.2", + "do_as_backend": True, + "do_bucket": "your-configuration", + } + + build = DevopsTerraformBuild(project, config) + build.initialize_build_dir() + + +@task +def plan(project): + build = get_devops_build(project) + build.plan() + + +@task +def apply(project): + build = get_devops_build(project) + build.apply(True) + + +@task +def destroy(project): + build = get_devops_build(project) + build.destroy() + + +@task +def tf_import(project): + build = get_devops_build(project) + build.tf_import( + "terraform.resource", "providers id" + ) +``` + +### call the build + +```bash +pyb image plan apply destroy +``` diff --git a/doc/DevopsTerraformBuildWithHetznerProvider.md b/doc/DevopsTerraformBuildWithHetznerProvider.md new file mode 100644 index 0000000..791acaf --- /dev/null +++ b/doc/DevopsTerraformBuildWithHetznerProvider.md @@ -0,0 +1,89 @@ +# Hetzner Provider + + + +## Input + +| name | description | default | +| --------------- | ------------------- | ------- | +| hetzner_api_key | the hetzner api key | | +| | + +### Credentials Mapping defaults + +```python +[ +] +``` + +## Example Usage +### build.py + +```python +from os import environ +from pybuilder.core import task, init +from ddadevops import * + +name = 'my-project' +MODULE = 'my-module' +PROJECT_ROOT_PATH = '..' + +@init +def initialize(project): + project.build_depends_on("ddadevops>=4.0.0") + + input = { + "credentials_mapping": [ + { + "gopass_path": environ.get("HETZNER_API_KEY_PATH", None), + "name": "hetzner_api_key", + }, + ], + "name": name, + "module": MODULE, + "name": name, + "module": MODULE, + "stage": environ["STAGE"], + "project_root_path": PROJECT_ROOT_PATH, + "build_types": ["TERRAFORM"], + "mixin_types": [], + "tf_provider_types": ["HETZNER"], + "tf_use_workspace": False, + "tf_terraform_semantic_version": "1.4.2", + } + + build = DevopsTerraformBuild(project, config) + build.initialize_build_dir() + + +@task +def plan(project): + build = get_devops_build(project) + build.plan() + + +@task +def apply(project): + build = get_devops_build(project) + build.apply(True) + + +@task +def destroy(project): + build = get_devops_build(project) + build.destroy() + + +@task +def tf_import(project): + build = get_devops_build(project) + build.tf_import( + "terraform.resource", "providers id" + ) +``` + +### call the build + +```bash +pyb image plan apply destroy +``` diff --git a/src/main/python/ddadevops/domain/provider_digitalocean.py b/src/main/python/ddadevops/domain/provider_digitalocean.py index e00ce4f..f21fa83 100644 --- a/src/main/python/ddadevops/domain/provider_digitalocean.py +++ b/src/main/python/ddadevops/domain/provider_digitalocean.py @@ -15,7 +15,7 @@ class Digitalocean(Validateable, CredentialMappingDefault): self.do_as_backend = inp.get("do_as_backend", False) self.do_account_name = inp.get("do_account_name", self.stage) self.do_bucket = inp.get("do_bucket") - self.do_bucket_key = inp.get("do_bucket_key") + self.do_bucket_key = inp.get("do_bucket_key", self.module) self.do_endpoint = inp.get("do_endpoint", "fra1.digitaloceanspaces.com") self.do_region = inp.get("do_region", "eu-central-1") diff --git a/src/test/python/domain/helper.py b/src/test/python/domain/helper.py index b6094eb..02cc03d 100644 --- a/src/test/python/domain/helper.py +++ b/src/test/python/domain/helper.py @@ -37,9 +37,6 @@ def devops_config(overrides: dict) -> dict: "do_api_key": "api_key", "do_spaces_access_id": "spaces_id", "do_spaces_secret_key": "spaces_secret", - "do_api_key": "api_key", - "do_spaces_access_id": "spaces_id", - "do_spaces_secret_key": "spaces_secret", "do_as_backend": True, "do_endpoint": "endpoint", "do_bucket": "bucket",