https://pulumi.com logo
#getting-started
Title
# getting-started
a

adventurous-camera-87788

07/08/2021, 6:48 PM
Hey guys, I have another interpolation question. I have an instance of
cache.Redis (v20201201)
& I am trying to get the following statement to produce a string:
Copy code
const REDIS_CONNECTION_STRING = pulumi.interpolate `rediss://:${redis.accessKeys.primaryKey}@${redis.hostName}${redis.sslPort}`;
I am getting the following error:
Copy code
"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."
I’ve tried doing this with
pulumi.apply
as well & had no luck. Can someone please point me in the right direction?
b

billowy-army-68599

07/08/2021, 6:50 PM
what are you passing
REDIS_CONNECTION_STRING
to? can you share more of your code?
a

adventurous-camera-87788

07/08/2021, 6:52 PM
we are passing it to a constructor for a new instance of an azure function app for the app settings.
b

billowy-army-68599

07/08/2021, 7:44 PM
i'll need to see more code to see what's throwing the error
c

crooked-parrot-53351

07/12/2021, 3:04 PM
hi @billowy-army-68599 Thanks for helping take a look at our question. Here is a more detailed example of what we're running into:
Copy code
const redis = new cache.Redis(redisInstanceName, {
        name: redisInstanceName,
        redisVersion: `${redisInstanceVersion}`,
        enableNonSslPort: false,
        location: resourceGroup.location,
        minimumTlsVersion: `${redisInstanceMinTlsVersion}`,
        resourceGroupName: resourceGroup.name,
        sku: {
            capacity: parseInt(redisInstanceSKUCapacity),
            family: `${redisInstanceSKUFamily}`,
            name: `${redisInstanceSKUName}`
        }
    });

const redisHostName = redis.hostName.apply(t => t);
const redisPrimaryKey = redis.accessKeys.apply(accessKeys => accessKeys.primaryKey);
const redisSslPort = redis.sslPort.apply(t => t);

const REDIS_CONNECTION_STRING = pulumi.interpolate`rediss://:${redisPrimaryKey}@${redisHostName}:${redisSslPort}`;

const azfInstance = new azure_native.web.WebApp(
    azureFunctionName,
    {
        name: azureFunctionName,
        kind: 'functionapp',
        location: resourceGroup.location,
        resourceGroupName: resourceGroup.name,
        serverFarmId: appServicePlan.id,
        storageAccountName: storageAccount.name,
        storageAccountAccessKey: storageAccount.primaryAccessKey,
        siteConfig: {
            appSettings: [
                ...
                {name: 'REDIS_CONNETION_STRING', value: REDIS_CONNECTION_STRING},
                ...
            ],
            nodeVersion: `${WEBSITE_NODE_DEFAULT_VERSION}`
        }
    }
);
We're using the Typescript SDK. You can see we moved past the error above, but we're now getting
output<string>
as the value of
REDIS_CONNECTION_STRING
when looking at the diff from a dry run of
pulumi up
. I've tried attaching the Node debugger and stepping through the code, but navigating the Proxy relationships have proved complicated for us.
b

billowy-army-68599

07/12/2021, 3:45 PM
take a look at this exzample: https://github.com/pulumi/examples/blob/258d3bad0a00020704743e37911c51be63c06bb4/azure-ts-appservice-docker/index.ts#L86 - you'll need to use .All instead of interpolate there
c

crooked-parrot-53351

07/12/2021, 3:54 PM
Hi @billowy-army-68599 Just tried
Copy code
const REDIS_CONNECTION_STRING = pulumi.all([redis.hostName, redis.accessKeys.primaryKey, redis.sslPort]).apply(([hostName, primaryKey, sslPort])=> {
        return `rediss://:${primaryKey}@${hostName}:${sslPort}`;
    })
and updated the section to use interpolate as the link showed:
Copy code
{name: 'REDIS_CONNECTION_STRING', value: pulumi.interpolate`${REDIS_CONNECTION_STRING}`},
and I ran into the same issue. Is this along the lines of your suggestion?
I'm noticing that when I omit the
accessKeys
portion and build the string w/just hostname and port, all works as expected. Are there good practices for nested keys like
accessKeys.primaryKey
?
b

billowy-army-68599

07/12/2021, 4:27 PM
that should definitely work, is it a valid value?
c

crooked-parrot-53351

07/12/2021, 5:31 PM
@billowy-army-68599 according to the docs @ https://www.pulumi.com/docs/reference/pkg/azure-native/cache/redis/#redisaccesskeysresponse I think it's correct. We're using
@pulumi/azure-native/cache/v20201201
as our dependency version though.
I can see
accessKeys
and the type in the TS files distributed with the SDK, I'm just not sure why they're not resolving 😞
b

billowy-army-68599

07/12/2021, 6:06 PM
can you open an issue?
i'll try repro this when I get a few minutes
c

crooked-parrot-53351

07/12/2021, 6:08 PM
Sure, I've not opened one with this project thus far, any tips for how y'all like things structured?
b

billowy-army-68599

07/12/2021, 6:08 PM
just drop an issue with your code repro here: https://github.com/pulumi/pulumi-azure-native/issues
c

crooked-parrot-53351

07/14/2021, 2:37 AM
@billowy-army-68599 I messed around on this further and it turns out the issue with the keys simply not being available on the Redis instance because
pulumi up
didn't need to update the Redis service due to no changes being needed. For those searching, the solution here was to use the
listRedisKeys
function from the
cache
namespace to explicitly query for the keys needed to build the connection string.
3 Views