This is a bit.. wonky. I've got my test-infra reso...
# azure
b
This is a bit.. wonky. I've got my test-infra resource group where i bring things up and down. I tore down aks ++, and now about to bring it up - but it fails immediately as it's about to start working. The reason is that this fails:
Copy code
aksStack.cluster[thisCluster.name].kubeconfig = await azure.containerservice.listManagedClusterAdminCredentials({resourceGroupName: aksStack.parameters.name, resourceName: aksStack.cluster[thisCluster.name].parameters.name})
And the reason from the error message is that the cluster it refers to (in this case the one named
aks.paramters.name
) doesn't exist. Because of course it doesn't. I've tried using
aks.name
,
aks.name.apply(name => name)
, pulumi.interpolate`${aks.name}` (where aks is the result of the creation of the cluster resource) to try to ensure that there's a dependency - but it seems pulumi just doesn't care. I must be missing something obvious - and I can't set "dependsOn" for this either because it's not a resource, so.. thoughts?
Basically getting this error:
Copy code
Error: invocation of azure-native:containerservice:listManagedClusterAdminCredentials returned an error: request failed /subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.ContainerService/managedClusters/{resourceName}/listClusterAdminCredential: autorest/azure: Service returned an error. Status=404 Code="ResourceNotFound" Message="The Resource 'Microsoft.ContainerService/managedClusters/{resourceName}' under resource group '<rg>' was not found. For more details please go to <https://aka.ms/ARMResourceNotFoundFix>"
I'm not the one hiding {resourceName} btw - so it looks like some form of internal resolution..
Copy code
aksStack.cluster[thisCluster.name].parameters = {
            name: aks.name.apply(name => name),
            id: aks.id.apply(id => id)
        }
that's where the resourceName comes from - hailing back to aks which is
Copy code
const aks = new azure.containerservice.ManagedCluster(thisCluster.name, aksStack.cluster[thisCluster.name].conf)
Using thisCluster.name for the listManagedClusterAdminCredentials brings the same error, just this time it lists the name as it should be created.
b
could you share the full code in a gist?
you might have to do an
apply
on the
kubeconfig
parameter rather than the name
b
wait what? I'm -setting- the kubeconfig parameter.. I'll try to simplify and share the relevant parts of the code as one block:
Copy code
const aks = new azure.containerservice.ManagedCluster(thisCluster.name, aksStack.cluster[thisCluster.name].conf)
        aksStack.cluster[thisCluster.name].resource = aks;
        aksStack.cluster[thisCluster.name].parameters = {
            name: aks.name.apply(name => name),
            id: aks.id.apply(id => id)
        }
// above is perfectly fine, succeeds without a problem - note though that this stack currently has no AKS cluster, the "up" command would create it as it does not yet exist.

// next follows creation & attachment of node pools to the aks cluster - irrelevant for this. Then, as the last bit of code for the cluster block, I get the kubeconfig of the newly created cluster:

        aksStack.cluster[thisCluster.name].kubeconfig = await azure.containerservice.listManagedClusterAdminCredentials({resourceGroupName: aksStack.parameters.name, resourceName: aksStack.cluster[thisCluster.name].parameters.name})
        aksStack.cluster.kubeConfig = pulumi.unsecret(aksStack.cluster[thisCluster.name].kubeconfig);

