11param (
22 $SubscriptionId ,
33 $ApiKey ,
4- $EventhubNamespace = " " ,
5- $ResourceGroupName = " datadog-log-forwarder-rg " ,
4+ $EventhubNamespace ,
5+ $FunctionAppName ,
66 $ResourceGroupLocation = " westus2" ,
7+ $ResourceGroupName = " datadog-log-forwarder-rg" ,
78 $EventhubName = " datadog-eventhub" ,
8- $FunctionAppName = " datadog-functionapp" ,
99 $FunctionName = " datadog-function" ,
1010 $DiagnosticSettingName = " datadog-activity-logs-diagnostic-setting" ,
1111 $DatadogSite = " datadoghq.com" ,
@@ -23,40 +23,26 @@ New-AzResourceGroup -Name $ResourceGroupName -Location $ResourceGroupLocation
2323$environment = Get-AzEnvironment - Name $Environment
2424$endpointSuffix = $environment.StorageEndpointSuffix
2525
26- try {
27- if ( $EventhubNamespace -eq " " ) {
28- $output = New-AzResourceGroupDeployment `
29- - TemplateUri " https://raw.githubusercontent.com/DataDog/datadog-serverless-functions/master/azure/eventhub_log_forwarder/parent_template.json " `
30- - ResourceGroupName $ResourceGroupName `
31- - functionCode $code `
32- - apiKey $ApiKey `
33- - location $ResourceGroupLocation `
34- - eventHubName $EventhubName `
35- - functionAppName $FunctionAppName `
36- - functionName $FunctionName `
37- - datadogSite $DatadogSite `
38- - endpointSuffix $endpointSuffix `
39- - Verbose `
40- - ErrorAction Stop
26+ $deploymentArgs = @ {
27+ TemplateUri = " https://raw.githubusercontent.com/DataDog/datadog-serverless-functions/master/azure/eventhub_log_forwarder/parent_template.json "
28+ ResourceGroupName = $ResourceGroupName
29+ functionCode = $code
30+ apiKey = $ApiKey
31+ location = $ResourceGroupLocation
32+ eventHubName = $EventhubName
33+ functionName = $FunctionName
34+ datadogSite = $DatadogSite
35+ endpointSuffix = $endpointSuffix
36+ }
37+
38+ # Use values if parameters passed, otherwise we rely on the default value generated by the ARM template
39+ if ( $EventhubNamespace ) { $deploymentArgs [ " eventhubNamespace " ] = $EventhubNamespace }
40+ if ( $FunctionAppName ) { $deploymentArgs [ " functionAppName " ] = $FunctionAppName }
4141
42- # Get the generated globally-unique eventhub namespace
43- $EventhubNamespace = $output.Outputs.eventHubNamespace.Value
44- } else {
45- New-AzResourceGroupDeployment `
46- - TemplateUri " https://raw.githubusercontent.com/DataDog/datadog-serverless-functions/master/azure/eventhub_log_forwarder/parent_template.json" `
47- - ResourceGroupName $ResourceGroupName `
48- - functionCode $code `
49- - apiKey $ApiKey `
50- - location $ResourceGroupLocation `
51- - eventhubNamespace $EventhubNamespace `
52- - eventHubName $EventhubName `
53- - functionAppName $FunctionAppName `
54- - functionName $FunctionName `
55- - datadogSite $DatadogSite `
56- - endpointSuffix $endpointSuffix `
57- - Verbose `
58- - ErrorAction Stop
59- }
42+ try {
43+ $output = New-AzResourceGroupDeployment @deploymentArgs - Verbose - ErrorAction Stop
44+ # Get the generated globally-unique eventhub namespace
45+ $EventhubNamespace = $output.Outputs.eventHubNamespace.Value
6046} catch {
6147 Write-Error $_
6248 Return
0 commit comments