Skip to content
This repository has been archived by the owner on Jun 20, 2019. It is now read-only.

RobotsAndPencils/terrible

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terrible

A command line tool for transforming terraform state into ansible inventory files

Terraform is great at deploying infrastructure. This project aims to make using ansible and terraform together easy.

Installing

pip install git+git://github.com/RobotsAndPencils/terrible

Using

Write your terraform config as you usually would

# app.tf
resource "aws_instance" "app-server" {
    ami = "aminumber"
    instance_type = "t2.small"
    key_name = "keyname"
    count = 1
    tags {
        Name = "server"
    }

    connection {
        user = "ubuntu"
        key_file = "key_path"
    }
}

Create a Jinja2 template for your ansible inventory file

# ansible-inventory.j2
# Inventory for provisioning app-server
#
{% for resource in resources %}
{% for key, value in resource.iteritems() -%}
{% if "aws_instance.app-server" in key %}

[app-server]
# you can reference any terraform attribute
# https://www.terraform.io/docs/providers/aws/r/instance.html
{{ value.primary.attributes.public_ip }} ansible_ssh_user=ubuntu

{%- endif %}
{%- endfor %}
{%- endfor %}

Run terraform normally, then use terrible to convert terraform state to ansible inventory

terraform plan
terraform apply

terrible --template-path $PWD \
--template ansible-inventory.j2 \
--tfstate terraform.tfstate \
--inventory-output inventory.ini \

Now you can do normal ansible commands

ansible app-server -m ping --inventory-file=inventory.ini

Contributing

git clone git@github.com:RobotsAndPencils/terrible.git

You may want to set up a virtualenv by running virtualenv .venv; source .venv/bin/activate before you use the make file.

make setup
make test

Contact

Robots & Pencils Logo

Made with ❤️ by Robots & Pencils (@robotsNpencils)

Maintainers

About

Transform Terraform state into Ansible inventories

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published