Terraform Naming Conventions #
-
Use consistent naming conventions for Terraform resources, variables, and outputs to ensure clarity and maintainability across your Terraform configurations. Terraform symbolic names should be descriptive yet concise, reflecting the purpose and type of resource they represent.
-
Standardize inputs and outputs choosing simple and identifiable keys like
nameoridrather than resource-specific terms likevnet_nameorkeyvault_id. This approach ensures that variables and outputs are generic and reusable, making the codebase easier to maintain and extend. For example:- Use
nameinstead ofvnet_nameorkeyvault_name - Use
idinstead ofvnet_idorkeyvault_id
- Use
-
Use simple yet descriptive symbolic names for reusable Terraform modules code to enhance readability and maintainability. For example:
azurerm_virtual_network.thisfor a general-purpose virtual network resource.azurerm_role_assignment.network_contributor_on_vnetfor a role assignment specific to network contributors on a virtual network.
-
Examples of Terraform Symbolic Naming Patterns:
- Terraform Resource Name:
azurerm_virtual_network.external - Variable Name:
azurerm_virtual_network.external.nameinstead ofazurerm_virtual_network.external.vnet_name - Output Name:
azurerm_virtual_network.external.idinstead ofazurerm_virtual_network.external.vnet_id
- Terraform Resource Name: