Terraform Naming

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 name or id rather than resource-specific terms like vnet_name or keyvault_id. This approach ensures that variables and outputs are generic and reusable, making the codebase easier to maintain and extend. For example:

    • Use name instead of vnet_name or keyvault_name
    • Use id instead of vnet_id or keyvault_id
  • Use simple yet descriptive symbolic names for reusable Terraform modules code to enhance readability and maintainability. For example:

    • azurerm_virtual_network.this for a general-purpose virtual network resource.
    • azurerm_role_assignment.network_contributor_on_vnet for 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.name instead of azurerm_virtual_network.external.vnet_name
    • Output Name: azurerm_virtual_network.external.id instead of azurerm_virtual_network.external.vnet_id