All Projects → adammck → Terraform Inventory

adammck / Terraform Inventory

Licence: mit
Terraform State → Ansible Dynamic Inventory

Programming Languages

go
31211 projects - #10 most used programming language
HCL
1544 projects
shell
77523 projects

Projects that are alternatives of or similar to Terraform Inventory

Magic Modules
Automatically generate Google Cloud Platform support for OSS IaaC Projects
Stars: ✭ 358 (-77.5%)
Mutual labels:  ansible, terraform
Terraform Null Ansible
Terraform Module to run ansible playbooks
Stars: ✭ 114 (-92.83%)
Mutual labels:  ansible, terraform
Tads Boilerplate
Terraform + Ansible + Docker Swarm boilerplate = DevOps on 🔥🔥🔥 | Infrastructure as Code
Stars: ✭ 424 (-73.35%)
Mutual labels:  ansible, terraform
Cloudblock
Cloudblock automates deployment of secure ad-blocking for all of your devices - even when mobile. Step-by-step text and video guides included! Compatible clouds include AWS, Azure, Google Cloud, and Oracle Cloud. Cloudblock deploys Wireguard VPN, Pi-Hole DNS Ad-blocking, and DNS over HTTPS in a cloud provider - or locally - using Terraform and Ansible.
Stars: ✭ 257 (-83.85%)
Mutual labels:  ansible, terraform
Cloud Portal
Self service web portal for different Cloud platforms like Azure, AWS and VMWare vSphere.
Stars: ✭ 60 (-96.23%)
Mutual labels:  ansible, terraform
Tks
Enable enthusiasts and administrators alike to easily provision highly available and production-ready Kubernetes clusters on Proxmox VE.
Stars: ✭ 319 (-79.95%)
Mutual labels:  ansible, terraform
Terrible
Transform Terraform state into Ansible inventories
Stars: ✭ 18 (-98.87%)
Mutual labels:  ansible, terraform
Stubbornjava
Unconventional Java code for building web servers / services without a framework. Think dropwizard but as a seed project instead of a framework. If this project had a theme it would be break the rules but be mindful of your decisions.
Stars: ✭ 184 (-88.43%)
Mutual labels:  ansible, terraform
Hkube
Kubernetes cluster deployment to Hetzner Cloud
Stars: ✭ 55 (-96.54%)
Mutual labels:  ansible, terraform
Devops Exercises
Linux, Jenkins, AWS, SRE, Prometheus, Docker, Python, Ansible, Git, Kubernetes, Terraform, OpenStack, SQL, NoSQL, Azure, GCP, DNS, Elastic, Network, Virtualization. DevOps Interview Questions
Stars: ✭ 20,905 (+1213.95%)
Mutual labels:  ansible, terraform
Detectionlab
Automate the creation of a lab environment complete with security tooling and logging best practices
Stars: ✭ 3,237 (+103.46%)
Mutual labels:  ansible, terraform
Learning Tools
A collection of tools and files for learning new technologies
Stars: ✭ 1,287 (-19.11%)
Mutual labels:  ansible, terraform
Azure arc
Automated Azure Arc environments
Stars: ✭ 224 (-85.92%)
Mutual labels:  ansible, terraform
Kubeoperator
KubeOperator 是一个开源的轻量级 Kubernetes 发行版,专注于帮助企业规划、部署和运营生产级别的 K8s 集群。
Stars: ✭ 4,147 (+160.65%)
Mutual labels:  ansible, terraform
Laravel Deployment
📗[WIP] 追求质量的 Laravel 应用部署上线课程。
Stars: ✭ 190 (-88.06%)
Mutual labels:  ansible, terraform
Terraform Provisioner Ansible
Ansible with Terraform 0.13.x
Stars: ✭ 520 (-67.32%)
Mutual labels:  ansible, terraform
Terraform Inventory
An Ansible dynamic inventory script to pair with nbering/terraform-provider-ansible.
Stars: ✭ 154 (-90.32%)
Mutual labels:  ansible, terraform
Terrible
An Ansible playbook that apply the principle of the Infrastructure as Code on a QEMU/KVM environment.
Stars: ✭ 161 (-89.88%)
Mutual labels:  ansible, terraform
Ansible Dcos
[DEPRECATED] Please consider using the Ansible Roles for DC/OS maintained by the Mesosphere SRE team
Stars: ✭ 41 (-97.42%)
Mutual labels:  ansible, terraform
Mikado
🤖💨Mikado helps managing your AWS infrastructure for WordPress sites by defining an out-of-box, highly available, easy-to-deploy setup
Stars: ✭ 80 (-94.97%)
Mutual labels:  ansible, terraform

Terraform Inventory

Build Status GitHub release GitHub release

This is a little Go app which generates a dynamic Ansible inventory from a Terraform state file. It allows one to spawn a bunch of instances with Terraform, then (re-)provision them with Ansible.

