add terraform doc

This commit is contained in:
Michael Jerger 2023-06-13 08:50:26 +02:00
parent bd54ceb938
commit ae11713fc7
6 changed files with 126 additions and 11 deletions

View file

@ -25,10 +25,7 @@ classDiagram
initialize_build_dir()
}
class DevopsTerraformBuild {
terraform_build_commons_path()
project_vars()
initialize_build_dir()
post_build()
read_output_json()
@ -37,12 +34,11 @@ classDiagram
apply(auto_approve=False)
refresh()
destroy(auto_approve=False)
tf_import(tf_import_name, tf_import_resource,)
print_terraform_command(terraform)
tf_import(tf_import_name,tf_import_resource)
}
class DevopsImageBuild {
def initialize_build_dir()
initialize_build_dir()
image()
drun()
dockerhub_login()

View file

@ -1,6 +1,6 @@
# DevopsBuild
DevopsBuild stellt die build Grundlagen zur Verfügung.
DevopsBuild provides the build foundations.
```mermaid
classDiagram

View file

@ -1,11 +1,11 @@
# DevopsImageBuild
DevopsBuild stellt die build Grundlagen zur Verfügung.
DevopsImageBuild provides functionality for building container images.
```mermaid
classDiagram
class DevopsImageBuild {
initialize_build_dir() - copy current directory & additional files to target
initialize_build_dir() - copy current directory & additional files to target. Additional files can be found [here](../src/main/resources/docker)
image() - build image localy. Sources for image build are expected at ./image
drun() - start your localy build image
dockerhub_login() - login to dockerhub

119
doc/DevopsTerraformBuild.md Normal file
View file

@ -0,0 +1,119 @@
# DevopsTerraformBuild
DevopsTerraformBuild provides capabilities to use terraform in your build.
```mermaid
classDiagram
class DevopsTerraformBuild {
initialize_build_dir() - copy current directory & additional files to target. Additional files can be found [here](../src/main/resources/terraform)
post_build() - a post build hook
read_output_json() - read your json encoded output and parse into a nested map
plan() - execute terraform plan
plan_fail_on_diff() - execute terraform plan and throw an exception if there are diffs
apply(auto_approve=False) - execute terraform apply
refresh() - execute terraform refresh
destroy(auto_approve=False) - execute terraform destroy
tf_import(tf_import_name,tf_import_resource) - execute terraform import
}
```
## Input
| name | description | default |
| -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | --------- |
| name | dedicated name of the build - also used as image name | module |
| module | module name - may result in a hierarchy like name/module | |
| stage | not used in this build | |
| project_root_path | relative path to projects root. Is used to locate the target dir | |
| build_dir_name | name of dir, build is executed in | target |
| build_types | list of special builds used. Value has to be contained["IMAGE"] | [] |
| mixin_types | mixins are orthoganl to builds and represent additional capabilities. Valid Values are ["RELEASE"] | [] |
| tf_provider_types | Build in terraform providers. Possible values are ["DIGITALOCEAN", "HETZNER", "AWS"] | [] |
| tf_additional_vars | hand over vars to your terraform build | {} |
| tf_additional_tfvar_files | use additional var files | [] |
| tf_output_json_name | name of your output as json | NONE |
| tf_use_workspace | use terraform workspaces | True |
| tf_use_package_common_files | use some boilerplate files from dda-devops-build located [here](../src/main/resources/terraform) | True |
| tf_build_commons_path | copy boilerplate files from a {tf_build_commons_path}/{tf_build_commons_dir_name} dir instead of using package-commons files | |
| tf_build_commons_dir_name | | terraform |
| tf_debug_print_terraform_command | Print out all terraform commands for debuging issues | False |
| tf_terraform_semantic_version | specify terraform version | "1.0.8" |
| |
### Credentials Mapping defaults
#### without a defined provider
```python
[
]
```
## Example Usage
### build.py
```python
from subprocess import run
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 = {
"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": [],
"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
```
### full example
... can be found [here](../infrastructure/devops-build)

View file

@ -21,7 +21,7 @@ class TerraformDomain(Validateable):
self.tf_additional_resources_from_package = inp.get(
"tf_additional_resources_from_package", set()
)
self.tf_additional_tfvar_files = inp.get("tf_additional_tfvar_files", [])
self.tf_additional_tfvar_files = inp.get("tf_additional_tfvar_files", {})
self.tf_use_workspace = inp.get("tf_use_workspace", True)
self.tf_debug_print_terraform_command = inp.get(
"tf_debug_print_terraform_command", False

View file

@ -32,7 +32,7 @@ def devops_config(overrides: dict) -> dict:
"tf_build_commons_path": "build_commons_path",
"tf_build_commons_dir_name": "terraform",
"tf_debug_print_terraform_command": None,
"tf_additional_tfvar_files": [],
"tf_additional_tfvar_files": {},
"tf_terraform_semantic_version": None,
"do_api_key": "api_key",
"do_spaces_access_id": "spaces_id",