ansible / terraform-provider-ansible

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

Improve the implementation of extra_vars #96

Open ralgar opened 8 months ago

ralgar commented 8 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.