// somehow the above code is exectued before -any-other-pulumi-operation-
note that the resourceName resolves through aksStack to aks.name.apply(name => name).
But I'm realizing something even more strange about this.. listManagedClusterAdminCredentials is failing at the
preview
stage ?! why does it try to execute this at the preview stage?
here's the full output of PREVIEW:
Copy code
λ pulumi preview --suppress-outputs
Previewing update (dev.infra.infratesting):
     Type                                             Name                                   Plan       Info
     pulumi:pulumi:Stack                              baseline-infra-dev.infra.infratesting             1 error; 27 messages
 +   ├─ random:index:RandomUuid                       aks-to-des-RA                          create
 +   ├─ random:index:RandomUuid                       aks-to-acr-RA                          create
 +   ├─ random:index:RandomUuid                       des-to-kv-RA                           create
 +   ├─ random:index:RandomString                     aksWindowsUser                         create
 +   ├─ random:index:RandomPassword                   aksWindowsPass                         create
 +   ├─ random:index:RandomString                     aksLinuxUser                           create
 +   ├─ random:index:RandomString                     diskKeyName                            create
 +   ├─ azure-native:containerregistry:Registry       <grp>acr                               create
 +   ├─ azure-native:network:PublicIPAddress          x39482appgw-publicIp                   create
 +   ├─ azure-native:keyvault:Key                     aks-des-key                            create
 +   ├─ azure-native:compute:DiskEncryptionSet        aks-des                                create
 +   ├─ azure-native:network:ApplicationGateway       x39482appgw                            create
 +   ├─ azure-native:authorization:RoleAssignment     des-to-kv                              create
 +   ├─ azure-native:containerservice:ManagedCluster  infratest-k8s                          create
 +   ├─ azure-native:authorization:RoleAssignment     aks-to-acr                             create
 +   ├─ azure-native:authorization:RoleAssignment     aks-to-des                             create
 +   └─ azure-native:containerservice:AgentPool       spot00                                 create

Diagnostics:
  pulumi:pulumi:Stack (baseline-infra-dev.infra.infratesting):
    unhandled rejection: CONTEXT(3401): Invoking function: tok=azure-native:containerservice:listManagedClusterAdminCredentials asynchronously
    STACK_TRACE:
    Error:
        at Object.debuggablePromise (c:\dev\<pulumi-path>\baseline-infra\node_modules\@pulumi\pulumi\runtime\debuggable.js:69:75)
        at c:\dev\<pulumi-path>\baseline-infra\node_modules\@pulumi\pulumi\runtime\invoke.js:126:45
        at Generator.next (<anonymous>)
        at fulfilled (c:\dev\<pulumi-path>\baseline-infra\node_modules\@pulumi\pulumi\runtime\invoke.js:18:58)
        at runMicrotasks (<anonymous>)
        at processTicksAndRejections (node:internal/process/task_queues:94:5)
    (this is repeaded for a total of three times)

    error: Running program 'c:\dev\<pulumi-path>\baseline-infra' failed with an unhandled exception:
    Error: invocation of azure-native:containerservice:listManagedClusterAdminCredentials returned an error: request failed /subscriptions/<sub>/resourceGroups/<grp>_westeurope/providers/Microsoft.ContainerService/managedClusters/{resourceName}/listClusterAdminCredential: autorest/azure: Service returned an error. Status=404 Code="ResourceNotFound" Message="The Resource 'Microsoft.ContainerService/managedClusters/{resourceName}' under resource group '<grp>_westeurope' was not found. For more details please go to <https://aka.ms/ARMResourceNotFoundFix>"
        at Object.callback (c:\dev\<pulumi-path>\baseline-infra\node_modules\@pulumi\pulumi\runtime\invoke.js:139:33)
        at Object.onReceiveStatus (c:\dev\<pulumi-path>\baseline-infra\node_modules\@grpc\grpc-js\src\client.ts:334:26)
        at Object.onReceiveStatus (c:\dev\<pulumi-path>\baseline-infra\node_modules\@grpc\grpc-js\src\client-interceptors.ts:426:34)
        at Object.onReceiveStatus (c:\dev\<pulumi-path>\baseline-infra\node_modules\@grpc\grpc-js\src\client-interceptors.ts:389:48)
        at c:\dev\<pulumi-path>\baseline-infra\node_modules\@grpc\grpc-js\src\call-stream.ts:276:24
        at processTicksAndRejections (node:internal/process/task_queues:76:11)
Is it normal that a "preview" command tries to execute the
listManagedClusterAdminCredentials
at that stage?! even before the cluster it needs to get its credentials from is created? Is it because I have the kubeconfig as part of the output?
Anyone else have any idea why
pulumi preview
executes
ilstManagedClusterAdminCredentials
even though it is currently planning on creating the resource on which that function depends?
t
A function can’t depend on a resource yet. You have to arrange that dependency with output.apply as Lee suggested above
b
ahhhhh that makes more sense - thank you!