1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-02-04 07:51:50 +00:00

[PR #11003/9cb619ff backport][stable-10] [stable-11] terraform: Fix bug when None values aren't processed correctly (#10961) (#11004)

[stable-11] terraform: Fix bug when None values aren't processed correctly (#10961) (#11003)

terraform: Fix bug when None values aren't processed correctly (#10961)

* terraform: Fix bug when None values aren't processed correctly

Just found that i can't pass null values as complex variables into terraform using this module, while i can do that with terraform itself. Fixed undesired behavior.

* chore: changelog fragment 10961-terraform-complexvars-null-bugfix.yaml

* Update changelogs/fragments/10961-terraform-complexvars-null-bugfix.yaml

* Update plugins/modules/terraform.py

* Update plugins/modules/terraform.py

* Fix condition to check for None type in terraform.py

---------

(cherry picked from commit af8c4fb95e)


(cherry picked from commit 9cb619ff6c)

Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: nbragin4 <139489942+nbragin4@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2025-10-28 21:23:35 +01:00 committed by GitHub
parent b5abccfe31
commit b8f55cccdf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View file

@ -548,7 +548,9 @@ def main():
command.append('-parallelism=%d' % module.params.get('parallelism'))
def format_args(vars):
if isinstance(vars, str):
if vars is None:
return 'null'
elif isinstance(vars, str):
return '"{string}"'.format(string=vars.replace('\\', '\\\\').replace('"', '\\"')).replace('\n', '\\n')
elif isinstance(vars, bool):
if vars:
@ -565,7 +567,7 @@ def main():
ret_out.append('{0}={{{1}}}'.format(k, process_complex_args(v)))
elif isinstance(v, list):
ret_out.append("{0}={1}".format(k, process_complex_args(v)))
elif isinstance(v, (integer_types, float, str, bool)):
elif isinstance(v, (integer_types, float, str, bool)) or v is None:
ret_out.append('{0}={1}'.format(k, format_args(v)))
else:
# only to handle anything unforeseen
@ -577,7 +579,7 @@ def main():
l_out.append("{{{0}}}".format(process_complex_args(item)))
elif isinstance(item, list):
l_out.append("{0}".format(process_complex_args(item)))
elif isinstance(item, (str, integer_types, float, bool)):
elif isinstance(item, (str, integer_types, float, bool)) or item is None:
l_out.append(format_args(item))
else:
# only to handle anything unforeseen