Skip to content

Commit 0a44f2d

Browse files
committed
feat: improve deployment stack names
1 parent d6b9bce commit 0a44f2d

13 files changed

Lines changed: 34 additions & 147 deletions

File tree

alz/azuredevops/locals.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ locals {
3434
}
3535

3636
locals {
37-
target_subscriptions_legacy = distinct([var.subscription_id_connectivity, var.subscription_id_identity, var.subscription_id_management])
38-
target_subscriptions = length(var.subscription_ids) > 0 ? distinct(values(var.subscription_ids)) : local.target_subscriptions_legacy
37+
target_subscriptions = distinct(values(var.subscription_ids))
3938
}
4039

4140
locals {

alz/azuredevops/pipelines/bicep/templates/cd-template.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ stages:
8282
- $${{ if eq(parameters['${script_file.name}'], true) }}:
8383
- template: ./helpers/bicep-deploy.yaml
8484
parameters:
85+
name: '${script_file.name}'
8586
displayName: '${script_file.displayName}'
8687
serviceConnection: '${service_connection_name_plan}'
8788
templateFilePath: '${script_file.templateFilePath}'
@@ -162,6 +163,7 @@ stages:
162163
- $${{ if eq(parameters['${script_file.name}'], true) }}:
163164
- template: ./helpers/bicep-deploy.yaml
164165
parameters:
166+
name: '${script_file.name}'
165167
displayName: '${script_file.displayName}'
166168
serviceConnection: '${service_connection_name_apply}'
167169
templateFilePath: '${script_file.templateFilePath}'

alz/azuredevops/pipelines/bicep/templates/ci-template.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ stages:
9797
%{ for script_file in script_files ~}
9898
- template: ./helpers/bicep-deploy.yaml
9999
parameters:
100+
name: '${script_file.name}'
100101
displayName: '${script_file.displayName}'
101102
serviceConnection: '${service_connection_name_plan}'
102103
templateFilePath: '${script_file.templateFilePath}'

alz/azuredevops/pipelines/bicep/templates/helpers/bicep-deploy.yaml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
22
parameters:
3+
- name: name
4+
type: string
35
- name: displayName
46
type: string
57
- name: serviceConnection
@@ -68,18 +70,13 @@ steps:
6870
Write-Host ""
6971
}
7072
71-
# Generate deployment name without timestamp for consistent deployment stack names
72-
$deploymentPrefix = "alz"
73-
74-
$deploymentNameBase = "$${{ parameters.displayName }}".Replace(" ", "-")
75-
$deploymentNameBase = "$deploymentNameBase-$($env:TIME_STAMP)"
76-
73+
# Generate deployment stack name
74+
$deploymentPrefix = $env:INTERMEDIATE_ROOT_MANAGEMENT_GROUP_ID
75+
$deploymentNameBase = "$${{ parameters.name }}".Replace(" ", "-")
7776
$deploymentNameMaxLength = 64 - $deploymentPrefix.Length - 1
78-
7977
if ($deploymentNameBase.Length -gt $deploymentNameMaxLength) {
8078
$deploymentNameBase = $deploymentNameBase.Substring(0, $deploymentNameMaxLength)
8179
}
82-
8380
$deploymentName = "$deploymentPrefix-$deploymentNameBase"
8481
8582
$modeText = if ($whatIfEnabled) { "What-If" } else { "Deployment Stack" }

