mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Terraform overwrite init (#2573)
* feat: implement overwrite_init option * chore: changelog
This commit is contained in:
parent
7cd96d963e
commit
285639a4f9
2 changed files with 12 additions and 1 deletions
2
changelogs/fragments/2573-terraform-overwrite-init.yml
Normal file
2
changelogs/fragments/2573-terraform-overwrite-init.yml
Normal 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).
|
|
@ -107,6 +107,12 @@ options:
|
||||||
you intend to provision an entirely new Terraform deployment.
|
you intend to provision an entirely new Terraform deployment.
|
||||||
default: false
|
default: false
|
||||||
type: bool
|
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:
|
backend_config:
|
||||||
description:
|
description:
|
||||||
- A group of key-values to provide at init stage to the -backend-config parameter.
|
- 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=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),
|
init_reconfigure=dict(required=False, type='bool', default=False),
|
||||||
|
overwrite_init=dict(type='bool', default=True),
|
||||||
),
|
),
|
||||||
required_if=[('state', 'planned', ['plan_file'])],
|
required_if=[('state', 'planned', ['plan_file'])],
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
|
@ -367,6 +374,7 @@ def main():
|
||||||
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')
|
init_reconfigure = module.params.get('init_reconfigure')
|
||||||
|
overwrite_init = module.params.get('overwrite_init')
|
||||||
|
|
||||||
if bin_path is not None:
|
if bin_path is not None:
|
||||||
command = [bin_path]
|
command = [bin_path]
|
||||||
|
@ -383,6 +391,7 @@ def main():
|
||||||
APPLY_ARGS = ('apply', '-no-color', '-input=false', '-auto-approve')
|
APPLY_ARGS = ('apply', '-no-color', '-input=false', '-auto-approve')
|
||||||
|
|
||||||
if force_init:
|
if force_init:
|
||||||
|
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)
|
init_plugins(command[0], project_path, backend_config, backend_config_files, init_reconfigure, plugin_paths)
|
||||||
|
|
||||||
workspace_ctx = get_workspace_context(command[0], project_path)
|
workspace_ctx = get_workspace_context(command[0], project_path)
|
||||||
|
|
Loading…
Reference in a new issue