Consider that under terraform folder, there are dev/ prod/ global/. So how many times do we need to run terraform init
?
Based on the transcript, you have the following folders under your terraform folder:
- dev/
- prod/
- global/
You also have a V2 folder that represents a single Git repository, which contains subfolders for environments (dev, prod, global) and modules.
To answer your question, you would need to run terraform init
in each environment folder (dev, prod, global) because each environment folder has its own Terraform state file.
However, in the V2 folder, you have a more advanced structure where each module is in its own Git repository. In this case, you would need to run terraform init
in each environment folder (dev, prod, global) as well as in each module repository.
So, in total, you would need to run terraform init
at least 5 times:
- 3 times in the environment folders (dev, prod, global)
- 2 times in the module repositories (VPC and subnet)
But, if you have more modules, the number of terraform init
commands would increase accordingly.
terraform fmt
Considering in each subfolders there are many terraform code artifacts, how do we ran
terraform fmt
?Answer
To run
terraform fmt
on all the Terraform code artifacts in your subfolders, you can use the following command:This will recursively apply the
terraform fmt
command to all the Terraform files in your current directory and its subdirectories.Alternatively, you can also use the following command to format only the Terraform files in the specific subfolders you mentioned:
This will format only the Terraform files in the dev, prod, and global subfolders.
Note that the
-recursive
flag is optional, but it's recommended to use it to ensure that all Terraform files in the subfolders are formatted correctly.