All Projects → transcend-io → Terragrunt Atlantis Config

transcend-io / Terragrunt Atlantis Config

Licence: mit
Generate Atlantis config for Terragrunt projects.

Projects that are alternatives of or similar to Terragrunt Atlantis Config

Terraform Aws Key Pair
Terraform Module to Automatically Generate SSH Key Pairs (Public/Private Keys)
Stars: ✭ 121 (-7.63%)
Mutual labels:  terraform, hcl
Terraform Up And Running Code
Code samples for the book "Terraform: Up & Running" by Yevgeniy Brikman
Stars: ✭ 1,739 (+1227.48%)
Mutual labels:  terraform, hcl
Terraform Aws Ecr
Terraform Module to manage Docker Container Registries on AWS ECR
Stars: ✭ 110 (-16.03%)
Mutual labels:  terraform, hcl
Vishwakarma
Terraform modules to create a self-hosting Kubernetes cluster on opinionated Cloud Platform.
Stars: ✭ 127 (-3.05%)
Mutual labels:  terraform, hcl
Config Lint
Command line tool to validate configuration files
Stars: ✭ 118 (-9.92%)
Mutual labels:  terraform, hcl
Terraform Aws Config
Enables AWS Config and adds managed config rules with good defaults.
Stars: ✭ 107 (-18.32%)
Mutual labels:  terraform, hcl
Terraform
Terraform automation for Cloud
Stars: ✭ 121 (-7.63%)
Mutual labels:  terraform, hcl
Aws Minikube
Single node Kubernetes instance implemented using Terraform and kubeadm
Stars: ✭ 101 (-22.9%)
Mutual labels:  terraform, hcl
Hybrid multicloud overlay
MutiCloud_Overlay demonstrates a use case of overlay over one or more clouds such as AWS, Azure, GCP, OCI, Alibaba and a vSphere private infrastructure in Hub and spoke topology, point to point topology and in a Single cloud. Overlay protocols IPv6 and IPv4 are independent of underlying infrastructure. This solution can be integrated with encryption and additional security features.
Stars: ✭ 127 (-3.05%)
Mutual labels:  terraform, hcl
Hello Lambda
🔥 An example of a Python (AWS) Lambda exposed with API Gateway, configured with Terraform.
Stars: ✭ 114 (-12.98%)
Mutual labels:  terraform, hcl
Aws Ecs Airflow
Run Airflow in AWS ECS(Elastic Container Service) using Fargate tasks
Stars: ✭ 107 (-18.32%)
Mutual labels:  terraform, hcl
Terraform Aws Spotgpu
Fully automated provisioning of AWS EC2 Spot Instances for Deep Learning workloads using Terraform.
Stars: ✭ 127 (-3.05%)
Mutual labels:  terraform, hcl
Terraform Aws Dynamic Subnets
Terraform module for public and private subnets provisioning in existing VPC
Stars: ✭ 106 (-19.08%)
Mutual labels:  terraform, hcl
Reference Architectures
[WIP] Get up and running quickly with one of our reference architecture using our fully automated cold-start process.
Stars: ✭ 127 (-3.05%)
Mutual labels:  terraform, hcl
Typhoon
Minimal and free Kubernetes distribution with Terraform
Stars: ✭ 1,397 (+966.41%)
Mutual labels:  terraform, hcl
Terraform Config
Terraform bits and bytes
Stars: ✭ 111 (-15.27%)
Mutual labels:  terraform, hcl
Vaultron
🤖 Vault clusters Terraformed onto Docker for great fun and learning!
Stars: ✭ 96 (-26.72%)
Mutual labels:  terraform, hcl
Cobalt
Infrastructure turn-key solution for app service workloads
Stars: ✭ 97 (-25.95%)
Mutual labels:  terraform, hcl
Terraform Null Ansible
Terraform Module to run ansible playbooks
Stars: ✭ 114 (-12.98%)
Mutual labels:  terraform, hcl
Terraform Aws Kubernetes
Install a Kubernetes cluster the CoreOS Tectonic Way: HA, self-hosted, RBAC, etcd Operator, and more
Stars: ✭ 118 (-9.92%)
Mutual labels:  terraform, hcl

Terragrunt Atlantis Config by Transcend

Terragrunt Atlantis Config

