Skip to content

Commit aff498c

Browse files
authored
AZI-360 Make Log Forwarder default function app name unique (#500)
1 parent 4849987 commit aff498c

File tree

4 files changed

+43
-71
lines changed

4 files changed

+43
-71
lines changed

azure/eventhub_log_forwarder/activity_logs_deploy.ps1

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
param (
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

azure/eventhub_log_forwarder/function_template.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"parameters": {
55
"functionAppName": {
66
"type": "string",
7-
"defaultValue": "datadog-functionapp",
7+
"defaultValue": "[concat('datadog-functionapp-', newGuid())]",
88
"metadata": {
99
"description": "The name of the function app "
1010
}

azure/eventhub_log_forwarder/parent_template.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"functionAppName": {
2020
"type": "string",
21-
"defaultValue": "datadog-functionapp",
21+
"defaultValue": "[concat('datadog-functionapp-', newGuid())]",
2222
"metadata": {
2323
"description": "The name of the function app "
2424
}

azure/eventhub_log_forwarder/resource_deploy.ps1

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
param (
22
$SubscriptionId,
33
$ApiKey,
4-
$EventhubNamespace = "",
4+
$EventhubNamespace,
5+
$FunctionAppName,
56
$ResourceGroupLocation = "westus2",
67
$ResourceGroupName = "datadog-log-forwarder-rg-" + $ResourceGroupLocation,
78
$EventhubName = "datadog-eventhub-" + $ResourceGroupLocation,
8-
$FunctionAppName = "datadog-functionapp-" + $ResourceGroupLocation,
99
$FunctionName = "datadog-function-" + $ResourceGroupLocation,
1010
$DatadogSite = "datadoghq.com",
1111
$Environment = "AzureCloud"
@@ -22,38 +22,24 @@ New-AzResourceGroup -Name $ResourceGroupName -Location $ResourceGroupLocation
2222
$environment = Get-AzEnvironment -Name $Environment
2323
$endpointSuffix = $environment.StorageEndpointSuffix
2424

25-
try {
26-
if ($EventhubNamespace -eq "") {
27-
New-AzResourceGroupDeployment `
28-
-TemplateUri "https://raw.githubusercontent.com/DataDog/datadog-serverless-functions/master/azure/eventhub_log_forwarder/parent_template.json" `
29-
-ResourceGroupName $ResourceGroupName `
30-
-functionCode $code `
31-
-apiKey $ApiKey `
32-
-location $ResourceGroupLocation `
33-
-eventHubName $EventhubName `
34-
-functionAppName $FunctionAppName `
35-
-functionName $FunctionName `
36-
-datadogSite $DatadogSite `
37-
-endpointSuffix $endpointSuffix `
38-
-Verbose `
39-
-ErrorAction Stop
40-
} else {
41-
New-AzResourceGroupDeployment `
42-
-TemplateUri "https://raw.githubusercontent.com/DataDog/datadog-serverless-functions/master/azure/eventhub_log_forwarder/parent_template.json" `
43-
-ResourceGroupName $ResourceGroupName `
44-
-functionCode $code `
45-
-apiKey $ApiKey `
46-
-location $ResourceGroupLocation `
47-
-eventhubNamespace $EventhubNamespace `
48-
-eventHubName $EventhubName `
49-
-functionAppName $FunctionAppName `
50-
-functionName $FunctionName `
51-
-datadogSite $DatadogSite `
52-
-endpointSuffix $endpointSuffix `
53-
-Verbose `
54-
-ErrorAction Stop
55-
}
25+
$deploymentArgs = @{
26+
TemplateUri = "https://raw.githubusercontent.com/DataDog/datadog-serverless-functions/master/azure/eventhub_log_forwarder/parent_template.json"
27+
ResourceGroupName = $ResourceGroupName
28+
functionCode = $code
29+
apiKey = $ApiKey
30+
location = $ResourceGroupLocation
31+
eventHubName = $EventhubName
32+
functionName = $FunctionName
33+
datadogSite = $DatadogSite
34+
endpointSuffix = $endpointSuffix
35+
}
5636

37+
# Use values if parameters passed, otherwise we rely on the default value generated by the ARM template
38+
if ($EventhubNamespace) { $deploymentArgs["eventhubNamespace"] = $EventhubNamespace }
39+
if ($FunctionAppName) { $deploymentArgs["functionAppName"] = $FunctionAppName }
40+
41+
try {
42+
New-AzResourceGroupDeployment @deploymentArgs -Verbose -ErrorAction Stop
5743
} catch {
5844
Write-Error $_
5945
Return

0 commit comments

Comments
 (0)