Terraform files
Description
When you create your architecture, Brainboard automatically and instantly generates a Terraform code for your infrastructure.
This code is stored in different files according to the best practices of Terraform.
Files structure
By default, if you don't change rename or change the generated files, you have the following ones:
main.tf: contains all the definition of resources and their configuration. See how you can change or rename it below.
output.tf: contains the output variables.
providers.tf: contains the definition of
terraform
block and the providers.terraform.tfvars: contains only the values of the variables if defined.
variables.tf: contains the definition of variables and their blocks.
locals.tf: contains the definition of Terraform
locals
.backend.tf: contains the configuration of the remote backend.
Create new Terraform file
To create a new Terraform file that contains some resources:
Select the resource you want to put in the same file.
Click on
Group resource in the same Terraform file
button:Give a new name of the file.
Click on
Save
to create the new file and put resources inside it.
Once the file is created, it will be visible in the list of Terraform files:
Rename existing Terraform file
To rename an existing file:
Click on the button to display the list of groups:
Click on the name of the group:
Rename it and save.
Delete a Terraform file
To delete an existing file:
Click on the button to display the list of groups:
Click on the
Delete group
button:Confirm to permanently delete it.
When you delete a group, the resources inside it will not be deleted. They will be put back in main.tf
. To delete them, you need to select and delete them
Add resource into an existing file
To add a resource into an existing or new Terraform file (group):
Select the resource.
Click on the
Group resource in the same Terraform file
button:Either select group from the available list or create a new one.
Click on
Save
to persist the change.
Remove resource from a file
To remove a resource from an existing Terraform file (group):
Select the resource.
Click on the
Group resource in the same Terraform file
button:Select
main
.Click on
Save
to persist the change.
Best practices
Always group resources that are supposed to work together or have the same logic in a separate group / Terraform file.
Use explicit names for your Terraform files. Usually, there are 2 conventions of naming:
Infrastructure base naming:
vpc.tf
,db.tf
...Application base naming:
microservice1.tf
,backend.tf
...
Last updated