Terraform – best practices and troubleshooting
We will cover some of the recommendations we have already touched upon in the General IaC best practices section. Still, as mentioned at the start of the chapter, we will go into more detail about how they apply to just Terraform.
Terraform – best practices
Here are some best practices for approaching your Terraform deployment:
- Use a modular approach: Break down infrastructure into reusable modules, simplifying code maintenance and enabling reusability across different environments.
As we discussed in Chapter 6, Building upon the Foundations, Terraform modules can be hosted in the Terraform Registry or, which I have not mentioned, privately in your own Git repository. The following example code downloads the module from GitHub using Secure Shell (SSH):
module "somefunction" { source = "[email protected]:someuser/tfmodule.git" }
Assuming you are executing your Terraform...