ansible / terraform-provider-ansible

community terraform provider for ansible
https://registry.terraform.io/providers/ansible/ansible/latest
GNU General Public License v3.0
183 stars 42 forks source link

Improve the implementation of extra_vars #96

Open ralgar opened 4 months ago

ralgar commented 4 months ago

Issue

Currently, the extra_vars parameter is just a map of key-value pairs (string only). However, in Ansible we can pass extra vars as a JSON string, allowing us to pass more data types / structures.

For example:

ansible-playbook -e '{"ansible_ssh_user": "rocky", "ansible_ssh_private_key_file": "id_ed25519_ephemeral", "ansible_host_key_checking": "false", "my_list": ["item1", "item2", "item3"]}' playbook.yml

The Terraform provider should take advantage of this feature.

Proposal

Parse the extra_vars map, and encode it as a JSON string to pass to Ansible. This would easily allow us to define native HCL types for extra_vars. Looking at the code, it seems like it would be relatively easy to implement this change.