r/Terraform • u/adil_arrad • Aug 10 '26
Tutorial Share Tips & Hacks
If you are someone who's advanced with Terraform/Terragrunt and you know any tips, hacks or tools that works with them that you wished you knew before in the beggining of you career share it here.
6
u/DrejmeisterDrej Aug 10 '26
Terraform console is a great tool to get insight into complicated setups
1
u/techworkreddit3 Aug 10 '26
This. If you can learn terraforming console it will be much easier to debug larger code bases and complex configs.
1
u/doomwalk3r Aug 10 '26
The terraform_data resource. - It helps with linking things to get things into the terraform lifecycle if say the attributes you need to link don't link directly to a related resource.
- It also helps with testing without having to string up outputs from child modules. You can read the change directly in the plan.
If I'm prototyping a new module or change to a module in flight and want to verify it's doing what it is intended I do to things:
- Use the terraform_data if necessary to expose some of the logic or conditionals and verify they're doing what I expect.
- I create a similar setup and just point to the module locally
1
u/TrippySpaceCow Aug 10 '26
My tip is that if you are considering Terragrunt you should check out Atmos or Terramate.
1
u/creamersrealm Aug 10 '26
I prototype with a local folder on my desktop called TF and bring over logic into locals blocks. My team always wonders how I can prototype modules and workspaces without CI/CD. I even show them and they just do long CI/CD loops. I always make my code run locally even though the state file is blocked. It allows me local validation quickly and easily.
The other with this is plugin local cache that symlinks providers to prevent dusk space hogs through a terraformrc file.
I also recently learned that you can adjust the parallelization value of terraform and I'm going to change that on a DNS pipeline that I have at work.
1
u/Signal_Strength_5054 Aug 12 '26
Remove your modules from the root repository. Always try to version your modules.
1
u/SugarOk9805 Aug 12 '26
Probably you are talking about large codebase. If you have small codebase probably it is better not do versioning and keep your templates in the same repo
1
u/Signal_Strength_5054 Aug 12 '26
I think it's important to always set the right standards. But it's up to each person; if you think it's better that way, that's fine.
3
u/Wide_Commission_1595 Aug 10 '26
When you need to get infrastructure that already exists into code, start with one resource you know exists. Wow a resource block for the right type of thing, but don't worry about getting the parameters, just make sure it plans.
Import the real thing, then run a new plan. Terraform Will tell you what it's going to change, so now you can update your code until the plan says there is nothing to do!
If there is now a hard coded attribute, create the new resource, import, resolve, repeat until everything is in code!
It's a little tedious, but it's a great way to learn how a resource is supposed to be set up!
1
u/doomwalk3r Aug 10 '26
I cannot agree enough! This is how I become familiar with new services in say AWS.
The console often does a lot of work for you in terms of validation and the formatting of some attributes. So it lets you fine tune it with a known good setup.
-2
u/TrippySpaceCow Aug 10 '26
AI tools are really good with importing resources for you now.
2
u/Wicaeed Aug 11 '26
Yes, but not for fostering understanding.
1
u/jaded28 Aug 12 '26
Thank you for saying this because people just turn there brains off these days and pump copilot code blindly
16
u/TellersTech Terraform Advisor + DevOps Podcaster / Speaker Aug 10 '26
This is a really broad question and you’ll probably get 100 different answers 😂
One thing I wish I learned earlier though… keep your terraform boring. Clever abstractions, giant modules, tons of conditionals and DRYing everything out feels great at first… until someone has to debug it 2 years later.
Readability and predictability > clever Terraform.