Azure-cli: az monitor log-profiles create gives 'Expect fully qualified resource Id

Created on 21 Jan 2019  路  3Comments  路  Source: Azure/azure-cli

I'm automating configuring Azure Monitor to send the logs to EventHub. Here's how I get the EventHub id:

sbRule="$(az eventhubs namespace authorization-rule list \
                    --resource-group $MONITORING_RESOURCE_GROUP_NAME \
                    --namespace-name $MONITORING_EVENTHUB_NAMESPACE_NAME --query [0].id)"
echo "Service bus auth rule: "
echo "$sbRule"

Followed by:

az monitor log-profiles delete --name default
az monitor log-profiles create --name "default" \
                               --location null --locations "global" "westeurope" \
                               --categories "Delete" "Write" "Action"  \
                               --enabled false --days 0 \
                               --service-bus-rule-id "$sbRule"
echo "Az monitor configured to log to EventHub "

I get the following error message:

Property id '"/subscriptions/--subscriptionid--/resourceGroups/--resource-group--/providers/Microsoft.EventHub/namespaces/--namespace--/AuthorizationRules/RootManageSharedAccessKey"'
at path 'properties.serviceBusRuleId' is invalid. Expect fully qualified resource Id that start with '/subscriptions/{subscriptionId}' or '/providers/{resourceProviderNamespace}/'.

The id provided seems to be formatted as required. Even better - if copy the value for sbRule and paste that in the command like so:

az monitor log-profiles delete --name default
az monitor log-profiles create --name "default" \
                               --location null --locations "global" "westeurope" \
                               --categories "Delete" "Write" "Action"  \
                               --enabled false --days 0 \
                               --service-bus-rule-id "/subscriptions/--subscriptionid--/resourceGroups/--resource-group--/providers/Microsoft.EventHub/namespaces/--namespace--/AuthorizationRules/RootManageSharedAccessKey"
echo "Az monitor configured to log to EventHub "

It works !

question

Most helpful comment

From the error message, it looks like however you were passing the ID to the command was preserving the quotes. So it was seeing "this" as the ID value instead of this.

When you query the ID, you need to pass it with -o tsv, which should strip those double quotes.

All 3 comments

OK - I found a workaround:

az monitor log-profiles delete --name default
az monitor log-profiles create --name "default" \
                               --location null --locations "global" "westeurope" \
                               --categories "Delete" "Write" "Action"  \
                               --enabled false --days 0 \
                               --service-bus-rule-id "${sbRule//\"}"

From the error message, it looks like however you were passing the ID to the command was preserving the quotes. So it was seeing "this" as the ID value instead of this.

When you query the ID, you need to pass it with -o tsv, which should strip those double quotes.

@tjprescott Thanks for the tip - I'll use that going forward.

Was this page helpful?
0 / 5 - 0 ratings