Coder Social home page Coder Social logo

acumenix / terratag Goto Github PK

View Code? Open in Web Editor NEW

This project forked from env0/terratag

0.0 1.0 0.0 185 KB

Terratag is a CLI tool that enables users of Terraform to automatically create and maintain tags across their entire set of AWS, Azure, and GCP resources

Home Page: https://env0.com

License: Mozilla Public License 2.0

Go 38.35% HCL 61.65%

terratag's Introduction

Terratag by env0 ci FOSSA Status

Terratag is brought to you with ❤️  by

Let your team manage their own environment in AWS, Azure and Google.
Governed by your policies and with complete visibility and cost management.

What?

Terratag is a CLI tool allowing for tags or labels to be applied across an entire set of Terraform files. Terratag will apply tags or labels to any AWS, GCP and Azure resources.

Why?

Maintaining tags across your application is hard, especially when done manually. Terratag enables you to easily add tags to your existing IaC and benefit from some cross-resource tag applications you wish you had thought of when you had just started writing your Terraform, saving you tons of time and making future updates easy. Read more on why tagging is important.

How?

Prerequisites

  • Terraform 0.11, 0.12 or 0.13

Usage

  1. Install from homebrew:

    ➜ brew install env0/terratag/terratag
    

    Or download the latest release binary .

  2. Initialize Terraform modules to get provider schema and pull child modules:

     terraform init  
  3. Run Terratag

     terratag -dir=foo/bar -tags={\"environment_id\": \"prod\"}

    Terratag supports the following arguments:

    • -dir - optional, the directory to recursively search for any .tf file and try to terratag it.
    • -tags - tags, as valid JSON (NOT HCL)
    • -skipTerratagFiles - optional. Default to true. Skips any previously tagged - (files with terratag.tf suffix)

Example Output

Before Terratag

|- aws.tf
|- gcp.tf
# aws.tf
provider "aws" {
  version = "~> 2.0"
  region  = "us-east-1"
}

resource "aws_s3_bucket" "b" {
  bucket = "my-tf-test-bucket"
  acl    = "private"

  tags {
    Name        = "My bucket"
  }
}
#gcp.tf
resource "google_storage_bucket" "static-site" {
  name          = "image-store.com"
  location      = "EU"
  force_destroy = true

  bucket_policy_only = true

  website {
    main_page_suffix = "index.html"
    not_found_page   = "404.html"
  }
  cors {
    origin          = ["http://image-store.com"]
    method          = ["GET", "HEAD", "PUT", "POST", "DELETE"]
    response_header = ["*"]
    max_age_seconds = 3600
  }
  labels = {
    "foo" = "bar"
  }
}

After Terratag

Running terratag -tags={\"env0_environment_id\":\"dev\",\"env0_project_id\":\"clientA\"} will output:

|- aws.terratag.tf
|- gcp.terratag.tf
|- aws.tf.bak
|- gcp.tf.bak
# aws.terratag.tf
provider "aws" {
  version = "~> 2.0"
  region  = "us-east-1"
}

resource "aws_s3_bucket" "b" {
  bucket = "my-tf-test-bucket"
  acl    = "private"

  tags = merge( map("Name", "My bucket" ), local.terratag_added_main)
}
locals {
  terratag_added_main = {"env0_environment_id"="dev","env0_project_id"="clientA"}
}
# gcp.terratag.tf
resource "google_storage_bucket" "static-site" {
  name          = "image-store.com"
  location      = "EU"
  force_destroy = true

  bucket_policy_only = true

  website {
    main_page_suffix = "index.html"
    not_found_page   = "404.html"
  }
  cors {
    origin          = ["http://image-store.com"]
    method          = ["GET", "HEAD", "PUT", "POST", "DELETE"]
    response_header = ["*"]
    max_age_seconds = 3600
  }
  labels = merge( map("foo" , "bar"), local.terratag_added_main)
}
locals {
  terratag_added_main = {"env0_environment_id"="dev","env0_project_id"="clientA"}
}
See more samples here

Notes

  • Resources already having the exact same tag as the one being appended will be overridden

Develop

Issues and Pull Requests are very welcome!

Prerequisites

  • Go > 1.13.5

Build

git clone https://github.com/env0/terratag
go get
go build

Test

Structure

The test suite will look for fixtures under test/fixtures/terraform_xx.
Each fixture placed there should have the following directory structure:

my_fixture
|+ input
  ...            // any depth under /input
     |- main.tf  // this is where we will run all terraform/terratag commands
|- expected
  • input is where you should place the terraform files of your fixture.
    All commands will be executed wherever down the hierarchy where main.tf is located.
    We do that to allow cases where complex nested submodule resolution may take place, and one would like to test how a directory higher up the hierarchy gets resolved.
  • expected is a directory in which all .terratag.tf files will be matched with the output directory

What's being tested?

Each test will run:

  • terraform init
  • terratag
  • terraform validate

And finally, will compare the results in out with the expected directory

Running Tests

Focus on a particular Terraform version:

go test -run TestTerraformXX

terratag's People

Contributors

omry-hay avatar rlrabinowitz avatar roni-frantchi avatar yaronya avatar

Watchers

 avatar

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.