alz/azuredevops/variables.tf

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -45,54 +45,16 @@ variable "subscription_ids" {
4545
default = {}
4646
nullable = false
4747
validation {
48-
condition = length(var.subscription_ids) == 0 || alltrue([for id in values(var.subscription_ids) : can(regex("^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$", id))])
48+
condition = alltrue([for id in values(var.subscription_ids) : can(regex("^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$", id))])
4949
error_message = "All subscription IDs must be valid GUIDs"
5050
}
5151
validation {
52-
condition = length(var.subscription_ids) == 0 || alltrue([for id in keys(var.subscription_ids) : contains(["management", "connectivity", "identity", "security"], id)])
52+
condition = alltrue([for id in keys(var.subscription_ids) : contains(["management", "connectivity", "identity", "security"], id)])
5353
error_message = "The keys of the subscription_ids map must be one of 'management', 'connectivity', 'identity' or 'security'"
5454
}
55-
}
56-
57-
variable "subscription_id_connectivity" {
58-
description = <<-EOT
59-
**(Optional, default: `null`)** **DEPRECATED** (use subscription_ids instead)
60-
61-
The identifier of the Connectivity Subscription.
62-
EOT
63-
type = string
64-
default = null
65-
validation {
66-
condition = var.subscription_id_connectivity == null || can(regex("^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$", var.subscription_id_connectivity))
67-
error_message = "The subscription ID must be a valid GUID"
68-
}
69-
}
70-
71-
variable "subscription_id_identity" {
72-
description = <<-EOT
73-
**(Optional, default: `null`)** **DEPRECATED** (use subscription_ids instead)
74-
75-
The identifier of the Identity Subscription.
76-
EOT
77-
type = string
78-
default = null
79-
validation {
80-
condition = var.subscription_id_identity == null || can(regex("^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$", var.subscription_id_identity))
81-
error_message = "The subscription ID must be a valid GUID"
82-
}
83-
}
84-
85-
variable "subscription_id_management" {
86-
description = <<-EOT
87-
**(Optional, default: `null`)** **DEPRECATED** (use subscription_ids instead)
88-
89-
The identifier of the Management Subscription.
90-
EOT
91-
type = string
92-
default = null
9355
validation {
94-
condition = var.subscription_id_management == null || can(regex("^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$", var.subscription_id_management))
95-
error_message = "The subscription ID must be a valid GUID"
56+
condition = contains(keys(var.subscription_ids), "management") && contains(keys(var.subscription_ids), "connectivity") && contains(keys(var.subscription_ids), "identity")
57+
error_message = "You must provide subscription IDs for: 'management', 'connectivity', and 'identity'"
9658
}
9759
}
9860

alz/github/actions/bicep/templates/actions/bicep-deploy/action.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
name: Run Bicep Deploy with Deployment Stack
33
description: Run Bicep Deployment using Azure Deployment Stacks
44
inputs:
5+
name:
6+
description: 'Name'
7+
required: true
58
displayName:
69
description: 'Display Name'
710
required: true
@@ -62,16 +65,13 @@ runs:
6265
exit 0
6366
}
6467
65-
# Generate deployment name without timestamp for consistent deployment stack names
66-
$deploymentPrefix = "alz"
67-
$deploymentNameBase = "$($env:DISPLAY_NAME.Replace(" ", "-"))-$($env:TIME_STAMP)"
68-
68+
# Generate deployment stack name
69+
$deploymentPrefix = $env:INTERMEDIATE_ROOT_MANAGEMENT_GROUP_ID
70+
$deploymentNameBase = ($env:NAME).Replace(" ", "-")
6971
$deploymentNameMaxLength = 64 - $deploymentPrefix.Length - 1
70-
7172
if ($deploymentNameBase.Length -gt $deploymentNameMaxLength) {
7273
$deploymentNameBase = $deploymentNameBase.Substring(0, $deploymentNameMaxLength)
7374
}
74-
7575
$deploymentName = "$deploymentPrefix-$deploymentNameBase"
7676
7777
$modeText = if ($whatIfEnabled) { "What-If" } else { "Deployment Stack" }
@@ -336,6 +336,7 @@ runs:
336336
}
337337
}
338338
env:
339+
NAME: $${{ inputs.name }}
339340
DISPLAY_NAME: $${{ inputs.displayName }}
340341
TEMPLATE_FILE_PATH: $${{ inputs.templateFilePath }}
341342
TEMPLATE_PARAMETERS_FILE_PATH: $${{ inputs.templateParametersFilePath }}

alz/github/actions/bicep/templates/workflows/cd-template.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
uses: ${project_or_organization_name}/${repository_name_templates}/.github/actions/bicep-deploy@main
6262
if: $${{ inputs.${script_file.name} }}
6363
with:
64+
name: '${script_file.name}'
6465
displayName: '${script_file.displayName}'
6566
templateFilePath: '${script_file.templateFilePath}'
6667
templateParametersFilePath: '${script_file.templateParametersFilePath}'
@@ -118,6 +119,7 @@ jobs:
118119
uses: ${project_or_organization_name}/${repository_name_templates}/.github/actions/bicep-deploy@main
119120
if: $${{ inputs.${script_file.name} }}
120121
with:
122+
name: '${script_file.name}'
121123
displayName: '${script_file.displayName}'
122124
templateFilePath: '${script_file.templateFilePath}'
123125
templateParametersFilePath: '${script_file.templateParametersFilePath}'

