-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Update QuickStart documentation with an additional example to control the output directory #4299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2ce3039
6001905
c05dcda
cf33a70
666b58d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -315,6 +315,42 @@ You can also see what to expect in your filesystem at each step [here](https://g | |
|
||
This is where that additional verbosity in Terragrunt logging is really handy. You can see that Terragrunt concurrently ran `apply -auto-approve` in both the `foo` and `bar` units. The extra logging for Terragrunt also included information on the names of the units that were processed, and disambiguated the output from each unit. | ||
|
||
When Terragrunt runs these commands, it creates a `.terragrunt-cache` directory in each unit's directory. This cache directory serves as Terragrunt's scratch directory where it: | ||
|
||
- Downloads your remote OpenTofu/Terraform configurations | ||
- Runs your OpenTofu/Terraform commands | ||
- Stores downloaded modules and providers | ||
- Stores generated files (in this case, the `hi.txt` file will be created under `.terragrunt-cache/[HASH]/[HASH]/hi.txt` rather than directly in the `foo` or `bar` directories) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can cut this. We mention this in the next line, and "generated files" is confusing in this context. OpenTofu/Terraform generates this file, not Terragrunt. |
||
|
||
With this configuration, the `hi.txt` files will be created directly in the `foo` and `bar` directories instead of the `.terragrunt-cache` directory. | ||
|
||
The `.terragrunt-cache` directory is typically added to `.gitignore` files, similar to the `.terraform` directory that OpenTofu generates. You can safely delete this folder at any time, and Terragrunt will recreate it as necessary. | ||
|
||
If you want to control where the files are created, you can modify the module to accept an output directory parameter. For example, you can update the `shared/main.tf` file to: | ||
|
||
```hcl | ||
variable "content" {} | ||
variable "output_dir" {} | ||
|
||
resource "local_file" "file" { | ||
content = var.content | ||
filename = "${var.output_dir}/hi.txt" | ||
} | ||
``` | ||
|
||
Then in your `foo/terragrunt.hcl` and `bar/terragrunt.hcl` files, you can use the `get_terragrunt_dir()` built-in function to get the directory where the `terragrunt.hcl` file is located: | ||
|
||
```hcl | ||
terraform { | ||
source = "../shared" | ||
} | ||
|
||
inputs = { | ||
output_dir = get_terragrunt_dir() | ||
content = "Hello from bar, Terragrunt!" | ||
} | ||
``` | ||
|
||
Similar to the `tofu` CLI, there is a prompt to confirm that you are sure you want to run the command in each unit when performing a command that's potentially destructive. You can skip this prompt by using the `--non-interactive` flag, just as you would with `-auto-approve` in OpenTofu. | ||
|
||
```bash | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -306,6 +306,42 @@ Are you sure you want to run 'terragrunt apply' in each folder of the stack desc | |
|
||
This is where that additional verbosity in Terragrunt logging is really handy. You can see that Terragrunt concurrently ran `apply -auto-approve` in both the `foo` and `bar` units. The extra logging for Terragrunt also included information on the names of the units that were processed, and disambiguated the output from each unit. | ||
|
||
When Terragrunt runs these commands, it creates a `.terragrunt-cache` directory in each unit's directory. This cache directory serves as Terragrunt's scratch directory where it: | ||
|
||
- Downloads your remote OpenTofu/Terraform configurations | ||
- Runs your OpenTofu/Terraform commands | ||
- Stores downloaded modules and providers | ||
- Stores generated files (in this case, the `hi.txt` file will be created under `.terragrunt-cache/[HASH]/[HASH]/hi.txt` rather than directly in the `foo` or `bar` directories) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure to replicate the edit between these two if you accept the suggestion above. |
||
|
||
With this configuration, the `hi.txt` files will be created directly in the `foo` and `bar` directories instead of the `.terragrunt-cache` directory. | ||
|
||
The `.terragrunt-cache` directory is typically added to `.gitignore` files, similar to the `.terraform` directory that OpenTofu generates. | ||
|
||
If you want to control where the files are created, you can modify the module to accept an output directory parameter. For example, you can update the `shared/main.tf` file to: | ||
|
||
```hcl | ||
variable "content" {} | ||
variable "output_dir" {} | ||
|
||
resource "local_file" "file" { | ||
content = var.content | ||
filename = "${var.output_dir}/hi.txt" | ||
} | ||
``` | ||
|
||
Then in your `foo/terragrunt.hcl` and `bar/terragrunt.hcl` files, you can use the `get_terragrunt_dir()` built-in function to get the directory where the `terragrunt.hcl` file is located: | ||
|
||
```hcl | ||
terraform { | ||
source = "../shared" | ||
} | ||
|
||
inputs = { | ||
output_dir = get_terragrunt_dir() | ||
content = "Hello from bar, Terragrunt!" | ||
} | ||
``` | ||
|
||
Similar to the `tofu` CLI, there is a prompt to confirm that you are sure you want to run the command in each unit when performing a command that's potentially destructive. You can skip this prompt by using the `--non-interactive` flag, just as you would with `-auto-approve` in OpenTofu. | ||
|
||
```bash | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.terragrunt-cache | ||
hi.txt |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This example demonstrates how to control output file locations using get_terragrunt_dir(). | ||
|
||
The hi.txt files will be created directly in the foo and bar directories instead of the .terragrunt-cache directory. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
terraform { | ||
source = "../shared" | ||
} | ||
|
||
inputs = { | ||
output_dir = get_terragrunt_dir() | ||
content = "Hello from bar, Terragrunt!" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
terraform { | ||
source = "../shared" | ||
} | ||
|
||
inputs = { | ||
output_dir = get_terragrunt_dir() | ||
content = "Hello from foo, Terragrunt!" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
variable "content" {} | ||
variable "output_dir" {} | ||
|
||
resource "local_file" "file" { | ||
content = var.content | ||
filename = "${var.output_dir}/hi.txt" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all good content!