Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rgreinho/tfpy

Create Terraform resources using Python
https://github.com/rgreinho/tfpy

python terraform

Last synced: 12 days ago
JSON representation

Create Terraform resources using Python

Awesome Lists containing this project

README

        

tfpy
====

.. image:: https://github.com/rgreinho/tfpy/workflows/ci/badge.svg
:target: https://github.com/rgreinho/tfpy/actions?query=workflow%3Aci

.. image:: https://badge.fury.io/py/tfpy.svg
:target: https://badge.fury.io/py/tfpy

Create Terraform resources using Python.

Description
-----------

``tfpy`` is a thin wrapper around `terraformpy`_, aiming at providing a well defined
structure to organize your `terraform`_ stacks and leverage the power of Python to
define them rather than using `HCL`_.

The goal is to have a repository layout inspired from `Ansible `_
where the stacks are driven by the variables.

For more information regarding how to create your stacks, please refer to the official
`terraformpy`_ documentation.

Installation
------------

tfpy requires Python 3.7+ to work

::

pip install tfpy

Usage
-----

The ``tfpy`` command needs to be run at the root of your project.

The output will be created in a new subfolder within your project, named ``generated``.
For instance ``generated/gke/production/main.tf.json``

Project layout
^^^^^^^^^^^^^^

::

.
├── generated
│   └── commerce
│   └── staging
│   └── main.tf.json
├── library
│   ├── backend.py
│   └── provider.py
├── stacks
│   └── commerce
│   ├── README.md
│   ├── gke.tf.py
│   └── terraform.tf.py
└── vars
├── all
│   ├── cartigan.yml
│   └── config.yml
└── staging
└── commerce
├── gke.yml
└── project.yml

* ``generated``: folder where the stack are stored as JSON once generated.
* ``library``: folder where you can place custom functions.
* ``stacks``: the stacks created using TerraformPy.
* ``vars``: the variables used to create the stacks.

Examples
^^^^^^^^

Build a project stack without an environment::

tfpy generate organization

Build a project stack for a specific environment::

tfpy generate gke production

.. _HCL: https://github.com/hashicorp/hcl
.. _terraform: https://www.terraform.io
.. _terraformpy: https://github.com/NerdWalletOSS/terraformpy