Skip to content

Commit

Permalink
Removed environmentName from the start of resources (Azure-Samples#539)
Browse files Browse the repository at this point in the history
* Removed environmentName from the start of resources

* Add backwards compatability

* Defaults should be new values if not found

* describe the manipulation of Service Service

* Line spacing
  • Loading branch information
ross-p-smith authored Mar 27, 2024
1 parent b759a0d commit 8a94caf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
16 changes: 8 additions & 8 deletions infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ param resourceToken string = toLower(uniqueString(subscription().id, environment
param location string

@description('Name of App Service plan')
param hostingPlanName string = '${environmentName}-hosting-plan-${resourceToken}'
param hostingPlanName string = 'hosting-plan-${resourceToken}'

@description('The pricing tier for the App Service plan')
@allowed([
Expand All @@ -34,7 +34,7 @@ param hostingPlanSku string = 'B3'
param websiteName string = 'web-${resourceToken}'

@description('Name of Application Insights')
param applicationInsightsName string = '${environmentName}-appinsights-${resourceToken}'
param applicationInsightsName string = 'appinsights-${resourceToken}'

@description('Use semantic search')
param azureSearchUseSemanticSearch string = 'false'
Expand Down Expand Up @@ -64,7 +64,7 @@ param azureSearchTitleColumn string = 'title'
param azureSearchUrlColumn string = 'url'

@description('Name of Azure OpenAI Resource')
param azureOpenAIResourceName string = '${environmentName}-openai-${resourceToken}'
param azureOpenAIResourceName string = 'openai-${resourceToken}'

@description('Name of Azure OpenAI Resource SKU')
param azureOpenAISkuName string = 'S0'
Expand Down Expand Up @@ -112,7 +112,7 @@ param azureOpenAIEmbeddingModel string = 'text-embedding-ada-002'
param azureOpenAIEmbeddingModelName string = 'text-embedding-ada-002'

@description('Azure AI Search Resource')
param azureAISearchName string = '${environmentName}-search-${resourceToken}'
param azureAISearchName string = 'search-${resourceToken}'

@description('The SKU of the search service you want to create. E.g. free or standard')
@allowed([
Expand All @@ -125,7 +125,7 @@ param azureAISearchName string = '${environmentName}-search-${resourceToken}'
param azureSearchSku string = 'standard'

@description('Azure AI Search Index')
param azureSearchIndex string = '${environmentName}-index-${resourceToken}'
param azureSearchIndex string = 'index-${resourceToken}'

@description('Azure AI Search Conversation Log Index')
param azureSearchConversationLogIndex string = 'conversations'
Expand All @@ -137,13 +137,13 @@ param storageAccountName string = 'str${resourceToken}'
param functionName string = 'backend-${resourceToken}'

@description('Azure Form Recognizer Name')
param formRecognizerName string = '${environmentName}-formrecog-${resourceToken}'
param formRecognizerName string = 'formrecog-${resourceToken}'

@description('Azure Content Safety Name')
param contentSafetyName string = '${environmentName}-contentsafety-${resourceToken}'
param contentSafetyName string = 'contentsafety-${resourceToken}'

@description('Azure Speech Service Name')
param speechServiceName string = '${environmentName}-speechservice-${resourceToken}'
param speechServiceName string = 'speech-${resourceToken}'

param newGuidString string = newGuid()
param searchTag string = 'chatwithyourdata-sa'
Expand Down
23 changes: 22 additions & 1 deletion infra/main.bicepparam
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,25 @@ param useKeyVault = bool(readEnvironmentVariable('USE_KEY_VAULT', 'true'))

param authType = readEnvironmentVariable('AZURE_AUTH_TYPE', 'keys')

param hostingModel = readEnvironmentVariable('AZURE_APP_SERVICE_HOSTING_MODEL', 'container')
param hostingModel = readEnvironmentVariable('AZURE_APP_SERVICE_HOSTING_MODEL', 'code')

// The following are being renamed to align with the new naming convention
// we manipulate existing resources here to maintain backwards compatibility

// We need the resourceToken to be unique for each deployment (copied from the main.bicep)
var subscriptionId = readEnvironmentVariable('AZURE_SUBSCRIPTION_ID', 'subscription_id')
param resourceToken = toLower(uniqueString(subscriptionId, environmentName, location))

// Retrieve the Search Name from the Search Endpoint which will be in the format
// "https://uniquename.search.windows.net/" It will end in a slash. Bicep forces us to have a default, so we use
// a default that we can manipulate in the same way to reduce another condition.
// length(azureAISearchEndpoint) - 9) cuts the https:// and the trailing slash. We then take the first "part" of
// the split which will be '' if there is no value set. If its null we assume the user is creating a new search
// service.
var azureAISearchEndpoint = readEnvironmentVariable('AZURE_SEARCH_SERVICE', 'https://./')
var searchServiceName = split(substring(azureAISearchEndpoint, 8, length(azureAISearchEndpoint) - 9), '.')[0]
param azureAISearchName = searchServiceName == '' ? 'search-${resourceToken}' : searchServiceName

param azureSearchIndex = readEnvironmentVariable('AZURE_SEARCH_INDEX', 'index-${resourceToken}')
param azureOpenAIResourceName = readEnvironmentVariable('AZURE_OPENAI_RESOURCE', 'openai-${resourceToken}')

18 changes: 9 additions & 9 deletions infra/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"_generator": {
"name": "bicep",
"version": "0.26.54.24096",
"templateHash": "13425064420748264745"
"templateHash": "15896839495287086142"
}
},
"parameters": {
Expand All @@ -29,7 +29,7 @@
},
"hostingPlanName": {
"type": "string",
"defaultValue": "[format('{0}-hosting-plan-{1}', parameters('environmentName'), parameters('resourceToken'))]",
"defaultValue": "[format('hosting-plan-{0}', parameters('resourceToken'))]",
"metadata": {
"description": "Name of App Service plan"
}
Expand Down Expand Up @@ -64,7 +64,7 @@
},
"applicationInsightsName": {
"type": "string",
"defaultValue": "[format('{0}-appinsights-{1}', parameters('environmentName'), parameters('resourceToken'))]",
"defaultValue": "[format('appinsights-{0}', parameters('resourceToken'))]",
"metadata": {
"description": "Name of Application Insights"
}
Expand Down Expand Up @@ -134,7 +134,7 @@
},
"azureOpenAIResourceName": {
"type": "string",
"defaultValue": "[format('{0}-openai-{1}', parameters('environmentName'), parameters('resourceToken'))]",
"defaultValue": "[format('openai-{0}', parameters('resourceToken'))]",
"metadata": {
"description": "Name of Azure OpenAI Resource"
}
Expand Down Expand Up @@ -240,7 +240,7 @@
},
"azureAISearchName": {
"type": "string",
"defaultValue": "[format('{0}-search-{1}', parameters('environmentName'), parameters('resourceToken'))]",
"defaultValue": "[format('search-{0}', parameters('resourceToken'))]",
"metadata": {
"description": "Azure AI Search Resource"
}
Expand All @@ -261,7 +261,7 @@
},
"azureSearchIndex": {
"type": "string",
"defaultValue": "[format('{0}-index-{1}', parameters('environmentName'), parameters('resourceToken'))]",
"defaultValue": "[format('index-{0}', parameters('resourceToken'))]",
"metadata": {
"description": "Azure AI Search Index"
}
Expand Down Expand Up @@ -289,21 +289,21 @@
},
"formRecognizerName": {
"type": "string",
"defaultValue": "[format('{0}-formrecog-{1}', parameters('environmentName'), parameters('resourceToken'))]",
"defaultValue": "[format('formrecog-{0}', parameters('resourceToken'))]",
"metadata": {
"description": "Azure Form Recognizer Name"
}
},
"contentSafetyName": {
"type": "string",
"defaultValue": "[format('{0}-contentsafety-{1}', parameters('environmentName'), parameters('resourceToken'))]",
"defaultValue": "[format('contentsafety-{0}', parameters('resourceToken'))]",
"metadata": {
"description": "Azure Content Safety Name"
}
},
"speechServiceName": {
"type": "string",
"defaultValue": "[format('{0}-speechservice-{1}', parameters('environmentName'), parameters('resourceToken'))]",
"defaultValue": "[format('speech-{0}', parameters('resourceToken'))]",
"metadata": {
"description": "Azure Speech Service Name"
}
Expand Down

0 comments on commit 8a94caf

Please sign in to comment.