diff --git a/azure/eventhub_log_forwarder/activity_logs_deploy.ps1 b/azure/eventhub_log_forwarder/activity_logs_deploy.ps1 index 69a51e3dc..a8eee0189 100644 --- a/azure/eventhub_log_forwarder/activity_logs_deploy.ps1 +++ b/azure/eventhub_log_forwarder/activity_logs_deploy.ps1 @@ -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", @@ -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 } +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 diff --git a/azure/eventhub_log_forwarder/function_template.json b/azure/eventhub_log_forwarder/function_template.json index 8404f6ffb..b1c81b6f4 100644 --- a/azure/eventhub_log_forwarder/function_template.json +++ b/azure/eventhub_log_forwarder/function_template.json @@ -4,7 +4,7 @@ "parameters": { "functionAppName": { "type": "string", - "defaultValue": "datadog-functionapp", + "defaultValue": "[concat('datadog-functionapp-', newGuid())]", "metadata": { "description": "The name of the function app " } diff --git a/azure/eventhub_log_forwarder/parent_template.json b/azure/eventhub_log_forwarder/parent_template.json index d2ac5175c..2d908a1ab 100644 --- a/azure/eventhub_log_forwarder/parent_template.json +++ b/azure/eventhub_log_forwarder/parent_template.json @@ -18,7 +18,7 @@ }, "functionAppName": { "type": "string", - "defaultValue": "datadog-functionapp", + "defaultValue": "[concat('datadog-functionapp-', newGuid())]", "metadata": { "description": "The name of the function app " } diff --git a/azure/eventhub_log_forwarder/resource_deploy.ps1 b/azure/eventhub_log_forwarder/resource_deploy.ps1 index 3fd7437ba..60a2d9752 100644 --- a/azure/eventhub_log_forwarder/resource_deploy.ps1 +++ b/azure/eventhub_log_forwarder/resource_deploy.ps1 @@ -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" @@ -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