Generate Atlantis Config for Terragrunt projects.


What is this?

Atlantis is an awesome tool for Terraform pull request automation. Each repo can have a YAML config file that defines Terraform module dependencies, so that PRs that affect dependent modules will automatically generate terraform plans for those modules.

Terragrunt is a Terraform wrapper, which has the concept of dependencies built into its configuration.

This tool creates Atlantis YAML configurations for Terragrunt projects by:

  • Finding all terragrunt.hcl in a repo
  • Evaluating their "dependency" and "terraform" source blocks to find their dependencies
  • Creating a Directed Acyclic Graph of all dependencies
  • Constructing and logging YAML in Atlantis' config spec that reflects the graph

This is especially useful for organizations that use monorepos for their Terragrunt config (as we do at Transcend), and have thousands of lines of config.

Integrate into your Atlantis Server

The recommended way to use this tool is to install it onto your Atlantis server, and then use a Pre-Workflow hook to run it after every clone. This way, Atlantis can automatically determine what modules should be planned/applied for any change to your repository.

To get started, add a pre_workflow_hooks field to your repos section of your server-side repo config:

{
  "repos": [
    {
      "id": "<your_github_repo>",
      "workflow": "default",
      "pre_workflow_hooks": [
        {
          "run": "terragrunt-atlantis-config generate --output atlantis.yaml --autoplan --parallel --create-workspace"
        }
      ]
    }
  ]
}

Then, make sure terragrunt-atlantis-config is present on your Atlantis server. There are many different ways to configure a server, but this example in Packer should show the bash commands you'll need just about anywhere:

variable "terragrunt_atlantis_config_version" {
  default = "1.2.1"
}

build {
  // ...
  provisioner "shell" {
    inline = [
      "wget https://github.com/transcend-io/terragrunt-atlantis-config/releases/download/v${var.terragrunt_atlantis_config_version}/terragrunt-atlantis-config_${var.terragrunt_atlantis_config_version}_linux_amd64.tar.gz",
      "sudo tar xf terragrunt-atlantis-config_${var.terragrunt_atlantis_config_version}_linux_amd64.tar.gz",
      "sudo mv terragrunt-atlantis-config_${var.terragrunt_atlantis_config_version}_linux_amd64/terragrunt-atlantis-config_${var.terragrunt_atlantis_config_version}_linux_amd64 terragrunt-atlantis-config",
      "sudo install terragrunt-atlantis-config /usr/local/bin",
    ]
    inline_shebang = "/bin/bash -e"
  }
  // ...
}

and just like that, your developers should never have to worry about an atlantis.yaml file, or even need to know what it is.

Extra dependencies

For 99% of cases, this tool can sniff out all dependencies in a module. However, you may have times when you want to add in additional dependencies such as:

  • You use Terragrunt's read_terragrunt_config function in your locals, and want to depend on the read file
  • Your Terragrunt module should be run anytime some non-terragrunt file is updated, such as a Dockerfile or Packer template
  • You want to run all modules any time your product has a major version bump
  • You believe a module should be reapplied any time some other file or directory is updated

In these cases, you can customize the locals block in that Terragrunt module to have a field named extra_atlantis_dependencies with a list of values you want included in the config, such as:

locals {
  extra_atlantis_dependencies = [
    "some_extra_dep",
    find_in_parent_folders(".gitignore")
  ]
}

In your atlantis.yaml file, you will end up seeing output like:

- autoplan:
    enabled: false
    when_modified:
      - "*.hcl"
      - "*.tf*"
      - some_extra_dep
      - ../../.gitignore
  dir: example-setup/extra_dependency

If you specify extra_atlantis_dependencies in the parent Terragrunt module, they will be merged with the child dependencies using the following rules:

  1. Any function in a parent will be evaluated from the child's directory. So you can use get_parent_terragrunt_dir() and other functions like you normally would in terragrunt.
  2. Absolute paths will work as they would in a child module, and the path in the output will be relative from the child module to the absolute path
  3. Relative paths, like the string "foo.json", will be evaluated as relative to the Child module. This means that if you need something relative to the parent module, you should use something like "${get_parent_terragrunt_dir()}/foo.json"

All Flags

One way to customize the behavior of this module is through CLI flag values passed in at runtime. These settings will apply to all modules.

