runway.module.terraform module¶
Terraform module.
- class runway.module.terraform.Terraform[source]¶
Bases:
RunwayModule
[TerraformOptions
],DelCachedPropMixin
Terraform Runway Module.
- __init__(context: RunwayContext, *, explicitly_enabled: bool | None = False, logger: RunwayLogger = <RunwayLogger runway.module.terraform (WARNING)>, module_root: Path, name: str | None = None, options: dict[str, Any] | ModuleOptions | None = None, parameters: dict[str, Any] | None = None, **_: Any) None [source]¶
Instantiate class.
- Parameters:
context – Runway context object for the current session.
explicitly_enabled – Whether or not the module is explicitly enabled. This is can be set in the event that the current environment being deployed to matches the defined environments of the module/deployment.
logger – Used to write logs.
module_root – Root path of the module.
name – Name of the module.
options – Options passed to the module class from the config as
options
ormodule_options
if coming from the deployment level.parameters – Values to pass to the underlying infrastructure as code tool that will alter the resulting infrastructure being deployed. Used to templatize IaC.
- cleanup_dot_terraform() None [source]¶
Remove .terraform excluding the plugins directly.
This step is crucial for allowing Runway to deploy to multiple regions or deploy environments without prompting the user for input.
The plugins directory is retained to improve performance when they are used by subsequent runs.
- property current_workspace: str¶
Wrap “terraform_workspace_show” to cache the value.
- Returns:
The currently active Terraform workspace.
- gen_command(command: list[str] | str | tuple[str, ...], args_list: list[str] | None = None) list[str] [source]¶
Generate Terraform command.
- handle_backend() None [source]¶
Handle backend configuration.
This needs to be run before “skip” is assessed or env_file/auto_tfvars is used in case their behavior needs to be altered.
- handle_parameters() None [source]¶
Handle parameters.
Either updating environment variables or writing to a file.
- run(action: Literal['apply', 'destroy', 'get', 'init', 'plan', 'workspace_list', 'workspace_new', 'workspace_select', 'workspace_show']) None [source]¶
Run module.
- terraform_workspace_list() str [source]¶
Execute
terraform workspace list
command.https://www.terraform.io/docs/cli/commands/workspace/list.html
- Returns:
The available Terraform workspaces.
- Return type:
- terraform_workspace_new(workspace: str) None [source]¶
Execute
terraform workspace new
command.permanently to https://www.terraform.io/docs/cli/commands/workspace/new.html
- Parameters:
workspace – Terraform workspace to create.
- terraform_workspace_select(workspace: str) None [source]¶
Execute
terraform workspace select
command.https://www.terraform.io/docs/cli/commands/workspace/select.html
- Parameters:
workspace – Terraform workspace to select.
- terraform_workspace_show() str [source]¶
Execute
terraform workspace show
command.https://www.terraform.io/docs/cli/commands/workspace/show.html
- Returns:
The current Terraform workspace.
- property tfenv: TFEnvManager¶
Terraform environment manager.
- property version: Version¶
Version of Terraform being used.
- class runway.module.terraform.TerraformBackendConfig[source]¶
Bases:
ModuleOptions
Terraform backend configuration module options.
- __init__(data: RunwayTerraformBackendConfigDataModel, deploy_environment: DeployEnvironment, path: Path) None [source]¶
Instantiate class.
- Parameters:
data – Options parsed into a data model.
deploy_environment – Current deploy environment.
path – Module path.
- static gen_backend_filenames(environment: str, region: str) list[str] [source]¶
Generate possible Terraform backend filenames.
- Parameters:
environment – Current deploy environment.
region – Current AWS region.
- classmethod get_backend_file(path: Path, environment: str, region: str) Path | None [source]¶
Determine Terraform backend file.
- Parameters:
path – Path to the module.
environment – Current deploy environment.
region – Current AWS region.
- classmethod parse_obj(deploy_environment: DeployEnvironment, obj: object, path: Path | None = None) TerraformBackendConfig [source]¶
Parse options definition and return an options object.
- Parameters:
deploy_environment – Current deploy environment.
obj – Object to parse.
path – Module path.
- class runway.module.terraform.TerraformOptions[source]¶
Bases:
ModuleOptions
Module options for Terraform.
- args¶
CLI arguments/options to pass to Terraform.
- data¶
Options parsed into a data model.
- env¶
Current deploy environment.
- path¶
Module path.
- version¶
String containing a Terraform version.
- write_auto_tfvars¶
Optionally write parameters to a tfvars file instead of updating variables.
- __init__(data: RunwayTerraformModuleOptionsDataModel, deploy_environment: DeployEnvironment, path: Path | None = None) None [source]¶
Instantiate class.
- Parameters:
deploy_environment – Current deploy environment.
data – Options parsed into a data model.
path – Module path.
- property backend_config: TerraformBackendConfig¶
Backend configuration options.
- classmethod parse_obj(deploy_environment: DeployEnvironment, obj: object, path: Path | None = None) TerraformOptions [source]¶
Parse options definition and return an options object.
- Parameters:
deploy_environment – Current deploy environment.
obj – Object to parse.
path – Module path.