1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Terraform overwrite init (#2573) (#2654)

* feat: implement overwrite_init option

* chore: changelog

(cherry picked from commit 285639a4f9)

Co-authored-by: christophemorio <49184206+christophemorio@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2021-05-27 20:15:33 +02:00 committed by GitHub
parent fb9730f75e
commit 5a7d234d80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- terraform - add option ``overwrite_init`` to skip init if exists (https://github.com/ansible-collections/community.general/pull/2573).

View file

@ -107,6 +107,12 @@ options:
you intend to provision an entirely new Terraform deployment.
default: false
type: bool
overwrite_init:
description:
- Run init even if C(.terraform/terraform.tfstate) already exists in I(project_path).
default: true
type: bool
version_added: '3.2.0'
backend_config:
description:
- A group of key-values to provide at init stage to the -backend-config parameter.
@ -348,6 +354,7 @@ def main():
backend_config=dict(type='dict', default=None),
backend_config_files=dict(type='list', elements='path', default=None),
init_reconfigure=dict(required=False, type='bool', default=False),
overwrite_init=dict(type='bool', default=True),
),
required_if=[('state', 'planned', ['plan_file'])],
supports_check_mode=True,
@ -367,6 +374,7 @@ def main():
backend_config = module.params.get('backend_config')
backend_config_files = module.params.get('backend_config_files')
init_reconfigure = module.params.get('init_reconfigure')
overwrite_init = module.params.get('overwrite_init')
if bin_path is not None:
command = [bin_path]
@ -383,7 +391,8 @@ def main():
APPLY_ARGS = ('apply', '-no-color', '-input=false', '-auto-approve')
if force_init:
init_plugins(command[0], project_path, backend_config, backend_config_files, init_reconfigure, plugin_paths)
if overwrite_init or not os.path.isfile(os.path.join(project_path, ".terraform", "terraform.tfstate")):
init_plugins(command[0], project_path, backend_config, backend_config_files, init_reconfigure, plugin_paths)
workspace_ctx = get_workspace_context(command[0], project_path)
if workspace_ctx["current"] != workspace: