prehistoric-nail-50687
01/18/2021, 7:42 PMoperationalinsights.getWorkspace()
to get the id of a `Log Analytics workspace`:
const insightsWorkspaceId = operationalinsights
.getWorkspace({
resourceGroupName: `tal-env-ci`,
workspaceName: `tal-logs`,
})
.then((w) => w.id);
and use it to create a new DiagnosticSetting
new monitoring.DiagnosticSetting(
`diagnostic-setting`,
{
name: `diagnostic-setting`,
targetResourceId: app.id,
logAnalyticsWorkspaceId: insightsWorkspaceId,
logs: [ ...
This works fine, but for some reason, Pulumi wants to update the DiagnosticSetting
with every single run (even if nothing changes in the whole stack). The reason seems to be, that getWorkspace()
returns the the workspace ID with some characters in upper case, but when it gets saved, it changes to lowercase (see Microsoft.OperationalInsights
):
~ logAnalyticsWorkspaceId: "/subscriptions/fd90a697-afda-4fdd-9b9e-2bdffe0d2601/resourceGroups/tal-env-ci/providers/Microsoft.OperationalInsights/workspaces/tal-logs" => "/subscriptions/fd90a697-afda-4fdd-9b9e-2bdffe0d2601/resourcegroups/tal-env-ci/providers/microsoft.operationalinsights/workspaces/tal-logs"
Is this a known problem, is there any way around it?tall-librarian-49374
01/18/2021, 9:18 PMthen
, does it stop showing the diff?prehistoric-nail-50687
01/19/2021, 7:56 AMtall-librarian-49374
01/19/2021, 8:42 AMprehistoric-nail-50687
01/19/2021, 9:30 AMnextgen
import * as insights from "@pulumi/azure-nextgen/insights/v20150501";
import * as operationalinsights from "@pulumi/azure-nextgen/operationalinsights/v20200801";
tall-librarian-49374
01/19/2021, 9:46 AMmonitoring
?prehistoric-nail-50687
01/19/2021, 10:14 AMimport * as monitoring from "@pulumi/azure/monitoring";
tall-librarian-49374
01/19/2021, 10:31 AMprehistoric-nail-50687
01/19/2021, 10:42 AMgetWorkspace
function.
An other option to ensure this, would be to do both (build it my self and also call getWorkspace
) and compare the two myself. I tried this:
export function getLogWorkspaceId(resourceGroupName: string, workspaceName: string): Promise<pulumi.Output<string>> {
// The workspaceId returned by the `operationalinsights.getWorkspace()`-call is allways lower case.
// Altough azure has no problem when using this one as a reference, the reference stored on the target
// obejct gets converted to CamelCase and ends up in the pulumi state, causing the resource (e.g. DiagnosticSetting)
// to be recreated on every run.
const subscriptionId = authorization.getClientConfig().then((c) => c.subscriptionId);
const predictedWorkspaceId = pulumi.interpolate`/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/${workspaceName}`;
return operationalinsights
.getWorkspace({
resourceGroupName: resourceGroupName,
workspaceName: workspaceName,
})
.then((w) => w.id)
.then((id) => {
const workSpaceId = predictedWorkspaceId.apply((cid) => {
var areEqual = id.toUpperCase() === cid.toUpperCase();
if (areEqual === false) {
throw new Error("workspace id not as expected!");
}
return id;
});
return workSpaceId;
});
}
But now I end up with a Promise<pulumi.Output<string>>
and don’t know how to get it converted to a pulumi.Input<string>
tall-librarian-49374
01/19/2021, 10:52 AM.then((w) => w.id);
so that it matches the expectationprehistoric-nail-50687
01/19/2021, 11:44 AMLogSettings
(LogSettings) seems not to be exported or at least I’m not able to define a proper import for it. Also I have an other “dumb” question about the versioning: DiagnosticSetting is only available in a preview version (v20170501preview
), does the version indicate it is in preview since May 2017? is this something I should be worried about?tall-librarian-49374
01/19/2021, 12:15 PMprehistoric-nail-50687
01/19/2021, 12:21 PMLogSettings
e.g.
function newDiagnosticSettingCategory(category: string, enabled: boolean, retentionInDays: number): LogSettings {
return {
category: category,
enabled: enabled,
retentionPolicy: {
enabled: enabled,
days: retentionInDays,
},
};
}
but I can’t find LogSettings
to define the proper TS importtall-librarian-49374
01/19/2021, 12:38 PMprehistoric-nail-50687
01/19/2021, 12:42 PMimport { LogSettings } from "@pulumi/azure-nextgen/types/input/insights/v20170501preview/LogSettings";
does not work
I get:
$ npx tsc
src/application/webApplication.ts:6:29 - error TS2307: Cannot find module '@pulumi/azure-nextgen/types/input/insights/v20170501preview/LogSettings' or its corresponding type declarations.
6 import { LogSettings } from "@pulumi/azure-nextgen/types/input/insights/v20170501preview/LogSettings";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 1 error.