A dynamic inventory script for Ansible and Terragrunt. This is a minor modification of ansible-terraform-inventory to use terragrunt in place of terraform.
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.
Set the TF_STATE environment variable to the directory which would contain the terraform.tfstate if the state was held locally.
Download the latest release.
$ go get github.com/pimsmath/ansible-terragrunt-inventory
$ go build -o $GOPATH/bin/terragrunt-inventory
$ ln -s $GOPATH/bin/terragrunt-inventory /path/to/ansible/inventory