Code Monkey home page Code Monkey logo

terramorf's Introduction

Terramorf

Terramorf is a thin wrapper for Terraform that provides environment management and automatic Terraform version download and setup.

Features

  • Enrironments management for variables and backend
  • Automatic terraform version download, setup and management

Installation

You can install or upgrade Terramorf using:

bash -c "$(curl -fsSL https://raw.githubusercontent.com/ecanuto/terramorf/main/install.sh)"

Usage

terramorf.hcl

terraform {
  required_version = "1.2.5"

  backend {
    profile = "company-${environment}"
    region  = "eu-west-1"
    bucket  = "terraform-${environment}"
    key     = "${module}/terraform.tfstate"
    encrypt = false
  }

  var_files = [
    "../common/${environment}.tfvars"
  ]

  variables {
    somevar = "somevalue"
  }
}

environment "dev" {

  variables {
    some_env_var = "somevalue devel"
  }
}

environment "prd" {
  variables {
    some_env_var = "somevalue prod"
  }
}
terramorf [envivonment] <subcommand> [args]

Where envivonment is one of the environments available on "envivonments" folder and all others parameters are terraform commands and arguments.

License

The code is free and unencumbered software released into the public domain.
For more information, please refer to https://unlicense.org

terramorf's People

Contributors

ecanuto avatar julianolf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

julianolf dotzinc

terramorf's Issues

Incorrect version displayed with --version argument (v0.5.5 shows v0.5.4)

Issue Description:
When using the --version argument with the installed software version v0.5.5, the displayed version is incorrect, showing v0.5.4 instead.

Steps to Reproduce:

  1. Install the package version v0.5.5 from the GitHub repository.
  2. Run the following command in the terminal:

package-name --version

  1. Expected output: v0.5.5
  2. Observed output: v0.5.4

Errot running fmt through terramorf

The argument -var-file is being appended to commands that does not support it when using the var_files feature inside terramorf.hcl configuration file.

Suppose we have the following configuration.

terraform {
  required_version = "1.6.6"

  backend {
    bucket = "terraform-${environment}"
  }

  var_files = [
    "environments/${environment}.tfvars"
  ]
}

environment "dev" {}

When trying to run the fmt command we endup with the following error.

% terramorf dev fmt
Terraform 1.6.6 required

+ /Users/juliano/.local/share/terramorf/bin/terraform-1.6.6 fmt -var-file=environments/dev.tfvars
Usage: terraform [global options] fmt [options] [target...]

  Rewrites all Terraform configuration files to a canonical format. All
  configuration files (.tf), variables files (.tfvars), and testing files
  (.tftest.hcl) are updated. JSON files (.tf.json, .tfvars.json, or
  .tftest.json) are not modified.

  By default, fmt scans the current directory for configuration files. If you
  provide a directory for the target argument, then fmt will scan that
  directory instead. If you provide a file, then fmt will process just that
  file. If you provide a single dash ("-"), then fmt will read from standard
  input (STDIN).

  The content must be in the Terraform language native syntax; JSON is not
  supported.

Options:

  -list=false    Don't list files whose formatting differs
                 (always disabled if using STDIN)

  -write=false   Don't write to source files
                 (always disabled if using STDIN or -check)

  -diff          Display diffs of formatting changes

  -check         Check if the input is formatted. Exit status will be 0 if all
                 input is properly formatted and non-zero otherwise.

  -no-color      If specified, output won't contain any color.

  -recursive     Also process files in subdirectories. By default, only the
                 given directory (or current directory) is processed.
Error parsing command-line flags: flag provided but not defined: -var-file

Error trying to run `validate` subcommand

Terraform validate subcommand does not accept -var-file option.

% terramorf dev validate
Terraform 1.5.3 required

+ /Users/juliano/.local/share/terramorf/bin/terraform-1.5.3 validate -var-file=.terraform/terramorf/terramorf.tfvars
╷
│ Error: Failed to parse command-line flags
│
│ flag provided but not defined: -var-file
╵

For more help on using this command, run:
  terraform validate -help

Environment:

  • OS: macOS Ventura 13.4.1
  • Shell: GNU Bash 3.2
  • Terraform: 1.5.3
  • Terramorf: 0.5.3

I believe this can be fixed by just suppressing the -var-file option the same way it is done for the version subcommand.

% terramorf dev version
Terraform 1.5.3 required

+ /Users/juliano/.local/share/terramorf/bin/terraform-1.5.3 version
Terraform v1.5.3
on darwin_amd64

Code quality analysis for pull requests

It can be helpful to have a tool checking the code for syntax errors or possible pitfalls.

Shellcheck is a great tool for doing exactly that on shell scripts.

Here's an example:

% shellcheck terramorf

In terramorf line 32:
VERSION=0.5.2
^-----^ SC2034 (warning): VERSION appears unused. Verify use (or export if used externally).

For more information:
  https://www.shellcheck.net/wiki/SC2034 -- VERSION appears unused. Verify us...

A GitHub Actions workflow running this tool against pull requests might interest you.

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.