Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 22 additions & 36 deletions azure/eventhub_log_forwarder/activity_logs_deploy.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
param (
$SubscriptionId,
$ApiKey,
$EventhubNamespace = "",
$ResourceGroupName = "datadog-log-forwarder-rg",
$EventhubNamespace,
$FunctionAppName,
$ResourceGroupLocation = "westus2",
$ResourceGroupName = "datadog-log-forwarder-rg",
$EventhubName = "datadog-eventhub",
$FunctionAppName = "datadog-functionapp",
$FunctionName = "datadog-function",
$DiagnosticSettingName = "datadog-activity-logs-diagnostic-setting",
$DatadogSite = "datadoghq.com",
Expand All @@ -23,40 +23,26 @@ New-AzResourceGroup -Name $ResourceGroupName -Location $ResourceGroupLocation
$environment = Get-AzEnvironment -Name $Environment
$endpointSuffix = $environment.StorageEndpointSuffix

try {
if ($EventhubNamespace -eq "") {
$output = New-AzResourceGroupDeployment `
-TemplateUri "https://raw.githubusercontent.com/DataDog/datadog-serverless-functions/master/azure/eventhub_log_forwarder/parent_template.json" `
-ResourceGroupName $ResourceGroupName `
-functionCode $code `
-apiKey $ApiKey `
-location $ResourceGroupLocation `
-eventHubName $EventhubName `
-functionAppName $FunctionAppName `
-functionName $FunctionName `
-datadogSite $DatadogSite `
-endpointSuffix $endpointSuffix `
-Verbose `
-ErrorAction Stop
$deploymentArgs = @{
TemplateUri = "https://raw.githubusercontent.com/DataDog/datadog-serverless-functions/master/azure/eventhub_log_forwarder/parent_template.json"
ResourceGroupName = $ResourceGroupName
functionCode = $code
apiKey = $ApiKey
location = $ResourceGroupLocation
eventHubName = $EventhubName
functionName = $FunctionName
datadogSite = $DatadogSite
endpointSuffix = $endpointSuffix
}

# Use values if parameters passed, otherwise we rely on the default value generated by the ARM template
if ($EventhubNamespace) { $deploymentArgs["eventhubNamespace"] = $EventhubNamespace }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is much cleaner :)

if ($FunctionAppName) { $deploymentArgs["functionAppName"] = $FunctionAppName }

# Get the generated globally-unique eventhub namespace
$EventhubNamespace = $output.Outputs.eventHubNamespace.Value
} else {
New-AzResourceGroupDeployment `
-TemplateUri "https://raw.githubusercontent.com/DataDog/datadog-serverless-functions/master/azure/eventhub_log_forwarder/parent_template.json" `
-ResourceGroupName $ResourceGroupName `
-functionCode $code `
-apiKey $ApiKey `
-location $ResourceGroupLocation `
-eventhubNamespace $EventhubNamespace `
-eventHubName $EventhubName `
-functionAppName $FunctionAppName `
-functionName $FunctionName `
-datadogSite $DatadogSite `
-endpointSuffix $endpointSuffix `
-Verbose `
-ErrorAction Stop
}
try {
$output = New-AzResourceGroupDeployment @deploymentArgs -Verbose -ErrorAction Stop
# Get the generated globally-unique eventhub namespace
$EventhubNamespace = $output.Outputs.eventHubNamespace.Value
} catch {
Write-Error $_
Return
Expand Down
2 changes: 1 addition & 1 deletion azure/eventhub_log_forwarder/function_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"parameters": {
"functionAppName": {
"type": "string",
"defaultValue": "datadog-functionapp",
"defaultValue": "[concat('datadog-functionapp-', newGuid())]",
"metadata": {
"description": "The name of the function app "
}
Expand Down
2 changes: 1 addition & 1 deletion azure/eventhub_log_forwarder/parent_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"functionAppName": {
"type": "string",
"defaultValue": "datadog-functionapp",
"defaultValue": "[concat('datadog-functionapp-', newGuid())]",
"metadata": {
"description": "The name of the function app "
}
Expand Down
52 changes: 19 additions & 33 deletions azure/eventhub_log_forwarder/resource_deploy.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
param (
$SubscriptionId,
$ApiKey,
$EventhubNamespace = "",
$EventhubNamespace,
$FunctionAppName,
$ResourceGroupLocation = "westus2",
$ResourceGroupName = "datadog-log-forwarder-rg-" + $ResourceGroupLocation,
$EventhubName = "datadog-eventhub-" + $ResourceGroupLocation,
$FunctionAppName = "datadog-functionapp-" + $ResourceGroupLocation,
$FunctionName = "datadog-function-" + $ResourceGroupLocation,
$DatadogSite = "datadoghq.com",
$Environment = "AzureCloud"
Expand All @@ -22,38 +22,24 @@ New-AzResourceGroup -Name $ResourceGroupName -Location $ResourceGroupLocation
$environment = Get-AzEnvironment -Name $Environment
$endpointSuffix = $environment.StorageEndpointSuffix

try {
if ($EventhubNamespace -eq "") {
New-AzResourceGroupDeployment `
-TemplateUri "https://raw.githubusercontent.com/DataDog/datadog-serverless-functions/master/azure/eventhub_log_forwarder/parent_template.json" `
-ResourceGroupName $ResourceGroupName `
-functionCode $code `
-apiKey $ApiKey `
-location $ResourceGroupLocation `
-eventHubName $EventhubName `
-functionAppName $FunctionAppName `
-functionName $FunctionName `
-datadogSite $DatadogSite `
-endpointSuffix $endpointSuffix `
-Verbose `
-ErrorAction Stop
} else {
New-AzResourceGroupDeployment `
-TemplateUri "https://raw.githubusercontent.com/DataDog/datadog-serverless-functions/master/azure/eventhub_log_forwarder/parent_template.json" `
-ResourceGroupName $ResourceGroupName `
-functionCode $code `
-apiKey $ApiKey `
-location $ResourceGroupLocation `
-eventhubNamespace $EventhubNamespace `
-eventHubName $EventhubName `
-functionAppName $FunctionAppName `
-functionName $FunctionName `
-datadogSite $DatadogSite `
-endpointSuffix $endpointSuffix `
-Verbose `
-ErrorAction Stop
}
$deploymentArgs = @{
TemplateUri = "https://raw.githubusercontent.com/DataDog/datadog-serverless-functions/master/azure/eventhub_log_forwarder/parent_template.json"
ResourceGroupName = $ResourceGroupName
functionCode = $code
apiKey = $ApiKey
location = $ResourceGroupLocation
eventHubName = $EventhubName
functionName = $FunctionName
datadogSite = $DatadogSite
endpointSuffix = $endpointSuffix
}

# Use values if parameters passed, otherwise we rely on the default value generated by the ARM template
if ($EventhubNamespace) { $deploymentArgs["eventhubNamespace"] = $EventhubNamespace }
if ($FunctionAppName) { $deploymentArgs["functionAppName"] = $FunctionAppName }

try {
New-AzResourceGroupDeployment @deploymentArgs -Verbose -ErrorAction Stop
} catch {
Write-Error $_
Return
Expand Down