Ansible Terraform Provider

A Terraform provider serving as an interop layer for an Ansible dynamic inventory script.

Read the introductory blog post for an explanation of the design motivations behind this provider.

Terraform Configuration Example

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
  }
}

Compatibility

Version 1.0.0 of this project is compatible with Terraform version 0.12-beta2. You will also need 2.0.0+ of the terraform-inventory script, as the internal structure of Terraform state files has changed.

If you need a version compatible with an earlier version of Terraform, use version 0.0.4.

When upgrading to Terraform 0.12.x, you may need to change your configuration files to reflect changes to the new version of the Hashicorp Configuration Lanaguage (HCL). The only known incompatibility is that vars attributes now require an equals operator (=).

0.11.x

resource "ansible_host" "example" {
    inventory_hostname = "example.com"
    vars {
        ansible_user = "admin"
    }
}

0.12.x

resource "ansible_host" "example" {
    inventory_hostname = "example.com"
    vars = {
        ansible_user = "admin"
    }
}

Alternatives and Similar Projects

jonmorehouse/terraform-provisioner-ansible

A Terraform Provisioner that runs Ansible-Local on a target machine at creation-time.

adammck/terraform-inventory

A very similar solution to this one, without the Logical provider. Depends on specific Terraform resource types, and relies heavily on cloud-providers’ tag implementations.

Ansible Module: Terraform

An Ansible module that runs Terraform plans and deployments.

License

Contributions specific to this project are made available under the Mozilla Public License.

Code under the vendor/ directory is copyright of the various package owners, and made available under their own license considerations.