Skip to content

Commit 396e72e

Browse files
Harmanpreet-MicrosoftHarmanpreet KaurAbdul-Microsoft
authored
ci: improve Azure infrastructure template pipeline workflow (#89)
* feat: Set default values for AI embedding and chat model deployments in main.bicep * fix: Update Cosmos DB module version and correct local authentication parameter * fix: Correct Cosmos DB module version and update local authentication parameter * fix for azd pipeline issue * fix for azd pipeline issue * fix for deployment pipeline issue * psrule fix * psrule fix issue for sql * psrule fix * fix: add secure attribute to administratorLoginCredential and update privateDnsZone reference * fix: suppress PSRule warning for location output in SQL Server deployment * fix: remove PSRule suppression comments for location output in SQL Server deployment * fix: update PSRule suppression comments for SQL Server module output exposure * fix: add PSRule configuration for SQL Server module output suppression * fix: add PSRule configuration to suppress false positive AZR-000279 for SQL Server deployments * fix: add PSRule configurations to suppress false positives for SQL Server deployments * fix: add PSRule suppression for AVM SQL Server module output to ignore non-sensitive data * fix: update virtual machine configuration to use 'adminPassword' variable for admin password * fix: update virtual machine configuration to use 'vmAdminPasswordOrKey' for admin password * fix: validate VM admin password length in main.bicep and simplify virtual machine module * fix: update SQL Server module to use hardcoded administrator login password for testing purposes * fix: update SQL Server module to use parameterized administrator login password * fix: set default values for deployment parameters in main.bicep and main.parameters.json * fix: add parameters for network isolation and private DNS zone configuration in cognitive services module * fix: remove PSRule configuration files to eliminate false positives with SQL Server module * fix: add deployerPrincipalType parameter to support different deployment principals in Bicep files * fix: add Azure login and resource group creation steps for template validation workflow * fix: remove resource group cleanup step and set deployer principal type for Azure login * fix: remove default values for various parameters to enforce explicit configuration * fix: set default value for sqlServerEnabled parameter to false * fix: add default values for infrastructure parameters in Azure workflows * fix: update infrastructure parameters for Azure workflows to enable AI search and Cosmos DB * fix: update AI feature flags and network isolation parameter for Azure deployment * fix: enable AI search and Cosmos DB features in deployment configuration * fix: update sqlServer module to use administratorLoginPassword instead of administratorLoginCredential * Refactor cognitive services Bicep module to separate private endpoint creation - Changed variable name from `privateDnsZones` to `privateDnsZoneConfigs` for clarity. - Removed private endpoints from the initial deployment to avoid timing issues. - Created a separate module for the private endpoint with explicit dependency on the cognitive service. - Updated private link service connection properties to align with new structure. * refactor: remove unused parameters for AI deployments and network isolation * refactor: add aiDeploymentsLocation and networkIsolation parameters * refactor: remove unused infrastructure parameters from azure-dev.yml * refactor: update deployerPrincipalType parameter to determine type based on deployment context --------- Co-authored-by: Harmanpreet Kaur <v-harmanpkau@microsoft.com> Co-authored-by: Abdul-Microsoft <v-amujeebta@microsoft.com>
1 parent c8537ef commit 396e72e

File tree

8 files changed

+14524
-9209
lines changed

8 files changed

+14524
-9209
lines changed

.github/workflows/azd-template-validation.yml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v4
1919

20+
- name: Azure Login
21+
uses: azure/login@v2
22+
with:
23+
client-id: ${{ vars.AZURE_CLIENT_ID }}
24+
tenant-id: ${{ vars.AZURE_TENANT_ID }}
25+
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
26+
27+
- name: Create Resource Group for Validation
28+
run: |
29+
ENV_NAME="${{ vars.AZURE_ENV_NAME }}"
30+
RG_NAME="rg-${ENV_NAME}"
31+
echo "Creating resource group for template validation: ${RG_NAME}"
32+
az group create \
33+
--name "${RG_NAME}" \
34+
--location "${{ vars.AZURE_LOCATION }}" \
35+
--tags "CreatedBy=GitHubActions"
36+
echo "Resource group ${RG_NAME} created successfully"
37+
2038
- uses: microsoft/template-validation-action@Latest
2139
with:
2240
validateAzd: ${{ vars.TEMPLATE_VALIDATE_AZD }}
@@ -28,7 +46,26 @@ jobs:
2846
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
2947
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
3048
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
49+
AZURE_RESOURCE_GROUP: rg-${{ vars.AZURE_ENV_NAME }}
3150
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
# Set correct principal type for GitHub Actions ServicePrincipal
52+
AZURE_DEPLOYER_PRINCIPAL_TYPE: ServicePrincipal
53+
# Infrastructure parameter defaults for pipeline
54+
AZURE_ACR_ENABLED: 'false'
55+
AZURE_API_MANAGEMENT_ENABLED: 'false'
56+
AZURE_AI_CONTENT_SAFETY_ENABLED: 'false'
57+
AZURE_AI_DOC_INTELLIGENCE_ENABLED: 'false'
58+
AZURE_AI_LANGUAGE_ENABLED: 'false'
59+
AZURE_AI_SEARCH_ENABLED: 'true'
60+
AZURE_AI_SPEECH_ENABLED: 'false'
61+
AZURE_AI_TRANSLATOR_ENABLED: 'false'
62+
63+
AZURE_AI_VISION_ENABLED: 'false'
64+
AZURE_APP_SAMPLE_ENABLED: 'false'
65+
AZURE_COSMOS_DB_ENABLED: 'true'
66+
AZURE_NETWORK_ISOLATION: 'false'
67+
AZURE_SQL_SERVER_ENABLED: 'false'
68+
AZURE_AI_DEPLOYMENTS_LOCATION: ${{ vars.AZURE_LOCATION }}
3269

3370
- name: print result
34-
run: cat ${{ steps.validation.outputs.resultFile }}
71+
run: cat ${{ steps.validation.outputs.resultFile }}

infra/main.bicep

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
targetScope = 'resourceGroup'
22

3+
34
@minLength(3)
45
@maxLength(12)
56
@description('The name of the environment/application. Use alphanumeric characters only.')
@@ -10,10 +11,20 @@ param name string
1011
param location string
1112

1213
@description('Specifies the AI embedding model to use for the AI Foundry deployment. This is the model used for text embeddings in AI Foundry. NOTE: Any adjustments to this parameter\'s values must also be made on the aiDeploymentsLocation metadata in the main.bicep file.')
13-
param aiEmbeddingModelDeployment modelDeploymentType
14+
param aiEmbeddingModelDeployment modelDeploymentType = {
15+
name: 'text-embedding-3-small'
16+
modelName: 'text-embedding-3-small'
17+
version: '1'
18+
capacity: 100
19+
}
1420

1521
@description('Specifies the AI chat model to use for the AI Foundry deployment. This is the model used for chat interactions in AI Foundry. NOTE: Any adjustments to this parameter\'s values must also be made on the aiDeploymentsLocation metadata in the main.bicep file.')
16-
param aiGPTModelDeployment modelDeploymentType
22+
param aiGPTModelDeployment modelDeploymentType = {
23+
name: 'gpt-4o'
24+
modelName: 'gpt-4o'
25+
version: '2024-05-13'
26+
capacity: 150
27+
}
1728

1829
@metadata({
1930
azd: {
@@ -28,7 +39,7 @@ param aiGPTModelDeployment modelDeploymentType
2839
param aiDeploymentsLocation string
2940

3041
@description('Specifies whether creating an Azure Container Registry.')
31-
param acrEnabled bool
42+
param acrEnabled bool
3243

3344
@description('Specifies the size of the jump-box Virtual Machine.')
3445
param vmSize string = 'Standard_DS4_v2'
@@ -50,26 +61,28 @@ param tags object = {}
5061
@description('Specifies the object id of a Microsoft Entra ID user. In general, this the object id of the system administrator who deploys the Azure resources. This defaults to the deploying user.')
5162
param userObjectId string = deployer().objectId
5263

64+
@description('The type of principal that is deploying the resources. Use "User" for interactive deployment and "ServicePrincipal" for automated deployment.')
65+
param deployerPrincipalType string = contains(deployer(), 'userPrincipalName') ? 'User' : 'ServicePrincipal'
5366
@description('Optional IP address to allow access to the jump-box VM. This is necessary to provide secure access to the private VNET via a jump-box VM with Bastion. If not specified, all IP addresses are allowed.')
5467
param allowedIpAddress string = ''
5568

5669
@description('Specifies if Microsoft APIM is deployed.')
57-
param apiManagementEnabled bool
70+
param apiManagementEnabled bool
5871

5972
@description('Specifies the publisher email for the API Management service. Defaults to admin@[name].com.')
6073
param apiManagementPublisherEmail string = 'admin@${name}.com'
6174

6275
@description('Specifies whether network isolation is enabled. When true, Foundry and related components will be deployed, network access parameters will be set to Disabled.')
63-
param networkIsolation bool
76+
param networkIsolation bool
6477

6578
@description('Whether to include Cosmos DB in the deployment.')
66-
param cosmosDbEnabled bool
79+
param cosmosDbEnabled bool
6780

6881
@description('Optional. List of Cosmos DB databases to deploy.')
6982
param cosmosDatabases sqlDatabaseType[] = []
7083

7184
@description('Whether to include SQL Server in the deployment.')
72-
param sqlServerEnabled bool
85+
param sqlServerEnabled bool = false
7386

7487
@description('Optional. List of SQL Server databases to deploy.')
7588
param sqlServerDatabases databasePropertyType[] = []
@@ -90,7 +103,7 @@ param languageEnabled bool
90103
param speechEnabled bool
91104

92105
@description('Whether to include Azure AI Translator in the deployment.')
93-
param translatorEnabled bool
106+
param translatorEnabled bool
94107

95108
@description('Whether to include Azure Document Intelligence in the deployment.')
96109
param documentIntelligenceEnabled bool
@@ -105,7 +118,7 @@ param networkAcls object = {
105118
param projectName string = '${take(name, 8)}proj'
106119

107120
@description('Whether to include the sample app in the deployment. NOTE: Cosmos and Search must also be enabled and Auth Client ID and Secret must be provided.')
108-
param appSampleEnabled bool
121+
param appSampleEnabled bool
109122

110123
@description('Client id for registered application in Entra for use with app authentication.')
111124
param authClientId string?
@@ -131,6 +144,10 @@ var resourceToken = substring(uniqueString(subscription().id, location, name), 0
131144
var sanitizedName = toLower(replace(replace(replace(replace(replace(replace(replace(replace(replace(name, '@', ''), '#', ''), '$', ''), '!', ''), '-', ''), '_', ''), '.', ''), ' ', ''), '&', ''))
132145
var servicesUsername = take(replace(vmAdminUsername,'.', ''), 20)
133146

147+
// VM Admin Password validation - ensure minimum 8 characters
148+
var randomString = uniqueString(resourceGroup().id, name, vmAdminPasswordOrKey)
149+
var validatedVmAdminPassword = (length(vmAdminPasswordOrKey) < 8) ? '${vmAdminPasswordOrKey}${take(randomString, 12)}' : vmAdminPasswordOrKey
150+
134151
var deploySampleApp = appSampleEnabled && cosmosDbEnabled && searchEnabled && !empty(authClientId) && !empty(authClientSecret) && !empty(cosmosDatabases) && !empty(aiGPTModelDeployment) && length(aiEmbeddingModelDeployment) >= 2
135152
var authClientSecretName = 'auth-client-secret'
136153

@@ -194,7 +211,7 @@ module keyvault 'modules/keyvault.bicep' = {
194211
roleAssignments: concat(empty(userObjectId) ? [] : [
195212
{
196213
principalId: userObjectId
197-
principalType: 'User'
214+
principalType: deployerPrincipalType
198215
roleDefinitionIdOrName: 'Key Vault Secrets User'
199216
}
200217
], deploySampleApp ? [
@@ -239,7 +256,7 @@ module storageAccount 'modules/storageAccount.bicep' = {
239256
roleAssignments: concat(empty(userObjectId) ? [] : [
240257
{
241258
principalId: userObjectId
242-
principalType: 'User'
259+
principalType: deployerPrincipalType
243260
roleDefinitionIdOrName: 'Storage Blob Data Contributor'
244261
}
245262
], [
@@ -286,6 +303,7 @@ module cognitiveServices 'modules/cognitive-services/cognitiveServices.bicep' =
286303
}
287304
]
288305
userObjectId: userObjectId
306+
deployerPrincipalType: deployerPrincipalType
289307
contentSafetyEnabled: contentSafetyEnabled
290308
visionEnabled: visionEnabled
291309
languageEnabled: languageEnabled
@@ -323,12 +341,12 @@ module aiSearch 'modules/aisearch.bicep' = if (searchEnabled) {
323341
roleAssignments: union(empty(userObjectId) ? [] : [
324342
{
325343
principalId: userObjectId
326-
principalType: 'User'
344+
principalType: deployerPrincipalType
327345
roleDefinitionIdOrName: 'Search Index Data Contributor'
328346
}
329347
{
330348
principalId: userObjectId
331-
principalType: 'User'
349+
principalType: deployerPrincipalType
332350
roleDefinitionIdOrName: 'Search Index Data Reader'
333351
}
334352
], [
@@ -361,7 +379,7 @@ module virtualMachine './modules/virtualMachine.bicep' = if (networkIsolation)
361379
imageSku: 'win11-23h2-ent'
362380
authenticationType: 'password'
363381
vmAdminUsername: servicesUsername
364-
vmAdminPasswordOrKey: vmAdminPasswordOrKey
382+
vmAdminPasswordOrKey: validatedVmAdminPassword
365383
diskStorageAccountType: 'Premium_LRS'
366384
numDataDisks: 1
367385
osDiskSize: 128

0 commit comments

Comments
 (0)