@@ -399,6 +399,110 @@ Task -Name "Set-Arm.Connections.ManagedApis.AzureBlob.ManagedIdentity.AsArmObjec
399399 Out-TaskFileArm - InputObject $armObj
400400}
401401
402+ # Original file: Set-Arm.Connections.ManagedApis.AzureSql.ManagedIdentity.AsArmObject.task.ps1
403+ $parm = @ {
404+ Description = @"
405+ Loops all `$ connections children
406+ -Validates that is of the type SQL and is using the Managed Identity authentication scheme
407+ --Creates a new resource in the ARM template, for the ApiConnection object
408+ --Makes sure the ARM Parameters logicAppLocation exists
409+ --The type is based on the Managed Identity authentication
410+ --Name & Displayname is extracted from the ConnectionName property
411+ Requires an authenticated session, either Az.Accounts or az cli
412+ "@
413+ Alias = " Arm.Set-Arm.Connections.ManagedApis.AzureSql.ManagedIdentity.AsArmObject"
414+ }
415+
416+ Task - Name " Set-Arm.Connections.ManagedApis.AzureSql.ManagedIdentity.AsArmObject" @parm - Action {
417+ Set-TaskWorkDirectory
418+
419+ # We can either use the az cli or the Az modules
420+ $tools = Get-PSFConfigValue - FullName PsLogicAppExtractor.Execution.Tools
421+
422+ $found = $false
423+ $conType = " sql"
424+
425+ $armObj = Get-TaskWorkObject
426+
427+ foreach ($connectionObj in $armObj.resources [0 ].properties.parameters.' $connections' .value.PsObject.Properties) {
428+ if ($connectionObj.Value.id -like " *managedApis/sql*" ) {
429+
430+ # This should only handle Managed Identity Servicebus connections
431+ if ($connectionObj.Value.connectionProperties.authentication.type -ne " ManagedServiceIdentity" ) { continue }
432+
433+ $found = $true
434+
435+ # Fetch the details from the connection object
436+ $uri = " {0}?api-version=2018-07-01-preview" -f $ ($connectionObj.Value.connectionId )
437+
438+ if ($tools -eq " AzCli" ) {
439+ $resObj = az rest -- url $uri | ConvertFrom-Json
440+ }
441+ else {
442+ $resObj = Invoke-AzRestMethod - Path $uri - Method Get | Select-Object - ExpandProperty content | ConvertFrom-Json
443+ }
444+
445+ # Use the display name as the name of the resource
446+ $conName = $resObj.Properties.DisplayName
447+ $resName = $resObj.Properties.DisplayName # fallback default value
448+
449+ # Fetch base template
450+ $pathArms = " $ ( Get-PSFConfigValue - FullName PsLogicAppExtractor.ModulePath.Base) \internal\arms"
451+ $apiObj = Get-Content - Path " $pathArms \API.Sql.Managed.json" - Raw | ConvertFrom-Json
452+
453+ # Set the names of the parameters
454+ $Prefix = Get-PSFConfigValue - FullName PsLogicAppExtractor.prefixsuffix.connection.prefix
455+ $idPreSuf = Format-Name - Type " Connection" - Value " $ ( $connectionObj.Name ) "
456+
457+ <# ! Needs work if we want to extract it from the first action that uses the connection
458+ # $nsPreSuf = Format-Name -Type "Connection" -Prefix $Prefix -Suffix "_Server" -Value "$($connectionObj.Name)"
459+ # $armObj = Add-ArmParameter -InputObject $armObj -Name "$nsPreSuf" `
460+ # -Type "string" `
461+ # -Value "$resName" `
462+ # -Description "The name/address of the Azure SQL Server (instance). ($($connectionObj.Name))"
463+ #>
464+
465+ $armObj = Add-ArmParameter - InputObject $armObj - Name " $idPreSuf " `
466+ - Type " string" `
467+ - Value $conName `
468+ - Description " The name / id of the ManagedApi connection object that is being utilized by the Logic App. Will be for the trigger and other actions that depend on connections."
469+
470+ # Update the api object properties
471+ $apiObj.Name = " [parameters('$idPreSuf ')]"
472+ $apiObj.properties.displayName = " [parameters('$idPreSuf ')]"
473+
474+ # Append the new resource to the ARM template
475+ $armObj.resources += $apiObj
476+
477+ if ($null -eq $armObj.resources [0 ].dependsOn) {
478+ # Create the dependsOn array if it does not exist
479+ $armObj.resources [0 ] | Add-Member - MemberType NoteProperty - Name " dependsOn" - Value @ ()
480+ }
481+
482+ # Add the new resource to the dependsOn array, so that the deployment will work
483+ $armObj.resources [0 ].dependsOn += " [resourceId('Microsoft.Web/connections', parameters('$idPreSuf '))]"
484+
485+ # Adjust the connection object to depend on the same name
486+ $connectionObj.Value.connectionId = " [resourceId('Microsoft.Web/connections', parameters('$idPreSuf '))]"
487+ $connectionObj.Value.connectionName = " [parameters('$idPreSuf ')]"
488+ $connectionObj.Value.id = " [format('/subscriptions/{0}/providers/Microsoft.Web/locations/{1}/managedApis/$conType ', subscription().subscriptionId, parameters('logicAppLocation'))]"
489+ }
490+
491+ }
492+
493+ if ($found ) {
494+ # We need the location parameter
495+ if ($null -eq $armObj.parameters.logicAppLocation ) {
496+ $armObj = Add-ArmParameter - InputObject $armObj - Name " logicAppLocation" `
497+ - Type " string" `
498+ - Value " [resourceGroup().location]" `
499+ - Description " Location of the Logic App. Best practice recommendation is to make this depending on the Resource Group and its location."
500+ }
501+ }
502+
503+ Out-TaskFileArm - InputObject $armObj
504+ }
505+
402506# Original file: Set-Arm.Connections.ManagedApis.Dataverse.ServicePrincipal.Advanced.AsArmObject.task.ps1
403507$parm = @ {
404508 Description = @"
0 commit comments