/terragrunt-ecs-modules

A repo used to show examples file/folder structures you can use with Terragrunt and Terraform

Primary LanguageHCL

Example ecs-modules for Terragrunt

This repo, along with the terragrunt-ecs-nginx repo, show an example file/folder structure you can use with Terragrunt to keep your Terraform code DRY. For background information, check out the Keep your Terraform code DRY section of the Terragrunt documentation.

This repo contains the following example code:

Note: This code is solely for demonstration purposes. This is not production-ready code, so use at your own risk. If you are interested in battle-tested, production-ready Terraform code, check out Gruntwork.

How do you use these modules?

To use a module, create a terragrunt.hcl file that specifies the module you want to use as well as values for the input variables of that module:

# Use Terragrunt to download the module code
terraform {
  source = "git::git@github.com:itmustbejj/terragrunt-ecs-modules.git//path/to/module?ref=master"
}

# Fill in the variables for that module
inputs = {
  foo = "bar"
  baz = 3
}

(Note: the double slash (//) in the source URL is intentional and required. It's part of Terraform's Git syntax for module sources.)

You then run Terragrunt, and it will download the source code specified in the source URL into a temporary folder, copy your terragrunt.hcl file into that folder, and run your Terraform command in that folder:

> terragrunt apply
[terragrunt] Reading Terragrunt config file at terragrunt.hcl
[terragrunt] Downloading Terraform configurations from git::git@github.com:itmustbejj/terragrunt-ecs-modules.git//path/to/module?ref=master
[terragrunt] Copying files from . into .terragrunt-cache
[terragrunt] Running command: terraform apply
[...]

Check out the terragrunt-ecs-nginx repo for examples and the Keep your Terraform code DRY documentation for more info

How do you change a module?

Local changes

Here is how to test out changes to a module locally:

  1. git clone this repo.
  2. Update the code as necessary.
  3. Go into the folder where you have the terragrunt.hcl file that uses a module from this repo (preferably for a dev or staging environment!).
  4. Run terragrunt plan --terragrunt-source <LOCAL_PATH>, where LOCAL_PATH is the path to your local checkout of the module code.
  5. If the plan looks good, run terragrunt apply --terragrunt-source <LOCAL_PATH>.

Using the --terragrunt-source parameter (or TERRAGRUNT_SOURCE environment variable) allows you to do rapid, iterative, make-a-change-and-rerun development.

Releasing a new version

When you're done testing the changes locally, here is how you release a new version:

  1. Update the code as necessary.

  2. Commit your changes to Git: git commit -m "commit message".

  3. Add a new Git tag using one of the following options:

    1. Using GitHub: Go to the releases page and click "Draft a new release".
    2. Using Git:
    git tag -a v0.0.2 -m "tag message"
    git push --follow-tags
    
  4. Now you can use the new Git tag (e.g. v0.0.2) in the ref attribute of the source URL in terragrunt.hcl.

  5. Run terragrunt plan.

  6. If the plan looks good, run terragrunt apply.