Categorygithub.com/jtopjian/ansible-terraform-inventory
repositorypackage
0.4.0
Repository: https://github.com/jtopjian/ansible-terraform-inventory.git
Documentation: pkg.go.dev

# README

ansible-terraform-inventory

A dynamic inventory script for Ansible and Terraform.

Quickstart

To use this inventory script, you must first create Terraform resources using the terraform-provider-ansible plugin:

resource "ansible_host" "example" {
  inventory_hostname = "example.com"
  groups = ["web"]
  vars {
    ansible_user = "admin"
  }
}

resource "ansible_group" "web" {
  inventory_group_name = "web"
  children = ["foo", "bar", "baz"]
  vars {
    foo = "bar"
    bar = 2
  }
}

Next, use this script as your Ansible dynamic inventory script.

If your Ansible playbooks are in a different directory than your Terraform resources, then set the TF_STATE environment variable to the location of the Terraform directory.

If you want to use terragrunt instead of terraform, set the TF_TERRAGRUNT environment variable to any non-empty value and set TF_STATE to the directory where the terragrunt.hcl file is located.

Installation

Download the latest release.

Building From Source

$ go get github.com/jtopjian/ansible-terraform-inventory
$ go build -o $GOPATH/bin/terraform-inventory
$ ln -s $GOPATH/bin/terraform-inventory /path/to/ansible/hosts