diff --git a/changelogs/fragments/6296-LanceNero-Terraform_statefile_check.yml b/changelogs/fragments/6296-LanceNero-Terraform_statefile_check.yml new file mode 100644 index 0000000000..f55129db82 --- /dev/null +++ b/changelogs/fragments/6296-LanceNero-Terraform_statefile_check.yml @@ -0,0 +1,2 @@ +minor_changes: + - terraform - remove state file check condition and error block, because in the native implementation of terraform will not cause errors due to the non-existent file (https://github.com/ansible-collections/community.general/pull/6296). diff --git a/plugins/modules/terraform.py b/plugins/modules/terraform.py index 0247da68cf..bbafad0e9e 100644 --- a/plugins/modules/terraform.py +++ b/plugins/modules/terraform.py @@ -312,11 +312,11 @@ def preflight_validation(bin_path, project_path, version, variables_args=None, p def _state_args(state_file): - if state_file and os.path.exists(state_file): - return ['-state', state_file] - if state_file and not os.path.exists(state_file): - module.fail_json(msg='Could not find state_file "{0}", check the path and try again.'.format(state_file)) - return [] + if not state_file: + return [] + if not os.path.exists(state_file): + module.warn(msg='Could not find state_file "{0}", the process will not destroy any resources, please check your state file path.'.format(state_file)) + return ['-state', state_file] def init_plugins(bin_path, project_path, backend_config, backend_config_files, init_reconfigure, provider_upgrade, plugin_paths, workspace):