Reputation: 59
Call the api to create an alert in Gov subscription:
ret = await HttpHelper.PutAsync(
new Uri($"https://{app.AzureManagementBaseUri}/subscriptions/{alert["SubscriptionId"]}/" +
$"resourcegroups/{alert["ResourceGroupName"]}/providers/microsoft.insights/" +
$"metricAlerts/{alert["Name"]}?api-version=2017-09-01-preview"),
alertJson, app.AccessToken, cancellationToken).ConfigureAwait(false);
But throws an error:
Error: 'Error while calling 'https://management.usgovcloudapi.net/subscriptions/subid/resourcegroups/ctxwsgs-appinsights/providers/microsoft.insights/alertrules/"alertName"'. StatusCode: BadRequest. Response: '{"code":"ResourceNotSupported","message":"The target resource id '/subscriptions/subid/resourceGroups/ not supported."
The same code works fine for others subscriptions, did I missed some configuration in the gov subscription?
Upvotes: 1
Views: 94
Reputation: 7720
This appears to be a known issue with enabling microsoft.insights in Azure Government. The only way to enable Application Insights via the traditional Add Application Insights Telemetry button in Visual Studio requires a small manual workaround. If you do not use this workaround you will get the error you described.
To mitigate the issue, you must perform these steps:
Switch Visual Studio to target the Azure Government cloud.
Create (or if already existing set) the User Environment variable for AzureGraphApiVersion as follows: (To create a User Environment variable go to Control Panel > System > Advanced system settings > Advanced > Environment Variables.)
Variable name: AzureGraphApiVersion Variable value: 2014-04-01
Make the appropriate Application Insights SDK endpoint modifications for either ASP.NET or ASP.NET Core depending on your project type.
Upvotes: 1