|
| 1 | +# Deployable Architecture authoring guidelines |
| 2 | + |
| 3 | +## Prefix in Deployable Architecture |
| 4 | + |
| 5 | +The **`prefix`** input variable allows you to prepend a custom string to the names of all resources created by this automation. This is especially useful for: |
| 6 | + |
| 7 | +- **Avoiding naming collisions** when deploying the same solution multiple times within the same account. |
| 8 | +- **Creating identical infrastructure** across multiple regions or environments. |
| 9 | +- **Improving resource traceability** by embedding environment or region identifiers into resource names. |
| 10 | + |
| 11 | +If you do not wish to use a prefix, you may set the value to `null` or an empty string (`""`). |
| 12 | + |
| 13 | +**Important**: The automation automatically inserts a hyphen between the prefix and the resource name. Therefore, you do not need to include a hyphen in the prefix yourself. |
| 14 | + |
| 15 | +### Examples |
| 16 | + |
| 17 | +Here are some common patterns for using the prefix: |
| 18 | + |
| 19 | +- **Environment-based**: |
| 20 | + - `dev`, `test`, `prod` |
| 21 | +- **Environment + Region**: |
| 22 | + - `dev-eu-gb`, `prod-us-south`, `test-jp-tok` |
| 23 | +- **Project-specific**: |
| 24 | + - `webapp-dev`, `ml-prod`, `iot-test` |
| 25 | +- **Team or department identifiers**: |
| 26 | + - `fin-dev`, `hr-prod`, `eng-test` |
| 27 | +- **Date or version-based** (for temporary or experimental deployments): |
| 28 | + - `exp-202505`, `v2-dev` |
| 29 | + |
| 30 | +These conventions help ensure that resources are clearly grouped and easily identifiable, especially in shared or multi-tenant accounts. |
| 31 | + |
| 32 | +### Naming Rules |
| 33 | + |
| 34 | +To ensure compatibility and consistency, the prefix must follow these rules: |
| 35 | + |
| 36 | +- Must begin with a **lowercase letter** |
| 37 | +- May contain only **lowercase letters**, **digits**, and **hyphens (`-`)** |
| 38 | +- Must **not end** with a hyphen (`-`) |
| 39 | +- Must **not contain consecutive hyphens** (`--`) |
| 40 | +- Maximum length: **16 characters** |
| 41 | + |
| 42 | +Here is the code snippet for your reference. |
| 43 | + |
| 44 | +```hcl |
| 45 | +variable "prefix" { |
| 46 | + type = string |
| 47 | + nullable = true |
| 48 | + description = "The prefix to be added to all resources created by this solution. To skip using a prefix, set this value to null or an empty string. The prefix must begin with a lowercase letter and may contain only lowercase letters, digits, and hyphens '-'. It should not exceed 16 characters, must not end with a hyphen('-'), and can not contain consecutive hyphens ('--'). Example: prod-0205-cos." |
| 49 | +
|
| 50 | + validation { |
| 51 | + # - null and empty string is allowed |
| 52 | + # - Must not contain consecutive hyphens (--): length(regexall("--", var.prefix)) == 0 |
| 53 | + # - Starts with a lowercase letter: [a-z] |
| 54 | + # - Contains only lowercase letters (a–z), digits (0–9), and hyphens (-) |
| 55 | + # - Must not end with a hyphen (-): [a-z0-9] |
| 56 | + condition = (var.prefix == null || var.prefix == "" ? true : |
| 57 | + alltrue([ |
| 58 | + can(regex("^[a-z][-a-z0-9]*[a-z0-9]$", var.prefix)), |
| 59 | + length(regexall("--", var.prefix)) == 0 |
| 60 | + ]) |
| 61 | + ) |
| 62 | + error_message = "Prefix must begin with a lowercase letter and may contain only lowercase letters, digits, and hyphens '-'. It must not end with a hyphen('-'), and cannot contain consecutive hyphens ('--')." |
| 63 | + } |
| 64 | + |
| 65 | + validation { |
| 66 | + # must not exceed 16 characters in length |
| 67 | + condition = length(var.prefix) <= 16 |
| 68 | + error_message = "Prefix must not exceed 16 characters." |
| 69 | + } |
| 70 | +} |
| 71 | +``` |
0 commit comments