The following providers are supported:

  • AWS
  • CloudStack
  • DigitalOcean
  • Docker
  • Exoscale
  • Google Compute Engine
  • Hetzner Cloud
  • libvirt
  • Linode
  • OpenStack
  • Packet
  • ProfitBricks
  • Scaleway
  • SoftLayer
  • VMware
  • Nutanix
  • Open Telekom Cloud
  • Yandex.Cloud
  • Telmate/Proxmox

It's very simple to add support for new providers. See pull requests with the provider label for examples.

Help Wanted 🙋

This library is stable, but I've been neglecting it somewhat on account of no longer using Ansible at work. Please drop me a line if you'd be interested in helping to maintain this tool.

Installation

On OSX, install it with Homebrew:

brew install terraform-inventory

Alternatively, you can download a release suitable for your platform and unzip it. Make sure the terraform-inventory binary is executable, and you're ready to go.

Usage

If you are using remote state (or if your state file happens to be named terraform.tfstate), cd to it and run:

ansible-playbook --inventory-file=/path/to/terraform-inventory deploy/playbook.yml

This will provide the resource names and IP addresses of any instances found in the state file to Ansible, which can then be used as hosts patterns in your playbooks. For example, given for the following Terraform config:

resource "digitalocean_droplet" "my_web_server" {
  image = "centos-7-0-x64"
  name = "web-1"
  region = "nyc1"
  size = "512mb"
}

The corresponding playbook might look like:

- hosts: my_web_server
  tasks:
    - yum: name=cowsay
    - command: cowsay hello, world!

Note that the instance was identified by its resource name from the Terraform config, not its instance name from the provider. On AWS, resources are also grouped by their tags. For example:

resource "aws_instance" "my_web_server" {
  instance_type = "t2.micro"
  ami = "ami-96a818fe"
  tags = {
    Role = "web"
    Env = "dev"
  }
}

resource "aws_instance" "my_worker" {
  instance_type = "t2.micro"
  ami = "ami-96a818fe"
  tags = {
    Role = "worker"
    Env = "dev"
  }
}

Can be provisioned separately with:

- hosts: role_web
  tasks:
    - command: cowsay this is a web server!

- hosts: role_worker
  tasks:
    - command: cowsay this is a worker server!

- hosts: env_dev
  tasks:
    - command: cowsay this runs on all dev servers!

More Usage

Ansible doesn't seem to support calling a dynamic inventory script with params, so if you need to specify the location of your state file or terraform directory, set the TF_STATE environment variable before running ansible-playbook, like:

TF_STATE=deploy/terraform.tfstate ansible-playbook --inventory-file=/path/to/terraform-inventory deploy/playbook.yml

or

TF_STATE=../terraform ansible-playbook --inventory-file=/path/to/terraform-inventory deploy/playbook.yml

If 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.

It looks for state config in this order

  • TF_STATE: environment variable of where to find either a statefile or a terraform project
  • TI_TFSTATE: another environment variable similar to TF_STATE
  • terraform.tfstate: it looks in the state file in the current directory.
  • .: lastly it assumes you are at the root of a terraform project.

Alternately, if you need to do something fancier (like downloading your state file from S3 before running), you might wrap this tool with a shell script, and call that instead. Something like:

#!/bin/bash
/path/to/terraform-inventory $@ deploy/terraform.tfstate

Then run Ansible with the script as an inventory:

ansible-playbook --inventory-file=bin/inventory deploy/playbook.yml

This tool returns the public IP of the host by default. If you require the private IP of the instance to run Ansible, set the TF_KEY_NAME environment variable to private_ip before running the playbook, like:

TF_KEY_NAME=private_ip ansible-playbook --inventory-file=/path/to/terraform-inventory deploy/playbook.yml

By default, the ip address is the ansible inventory name. The TF_HOSTNAME_KEY_NAME environment variable allows you to overwrite the source of the ansible inventory name.

TF_HOSTNAME_KEY_NAME=name ansible-playbook --inventory-file=/path/to/terraform-inventory deploy/playbook.yml

Development

It's just a Go app, so the usual:

go get github.com/adammck/terraform-inventory

To test against an example statefile, run:

terraform-inventory --list fixtures/example.tfstate
terraform-inventory --host=52.7.58.202 fixtures/example.tfstate

To update the fixtures, populate fixtures/secrets.tfvars with your DO and AWS account details, and run fixtures/update. To run a tiny Ansible playbook on the example resourecs, run:

TF_STATE=fixtures/example.tfstate ansible-playbook --inventory-file=/path/to/terraform-inventory fixtures/playbook.yml

You almost certainly don't need to do any of this. Use the tests instead.

Acknowledgements

Development of #14, #16, and #22 was generously sponsored by Transloadit.

License

MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].