Automation Plugins

Base

class app.terraform.BaseAutomation(working_dir: str | None = None)
automate(full: bool = False) Tuple[bool, str]
bin_write(filename: str, data: bytes, group_id: int | None = None) None
description: str = 'Abstract base automation.'
frequency: int
short_name: str = 'base'
tmpl_write(filename: str, template: str, **kwargs: Any) None

Write a Jinja2 template to the working directory for use by an automation module.

Parameters:
  • filename – filename to write to

  • template – Jinja2 template

  • kwargs – variables for use with the template

Returns:

None

working_dir: str | None

The short name of the automation provider. This is used as an opaque token throughout the portal system.

Terraform

class app.terraform.terraform.TerraformAutomation(working_dir: str | None = None)

An abstract class to be extended by automation plugins using Terraform providers to deploy resources.

always_refresh: bool = False

Force refresh even when not a full run.

automate(full: bool = False) Tuple[bool, str]

Runs the Terraform automation module. The run will follow these steps:

  1. The tf_prehook() hook is run.

  2. Generate a Terraform configuration and write it to a single main.tf file in the working directory (see working_directory).

  3. Run terraform init.

  4. Run terraform apply. This will only include a refresh if full is True. The apply will wait up to lock_timeout minutes for a lock to be released before failing. Up to parallelism requests will be sent to remote APIs concurrently.

  5. The tf_posthook() hook is run.

  6. The logs from the apply step are returned as a string.

Parameters:

full – include a Terraform refresh in the automation module run

Returns:

success status and Terraform apply logs

parallelism: int = 10

Default parallelism for remote API calls.

provider: CloudProvider

Short name for the provider used by this module.

tf_apply(working_dir: str, *, refresh: bool = True, parallelism: int | None = None, lock_timeout: int = 15) Tuple[int, str]
abstract tf_generate() None
tf_init(*, lock_timeout: int = 15) None
tf_output() Any
tf_plan(*, refresh: bool = True, parallelism: int | None = None, lock_timeout: int = 15) Tuple[int, str]
tf_posthook(*, prehook_result: Any = None) None

This hook function is called as part of normal automation, after the completion of tf_apply().

The default, if not overridden by a subclass, is to do nothing.

Parameters:

prehook_result – the returned value of tf_prehook()

Returns:

None

tf_prehook() Any | None

This hook function is called as part of normal automation, before generating the terraform configuration file. The return value will be passed to tf_posthook() but is otherwise ignored.

The default, if not overridden by a subclass, is to do nothing.

Returns:

state that is useful to tf_posthook(), if required

tf_show() Any
tf_write(template: str, **kwargs: Any) None