{"id":28566760,"url":"https://github.com/gruntwork-io/terragrunt-infrastructure-live-example","last_synced_at":"2025-06-10T15:31:07.361Z","repository":{"id":38485574,"uuid":"96038806","full_name":"gruntwork-io/terragrunt-infrastructure-live-example","owner":"gruntwork-io","description":"A repo used to show examples file/folder structures you can use with Terragrunt and Terraform","archived":false,"fork":false,"pushed_at":"2025-05-04T14:48:55.000Z","size":124,"stargazers_count":842,"open_issues_count":24,"forks_count":492,"subscribers_count":44,"default_branch":"main","last_synced_at":"2025-05-04T15:35:29.200Z","etag":null,"topics":["examples","terraform","terragrunt"],"latest_commit_sha":null,"homepage":"https://www.gruntwork.io/","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gruntwork-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-07-02T17:29:45.000Z","updated_at":"2025-04-30T07:38:24.000Z","dependencies_parsed_at":"2024-11-21T21:35:15.001Z","dependency_job_id":null,"html_url":"https://github.com/gruntwork-io/terragrunt-infrastructure-live-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gruntwork-io%2Fterragrunt-infrastructure-live-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gruntwork-io%2Fterragrunt-infrastructure-live-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gruntwork-io%2Fterragrunt-infrastructure-live-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gruntwork-io%2Fterragrunt-infrastructure-live-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gruntwork-io","download_url":"https://codeload.github.com/gruntwork-io/terragrunt-infrastructure-live-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gruntwork-io%2Fterragrunt-infrastructure-live-example/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259101118,"owners_count":22805206,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["examples","terraform","terragrunt"],"created_at":"2025-06-10T15:30:55.162Z","updated_at":"2025-06-10T15:31:07.334Z","avatar_url":"https://github.com/gruntwork-io.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Maintained by Gruntwork.io](https://img.shields.io/badge/maintained%20by-gruntwork.io-%235849a6.svg)](https://gruntwork.io/?ref=repo_terragrunt-infra-live-example)\n\n\u003e [!WARNING]\n\u003e This repository has been deprecated in favor of [terragrunt-infrastructure-live-stacks-example](https://github.com/gruntwork-io/terragrunt-infrastructure-live-stacks-example). Please use the new repository for the latest best practices and features.\n\u003e\n\u003e Take special notice of the [Migration Guide](https://github.com/gruntwork-io/terragrunt-infrastructure-live-stacks-example/blob/main/docs/migration-guide.md) specifically written to help you migrate from using this repo to the new one.\n\n# Example infrastructure-live for Terragrunt\n\nThis repo, along with the [terragrunt-infrastructure-modules-example\nrepo](https://github.com/gruntwork-io/terragrunt-infrastructure-modules-example), show an example file/folder structure\nyou can use with [Terragrunt](https://github.com/gruntwork-io/terragrunt) to keep your\n[OpenTofu](https://opentofu.org/) and [Terraform](https://www.terraform.io) code DRY. For background information,\ncheck out the [Keep your code DRY](https://github.com/gruntwork-io/terragrunt#keep-your-terraform-code-dry)\nsection of the Terragrunt documentation.\n\nThis repo shows an example of how to use the modules from the `terragrunt-infrastructure-modules-example` repo to\ndeploy an Auto Scaling Group (ASG) and a MySQL DB across three environments (qa, stage, prod) and two AWS accounts\n(non-prod, prod), all with minimal duplication of code. That's because there is just a single copy of\nthe code, defined in the `terragrunt-infrastructure-modules-example` repo, and in this repo, we solely define\n`terragrunt.hcl` files that reference that code (at a specific version, too!) and fill in variables specific to each\nenvironment.\n\nBe sure to read through [the Terragrunt documentation on DRY\nArchitectures](https://terragrunt.gruntwork.io/docs/features/keep-your-terragrunt-architecture-dry/) to understand the\nfeatures of Terragrunt used in this folder organization.\n\nNote: This code is solely for demonstration purposes. This is not production-ready code, so use at your own risk. If\nyou are interested in battle-tested, production-ready Terraform code, check out [Gruntwork](http://www.gruntwork.io/).\n\n## How do you deploy the infrastructure in this repo?\n\n\n### Pre-requisites\n\n1. Install [OpenTofu](https://opentofu.org/) version `1.6.0` or newer and\n   [Terragrunt](https://github.com/gruntwork-io/terragrunt) version `v0.52.0` or newer.\n2. Update the `bucket` parameter in the `root.hcl` file. We use S3 [as a Terraform\n   backend](https://opentofu.org/docs/language/settings/backends/s3/) to store your\n   state, and S3 bucket names must be globally unique. The name currently in\n   the file is already taken, so you'll have to specify your own. Alternatives, you can\n   set the environment variable `TG_BUCKET_PREFIX` to set a custom prefix.\n3. Update the `account_name` and `aws_account_id` parameters in [`non-prod/account.hcl`](/non-prod/account.hcl) and\n   [`prod/account.hcl`](/prod/account.hcl) with the names and IDs of accounts you want to use for non production and\n   production workloads, respectively.\n4. Configure your AWS credentials using one of the supported [authentication\n   mechanisms](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html).\n\n\n### Deploying a single module\n\n1. `cd` into the module's folder (e.g. `cd non-prod/us-east-1/qa/mysql`).\n1. Note: if you're deploying the MySQL DB, you'll need to configure your DB password as an environment variable:\n   `export TF_VAR_master_password=(...)`.\n1. Run `terragrunt plan` to see the changes you're about to apply.\n1. If the plan looks good, run `terragrunt apply`.\n\n\n### Deploying all modules in a region\n\n1. `cd` into the region folder (e.g. `cd non-prod/us-east-1`).\n1. Configure the password for the MySQL DB as an environment variable: `export TF_VAR_master_password=(...)`.\n1. Run `terragrunt run-all plan` to see all the changes you're about to apply.\n1. If the plan looks good, run `terragrunt run-all apply`.\n\n\n### Testing the infrastructure after it's deployed\n\nAfter each module is finished deploying, it will write a bunch of outputs to the screen. For example, the ASG will\noutput something like the following:\n\n```\nOutputs:\n\nasg_name = tf-asg-00343cdb2415e9d5f20cda6620\nasg_security_group_id = sg-d27df1a3\nelb_dns_name = webserver-example-prod-1234567890.us-east-1.elb.amazonaws.com\nelb_security_group_id = sg-fe62ee8f\nurl = http://webserver-example-prod-1234567890.us-east-1.elb.amazonaws.com:80\n```\n\nA minute or two after the deployment finishes, and the servers in the ASG have passed their health checks, you should\nbe able to test the `url` output in your browser or with `curl`:\n\n```\ncurl http://webserver-example-prod-1234567890.us-east-1.elb.amazonaws.com:80\n\nHello, World\n```\n\nSimilarly, the MySQL module produces outputs that will look something like this:\n\n```\nOutputs:\n\narn = arn:aws:rds:us-east-1:1234567890:db:tofu-00d7a11c1e02cf617f80bbe301\ndb_name = mysql_prod\nendpoint = tofu-1234567890.abcdefghijklmonp.us-east-1.rds.amazonaws.com:3306\n```\n\nYou can use the `endpoint` and `db_name` outputs with any MySQL client:\n\n```\nmysql --host=tofu-1234567890.abcdefghijklmonp.us-east-1.rds.amazonaws.com:3306 --user=admin --password mysql_prod\n```\n\n## How is the code in this repo organized?\n\nThe code in this repo uses the following folder hierarchy:\n\n```\naccount\n └ _global\n └ region\n    └ _global\n    └ environment\n       └ resource\n```\n\nWhere:\n\n* **Account**: At the top level are each of your AWS accounts, such as `stage-account`, `prod-account`, `mgmt-account`,\n  etc. If you have everything deployed in a single AWS account, there will just be a single folder at the root (e.g.\n  `main-account`).\n\n* **Region**: Within each account, there will be one or more [AWS\n  regions](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html), such as\n  `us-east-1`, `eu-west-1`, and `ap-southeast-2`, where you've deployed resources. There may also be a `_global`\n  folder that defines resources that are available across all the AWS regions in this account, such as IAM users,\n  Route 53 hosted zones, and CloudTrail.\n\n* **Environment**: Within each region, there will be one or more \"environments\", such as `qa`, `stage`, etc. Typically,\n  an environment will correspond to a single [AWS Virtual Private Cloud (VPC)](https://aws.amazon.com/vpc/), which\n  isolates that environment from everything else in that AWS account. There may also be a `_global` folder\n  that defines resources that are available across all the environments in this AWS region, such as Route 53 A records,\n  SNS topics, and ECR repos.\n\n* **Resource**: Within each environment, you deploy all the resources for that environment, such as EC2 Instances, Auto\n  Scaling Groups, ECS Clusters, Databases, Load Balancers, and so on. Note that the code for most of these\n  resources lives in the [terragrunt-infrastructure-modules-example repo](https://github.com/gruntwork-io/terragrunt-infrastructure-modules-example).\n\n## Creating and using root (account) level variables\n\nIn the situation where you have multiple AWS accounts or regions, you often have to pass common variables down to each\nof your modules. Rather than copy/pasting the same variables into each `terragrunt.hcl` file, in every region, and in\nevery environment, you can inherit them from the `inputs` defined in the `root.hcl` file.\n\n## What to do with `.terraform.lock.hcl` files\n\nWhen you run `terragrunt` commands you may find that `.terraform.lock.hcl` files are created in your working directories.\n\nThese files are intentionally not committed to this example repository, but you definitely should in your own repositories!\n\nThey help make sure that your IaC results in reproducible infrastructure. For more on this, read [Lock File Handling docs](https://terragrunt.gruntwork.io/docs/features/lock-file-handling/).\n\n## How to get help\n\nIf you need help troubleshooting usage of this repo, or Terragrunt in general, check out the [Support docs](https://terragrunt.gruntwork.io/docs/community/support/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgruntwork-io%2Fterragrunt-infrastructure-live-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgruntwork-io%2Fterragrunt-infrastructure-live-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgruntwork-io%2Fterragrunt-infrastructure-live-example/lists"}