To create diagnostic settings on an Azure Firewall I want to pass in logs and metrics settings.
I define these in 2 variables and then pass 'em into Azure CLI:
$logsSetting = "[{'category': 'AzureFirewallApplicationRule','enabled': true,'retentionPolicy': {'days': 0,'enabled': false}},{'category': 'AzureFirewallNetworkRule','enabled': true,'retentionPolicy': {'days': 0,'enabled': false}}]"
$metricsSetting = "[{'category': 'AllMetrics','enabled': true,'retentionPolicy': {'days': 0,'enabled': false},'timeGrain': null}]"
az monitor diagnostic-settings create --name $FW_NAME `
--resource $FW_NAME -g $VNET_GROUP --resource-type Microsoft.Network/azureFirewalls `
--resource-group $VNET_GROUP `
--workspace $FW_NAME `
--logs $logsSetting `
--metrics $metricsSetting
Executing this I get Expecting property name enclosed in double quotes: line 1 column 3 (char 2)
.
I tried without success
'
with "
Adding --debug
parameter to Azure CLI revealed, that single quotes are eliminated in a argument transformation process which seems to cause the error:
Alias Manager: Transformed args to ['monitor', ... '--logs', '[{category: AzureFirewallApplicationRule,enabled: true,retentionPolicy: {days: 0,enabled: false}},{category: AzureFirewallNetworkRule,enabled: true,retentionPolicy: {days: 0,enabled: false}}]', '--metrics', '[{category: AllMetrics,enabled: true,retentionPolicy: {days: 0,enabled: false},timeGrain: null}]', '--debug']
Solution: escaping the quotes with \"
made it work:
$logsSetting = "[{'category': 'AzureFirewallApplicationRule','enabled': true,'retentionPolicy': {'days': 0,'enabled': false}},{'category': 'AzureFirewallNetworkRule','enabled': true,'retentionPolicy': {'days': 0,'enabled': false}}]".Replace("'",'\"')
$metricsSetting = "[{'category': 'AllMetrics','enabled': true,'retentionPolicy': {'days': 0,'enabled': false},'timeGrain': null}]".Replace("'",'\"')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With