All Projects → craftypath → gotf

craftypath / gotf

Licence: Apache-2.0 license
Managing multiple environments with Terraform made easy

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to gotf

icp-ce-on-linux-containers
Multi node IBM Cloud Private Community Edition 3.2.x w/ Kubernetes 1.13.5 in a Box. Terraform, Packer and BASH based Infrastructure as Code script sets up a multi node LXD cluster, installs ICP-CE and clis on a metal or VM Ubuntu 18.04 host.
Stars: ✭ 52 (+108%)
Mutual labels:  iac, hashicorp, infrastructure-as-code
terraform-modules
Terraform Modules by Peak
Stars: ✭ 16 (-36%)
Mutual labels:  iac, infrastructure-as-code
Nietzsche
Scrap quotes from Goodreads and schedule random tweets.
Stars: ✭ 44 (+76%)
Mutual labels:  iac, infrastructure-as-code
terraform-vsphere-single-vm
Deploy single vSphere VM with Terraform - template.
Stars: ✭ 21 (-16%)
Mutual labels:  iac, infrastructure-as-code
Terraform Best Practices
Terraform Best Practices for AWS users
Stars: ✭ 931 (+3624%)
Mutual labels:  hashicorp, infrastructure-as-code
driftctl
Detect, track and alert on infrastructure drift
Stars: ✭ 2,020 (+7980%)
Mutual labels:  iac, infrastructure-as-code
azure-devops-terraform
Recipe to deploy Azure Infrastructure with Terraform via Azure DevOps
Stars: ✭ 18 (-28%)
Mutual labels:  iac, hashicorp
stein
A linter for config files with a customizable rule set
Stars: ✭ 92 (+268%)
Mutual labels:  hashicorp, infrastructure-as-code
PSRule-pipelines
Validate infrastructure as code (IaC) and DevOps repositories using Azure Pipelines.
Stars: ✭ 16 (-36%)
Mutual labels:  iac, infrastructure-as-code
heat-examples
Heat examples tested against the SysEleven Stack infrastructure cloud.
Stars: ✭ 36 (+44%)
Mutual labels:  iac, infrastructure-as-code
Trivy
Scanner for vulnerabilities in container images, file systems, and Git repositories, as well as for configuration issues
Stars: ✭ 9,673 (+38592%)
Mutual labels:  iac, infrastructure-as-code
Terraform Provider Digitalocean
Terraform DigitalOcean provider
Stars: ✭ 296 (+1084%)
Mutual labels:  hashicorp, infrastructure-as-code
Terrascan
Detect compliance and security violations across Infrastructure as Code to mitigate risk before provisioning cloud native infrastructure.
Stars: ✭ 2,687 (+10648%)
Mutual labels:  iac, infrastructure-as-code
tfu
tfu is a terraform helper to update the providers.
Stars: ✭ 13 (-48%)
Mutual labels:  iac, infrastructure-as-code
terraform-installer
Installer for HashiCorp Terraform - Automatic Download, Extract and Install of Latest or Specific Version
Stars: ✭ 74 (+196%)
Mutual labels:  hashicorp, hashicorp-terraform
awesome-iac-testing
A list of awesome IaC testing articles, speeches & links. Especially about Ansible.
Stars: ✭ 56 (+124%)
Mutual labels:  iac, infrastructure-as-code
Awesome Terraform
Curated list of resources on HashiCorp's Terraform
Stars: ✭ 2,618 (+10372%)
Mutual labels:  infrastructure-as-code, hashicorp-terraform
libvirt-ocp4-provisioner
Automate your OCP4 installation
Stars: ✭ 82 (+228%)
Mutual labels:  hashicorp, hashicorp-terraform
yor
Extensible auto-tagger for your IaC files. The ultimate way to link entities in the cloud back to the codified resource which created it.
Stars: ✭ 459 (+1736%)
Mutual labels:  iac, infrastructure-as-code
Pulumi
Pulumi - Developer-First Infrastructure as Code. Your Cloud, Your Language, Your Way 🚀
Stars: ✭ 10,887 (+43448%)
Mutual labels:  iac, infrastructure-as-code

gotf

License CI

gotf is a Terraform wrapper that makes it easy to support multiple configurations, e.g. for different environments.

Installation

GitHub Release

Download a release from GitHub:

https://github.com/craftypath/gotf/releases

Homebrew

$ brew tap craftypath/tap
$ brew install gotf

Usage

$ gotf --help

  ___   __  ____  ____
 / __) /  \(_  _)(  __)
