Repository is archived
No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
Map Terraform state to an Ansible inventory file
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6

Runtime

>= 0
 Project Readme

⚠️ DEPRECATED⚠️

terraform_inventory Build Status

Create an Ansible inventory file from a Terraform state file.

The main objective of this tool is to be able to select whatever resources you need in Terraform state and build an Ansible inventory file. This should be possible without changing a Terraform plan by only relying on the output of terraform show. It must be possible to place a resource in multiple host groups.

This mostly makes sense with the following resources since we are targetting Ansible:

Installation

gem install terraform_inventory

Example

tinventory --map=aws_instance.web:web aws_instance.web.0:blog aws_instance.web.1:api ./inventory

Translation:

  • Put all aws_instance resources named web in the web host group of the inventory file
  • Put the first aws_instance resource named web in the blog host group of the inventory file
  • Put the second aws_instance resource named web in the api host group of the inventory file
  • The inventory file is called "./inventory"

This scenario demonstrates that you can select resources from Terraform state and put the resulting resources in a specific host group of the Ansible inventory file.

Commands

Options:

  • --map=resource_selector:host_group (required)
    • Maps between Terraform resource selector and Ansible host group.
    • The "none" host group puts the hosts IP address at the top of the file without a group
  • --state=< path to state file > (optional)
    • Path to a Terraform state file.
    • Default: File.join(Dir.pwd, "terraform.tfstate")
  • --ip_type=< type >
    • public or private
    • Default: public

License

MIT