Skip to content

Commit

Permalink
Remove collisionSuffix in favour of specifying a valid name (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
mburumaxwell authored Sep 22, 2023
1 parent d4149b7 commit 4d0b360
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
12 changes: 5 additions & 7 deletions server/main.bicep
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@description('Location for all resources.')
param location string = resourceGroup().location

@description('Name of the resources')
@description('Name of the resources. Make sure it is unique e.g. dependabotcontoso to avoid conflicts or failures')
param name string = 'dependabot'

@description('JSON array string fo projects to setup. E.g. [{"url":"https://dev.azure.com/tingle/dependabot","token":"dummy","AutoComplete":true}]')
Expand Down Expand Up @@ -31,8 +31,6 @@ var fileShares = [

var sqlServerAdministratorLogin = uniqueString(resourceGroup().id) // e.g. zecnx476et7xm (13 characters)
var sqlServerAdministratorLoginPassword = '${skip(uniqueString(resourceGroup().id), 5)}%${uniqueString('sql-password', resourceGroup().id)}' // e.g. abcde%zecnx476et7xm (19 characters)
// avoid conflicts across multiple deployments for resources that generate FQDN based on the name
var collisionSuffix = uniqueString(resourceGroup().id) // e.g. zecnx476et7xm (13 characters)
var queueNames = [
'process-synchronization'
'repository-created'
Expand Down Expand Up @@ -63,7 +61,7 @@ resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-

/* Service Bus namespace */
resource serviceBusNamespace 'Microsoft.ServiceBus/namespaces@2021-11-01' = {
name: '${name}-${collisionSuffix}'
name: name
location: location
properties: { disableLocalAuth: false, zoneRedundant: false }
sku: { name: 'Basic' }
Expand All @@ -73,7 +71,7 @@ resource serviceBusNamespace 'Microsoft.ServiceBus/namespaces@2021-11-01' = {

/* AppConfiguration */
resource appConfiguration 'Microsoft.AppConfiguration/configurationStores@2023-03-01' = {
name: '${name}-${collisionSuffix}'
name: name
location: location
properties: { softDeleteRetentionInDays: 0 /* Free does not support this */ }
sku: { name: 'free' }
Expand All @@ -87,7 +85,7 @@ resource appConfiguration 'Microsoft.AppConfiguration/configurationStores@2023-0

/* Storage Account */
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {
name: '${name}${collisionSuffix}' // hyphens not allowed
name: name
location: location
kind: 'StorageV2'
sku: { name: 'Standard_LRS' }
Expand Down Expand Up @@ -119,7 +117,7 @@ resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {

/* SQL Server */
resource sqlServer 'Microsoft.Sql/servers@2022-05-01-preview' = {
name: '${name}-${collisionSuffix}'
name: name
location: location
properties: {
publicNetworkAccess: 'Enabled'
Expand Down
47 changes: 23 additions & 24 deletions server/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"type": "string",
"defaultValue": "dependabot",
"metadata": {
"description": "Name of the resources"
"description": "Name of the resources. Make sure it is unique e.g. dependabotcontoso to avoid conflicts or failures"
}
},
"projectSetups": {
Expand Down Expand Up @@ -66,7 +66,7 @@
"custom": {
"type": "azure-servicebus",
"metadata": {
"namespace": "[format('{0}-{1}', parameters('name'), variables('collisionSuffix'))]",
"namespace": "[parameters('name')]",
"queueName": "[variables('queueNames')[copyIndex('queueScaleRules')]]",
"messageCount": "100"
},
Expand Down Expand Up @@ -95,7 +95,6 @@
],
"sqlServerAdministratorLogin": "[uniqueString(resourceGroup().id)]",
"sqlServerAdministratorLoginPassword": "[format('{0}%{1}', skip(uniqueString(resourceGroup().id), 5), uniqueString('sql-password', resourceGroup().id))]",
"collisionSuffix": "[uniqueString(resourceGroup().id)]",
"queueNames": [
"process-synchronization",
"repository-created",
Expand All @@ -114,13 +113,13 @@
},
"type": "Microsoft.Storage/storageAccounts/fileServices/shares",
"apiVersion": "2022-09-01",
"name": "[format('{0}/{1}/{2}', format('{0}{1}', parameters('name'), variables('collisionSuffix')), 'default', variables('fileShares')[copyIndex()].name)]",
"name": "[format('{0}/{1}/{2}', parameters('name'), 'default', variables('fileShares')[copyIndex()].name)]",
"properties": {
"accessTier": "[if(contains(variables('fileShares')[copyIndex()], 'accessTier'), variables('fileShares')[copyIndex()].accessTier, 'TransactionOptimized')]",
"shareQuota": "[if(contains(variables('fileShares')[copyIndex()], 'shareQuota'), variables('fileShares')[copyIndex()].shareQuota, 1)]"
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', format('{0}{1}', parameters('name'), variables('collisionSuffix')))]"
"[resourceId('Microsoft.Storage/storageAccounts', parameters('name'))]"
]
},
{
Expand All @@ -133,15 +132,15 @@
"name": "[format('{0}/{1}', parameters('name'), variables('fileShares')[copyIndex()].name)]",
"properties": {
"azureFile": {
"accountName": "[format('{0}{1}', parameters('name'), variables('collisionSuffix'))]",
"accountKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', format('{0}{1}', parameters('name'), variables('collisionSuffix'))), '2022-09-01').keys[0].value]",
"accountName": "[parameters('name')]",
"accountKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('name')), '2022-09-01').keys[0].value]",
"shareName": "[variables('fileShares')[copyIndex()].name]",
"accessMode": "[if(and(contains(variables('fileShares')[copyIndex()], 'writeable'), bool(variables('fileShares')[copyIndex()].writeable)), 'ReadWrite', 'ReadOnly')]"
}
},
"dependsOn": [
"[resourceId('Microsoft.App/managedEnvironments', parameters('name'))]",
"[resourceId('Microsoft.Storage/storageAccounts', format('{0}{1}', parameters('name'), variables('collisionSuffix')))]"
"[resourceId('Microsoft.Storage/storageAccounts', parameters('name'))]"
]
},
{
Expand All @@ -153,7 +152,7 @@
{
"type": "Microsoft.ServiceBus/namespaces",
"apiVersion": "2021-11-01",
"name": "[format('{0}-{1}', parameters('name'), variables('collisionSuffix'))]",
"name": "[parameters('name')]",
"location": "[parameters('location')]",
"properties": {
"disableLocalAuth": false,
Expand All @@ -166,7 +165,7 @@
{
"type": "Microsoft.AppConfiguration/configurationStores",
"apiVersion": "2023-03-01",
"name": "[format('{0}-{1}', parameters('name'), variables('collisionSuffix'))]",
"name": "[parameters('name')]",
"location": "[parameters('location')]",
"properties": {
"softDeleteRetentionInDays": 0
Expand All @@ -187,7 +186,7 @@
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2022-09-01",
"name": "[format('{0}{1}', parameters('name'), variables('collisionSuffix'))]",
"name": "[parameters('name')]",
"location": "[parameters('location')]",
"kind": "StorageV2",
"sku": {
Expand All @@ -206,7 +205,7 @@
{
"type": "Microsoft.Sql/servers",
"apiVersion": "2022-05-01-preview",
"name": "[format('{0}-{1}', parameters('name'), variables('collisionSuffix'))]",
"name": "[parameters('name')]",
"location": "[parameters('location')]",
"properties": {
"publicNetworkAccess": "Enabled",
Expand All @@ -228,19 +227,19 @@
{
"type": "Microsoft.Sql/servers/firewallRules",
"apiVersion": "2022-08-01-preview",
"name": "[format('{0}/{1}', format('{0}-{1}', parameters('name'), variables('collisionSuffix')), 'AllowAllWindowsAzureIps')]",
"name": "[format('{0}/{1}', parameters('name'), 'AllowAllWindowsAzureIps')]",
"properties": {
"endIpAddress": "0.0.0.0",
"startIpAddress": "0.0.0.0"
},
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', format('{0}-{1}', parameters('name'), variables('collisionSuffix')))]"
"[resourceId('Microsoft.Sql/servers', parameters('name'))]"
]
},
{
"type": "Microsoft.Sql/servers/databases",
"apiVersion": "2022-05-01-preview",
"name": "[format('{0}/{1}', format('{0}-{1}', parameters('name'), variables('collisionSuffix')), parameters('name'))]",
"name": "[format('{0}/{1}', parameters('name'), parameters('name'))]",
"location": "[parameters('location')]",
"sku": {
"name": "Basic"
Expand All @@ -262,7 +261,7 @@
},
"dependsOn": [
"[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', parameters('name'))]",
"[resourceId('Microsoft.Sql/servers', format('{0}-{1}', parameters('name'), variables('collisionSuffix')))]"
"[resourceId('Microsoft.Sql/servers', parameters('name'))]"
]
},
{
Expand Down Expand Up @@ -340,11 +339,11 @@
},
{
"name": "connection-strings-sql",
"value": "[join(createArray(format('Server=tcp:{0},1433', reference(resourceId('Microsoft.Sql/servers', format('{0}-{1}', parameters('name'), variables('collisionSuffix'))), '2022-05-01-preview').fullyQualifiedDomainName), format('Initial Catalog={0}', parameters('name')), format('User ID={0}', variables('sqlServerAdministratorLogin')), format('Password={0}', variables('sqlServerAdministratorLoginPassword')), 'Persist Security Info=False', 'MultipleActiveResultSets=False', 'Encrypt=True', 'TrustServerCertificate=False', 'Connection Timeout=30'), ';')]"
"value": "[join(createArray(format('Server=tcp:{0},1433', reference(resourceId('Microsoft.Sql/servers', parameters('name')), '2022-05-01-preview').fullyQualifiedDomainName), format('Initial Catalog={0}', parameters('name')), format('User ID={0}', variables('sqlServerAdministratorLogin')), format('Password={0}', variables('sqlServerAdministratorLoginPassword')), 'Persist Security Info=False', 'MultipleActiveResultSets=False', 'Encrypt=True', 'TrustServerCertificate=False', 'Connection Timeout=30'), ';')]"
},
{
"name": "connection-strings-asb-scaler",
"value": "[listKeys(resourceId('Microsoft.ServiceBus/namespaces/AuthorizationRules', format('{0}-{1}', parameters('name'), variables('collisionSuffix')), 'RootManageSharedAccessKey'), '2021-11-01').primaryConnectionString]"
"value": "[listKeys(resourceId('Microsoft.ServiceBus/namespaces/AuthorizationRules', parameters('name'), 'RootManageSharedAccessKey'), '2021-11-01').primaryConnectionString]"
}
]
},
Expand Down Expand Up @@ -382,7 +381,7 @@
},
{
"name": "AzureAppConfig__Endpoint",
"value": "[reference(resourceId('Microsoft.AppConfiguration/configurationStores', format('{0}-{1}', parameters('name'), variables('collisionSuffix'))), '2023-03-01').endpoint]"
"value": "[reference(resourceId('Microsoft.AppConfiguration/configurationStores', parameters('name')), '2023-03-01').endpoint]"
},
{
"name": "AzureAppConfig__Label",
Expand Down Expand Up @@ -466,7 +465,7 @@
},
{
"name": "EventBus__Transports__azure-service-bus__FullyQualifiedNamespace",
"value": "[split(split(reference(resourceId('Microsoft.ServiceBus/namespaces', format('{0}-{1}', parameters('name'), variables('collisionSuffix'))), '2021-11-01').serviceBusEndpoint, '/')[2], ':')[0]]"
"value": "[split(split(reference(resourceId('Microsoft.ServiceBus/namespaces', parameters('name')), '2021-11-01').serviceBusEndpoint, '/')[2], ':')[0]]"
}
],
"resources": {
Expand Down Expand Up @@ -520,14 +519,14 @@
}
},
"dependsOn": [
"[resourceId('Microsoft.AppConfiguration/configurationStores', format('{0}-{1}', parameters('name'), variables('collisionSuffix')))]",
"[resourceId('Microsoft.AppConfiguration/configurationStores', parameters('name'))]",
"[resourceId('Microsoft.App/managedEnvironments', parameters('name'))]",
"[resourceId('Microsoft.Insights/components', parameters('name'))]",
"[resourceId('Microsoft.OperationalInsights/workspaces', parameters('name'))]",
"[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', parameters('name'))]",
"[resourceId('Microsoft.ServiceBus/namespaces', format('{0}-{1}', parameters('name'), variables('collisionSuffix')))]",
"[resourceId('Microsoft.Sql/servers', format('{0}-{1}', parameters('name'), variables('collisionSuffix')))]",
"[resourceId('Microsoft.Sql/servers/databases', format('{0}-{1}', parameters('name'), variables('collisionSuffix')), parameters('name'))]"
"[resourceId('Microsoft.ServiceBus/namespaces', parameters('name'))]",
"[resourceId('Microsoft.Sql/servers', parameters('name'))]",
"[resourceId('Microsoft.Sql/servers/databases', parameters('name'), parameters('name'))]"
]
},
{
Expand Down

0 comments on commit 4d0b360

Please sign in to comment.