{"id":13471645,"url":"https://github.com/adammck/terraform-inventory","last_synced_at":"2025-05-15T08:00:23.035Z","repository":{"id":20957557,"uuid":"24246220","full_name":"adammck/terraform-inventory","owner":"adammck","description":"Terraform State → Ansible Dynamic Inventory","archived":false,"fork":false,"pushed_at":"2021-08-02T10:52:14.000Z","size":200,"stargazers_count":1831,"open_issues_count":57,"forks_count":322,"subscribers_count":56,"default_branch":"master","last_synced_at":"2025-04-14T13:04:47.960Z","etag":null,"topics":["ansible","go","terraform"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adammck.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-19T21:34:58.000Z","updated_at":"2025-04-02T10:08:27.000Z","dependencies_parsed_at":"2022-09-04T03:00:16.466Z","dependency_job_id":null,"html_url":"https://github.com/adammck/terraform-inventory","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adammck%2Fterraform-inventory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adammck%2Fterraform-inventory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adammck%2Fterraform-inventory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adammck%2Fterraform-inventory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adammck","download_url":"https://codeload.github.com/adammck/terraform-inventory/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254301420,"owners_count":22047901,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","go","terraform"],"created_at":"2024-07-31T16:00:47.798Z","updated_at":"2025-05-15T08:00:22.918Z","avatar_url":"https://github.com/adammck.png","language":"Go","funding_links":[],"categories":["Go","terraform","Repositories"],"sub_categories":[],"readme":"# Terraform Inventory\n\n[![Build Status](https://travis-ci.org/adammck/terraform-inventory.svg?branch=master)](https://travis-ci.org/adammck/terraform-inventory)\n[![GitHub release](https://img.shields.io/github/release/adammck/terraform-inventory.svg?maxAge=2592000)](https://github.com/adammck/terraform-inventory/releases)\n[![GitHub release](https://img.shields.io/homebrew/v/terraform-inventory.svg?maxAge=2592000)](https://formulae.brew.sh/formula/terraform-inventory)\n\nThis is a little Go app which generates a dynamic [Ansible][ans] inventory from\na [Terraform][tf] state file. It allows one to spawn a bunch of instances with \nTerraform, then (re-)provision them with Ansible.\n\nThe following providers are supported:\n\n* AWS\n* CloudStack\n* DigitalOcean\n* Docker\n* Exoscale\n* Google Compute Engine\n* Hetzner Cloud\n* [libvirt](https://github.com/dmacvicar/terraform-provider-libvirt)\n* Linode\n* OpenStack\n* Packet\n* ProfitBricks\n* Scaleway\n* SoftLayer\n* VMware\n* Nutanix\n* Open Telekom Cloud\n* Yandex.Cloud\n* Telmate/Proxmox\n\nIt's very simple to add support for new providers. See pull requests with the\n[provider][pv] label for examples.\n\n\n# Help Wanted 🙋\n\nThis library is stable, but I've been neglecting it somewhat on account of no\nlonger using Ansible at work. Please drop me a line if you'd be interested in\nhelping to maintain this tool.\n\n\n# Installation\n\nOn OSX, install it with Homebrew:\n\n\tbrew install terraform-inventory\n\nAlternatively, you can download a [release][rel] suitable for your platform and\nunzip it. Make sure the `terraform-inventory` binary is executable, and you're\nready to go.\n\n\n## Usage\n\nIf you are using [remote state][rs] (or if your state file happens to be named\n`terraform.tfstate`), `cd` to it and run:\n\n\tansible-playbook --inventory-file=/path/to/terraform-inventory deploy/playbook.yml\n\nThis will provide the resource names and IP addresses of any instances found in\nthe state file to Ansible, which can then be used as hosts patterns in your\nplaybooks. For example, given for the following Terraform config:\n\n\tresource \"digitalocean_droplet\" \"my_web_server\" {\n\t  image = \"centos-7-0-x64\"\n\t  name = \"web-1\"\n\t  region = \"nyc1\"\n\t  size = \"512mb\"\n\t}\n\nThe corresponding playbook might look like:\n\n\t- hosts: my_web_server\n\t  tasks:\n\t    - yum: name=cowsay\n\t    - command: cowsay hello, world!\n\nNote that the instance was identified by its _resource name_ from the Terraform\nconfig, not its _instance name_ from the provider. On AWS, resources are also\ngrouped by their tags. For example:\n\n\tresource \"aws_instance\" \"my_web_server\" {\n\t  instance_type = \"t2.micro\"\n\t  ami = \"ami-96a818fe\"\n\t  tags = {\n\t    Role = \"web\"\n\t    Env = \"dev\"\n\t  }\n\t}\n\n\tresource \"aws_instance\" \"my_worker\" {\n\t  instance_type = \"t2.micro\"\n\t  ami = \"ami-96a818fe\"\n\t  tags = {\n\t    Role = \"worker\"\n\t    Env = \"dev\"\n\t  }\n\t}\n\nCan be provisioned separately with:\n\n\t- hosts: role_web\n\t  tasks:\n\t    - command: cowsay this is a web server!\n\n\t- hosts: role_worker\n\t  tasks:\n\t    - command: cowsay this is a worker server!\n\n\t- hosts: env_dev\n\t  tasks:\n\t    - command: cowsay this runs on all dev servers!\n\n\n## More Usage\n\nAnsible doesn't seem to support calling a dynamic inventory script with params,\nso if you need to specify the location of your state file or terraform directory, set the `TF_STATE`\nenvironment variable before running `ansible-playbook`, like:\n\n\n\tTF_STATE=deploy/terraform.tfstate ansible-playbook --inventory-file=/path/to/terraform-inventory deploy/playbook.yml\n\n\tor\n\n\tTF_STATE=../terraform ansible-playbook --inventory-file=/path/to/terraform-inventory deploy/playbook.yml\n\nIf `TF_STATE` is a file, it parses the file as json, if `TF_STATE` is a directory, it runs `terraform state pull` inside the directory, which is supports both local and remote terraform state.\n\nIt looks for state config in this order\n\n- `TF_STATE`: environment variable of where to find either a statefile or a terraform project\n- `TI_TFSTATE`: another environment variable similar to TF_STATE\n- `terraform.tfstate`: it looks in the state file in the current directory.\n- `.`: lastly it assumes you are at the root of a terraform project.\n\nAlternately, if you need to do something fancier (like downloading your state\nfile from S3 before running), you might wrap this tool with a shell script, and\ncall that instead. Something like:\n\n\t#!/bin/bash\n\t/path/to/terraform-inventory $@ deploy/terraform.tfstate\n\nThen run Ansible with the script as an inventory:\n\n\tansible-playbook --inventory-file=bin/inventory deploy/playbook.yml\n\nThis tool returns the public IP of the host by default. If you require the private\nIP of the instance to run Ansible, set the `TF_KEY_NAME` environment variable\nto `private_ip` before running the playbook, like:\n\n\tTF_KEY_NAME=private_ip ansible-playbook --inventory-file=/path/to/terraform-inventory deploy/playbook.yml\n\nBy default, the ip address is the ansible inventory name. The `TF_HOSTNAME_KEY_NAME` environment variable allows\nyou to overwrite the source of the ansible inventory name.\n\n\tTF_HOSTNAME_KEY_NAME=name ansible-playbook --inventory-file=/path/to/terraform-inventory deploy/playbook.yml\n\n## Development\n\nIt's just a Go app, so the usual:\n\n\tgo get github.com/adammck/terraform-inventory\n\nTo test against an example statefile, run:\n\n\tterraform-inventory --list fixtures/example.tfstate\n\tterraform-inventory --host=52.7.58.202 fixtures/example.tfstate\n\nTo update the fixtures, populate `fixtures/secrets.tfvars` with your DO and AWS\naccount details, and run `fixtures/update`. To run a tiny Ansible playbook on\nthe example resourecs, run:\n\n\tTF_STATE=fixtures/example.tfstate ansible-playbook --inventory-file=/path/to/terraform-inventory fixtures/playbook.yml\n\nYou almost certainly don't need to do any of this. Use the tests instead.\n\n\n## Acknowledgements\n\nDevelopment of\n[#14](https://github.com/adammck/terraform-inventory/issues/14),\n[#16](https://github.com/adammck/terraform-inventory/issues/16),\nand [#22](https://github.com/adammck/terraform-inventory/issues/22)\nwas generously sponsored by [Transloadit](https://transloadit.com).\n\n\n## License\n\nMIT.\n\n[ans]: https://www.ansible.com\n[tf]:  https://www.terraform.io\n[rel]: https://github.com/adammck/terraform-inventory/releases\n[rs]:  https://www.terraform.io/docs/state/remote.html\n[pv]:  https://github.com/adammck/terraform-inventory/pulls?q=is%3Apr+label%3Aprovider\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadammck%2Fterraform-inventory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadammck%2Fterraform-inventory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadammck%2Fterraform-inventory/lists"}