mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* Add support for extra options for terraform init
* Add missing var declaration
* feat: add changelog fragment
* feat: switch from an init_extra_args global option to an init_reconfigure specific option
* Update changelogs/fragments/823-terraform_init_reconfigure.yaml
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 282c1d546c
)
Co-authored-by: Damien Guihal <dguihal@gmail.com>
This commit is contained in:
parent
be27bf1eae
commit
924f18535a
2 changed files with 14 additions and 2 deletions
2
changelogs/fragments/823-terraform_init_reconfigure.yaml
Normal file
2
changelogs/fragments/823-terraform_init_reconfigure.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- terraform - add ``init_reconfigure`` option, which controls the ``-reconfigure`` flag (backend reconfiguration) (https://github.com/ansible-collections/community.general/pull/823).
|
|
@ -105,6 +105,12 @@ options:
|
||||||
type: list
|
type: list
|
||||||
elements: path
|
elements: path
|
||||||
version_added: '0.2.0'
|
version_added: '0.2.0'
|
||||||
|
init_reconfigure:
|
||||||
|
description:
|
||||||
|
- Forces backend reconfiguration during init.
|
||||||
|
default: false
|
||||||
|
type: bool
|
||||||
|
version_added: '1.3.0'
|
||||||
notes:
|
notes:
|
||||||
- To just run a `terraform plan`, use check mode.
|
- To just run a `terraform plan`, use check mode.
|
||||||
requirements: [ "terraform" ]
|
requirements: [ "terraform" ]
|
||||||
|
@ -201,7 +207,7 @@ def _state_args(state_file):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def init_plugins(bin_path, project_path, backend_config, backend_config_files):
|
def init_plugins(bin_path, project_path, backend_config, backend_config_files, init_reconfigure):
|
||||||
command = [bin_path, 'init', '-input=false']
|
command = [bin_path, 'init', '-input=false']
|
||||||
if backend_config:
|
if backend_config:
|
||||||
for key, val in backend_config.items():
|
for key, val in backend_config.items():
|
||||||
|
@ -212,6 +218,8 @@ def init_plugins(bin_path, project_path, backend_config, backend_config_files):
|
||||||
if backend_config_files:
|
if backend_config_files:
|
||||||
for f in backend_config_files:
|
for f in backend_config_files:
|
||||||
command.extend(['-backend-config', f])
|
command.extend(['-backend-config', f])
|
||||||
|
if init_reconfigure:
|
||||||
|
command.extend('-reconfigure')
|
||||||
rc, out, err = module.run_command(command, cwd=project_path)
|
rc, out, err = module.run_command(command, cwd=project_path)
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
module.fail_json(msg="Failed to initialize Terraform modules:\r\n{0}".format(err))
|
module.fail_json(msg="Failed to initialize Terraform modules:\r\n{0}".format(err))
|
||||||
|
@ -299,6 +307,7 @@ def main():
|
||||||
force_init=dict(type='bool', default=False),
|
force_init=dict(type='bool', default=False),
|
||||||
backend_config=dict(type='dict', default=None),
|
backend_config=dict(type='dict', default=None),
|
||||||
backend_config_files=dict(type='list', elements='path', default=None),
|
backend_config_files=dict(type='list', elements='path', default=None),
|
||||||
|
init_reconfigure=dict(required=False, type='bool', default=False),
|
||||||
),
|
),
|
||||||
required_if=[('state', 'planned', ['plan_file'])],
|
required_if=[('state', 'planned', ['plan_file'])],
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
|
@ -316,6 +325,7 @@ def main():
|
||||||
force_init = module.params.get('force_init')
|
force_init = module.params.get('force_init')
|
||||||
backend_config = module.params.get('backend_config')
|
backend_config = module.params.get('backend_config')
|
||||||
backend_config_files = module.params.get('backend_config_files')
|
backend_config_files = module.params.get('backend_config_files')
|
||||||
|
init_reconfigure = module.params.get('init_reconfigure')
|
||||||
|
|
||||||
if bin_path is not None:
|
if bin_path is not None:
|
||||||
command = [bin_path]
|
command = [bin_path]
|
||||||
|
@ -323,7 +333,7 @@ def main():
|
||||||
command = [module.get_bin_path('terraform', required=True)]
|
command = [module.get_bin_path('terraform', required=True)]
|
||||||
|
|
||||||
if force_init:
|
if force_init:
|
||||||
init_plugins(command[0], project_path, backend_config, backend_config_files)
|
init_plugins(command[0], project_path, backend_config, backend_config_files, init_reconfigure)
|
||||||
|
|
||||||
workspace_ctx = get_workspace_context(command[0], project_path)
|
workspace_ctx = get_workspace_context(command[0], project_path)
|
||||||
if workspace_ctx["current"] != workspace:
|
if workspace_ctx["current"] != workspace:
|
||||||
|
|
Loading…
Reference in a new issue