mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-26 21:33:12 +00:00
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 Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/terraform.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/terraform.py Co-authored-by: Felix Fontein <felix@fontein.de> * Fix condition to check for None type in terraform.py --------- Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
@@ -572,7 +572,9 @@ def main():
|
||||
command.append(f"-parallelism={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:
|
||||
@@ -589,7 +591,7 @@ def main():
|
||||
ret_out.append(f'{k}={{{process_complex_args(v)}}}')
|
||||
elif isinstance(v, list):
|
||||
ret_out.append(f"{k}={process_complex_args(v)}")
|
||||
elif isinstance(v, (int, float, str, bool)):
|
||||
elif isinstance(v, (int, float, str, bool)) or v is None:
|
||||
ret_out.append(f'{k}={format_args(v)}')
|
||||
else:
|
||||
# only to handle anything unforeseen
|
||||
@@ -601,7 +603,7 @@ def main():
|
||||
l_out.append(f"{{{process_complex_args(item)}}}")
|
||||
elif isinstance(item, list):
|
||||
l_out.append(f"{process_complex_args(item)}")
|
||||
elif isinstance(item, (str, int, float, bool)):
|
||||
elif isinstance(item, (str, int, float, bool)) or item is None:
|
||||
l_out.append(format_args(item))
|
||||
else:
|
||||
# only to handle anything unforeseen
|
||||
|
||||
Reference in New Issue
Block a user