In which cases would I use `require()` and when `r...
# typescript
c
In which cases would I use
require()
and when
requireSecret()
? From an end result point of view it seems identical. The secrets from the config are marked as
[secret]
no matter which one I use. However, I had issues working with
requireSecret()
now where it would complain that I'm not allowed to run
toString
on an output.
Copy code
const logAnalyticsWorkspacePrimarySharedKey = config.requireSecret('logAnalyticsWorkspacePrimarySharedKey').apply(s => s);
This is later on used as
Copy code
protectedSettings: `{"workspaceKey": "${logAnalyticsWorkspacePrimarySharedKey}"}`,
And that gives me the following:
Copy code
protectedSettings      : "\"{\\\"workspaceKey\\\": \\\"Calling [toString] on an [Output<T>] is not supported.\\n\\nTo get the value of an Output<T> as an Output<string> consider either:\\n1: o.apply(v => `prefix${v}suffix`)\\n2: pulumi.interpolate `prefix${v}suffix`\\n\\nSee <https://pulumi.io/help/outputs> for more details.\\nThis function may throw in a future version of @pulumi/pulumi.\\\"}\""
f
Swap
Copy code
protectedSettings: `{"workspaceKey": "${logAnalyticsWorkspacePrimarySharedKey}"}`,
with
Copy code
protectedSettings: pulumi.interpolate`{"workspaceKey": "${logAnalyticsWorkspacePrimarySharedKey}"}`,
because
logAnalyticsWorkspacePrimarySharedKey
is an
Output
You also don’t need the
.apply(s => s)
as that’s a no-op