I'm creating an AKS ManagedCluster in a stack. In a different stack I want to create a namespace in ...
w
I'm creating an AKS ManagedCluster in a stack. In a different stack I want to create a namespace in this cluster and use
dependsOn
to specify which cluster to create it in. I tried to use:
Copy code
const cluster = containerservice.getManagedClusterOutput({
  resourceGroupName: clusterRgName,
  resourceName: clusterName
})

const namespace = new kubernetes.core.v1.Namespace(
  "Create namespace",
  {
    metadata: { name: "my-namespace" },
  }, {
    dependsOn: [cluster] // Type 'GetManagedClusterResult' is missing the following properties from type 'Resource': urn, getProvider
  }
);
But this returns a
GetManagedClusterResult
not a
pulumi.Resource
. How would I go about fetching the actual resource in a different stack, is it possible?
a
dependsOn
is for defining dependencies within a single stack deployment. To configure pulumi-kubernetes operations to run against your cluster you'd • Use listManagedClusterUserCredentialsOutput to get the
kubeconfig
output for the cluster: • Define a pulumi Kubernetes Provider using the fetched
kubeconfig
• And for all your
pulumi-kubernetes
operations to use that provider set the
CustomResourceOptions
provider
parameter to the provider instance you defined Have a look at this example for how to define the provider: https://github.com/pulumi/examples/blob/master/azure-ts-aks-helm/cluster.ts#L56-L66 And here you can see an example of how it's used: https://github.com/pulumi/examples/blob/master/azure-ts-aks-helm/index.ts#L12-L22
s
so whatever you output in the ClusterStack can be referenced in the next stack using a StackReference
var clusterStack = new StackReference("clusterproject/cluster1");
var clusterRgName = clusterStack.RequireOutput("clusterRgName").Apply(s => s?.ToString() ?? string.Empty);
var clusterName = clusterStack.RequireOutput("clusterName").Apply(s => s?.ToString() ?? string.Empty);