sr2c.terraform.terraform_module role – Deploy resources using a Terraform module
Note
This role is part of the sr2c.terraform collection (version 1.0.0).
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it use: ansible-galaxy collection install sr2c.terraform.
To use it in a playbook, specify: sr2c.terraform.terraform_module.
Entry point main – Deploy resources using a Terraform module
Synopsis
Writes a root module that calls
terraform_module_sourceasmodule.this, generates a plan, and once the plan is approved (interactive mode) applies that saved plan. The module’s outputs are stored in the host variable named byterraform_module_outputs_var.Works with Terraform 1.5.7 or later and with OpenTofu. To use
tofu, setterraform_module_binary_path.Runs on any host with a POSIX shell that Terraform or OpenTofu supports, such as Linux, macOS, FreeBSD, OpenBSD and Solaris.
The role works in a temporary directory that is removed after the run, so it fails unless
terraform_module_backend_configorterraform_module_workdiris set. Alocalbackend with a relativepathstill loses the state.In check mode the role plans but never applies or destroys.
Sets the facts
terraform_module_plan(the plan as displayed),terraform_module_plan_file(removed with the temporary directory) andterraform_module_plan_has_changes.Requires the
jmespathPython library on the host running the role.
Parameters
Parameter |
Comments |
|---|---|
Choices:
|
|
The backend, as a dict with the backend type (for example The Default: |
|
The |
|
End the play for the host when a plan is rejected. When Choices:
|
|
Extra top-level blocks for the root module, such as The merge is not recursive, so a Default: |
|
Run Choices:
|
|
If the state is locked when planning, release the lock and plan again. This releases any lock, including one held by a run still in progress, so only use it for a stale lock. Choices:
|
|
Extra arguments for Default: |
|
The input variables for the module. Strings are Terraform templates, so Default: |
|
Wait for an operator to type The prompt is shown once per batch of hosts, so one With no terminal, as in AWX or CI, the role fails before applying, so set Choices:
|
|
Hide task results that can contain sensitive values (the JSON plan, outputs, apply and destroy results, and the generated configuration), even with Choices:
|
|
The host variable to store the module’s outputs in, as a dict keyed by output name. It is Default: |
|
Passed to Default: |
|
Extra arguments for Default: |
|
A saved plan file to apply instead of planning. A relative path is resolved from the working directory.
|
|
Display the plan before it is applied. Choices:
|
|
The Default: |
|
The module to deploy, as any module source, for example Local paths must be absolute, as a relative path is resolved from the working directory. |
|
The version constraint, for sources that support one, such as the Terraform registry. |
|
An existing, empty directory to work in instead of a temporary one. It is kept after the run. If Use a separate directory for each host. |
|
Remove the temporary working directory after the run. Has no effect when Choices:
|