Giter VIP home page Giter VIP logo

terraform-makefile's Introduction

Makefile for Terraform users

Build Status Docker Hub

This repository provides a Makefile to give you a simple interface for Terraform.

Why?

  • Simplify your CLI terraform runs
  • Don't Repeat Yourself while typing terraform commands
  • Easier adoption for people that are not used to Terraform
  • Document common usage
  • Unique entrypoint script for credentials management (only for AWS, Azure, DigitalOcean, Google, Hetzner and Scaleway for now)
    • either passing ENV variables. E.g. <PROVIDER>_<ENV>_SECRET will be mapped to DIGITALOCEAN_TOKEN if provider=do is provided as variable
    • either using pass as local secret manager. E.g. password terraform/<provider>/<env>/secret will be mapped to DIGITALOCEAN_TOKEN if provider=do is provided as variable
    • either using vault as distributed secret manager (Only for AWS credentials for now). E.g. by using VAULT_ADDR and either VAULT_ROLE_ID + VAULT_SECRET_ID or directly a VAULT_TOKEN your credentials will automatically be fetched into your vault.

Installation

Package install

(for now packages are only published in Github releases)

wget https://github.com/paulRbr/terraform-makefile/releases/download/<version>/tf-make_<version>_amd64.deb
dpkg -i tf-make_<version>.deb

Manual install

Simply download the Makefile and the terraform.sh files in safe place.

mkdir -p /opt/terraform
cd /opt/terraform
wget -N https://raw.githubusercontent.com/paulRbr/terraform-makefile/master/{Makefile,terraform.sh}

Then you will need to add the tf-make binary (it's a simple bash script) in your $PATH. WARNING: you'll need to change the Makefile path in the tf-make file.

Convention

This makefile assumes your terraform configuration files are stored in a specific directory structure:

I.e. providers/<provider>/<env>/*.tf

E.g. example for all supported providers:

providers/
├── aws
│   ├── prod
│   │   └── config.tf
│   └── test
│       └── config.tf
├── do
│   └── prod
│       └── config.tf
├── google
│   ├── prod
│   │   └── config.tf
│   └── test
│       └── config.tf
├── hetzner,scaleway
│   └── test
│       └── config.tf
├── hetzner
│   └── prod
│       └── config.tf
└── scaleway
    └── prod
        └── config.tf

Note: the provider name can be a combination of multiple providers when you are in a multi-cloud environment. E.g. providers/hetzner,scaleway/prod/config.tf.

Commands

List of commands made available

> make
Terraform-makefile v0.14.11

console                        Console infra resources
destroy                        Destroy resources
dry-run                        Dry run resources changes
fmt                            Rewrites config to canonical format
import                         Import infra resources
install                        Install terraform and dependencies
lint                           Lint the HCL code
raw                            Raw command sent to terraform
refresh                        Refresh infra resources
run                            Execute resources changes
show                           List infra resources
state                          Inspect or change the remote state of your resources
taint                          Taint infra resources
untaint                        Untaint infra resources
validate                       Basic syntax check
workspace                      Workspace infra resources

Variables

Details of the variables that can be passed to commands:

Name Default Values Description Example
provider - aws
azure
do
google
hetzner
scaleway
or any combination of those separated by commas ,
Name of the cloud provider(s) to target With your terraform file in provider/aws/production/production.tf you will be able to make dry-run provider=aws env=production
With a terraform file in provider/hetzner,scaleway/production/config.tf you will be able to make dry-run provider=hetzner,scaleway env=production and have credentials for both providers available
env - String Name of the environment you want to use With a terraform file in provider/google/production/production.tf you will be able to make dry-run provider=google env=production
args - String Add terraform understandable arguments make dry-run args='-no-color'

terraform-makefile's People

Contributors

chtitux avatar mvisonneau avatar paulrbr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-makefile's Issues

How to run from the docker container

I build a image with the dockerfile you provided in this repo but not able to use it correctly.
My provider structure:

providers/aws/
├── prod
│ └── empty.tf
├── sandbox
│ ├── empty.tf
│ ├── main.tf
│ └── ~
└── test
└── test.tf

$ cat providers/aws/test/test.tf
provider "aws" {
region = "us-east-1"
}

resource "aws_instance" "example" {
ami = "ami-08111162"
instance_type = "t2.micro"
}

$ docker run -v providers:/opt/terraform/providers terraform-make:v1.0 -e provider=aws -e env=test dry-run
Terraform v0.12.0

Your version of Terraform is out of date! The latest version
is 0.12.5. You can update by downloading from www.terraform.io/downloads.html

Initializing the backend...

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
No changes.`

It seems not able to see the terrafrom script (test.tf) at all
What did I do wrong?

Thanks for your work!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.