Skip to content

saif-utilities / examples / naming-database

This example demonstrates how to use the database naming module to generate valid Azure Cosmos DB account names according to Azure naming conventions.

What This Example Shows

This example demonstrates:

  1. Basic database naming with minimal configuration
  2. Environment and tenant specific naming
  3. Custom prefixes and suffixes for organizational standards
  4. Organization and owner fields for team identification
  5. Unique suffix generation for avoiding naming conflicts
  6. Actual Cosmos DB deployment using the generated names

Azure Cosmos DB Naming Requirements

The naming module ensures all generated names comply with Azure Cosmos DB naming rules: - Length: 3-44 characters - Characters: Letters, numbers, and hyphens - Must start and end with alphanumeric character - Hyphens allowed in the middle - Case-insensitive (but preserved)

Usage

  1. Initialize Terraform:

    terraform init
    

  2. Review the plan:

    terraform plan
    

  3. Apply the configuration:

    terraform apply
    

  4. View the generated names:

    terraform output
    

Example Outputs

Based on the configurations in this example, you might see names like:

  • Basic: Myapp
  • Environment + tenant: ProdContosoWebapp
  • Custom Prefix/Suffix: CorpDataTestFabrikamAnalyticsPrimaryV1
  • Organization + Owner: SaifDatateamEnterprisePlatform
  • With Unique Suffix: StagingAcmeMicroserviceAbc123 (suffix varies)

Customization

You can customize the naming by adjusting:

  • project_id: Your application/project identifier
  • environment_short_name: Environment (dev, test, prod, staging)
  • tenant: Your organization or tenant name
  • organization_name: Your organization name
  • owner_name: Team or owner name
  • prefix: List of prefixes to add
  • suffix: List of suffixes to add
  • unique_length: Length of unique suffix (0 to disable)
  • unique_include_numbers: Whether to include numbers in unique suffix

Resource Group

This example creates a resource group named rg-module-database in West US 2 for the demonstration. In a real scenario, you would typically use an existing resource group or integrate this into your broader infrastructure.

Clean Up

To remove all resources created by this example:

terraform destroy

Files

  • main.tf: Main configuration with all examples
  • README.md: This documentation file

View source on GitHub