nbering / terraform-inventory

An Ansible dynamic inventory script to pair with nbering/terraform-provider-ansible.
MIT License
175 stars 51 forks source link

Script -> plugin possibility #3

Closed Indigenuity closed 5 years ago

Indigenuity commented 6 years ago

Since ansible 2.4 they've started suggesting dynamic inventory scripts be changed to inventory plugins. Is this something you've considered doing?

I'm using your TF provider plugin and it seems great so far. I'll likely take a stab at making an ansible inventory plugin though. I'm trying to avoid having to set an active directory or env variables. The new plugin structure is similar to the way scripts worked except now you can actually pass in a parameter, which allows the env variables to go away. The possibility of multiple, prioritized plugins also makes it nice for having an option between an approach like yours that actually calls terraform state and an approach that just reads a remote state file directly. E.g. ansible-playbook -i tfstate:s3://my-state-bucket/my-app/terraform.tfstate my_playbook.yml vs ansible-playbook -i tfdir:~/my_repo/tf/my_app my_playbook.yml.

I'd be interested in your opinion. If you like, I'll let you know how my attempt goes with making the plugin.

nbering commented 6 years ago

This is something that I've already put some thought to.

Some of the sticking points so far have been that Inventory Plugins are poorly documented (as is much of the Ansible development experience). There aren't very many examples from yet, either. And last of all, even Ansible Tower doesn't have support for them, yet. So if I moved my effort to a plugin instead of a script, some percentage of potential users would still not be able to take advantage of that effort.

nbering commented 6 years ago

The idea of reading the state file directly is not bad. The main reason I shelled-out to the terraform command was that it automatically bought me support for every type of backend that Terraform supports. If I were to implement direct access to the storage mechanism, I would either be constantly playing catch-up as new backends are added, or I would be limiting support.

It might be worth a try anyway though, if it can be demonstrated that direct access to the storage mechanism gives some performance boost. I bet there would be... Terraform is actually pretty slow to start up.