I use `operationalinsights.getWorkspace()` to get ...
# azure
p
I use
operationalinsights.getWorkspace()
to get the id of a `Log Analytics workspace`:
Copy code
const insightsWorkspaceId = operationalinsights
  .getWorkspace({
    resourceGroupName: `tal-env-ci`,
    workspaceName: `tal-logs`,
  })
  .then((w) => w.id);
and use it to create a new
DiagnosticSetting
Copy code
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
):
Copy code
~ 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
So, if you replace uppercase with lowercase (or vice versa?) inside
then
, does it stop showing the diff?
p
Yes, if I build the workspaceId with the correct casing, then it stops showing the diff.
t
This is the “classic” Azure provider, isn’t it?
p
no, this is all
nextgen
Copy code
import * as insights from "@pulumi/azure-nextgen/insights/v20150501";
import * as operationalinsights from "@pulumi/azure-nextgen/operationalinsights/v20200801";
t
And what is
monitoring
?
p
Oh, sorry - yes your right this one is the classic:
import * as monitoring from "@pulumi/azure/monitoring";
t
Yeah, that’s Terraform being too picky with the diff I suppose
p
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:
Copy code
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
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
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
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
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.
Copy code
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
The path should be something like @pulumi/azure-nextgen/types/input/insights/v20170501preview/LogSetting
p
yeah, I thought so too, but
import { LogSettings } from "@pulumi/azure-nextgen/types/input/insights/v20170501preview/LogSettings";
does not work I get:
Copy code
$ 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.