Deploying a module
For each run, the terraform_module role works through the same steps:
Write a root module (
main.tf.json) that calls the module given interraform_module_sourceasmodule.this, withterraform_module_inputsas its inputs, the backend fromterraform_module_backend_configand any extra blocks fromterraform_module_extraRun
terraform initandterraform plan, saving the plan to a file, and display the planIf the plan has changes, wait for an operator to type
yes, unlessterraform_module_interactiveis falseApply the saved plan, so exactly what was shown is what is applied
Store the outputs of
module.thisin the host variable named byterraform_module_outputs_var(terraform_module_outputsby default)Remove the temporary working directory
terraform_module_action selects what the run does:
applyPlan and apply. This is the default.
destroyPlan a destroy and apply it.
plan-apply,plan-destroyPlan only. The plan is displayed and nothing is changed.
In check mode the role still plans and displays the plan, but never applies or destroys.
Warning
By default the role works in a temporary directory that is deleted at the end of the run. The
state must therefore be kept somewhere else: set terraform_module_backend_config to a remote
backend, or set terraform_module_workdir to a directory that is kept. With a local backend
and a relative path the state is written to the temporary directory and lost.
Approval prompts are shown once per batch of hosts, so a single yes approves the plan for every
host in the batch. Where there is no terminal (for example in AWX or CI), the prompt cannot be
answered and the role fails before applying anything: set terraform_module_interactive
to false for unattended runs.
Task results that can contain sensitive values (the plan in JSON form, outputs, apply results and the
generated configuration) are hidden from the output, even with -v or --diff. Set
terraform_module_no_log to false when debugging a run.