( (_ \(  O ) )(   ) _)
 \___/ \__/ (__) (__)   v0.16.0 (commit=00896ad, date=2021-12-10T18:21:54Z)

gotf is a Terraform wrapper facilitating configurations for various environments

Usage:
  gotf [flags] [Terraform args]

Flags:
  -c, --config string        Config file to be used (default "gotf.yaml")
  -d, --debug                Print additional debug output to stderr
  -h, --help                 help for gotf
  -m, --module-dir string    The module directory to run Terraform in (default ".")
  -n, --no-vars              Don't add any variables when running Terraform.
                             This is necessary when running 'terraform apply' with a plan file.
  -p, --params key=value     Params for templating in the config file. May be specified multiple times (default map[])
  -s, --skip-backend-check   Skip checking for changed backend configuration
  -v, --version              version for gotf

Demo

Check out the demo project which does not use cloud providers and keeps state locally. This allows you to play with the tool on your local machine.

Talks

🇩🇪 gotf – Umgebungen mit Terraform einfacher managen | Reinhard von codecentric auf der #SoftwerkerKonf
🇩🇪 gotf – Umgebungen mit Terraform einfacher managen | Reinhard von codecentric auf der #SoftwerkerKonf

Configuration

gotf is configured via config file. By default, gotf.yaml is loaded from the current directory. Config files support templating as specified below.

Parameters

terraformVersion

Optionally sets a specific Terraform version to use. gotf will download this version and cache it in $XDG_CACHE_HOME/gotf/terraform/<version> verifying GPG signature and SHA256 sum.

params

Config entries that can be used for templating. See section on templating below for details.

requiredParams

In addition to specifying params in the config file, they may also be specified on the command-line using the -p|--param flag. Params that are required can be configured here. Allowed values for a param must be specified as list. If no restrictions apply, no value or an empty list must be specified. Values must be strings.

globalVarFiles

A list of variables files which are added to the Terraform environment via TF_CLI_ARGS_<command>=-var-file=<file> for commands that support them. They are resolved relative to this config file.

moduleVarFiles.<moduleDir>

A list of module-specific variables files which are added to the Terraform environment if the corresponding module is run via TF_CLI_ARGS_<command>=-var-file=<file> for commands that support them. They are resolved relative to this config file.

globalVars

Variables which are added to the Terraform environment via TF_VAR_<var>=value for commands that support them.

moduleVars.<moduleDir>

Module-specific variables which are added to the Terraform environment if the corresponding module is run via TF_VAR_<var>=value for commands that support them. Module-specific variables override global ones.

varsFromEnvFiles

Allows variables to be configured as env files (name=value per line) which can also be sourced from a shell script. gotf interprets these files and passes each entry via TF_VAR_ environment variable. Names are automatically lower-cased to match the common Terraform style. This feature can be quite convenient if you create parts of your infrastructure via Terraform and other parts via shell scripts but want to have a common source for shared variables. This is also a workaround for getting rid of Terraform warnings in case a variable is not declared, which might happen if you use global var files for different modules. Comments and variable expansion are supported.

# comment for FOO
FOO=foo

# comment for BAR
BAR="bar is just a $FOO"

This would then be set as follows:

TF_VAR_foo=foo
TV_VAR_bar="bar is just a foo"

envs

Environment variables to be added to the Terraform process.

backendConfigs

Backend configuration added as -backend-config CLI options when the Terraform init command is run.

ignoreMissingVarFiles

If set to true, gotf checks whether configured variable files exist and does not pass them to Terraform if they don't.

Example

terraformVersion:  1.1.5

requiredParams:
  environment:
    - dev
    - prod

params:
  param: myval

globalVarFiles:
  - global-{{ .Params.environment }}.tfvars
  - global.tfvars

globalVars:
  foo: foovalue
  templated_var: "{{ .Params.param }}"
  mapvar: |-
    {
      entry1 = {
        value1 = testvalue1
        value2 = true
      }
      entry2 = {
        value1 = testvalue2
        value2 = false
      }
    }
  module_dir: "{{ .Params.moduleDir }}"
  state_key: '{{ (splitn "_" 2 .Params.moduleDir)._1 }}'

moduleVarFiles:
  01_networking:
    - 01_networking/{{ .Params.environment }}.tfvars
  02_compute:
    - 02_compute/{{ .Params.environment }}.tfvars

moduleVars:
  01_networking:
    myvar: value for networking
  02_compute:
    myvar: value for compute

varsFromEnvFiles:
  - '{{ .Params.environment }}.env'

envs:
  BAR: barvalue
  TEMPLATED_ENV: "{{ .Params.param }}"

