# Naming Convention Implementation Summary

**Last Updated**: 2025-01-27  
**Status**: ✅ Complete

---

## Overview

The standardized naming convention has been fully implemented across The Order project. All Azure resources now follow the pattern:

```
{provider}-{region}-{resource}-{env}-{purpose}
```

---

## Implementation Status

### ✅ Completed

1. **Naming Convention Document** (`docs/governance/NAMING_CONVENTION.md`)
   - Comprehensive naming rules and patterns
   - Region abbreviations
   - Resource type abbreviations
   - Environment abbreviations
   - Purpose identifiers
   - Examples for all resource types

2. **Terraform Implementation**
   - ✅ Created `locals.tf` with centralized naming functions
   - ✅ Updated `resource-groups.tf` to use new naming
   - ✅ Updated `storage.tf` to use new naming (with special rules)
   - ✅ Updated `outputs.tf` with naming convention outputs
   - ✅ Updated `variables.tf` with region validation
   - ✅ Updated `versions.tf` backend comments

3. **Deployment Scripts**
   - ✅ Updated `scripts/deploy/config.sh` with naming functions
   - ✅ Added region abbreviation mapping
   - ✅ Added environment abbreviation mapping
   - ✅ All resource names now use new convention

4. **Documentation**
   - ✅ Updated deployment guide with naming convention reference
   - ✅ Created naming validation document
   - ✅ All examples updated

---

## Naming Examples

### Resource Groups
- **Old**: `the-order-dev-rg`
- **New**: `az-we-rg-dev-main`

### Storage Accounts
- **Old**: `theorderdevdata`
- **New**: `azwesadevdata` (alphanumeric only, max 24 chars)

### Key Vaults
- **Old**: `the-order-dev-kv`
- **New**: `az-we-kv-dev-main` (max 24 chars)

### AKS Clusters
- **Old**: `the-order-dev-aks`
- **New**: `az-we-aks-dev-main`

### Container Registries
- **Old**: `theorderacr`
- **New**: `azweacrdev` (alphanumeric only, max 50 chars)

---

## Key Features

### Centralized Naming

All naming logic is centralized in `infra/terraform/locals.tf`:

```hcl
locals {
  provider = "az"
  region_short = "we"  # westeurope
  env_short = "dev"
  
  rg_name = "${local.provider}-${local.region_short}-rg-${local.env_short}-main"
  sa_data_name = "${local.provider}${local.region_short}sa${local.env_short}data"
  # ... etc
}
```

### Automatic Abbreviations

Region and environment abbreviations are automatically calculated:

- `westeurope` → `we`
- `northeurope` → `ne`
- `uksouth` → `uk`
- `dev` → `dev`
- `stage` → `stg`
- `prod` → `prd`

### Validation

Terraform variables include validation:

```hcl
validation {
  condition = contains([
    "westeurope", "northeurope", "uksouth", ...
  ], var.azure_region)
  error_message = "Region must be one of the supported non-US regions."
}
```

---

## Usage

### In Terraform

```hcl
resource "azurerm_resource_group" "main" {
  name     = local.rg_name  # az-we-rg-dev-main
  location = var.azure_region
}
```

### In Deployment Scripts

```bash
# Automatically calculated from environment variables
readonly RESOURCE_GROUP_NAME="${NAME_PREFIX}-rg-${ENV_SHORT}-main"
# Result: az-we-rg-dev-main
```

---

## Benefits

1. **Consistency**: All resources follow the same pattern
2. **Clarity**: Names are self-documenting
3. **Compliance**: Meets Azure naming requirements
4. **Maintainability**: Centralized naming logic
5. **Scalability**: Easy to add new resources
6. **Automation**: Scripts automatically generate correct names

---

## Next Steps

When adding new resources:

1. Add naming function to `locals.tf`
2. Use the local value in resource definition
3. Update documentation if needed
4. Test with Terraform plan

---

## References

- [Naming Convention Document](./NAMING_CONVENTION.md)
- [Terraform Locals](../infra/terraform/locals.tf)
- [Deployment Config](../../scripts/deploy/config.sh)
- [Naming Validation](../infra/terraform/NAMING_VALIDATION.md)

---

**Status**: ✅ Implementation complete and ready for use

