Skip to content

Commit b2aacb6

Browse files
committed
improve written content in general
1 parent a9be384 commit b2aacb6

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

content/blog/terragrunt-envs-management.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ Managing multiple environments was a never-ending headache for me. Like many oth
1111

1212
## The Repetition Trap
1313

14-
At first, my solution was simple: copy-paste. I created three separate folders: one for production, one for staging, and one for development. In each folder, I had the same Terraform files with minor tweaks like different variables or configurations for each environment. It worked, but I soon found myself dealing with the chaos of managing three sets of nearly identical infrastructure code.
14+
At first, my solution was simple: copy-paste. I created three separate folders: one for production, one for staging, and one for development. Each folder contained the same Terraform files with minor tweaks, such as different variables or configurations for each environment. It worked, but I soon found myself dealing with the chaos of managing three sets of nearly identical infrastructure code.
1515

16-
Let’s say I needed to update a configuration for my database service. This meant that I had to open each folder, make the same change in three different places, and run Terraform multiple times for each environment. It was a tedious and error-prone process, and as my infrastructure grew, so did the complexity. I knew there had to be a better way.
16+
Let’s say I needed to update a configuration for my database service. This meant opening each folder, making the same change in three different places, and running Terraform multiple times for each environment. It was a tedious and error-prone process, and as my infrastructure grew, so did the complexity. I knew there had to be a better way.
1717

1818
> My Initial Setup was like this
1919
@@ -33,17 +33,18 @@ Let’s say I needed to update a configuration for my database service. This mea
3333
└── redis.tf
3434
```
3535

36-
The terraform files are contains same resources in different environment but the only difference was the values of the variables.
37-
That is lot of Repeated Code.
36+
The Terraform files contain the same resources in different environments, but the only difference is the values of the variables.
37+
That is lot of repeated code.
3838

3939
## The Terragrunt Revelation
4040

4141
That’s when I discovered Terragrunt. Terragrunt is a thin wrapper for Terraform that provides extra tools for keeping your Terraform code DRY (Don’t Repeat Yourself). It allows you to manage multiple Terraform modules in a single repository and reuse code across different environments. Terragrunt’s ability to manage remote state, generate configurations, and apply configurations across multiple environments made it the perfect solution for my environment management woes.
4242

4343
How we reduce the repeated code using Terragrunt:
44+
4445
First step was to make a module of the resources with all the changeable variables exposed, Next was to use them in each environment.
4546

46-
> The new setup with Terragrunt
47+
> The new folder structure using Terragrunt
4748
4849
```text
4950
.
@@ -71,8 +72,7 @@ First step was to make a module of the resources with all the changeable variabl
7172
   └── terragrunt.hcl
7273
```
7374

74-
In the `terragrunt.hcl` file, we define the module to use and the
75-
variables to pass to the module.
75+
In the `terragrunt.hcl` file, we define the module to use and the variables to pass to the module.
7676

7777
```hcl
7878
# terragrunt.hcl
@@ -85,8 +85,8 @@ inputs = {
8585
}
8686
```
8787

88-
Similarly in the other terragrunt files we define the module to use and the variables to pass to the module.
89-
and now for the storing the state file we can use the remote state file.
88+
Similarly, in the other terragrunt files, we define the module to use and the variables to pass to the module.
89+
And now for the storing the state file we can use the remote state file.
9090

9191
```hcl
9292
# terragrunt.hcl
@@ -107,8 +107,7 @@ EOF
107107
}
108108
```
109109

110-
This tells terragrunt to create a new file `backend.tf` with the contents of the `contents` block, Even if backend.tf already exists it will overwrite the contents because we have specified `overwrite_terragrunt`.
111-
This is like a defining a function, Now we need to call it in the files i.e `terragrunt.hcl` files.
110+
This tells terragrunt to create a new file `backend.tf` with the contents of the `contents` block, Even if backend.tf already exists it will overwrite the contents because we have specified `overwrite_terragrunt`. This is like a defining a function, Now we need to call it in the files i.e `terragrunt.hcl` files.
112111

113112
> This would look like this
114113
@@ -118,7 +117,7 @@ include "root" {
118117
}
119118
```
120119

121-
here the `find_in_parent_folders` returns the absolute path to the first `terragrunt.hcl` file it finds in the parent folders above the current `terragrunt.hcl` file.
120+
Here the `find_in_parent_folders` returns the absolute path to the first `terragrunt.hcl` file it finds in the parent folders above the current `terragrunt.hcl` file.
122121
and the include block tells terragrunt to include all the cofigurations from the file with the path returned by the `find_in_parent_folders` function.
123122

124123
## The Terragrunt Workflow
@@ -136,7 +135,7 @@ This will run the terragrunt plan in each sub directory it finds, Then it reads
136135
5. Terragrunt stores the Terraform state in the remote state file
137136
6. Terragrunt returns the output of the Terraform run
138137

139-
This workflow allows me to manage multiple environments with ease. I can make changes to my infrastructure code in a single place and apply those changes across all environments with a single command. Terragrunt’s ability to keep my Terraform code DRY has saved me time and effort, and I no longer have to worry about managing multiple sets of nearly identical infrastructure code.
138+
This workflow allows me to manage multiple environments with ease. I am able to make changes to my infrastructure code in one place and then apply those changes across all environments with just one command. Terragrunt's capability to keep my Terraform code DRY has saved me time and effort, eliminating the need to manage multiple sets of nearly identical infrastructure code.
140139

141140
## How Terragrunt worked for me
142141

@@ -148,14 +147,13 @@ This workflow allows me to manage multiple environments with ease. I can make ch
148147

149148
4. Dependency Management: Another Terragrunt superpower is managing dependencies between infrastructure components. For example, my ECS service depends on the VPC and subnets being provisioned first. Terragrunt’s dependencies block ensures that I deploy resources in the correct order, so my ECS service doesn’t attempt to launch before the network is ready.
150149

151-
## Obvious Question: Why to use terragrunt instead of directly using terraform modules or terraform workspaces
150+
## Obvious Question: Why to use terragrunt instead of directly using terraform modules or terraform workspaces?
152151

153152
While terraform workspaces can be using for multiple environments , [hashicorp does not recommend it](https://developer.hashicorp.com/terraform/cli/workspaces)
154153

155154
> CLI workspaces within a working directory use the same backend, so they are not a suitable isolation mechanism for this scenario.
156155
157-
Even with terraform modules you can just pass the variable and use it but that's just adding more boilerplate and you are just trying to prove the point that modules can be used here and
158-
It will become more complex to maintain down the road, I'm not saying you should use terragrunt I'm just pointing the facts. Ultimately it depends on the type of project you are working on.
156+
Even with Terraform modules, you can simply pass the variable and use it. However, this adds more boilerplate, making it more complex to maintain in the long run. I'm not suggesting that you should use Terragrunt; I'm just pointing out the facts. Ultimately, the decision depends on the type of project you are working on.
159157

160158
## Wrapping Up
161159

0 commit comments

Comments
 (0)