Skip to content

Commit 523bfe8

Browse files
committed
Updated ADF templates
1 parent c8ce081 commit 523bfe8

File tree

2 files changed

+137
-1
lines changed

2 files changed

+137
-1
lines changed

Deployment/Deploy-Resources.ps1

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,105 @@ function Start-FunctionApps {
840840
}
841841
}
842842

843+
function Update-AppSettingsVersion {
844+
param (
845+
[Parameter(Mandatory = $true)]
846+
[string]$ComputeResourceGroupName
847+
)
848+
849+
Write-Host "`nChecking function app settings"
850+
$functionApps = Get-AzFunctionApp -ResourceGroupName $ComputeResourceGroupName
851+
foreach ($function in $functionApps) {
852+
853+
$settings = Get-AzFunctionAppSetting -ResourceGroupName $ComputeResourceGroupName -Name $function.Name
854+
foreach ($key in $settings.Keys) {
855+
if (-not ($settings[$key].Contains("Microsoft.KeyVault"))) {
856+
continue
857+
}
858+
859+
$kvReference = Get-KeyVaultReference -KeyVaultReference $settings[$key]
860+
$latestSecretVersion = Get-AzKeyVaultSecret -VaultName $kvReference.KeyVaultName -Name $kvReference.SecretName
861+
862+
if ($latestSecretVersion.Version -ne $kvReference.Version) {
863+
Write-Host "Updating $($function.Name) -> $($kvReference.SecretName) to $($latestSecretVersion.Version)"
864+
$updatedVersion = $settings[$key] -replace $version, $latestSecretVersion.Version
865+
$updatedSettings = Update-AzFunctionAppSetting -Name $function.Name -ResourceGroupName $ComputeResourceGroupName -AppSetting @{$key = $updatedVersion }
866+
}
867+
}
868+
}
869+
870+
Write-Host "`nChecking web app settings"
871+
$webApps = Get-AzWebApp -ResourceGroupName $ComputeResourceGroupName | Where-Object { $_.Kind -eq "app" }
872+
foreach ($webApp in $webApps) {
873+
874+
$hasUpdates = $false
875+
876+
foreach ($keyPair in $webApp.SiteConfig.AppSettings) {
877+
878+
$key = $keyPair.Name
879+
$value = $keyPair.Value
880+
881+
if (-not ($value.Contains("Microsoft.KeyVault"))) {
882+
continue
883+
}
884+
885+
$kvReference = Get-KeyVaultReference -KeyVaultReference $value
886+
$latestSecretVersion = Get-AzKeyVaultSecret -VaultName $kvReference.KeyVaultName -Name $kvReference.SecretName
887+
888+
if ($latestSecretVersion.Version -ne $kvReference.Version) {
889+
Write-Host "Updating $($webApp.Name) -> $key to $($latestSecretVersion.Version)"
890+
$updatedVersion = $value -replace $kvReference.Version, $latestSecretVersion.Version
891+
892+
$appSettings = $webApp.SiteConfig.AppSettings
893+
$settingsCount = $appSettings.Count
894+
for ($i = 0; $i -lt $settingsCount; $i++) {
895+
if ($appSettings[$i].Name -eq $key) {
896+
$appSettings[$i].Value = $updatedVersion
897+
break
898+
}
899+
}
900+
901+
$hasUpdates = $true
902+
}
903+
}
904+
905+
if ($hasUpdates) {
906+
$updatedSettings = @{}
907+
foreach ($setting in $webApp.SiteConfig.AppSettings) {
908+
$updatedSettings[$setting.Name] = $setting.Value
909+
}
910+
911+
Set-AzWebApp -ResourceGroupName $ComputeResourceGroupName -Name $webApp.Name -AppSettings $updatedSettings
912+
}
913+
914+
}
915+
}
916+
917+
function Get-KeyVaultReference {
918+
param (
919+
[Parameter(Mandatory = $true)]
920+
[string]$KeyVaultReference
921+
)
922+
923+
$keyVaultNamePattern = "SecretUri=https://(?<kvName>.*?)\.vault"
924+
$kvMatch = [regex]::Match($KeyVaultReference, $keyVaultNamePattern)
925+
$kvName = $kvMatch.Groups["kvName"].Value
926+
927+
$secretNamePattern = "secrets/(?<secret>.*?)/"
928+
$secretNameMatch = [regex]::Match($KeyVaultReference, $secretNamePattern)
929+
$secretName = $secretNameMatch.Groups["secret"].Value
930+
931+
$pattern = "$secretName/(?<version>.*)\)"
932+
$match = [regex]::Match($KeyVaultReference, $pattern)
933+
$version = $match.Groups["version"].Value
934+
935+
return @{
936+
KeyVaultName = $kvName;
937+
SecretName = $secretName;
938+
Version = $version;
939+
}
940+
}
941+
843942
function Set-GMMAppRegistrations {
844943
[CmdletBinding()]
845944
param(
@@ -1114,6 +1213,8 @@ function Deploy-Resources {
11141213

11151214
Start-Sleep -Seconds 30
11161215

1216+
Update-AppSettingsVersion -ComputeResourceGroupName $computeResourceGroup
1217+
11171218
Disable-KeyVaultFirewallRules -ResourceGroups $resourceGroups
11181219

11191220
Set-SqlServerFirewallRule `
@@ -1195,6 +1296,7 @@ function Deploy-Resources {
11951296
# open the web app
11961297
$staticWebApp = Get-AzStaticWebApp -Name "$SolutionAbbreviation-ui" -ResourceGroupName $computeResourceGroup
11971298
if ($null -ne $staticWebApp) {
1299+
Write-Host "`nOpening UI in browser, url: https://$($staticWebApp.DefaultHostname)"
11981300
Start-Process "https://$($staticWebApp.DefaultHostname)"
11991301
}
12001302
}

Infrastructure/adf/pipeline/azureDataFactory.bicep

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,43 @@ resource Pipeline_PopulateDestinationPipeline 'Microsoft.DataFactory/factories/p
9595
name: '${factoryName}/PopulateDestinationPipeline'
9696
properties: {
9797
activities: [
98+
{
99+
name: 'Create users schema'
100+
type: 'Script'
101+
dependsOn: []
102+
policy: {
103+
timeout: '0.12:00:00'
104+
retry: 0
105+
retryIntervalInSeconds: 30
106+
secureOutput: false
107+
secureInput: false
108+
}
109+
userProperties: []
110+
linkedServiceName: {
111+
referenceName: 'DestinationDatabase'
112+
type: 'LinkedServiceReference'
113+
}
114+
typeProperties: {
115+
scripts: [
116+
{
117+
type: 'Query'
118+
text: 'IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = \'users\')\nBEGIN\n EXEC (\'CREATE SCHEMA users AUTHORIZATION dbo;\')\n PRINT \'Schema Created\'\nEND'
119+
}
120+
]
121+
scriptBlockExecutionTimeout: '02:00:00'
122+
}
123+
}
98124
{
99125
name: 'AzureUserReader'
100126
type: 'AzureFunctionActivity'
101-
dependsOn: []
127+
dependsOn: [
128+
{
129+
activity: 'Create users schema'
130+
dependencyConditions: [
131+
'Succeeded'
132+
]
133+
}
134+
]
102135
policy: {
103136
timeout: '0.12:00:00'
104137
retry: 0
@@ -191,6 +224,7 @@ resource dataSet_DestinationTable 'Microsoft.DataFactory/factories/datasets@2018
191224
type: 'AzureSqlTable'
192225
schema: []
193226
typeProperties: {
227+
schema: 'users'
194228
table: {
195229
value: '@replace(pipeline().RunId,\'-\',\'\')'
196230
type: 'Expression'

0 commit comments

Comments
 (0)