* '''Terraform State File''': The JSON file generated by Terraform that keeps track of the infrastructure resources it manages. * '''terraform-inventory Binary''': The executable tool that reads the Terraform state file and outputs an Ansible inventory.
* '''Dynamic Inventory Generation''': Automatically creates an up-to-date inventory file from the Terraform state. * '''Group and Host Variables''': Supports grouping hosts and setting variables based on Terraform attributes. * '''Easy Integration''': Works with existing Terraform and Ansible setups without significant changes. * '''Customizable Output''': Can be configured to match specific inventory formats or requirements.
```bash wget https://github.com/adammck/terraform-inventory/releases/download/v0.9/terraform-inventory_v0.9_linux_amd64.zip unzip terraform-inventory_v0.9_linux_amd64.zip sudo mv terraform-inventory /usr/local/bin/ ```
```bash terraform-inventory -list /path/to/terraform.tfstate ```
```bash ansible-playbook -i $(terraform-inventory -list /path/to/terraform.tfstate) my-playbook.yml ```
```json { "_meta": { "hostvars": { "ec2-34-201-75-64.compute-1.amazonaws.com": { "ansible_ssh_host": "34.201.75.64", "instance_type": "t2.micro" } } }, "all": { "hosts": [ "ec2-34-201-75-64.compute-1.amazonaws.com" ] }, "aws_ec2": { "hosts": [ "ec2-34-201-75-64.compute-1.amazonaws.com" ], "vars": { "ansible_ssh_user": "ubuntu" } } } ```