https://pulumi.com logo
Title
p

prehistoric-nail-50687

01/18/2021, 7:42 PM
I use
operationalinsights.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?
t

tall-librarian-49374

01/18/2021, 9:18 PM
So, if you replace uppercase with lowercase (or vice versa?) inside
then
, does it stop showing the diff?
p

prehistoric-nail-50687

01/19/2021, 7:56 AM
Yes, if I build the workspaceId with the correct casing, then it stops showing the diff.
t

tall-librarian-49374

01/19/2021, 8:42 AM
This is the “classic” Azure provider, isn’t it?
p

prehistoric-nail-50687

01/19/2021, 9:30 AM
no, this is all
nextgen
import * as insights from "@pulumi/azure-nextgen/insights/v20150501";
import * as operationalinsights from "@pulumi/azure-nextgen/operationalinsights/v20200801";
t

tall-librarian-49374

01/19/2021, 9:46 AM
And what is
monitoring
?
p

prehistoric-nail-50687

01/19/2021, 10:14 AM
Oh, sorry - yes your right this one is the classic:
import * as monitoring from "@pulumi/azure/monitoring";
t

tall-librarian-49374

01/19/2021, 10:31 AM
Yeah, that’s Terraform being too picky with the diff I suppose
p

prehistoric-nail-50687

01/19/2021, 10:42 AM
Anything I can do about it? Although I can build (concat) the ID of the workspace myself, it will now not make sure the workspace really exists - which is the case when I use the
getWorkspace
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>
t

tall-librarian-49374

01/19/2021, 10:52 AM
I would just format the casing in
.then((w) => w.id);
so that it matches the expectation
Btw, why aren’t you using nextgen for this resource? (https://www.pulumi.com/docs/reference/pkg/azure-nextgen/insights/diagnosticsetting/)
p

prehistoric-nail-50687

01/19/2021, 11:44 AM
hmm, thats a good question 🙂
The type
LogSettings
(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?
t

tall-librarian-49374

01/19/2021, 12:15 PM
That’s what MS suggests too: https://docs.microsoft.com/en-us/azure/templates/microsoft.insights/diagnosticsettings Worried or not - question to them…
👍 1
The example from the docs compiles for me - which error do you get?
p

prehistoric-nail-50687

01/19/2021, 12:21 PM
yeah, its not that the example does not compile, its more that I wanted to make a utility method to create a
LogSettings
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 import
t

tall-librarian-49374

01/19/2021, 12:38 PM
The path should be something like @pulumi/azure-nextgen/types/input/insights/v20170501preview/LogSetting
p

prehistoric-nail-50687

01/19/2021, 12:42 PM
yeah, I thought so too, but
import { 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.