Flag Name Description Default Value
--autoplan The default value for autoplan settings. Can be overriden by locals. false
--automerge Enables the automerge setting for a repo. false
--cascade-dependencies When true, dependencies will cascade, meaning that a module will be declared to depend not only on its dependencies, but all dependencies of its dependencies all the way down. true
--ignore-parent-terragrunt Ignore parent Terragrunt configs (those which don't reference a terraform module).
In most cases, this should be set to true
true
--parallel Enables plans and applys to happen in parallel. Will typically be used with --create-workspace true
--create-workspace Use different auto-generated workspace for each project. Default is use default workspace for everything false
--create-project-name Add different auto-generated name for each project false
--preserve-workflows Preserves workflows from old output files. Useful if you want to define your workflow definitions on the client side true
--workflow Name of the workflow to be customized in the atlantis server. If empty, will be left out of output ""
--approval-requirements Requirements that must be satisfied before atlantis apply can be run. Currently the only supported requirements are approved and mergeable. Can be overridden by locals []
--output Path of the file where configuration will be generated. Typically, you want a file named "atlantis.yaml". Default is to write to stdout. ""
--root Path to the root directory of the git repo you want to build config for. current directory
--terraform-version Default terraform version to specify for all modules. Can be overriden by locals ""
--ignore-dependency-blocks When true, dependencies found in dependency and dependencies blocks will be ignored false
--filter Path to the directory you want scope down the config for. Default is all files in root ""

All Locals

Another way to customize the output is to use locals values in your terragrunt modules. These can be set in either the parent or child terragrunt modules, and the settings will only affect the current module (or all child modules for parent locals).

Locals Name Description type
atlantis_workflow The custom atlantis workflow name to use for a module string
atlantis_apply_requirements The custom apply_requirements array to use for a module list(string)
atlantis_terraform_version Allows overriding the --terraform-version flag for a single module string
atlantis_autoplan Allows overriding the --autoplan flag for a single module bool
atlantis_skip If true on a child module, that module will not appear in the output.
If true on a parent module, none of that parent's children will appear in the output.
bool
extra_atlantis_dependencies See Extra dependencies list(string)

Separate workspace for parallel plan and apply

Atlantis added support for running plan and apply parallel in v0.13.0.

To use this feature, projects have to be separated in different workspaces, and the create-workspace flag enables this by concatenating the project path as the name of the workspace.

As an example, project ${git_root}/stage/app/terragrunt.hcl will have the name stage_app as workspace name. This flag should be used along with parallel to enable parallel plan and apply:

terragrunt-atlantis-config generate --output atlantis.yaml --parallel --create-workspace

Enabling this feature may consume more resources like cpu, memory, network, and disk, as each workspace will now be cloned separately by atlantis.

As when defining the workspace this info is also needed when running atlantis plan/apply -d ${git_root}/stage/app -w stage_app to run the command on specific directory, you can also use the atlantis plan/apply -p stage_app in case you have enabled the create-project-name cli argument (it is false by default).

Local Installation and Usage

You can install this tool locally to checkout what kinds of config it will generate for your repo, though in production it is recommended to install this tool directly onto your Atlantis server

Recommended: Install any version via go get:

cd && GO111MODULE=on go get github.com/transcend-io/[email protected] && cd -

This module officially supports golang versions v1.13, v1.14, and v1.15, tested on CircleCI with each build This module also officially supports both Windows and Nix-based file formats, tested on CircleCI with each build

Usage Examples (see below sections for all options):

# From the root of your repo
terragrunt-atlantis-config generate

# or from anywhere
terragrunt-atlantis-config generate --root /some/path/to/your/repo/root

# output to a file
terragrunt-atlantis-config generate --autoplan --output ./atlantis.yaml

Finally, check the log output (or your output file) for the YAML.

Contributing

To test any changes you've made, run make test.

Once all your changes are passing and your PR is reviewed, a merge into master will trigger a CircleCI job to build the new binary, test it, and deploy it's artifacts to an S3 bucket.

You can then open a PR on our homebrew tap similar to https://github.com/transcend-io/homebrew-tap/pull/4, and as soon as that merges your code will be released.

Stargazers over time

Stargazers over time

License

FOSSA Status

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].