https://pulumi.com logo
Title
a

ancient-eve-13947

07/30/2021, 12:39 PM
Hi, I got a stack consisting of about 20 resources. I used it in the past and it worked fine. Now I'm trying to run
pulumi preview
on a clean slate, ie with no resources up yet and I get the following error:
Diagnostics:
  pulumi:pulumi:Stack (Cloud-dev):
    error: Running program 'C:\Projects\Deon\infrastructure\azureresources' failed with an unhandled exception:
    Error: invocation of azure-native:cache:listRedisKeys returned an error: request failed /subscriptions/25110286-d288-4e46-851b-4e2bc880672f/resourceGroups/rgDEV/providers/Microsoft.Cache/redis/redis2f94d61f/listKeys: autorest/azure: Service returned an error. Status=404 Code="ResourceNotFound" Message="The Resource 'Microsoft.Cache/Redis/redis2f94d61f' under resource group 'rgDEV' was not found. For more details please go to <https://aka.ms/ARMResourceNotFoundFix>"
        at Object.callback (C:\Projects\Deon\infrastructure\azureresources\node_modules\@pulumi\pulumi\runtime\invoke.js:139:33)
        at Object.onReceiveStatus (C:\Projects\Deon\infrastructure\azureresources\node_modules\@grpc\grpc-js\src\client.ts:338:26)
        at Object.onReceiveStatus (C:\Projects\Deon\infrastructure\azureresources\node_modules\@grpc\grpc-js\src\client-interceptors.ts:426:34)
        at Object.onReceiveStatus (C:\Projects\Deon\infrastructure\azureresources\node_modules\@grpc\grpc-js\src\client-interceptors.ts:389:48)
        at C:\Projects\Deon\infrastructure\azureresources\node_modules\@grpc\grpc-js\src\call-stream.ts:276:24
        at processTicksAndRejections (internal/process/task_queues.js:79:11)
The code for that passage is
function createRedis() : azure.types.input.web.NameValuePairArgs[]{
    var cache= new redis.Redis("redis", {
        resourceGroupName,
        enableNonSslPort: true,
        minimumTlsVersion: redis.TlsVersion.TlsVersion_1_2,
        sku: {
            name: "Basic",
            family: "C",
            capacity: cfg.requireNumber("Redis.Size")
        }
    });
    
    const keys= pulumi.all([resourceGroupName, cache.name])
                 .apply(([resourceGroupName, name])=>redis.listRedisKeys({resourceGroupName, name}))
    const connectionString= pulumi.interpolate `${cache.hostName}:6380,password=${keys.primaryKey},ssl=True,abortConnect=False`;
    return [
        {
            name: "Redis:ConnectionString",
            value: connectionString
        },
    ];
}
Now what I don't get is: of course when doing preview, the redis instance isn't there yet. But I kinda expected that Pulumi somehow deals with this in the background, maybe not calling apply if cache.Name is not available yet. Also, I think I didn't have the problem before - but that might just be because I called it incrementally, never on a completely clean slate. Note the same thing happens when I execute
pulumi up
when it's in the preview stage. So this is currently a big blocker for me. Any ideas, anyone?
t

tall-librarian-49374

07/30/2021, 12:44 PM
You likely need to put the
native:cache:listRedisKeys
call inside an apply, similar to https://github.com/pulumi/templates/blob/master/azure-typescript/index.ts#L18-L19
That way it will only run after the redis server is created
a

ancient-eve-13947

07/30/2021, 12:45 PM
but it is in an apply call, look at the code - or am I missing something?
t

tall-librarian-49374

07/30/2021, 12:46 PM
Oh, sorry, I didn’t read the code correctly… let me try it locally.
a

ancient-eve-13947

07/30/2021, 12:47 PM
thx!
t

tall-librarian-49374

07/30/2021, 12:50 PM
Hmm… this preview works for me
import * as pulumi from "@pulumi/pulumi";
import * as resources from "@pulumi/azure-native/resources";
import * as redis from "@pulumi/azure-native/cache";

const resourceGroup = new resources.ResourceGroup("rg");

var cache= new redis.Redis("redis", {
    resourceGroupName: resourceGroup.name,
    enableNonSslPort: true,
    minimumTlsVersion: redis.TlsVersion.TlsVersion_1_2,
    sku: {
        name: "Basic",
        family: "C",
        capacity: 1
    }
});
const keys= pulumi.all([resourceGroup.name, cache.name])
             .apply(([resourceGroupName, name])=>redis.listRedisKeys({resourceGroupName, name}))
export const connectionString= pulumi.interpolate `${cache.hostName}:6380,password=${keys.primaryKey},ssl=True,abortConnect=False`;
a

ancient-eve-13947

07/30/2021, 12:50 PM
could it be because I do the `const connectionstring =...`outside the apply? if yes, then how exactly would I rewrite that?
t

tall-librarian-49374

07/30/2021, 12:50 PM
No, interpolate does the right thing
a

ancient-eve-13947

07/30/2021, 12:52 PM
hmm. how can I dig further?
t

tall-librarian-49374

07/30/2021, 12:53 PM
Can you run my code in isolation and see you get the same?
a

ancient-eve-13947

07/30/2021, 12:53 PM
could it matter that the resourcegroup is not being created by pulumi? because that I changed, I now supply it's name via config. (Background: i need to create and configure a b2c instance outside of pulumi because what I need to there doesn't work within.)
run in a new stack?
t

tall-librarian-49374

07/30/2021, 12:54 PM
Aha! Yes, I reproduced your error with an existing RG.
a

ancient-eve-13947

07/30/2021, 12:55 PM
ah
okay, then I try what happens if I get the resourcegroup by name and use then resourcegroup.Name
maybe that is a workaround
t

tall-librarian-49374

07/30/2021, 12:55 PM
The workaround is to change
all
to this:
const keys= pulumi.all([resourceGroup.name, cache.name, cache.id])
cache.id
won’t resolve until redis exists. But it may be worth filing an issue for your original code.
a

ancient-eve-13947

07/30/2021, 12:56 PM
ah, thx for the workaround
re issue - github?
t

tall-librarian-49374

07/30/2021, 12:57 PM
a

ancient-eve-13947

07/30/2021, 12:57 PM
ok
t

tall-librarian-49374

07/30/2021, 12:57 PM
please mention the pre-existing resource group
a

ancient-eve-13947

07/30/2021, 1:43 PM
hmm. I have a related question: In order to get the existing resourcegroup, I first tried to do just
const resourceGroup= new resources.ResourceGroup(resourceGroupName);
for preview that looked fine, but when I run it, it leads to the creation of a new resourcegroup. on the other hand, when I do
const resourceGroup= resources.getResourceGroup({resourceGroupName});
then the result is a `Promise<GetResourceGroupResult>`and I get compile-time errors. when I try
const resourceGroup= await resources.getResourceGroup({resourceGroupName});
I get another error saying that top-level await is not allowed. So what do I do?
ah, I see I misunderstood your workaround
t

tall-librarian-49374

07/30/2021, 2:38 PM
yes, you don’t have to do that