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:
-
vpc: An example AWS VPC with terraform-aws-vpc
-
ecs: An example AWS Elastic Container Service (ECS) Cluster with terraform-aws-ecs.
-
alb: An example AWS Application Load Balancer (ALB) with terraform-aws-ecs.
-
svc: An example AWS ECS Service with terraform-aws-ecs.
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:
git clone
this repo.- Update the code as necessary.
- 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!). - Run
terragrunt plan --terragrunt-source <LOCAL_PATH>
, whereLOCAL_PATH
is the path to your local checkout of the module code. - 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:
-
Update the code as necessary.
-
Commit your changes to Git:
git commit -m "commit message"
. -
Add a new Git tag using one of the following options:
- Using GitHub: Go to the releases page and click "Draft a new release".
- Using Git:
git tag -a v0.0.2 -m "tag message" git push --follow-tags
-
Now you can use the new Git tag (e.g.
v0.0.2
) in theref
attribute of thesource
URL interragrunt.hcl
. -
Run
terragrunt plan
. -
If the plan looks good, run
terragrunt apply
.