runway.module.terraform module
Terraform module.
- runway.module.terraform.gen_workspace_tfvars_files(environment: str, region: str) List[str] [source]
Generate possible Terraform workspace tfvars filenames.
- runway.module.terraform.update_env_vars_with_tf_var_values(os_env_vars: Dict[str, str], tf_vars: Dict[str, Union[Dict[str, Any], List[Any], str]]) Dict[str, str] [source]
Return os_env_vars with TF_VAR values for each tf_var.
- class runway.module.terraform.Terraform[source]
Bases:
runway.module.base.RunwayModule
,runway.mixins.DelCachedPropMixin
Terraform Runway Module.
- __init__(context: RunwayContext, *, explicitly_enabled: Optional[bool] = False, logger: RunwayLogger = <RunwayLogger runway.module.terraform (WARNING)>, module_root: Path, name: Optional[str] = None, options: Optional[Union[Dict[str, Any], ModuleOptions]] = None, parameters: Optional[Dict[str, Any]] = 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.
- property auto_tfvars: pathlib.Path
Return auto.tfvars file if one is being used.
- property current_workspace: str
Wrap “terraform_workspace_show” to cache the value.
- Returns
The currently active Terraform workspace.
- property tfenv: runway.env_mgr.tfenv.TFEnvManager
Terraform environment manager.
- property version: runway.utils._version.Version
Version of Terraform being used.
- 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.
- gen_command(command: Union[List[str], str, Tuple[str, ...]], args_list: Optional[List[str]] = 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.
- 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.
- run(action: Literal['apply', 'destroy', 'get', 'init', 'plan', 'workspace_list', 'workspace_new', 'workspace_select', 'workspace_show']) None [source]
Run module.
- __new__(**kwargs)
- class runway.module.terraform.TerraformOptions[source]
Bases:
runway.module.base.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: Optional[Path] = None) None [source]
Instantiate class.
- Parameters
deploy_environment – Current deploy environment.
data – Options parsed into a data model.
path – Module path.
- property backend_config: runway.module.terraform.TerraformBackendConfig
Backend configuration options.
- classmethod parse_obj(deploy_environment: DeployEnvironment, obj: object, path: Optional[Path] = None) TerraformOptions [source]
Parse options definition and return an options object.
- Parameters
deploy_environment – Current deploy environment.
obj – Object to parse.
path – Module path.
- __new__(**kwargs)
- class runway.module.terraform.TerraformBackendConfig[source]
Bases:
runway.module.base.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.
- property config_file: Optional[pathlib.Path]
Backend configuration file.
- classmethod get_backend_file(path: pathlib.Path, environment: str, region: str) Optional[pathlib.Path] [source]
Determine Terraform backend file.
- Parameters
path – Path to the module.
environment – Current deploy environment.
region – Current AWS region.
- 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 parse_obj(deploy_environment: DeployEnvironment, obj: object, path: Optional[Path] = None) TerraformBackendConfig [source]
Parse options definition and return an options object.
- Parameters
deploy_environment – Current deploy environment.
obj – Object to parse.
path – Module path.
- __new__(**kwargs)