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(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)[source]

Bases: runway.module.base.RunwayModule, runway.mixins.DelCachedPropMixin

Terraform Runway Module.

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 or module_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

Return auto.tfvars file if one is being used.

property current_workspace

Wrap “terraform_workspace_show” to cache the value.

Returns

The currently active Terraform workspace.

property env_file

Find the environment file for the module.

property skip

Determine if the module should be skipped.

property tfenv

Terraform environmet manager.

property tf_bin

Path to Terraform binary.

property 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 promping the user for input.

The plugins directory is retained to improve performance when they are used by subsequent runs.

deploy()None[source]

Run Terraform apply.

destroy()None[source]

Run Terraform destroy.

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.

init()None[source]

Run init.

plan()None[source]

Run Terraform plan.

terraform_apply()None[source]

Execute terraform apply command.

https://www.terraform.io/docs/cli/commands/apply.html

terraform_destroy()None[source]

Execute terraform destroy command.

https://www.terraform.io/docs/cli/commands/destroy.html

terraform_get()None[source]

Execute terraform get command.

https://www.terraform.io/docs/cli/commands/get.html

terraform_init()None[source]

Execute terraform init command.

https://www.terraform.io/docs/cli/commands/init.html

terraform_plan()None[source]

Execute terraform plan command.

https://www.terraform.io/docs/cli/commands/plan.html

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

str

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.

__getitem__(key: str)typing.Any

Make the object subscriptable.

Parameters

key – Attribute to get.

class runway.module.terraform.TerraformOptions(data: RunwayTerraformModuleOptionsDataModel, deploy_environment: DeployEnvironment, path: Optional[Path] = None)[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 continaing a Terraform version.

write_auto_tfvars

Optionally write parameters to a tfvars file instead of updating variables.

Instantiate class.

Parameters
  • deploy_environment – Current deploy environment.

  • data – Options parsed into a data model.

  • path – Module path.

property backend_config

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.

__eq__(other: typing.Any)bool

Assess equality.

get(name: str, default: Optional[typing.Any] = None)typing.Any

Get a value or return the default.

class runway.module.terraform.TerraformBackendConfig(data: RunwayTerraformBackendConfigDataModel, deploy_environment: DeployEnvironment, path: Path)[source]

Bases: runway.module.base.ModuleOptions

Terraform backend configuration module options.

Instantiate class.

Parameters
  • data – Options parsed into a data model.

  • deploy_environment – Current deploy environment.

  • path – Module path.

property config_file

Backend configuration file.

property init_args

Return command line arguments for init.

get_full_configuration()Dict[str, str][source]

Get full backend configuration.

classmethod get_backend_file(path: Path, environment: str, region: str)Optional[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.

__eq__(other: typing.Any)bool

Assess equality.

get(name: str, default: Optional[typing.Any] = None)typing.Any

Get a value or return the default.