- Learning DevOps
- Mikael Krief
- 116字
- 2021-06-24 12:32:06
Better visibility with the separation of files
When executing Terraform code, all files in the execution directory that have the .tf extension are automatically executed; in our example, we have provider.tf and main.tf. It is good to separate the code into several files in order to improve the readability of the code and its evolution.
Using our example script, we can do better and separate it with the following:
- Rg.tf, which contains the code for the resource group
- Network.tf, which contains the code for the VNet and subnet
- Compute.tf, which contains the code for the network interface, public IP, storage, and virtual machine
The complete code with separate files is here: https://github.com/PacktPublishing/Learning_DevOps/tree/master/CHAP02/terraform_separate_files.