alz/github/actions/bicep/templates/workflows/ci-template.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ jobs:
8181
- name: 'What If: ${script_file.displayName}'
8282
uses: ${project_or_organization_name}/${repository_name_templates}/.github/actions/bicep-deploy@main
8383
with:
84+
name: '${script_file.name}'
8485
displayName: '${script_file.displayName}'
8586
templateFilePath: '${script_file.templateFilePath}'
8687
templateParametersFilePath: '${script_file.templateParametersFilePath}'

alz/github/locals.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ locals {
4141
}
4242

4343
locals {
44-
target_subscriptions_legacy = distinct([var.subscription_id_connectivity, var.subscription_id_identity, var.subscription_id_management])
45-
target_subscriptions = length(var.subscription_ids) > 0 ? distinct(values(var.subscription_ids)) : local.target_subscriptions_legacy
44+
target_subscriptions = distinct(values(var.subscription_ids))
4645
}
4746

4847
locals {

alz/github/variables.tf

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -45,54 +45,16 @@ variable "subscription_ids" {
4545
default = {}
4646
nullable = false
4747
validation {
48-
condition = length(var.subscription_ids) == 0 || alltrue([for id in values(var.subscription_ids) : can(regex("^[0-9a-fA-F-]{36}$", id))])
48+
condition = alltrue([for id in values(var.subscription_ids) : can(regex("^[0-9a-fA-F-]{36}$", id))])
4949
error_message = "All subscription IDs must be valid GUIDs"
5050
}
5151
validation {
52-
condition = length(var.subscription_ids) == 0 || alltrue([for id in keys(var.subscription_ids) : contains(["management", "connectivity", "identity", "security"], id)])
52+
condition = alltrue([for id in keys(var.subscription_ids) : contains(["management", "connectivity", "identity", "security"], id)])
5353
error_message = "The keys of the subscription_ids map must be one of 'management', 'connectivity', 'identity' or 'security'"
5454
}
55-
}
56-
57-
variable "subscription_id_connectivity" {
58-
description = <<-EOT
59-
**(Optional, default: `null`)** **DEPRECATED** (use subscription_ids instead)
60-
61-
The identifier of the Connectivity Subscription.
62-
EOT
63-
type = string
64-
default = null
65-
validation {
66-
condition = var.subscription_id_connectivity == null || can(regex("^[0-9a-fA-F-]{36}$", var.subscription_id_connectivity))
67-
error_message = "The bootstrap subscription ID must be a valid GUID"
68-
}
69-
}
70-
71-
variable "subscription_id_identity" {
72-
description = <<-EOT
73-
**(Optional, default: `null`)** **DEPRECATED** (use subscription_ids instead)
74-
75-
The identifier of the Identity Subscription.
76-
EOT
77-
type = string
78-
default = null
79-
validation {
80-
condition = var.subscription_id_identity == null || can(regex("^[0-9a-fA-F-]{36}$", var.subscription_id_identity))
81-
error_message = "The bootstrap subscription ID must be a valid GUID"
82-
}
83-
}
84-
85-
variable "subscription_id_management" {
86-
description = <<-EOT
87-
**(Optional, default: `null`)** **DEPRECATED** (use subscription_ids instead)
88-
89-
The identifier of the Management Subscription.
90-
EOT
91-
type = string
92-
default = null
9355
validation {
94-
condition = var.subscription_id_management == null || can(regex("^[0-9a-fA-F-]{36}$", var.subscription_id_management))
95-
error_message = "The bootstrap subscription ID must be a valid GUID"
56+
condition = contains(keys(var.subscription_ids), "management") && contains(keys(var.subscription_ids), "connectivity") && contains(keys(var.subscription_ids), "identity")
57+
error_message = "You must provide subscription IDs for: 'management', 'connectivity', and 'identity'"
9658
}
9759
}
9860

0 commit comments

Comments
 (0)