backendConfigs:
  key: "{{ .Vars.state_key }}"
  storage_account_name: mytfstateaccount{{ .Params.environment }}
  resource_group_name: mytfstate-{{ .Params.environment }}
  container_name: mytfstate-{{ .Params.environment }}

Templating

Go templating can be used in the config file as follows. Hermetic, i.e. repeatable, functions from the Sprig function library are included.

  • In the first templating pass, globalVarFiles, globalVars, moduleVarFiles, moduleVars, and envs are processed. All parameters specified under params and using the -p|--param flag are available in the .Params object. CLI params override those specified in the config file. The basename of the module directory passed with the --module-dir|-m parameter is available as moduleDir dir in the .Params object.
  • In the second templating pass, backendConfigs are processed. globalVars and moduleVars are available as .Vars and envs are available as .Envs with the results from the first templating pass. Additionally, .Params is also available again.

Using the above config file, running terraform init could look like this:

$ gotf -c example-config.yaml -p environment=dev -m 01_networking init

After processing, the config file would look like this:

terraformVersion:  1.1.5

requiredParams:
  environment:
    - dev
    - prod

params:
  param: myval

globalVarFiles:
  - global-dev.tfvars
  - global.tfvars

globalVars:
  foo: foovalue
  templated_var: "myval"
  mapvar: |-
    {
      entry1 = {
        value1 = testvalue1
        value2 = true
      }
      entry2 = {
        value1 = testvalue2
        value2 = false
      }
    }
  module_dir: "01_networking"
  state_key: 'networking'

moduleVarFiles:
  01_networking:
    - 01_networking/dev.tfvars
  02_compute:
    - 02_compute/dev.tfvars

moduleVars:
  01_networking:
    myvar: value for networking
  02_compute:
    myvar: value for compute

envs:
  BAR: barvalue
  TEMPLATED_ENV: "myval"

backendConfigs:
  key: "networking"
  storage_account_name: mytfstateaccountdev
  resource_group_name: mytfstate-dev
  container_name: mytfstate-dev

Debug Output

Specifying the --debug flag produces debug output which is written to stderr. For example, the integration test in cmd/gotf/gotf_test.go produces the following debug output before running Terraform:

gotf> Loading config file: testdata/test-config.yaml
gotf> Processing var files...
gotf> File testdata/global-does-not-exists.tfvars does not exist. Ignoring it.
gotf> Processing module var files...
gotf> Processing vars from env files...
gotf> Processing global vars...
gotf> Processing module vars...
gotf> Processing envs...
gotf> Processing backend configs...
gotf> Using Terraform version 1.1.5
gotf> Terraform version 1.1.5 already installed.
gotf> Terraform binary: /Users/myuser/Library/Caches/gotf/terraform/1.1.5/terraform
gotf>
gotf> Terraform command-line:
gotf> -----------------------
gotf> /Users/myuser/Library/Caches/gotf/terraform/1.1.5/terraform apply -auto-approve -no-color
gotf>
gotf> Terraform environment:
gotf> ----------------------
gotf> TF_CLI_ARGS_import=-var-file="../global-prod.tfvars" -var-file="../global.tfvars" -var-file="prod.tfvars"
gotf> TF_CLI_ARGS_init=-backend-config=path=".terraform/terraform-networking-prod.tfstate"
gotf> TEMPLATED_ENV=myval
gotf> TF_CLI_ARGS_plan=-var-file="../global-prod.tfvars" -var-file="../global.tfvars" -var-file="prod.tfvars"
gotf> TF_VAR_myvar=value for networking
gotf> TF_CLI_ARGS_apply=-var-file="../global-prod.tfvars" -var-file="../global.tfvars" -var-file="prod.tfvars"
gotf> TF_CLI_ARGS_refresh=-var-file="../global-prod.tfvars" -var-file="../global.tfvars" -var-file="prod.tfvars"
gotf> TF_VAR_foo=42
gotf> TF_VAR_var_from_env_file=prod-env
gotf> TF_VAR_mapvar={
  entry1 = {
    value1 = testvalue1
    value2 = true
  }
  entry2 = {
    value1 = testvalue2
    value2 = false
  }
}
gotf> TF_VAR_state_key=networking
gotf> BAR=barvalue
gotf> TF_CLI_ARGS_destroy=-var-file="../global-prod.tfvars" -var-file="../global.tfvars" -var-file="prod.tfvars"
gotf> TF_VAR_templated_var=myval
gotf> TF_VAR_module_dir=01_networking
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].