https://pulumi.com logo
#general
Title
# general
f

freezing-flag-53289

03/03/2020, 12:15 AM
What's the right way to lookup a resource that's been created in a loop to use in the
parent:
block of another resource? I got stuck because I can unwrap the promise to check the string, but I can't seem to do that and keep a reference to the resource which is what I actually need. For example, say I created a bunch of
kubernetes.core.v1.Namespace
resources in a function and now I have an array of them. What's the right way to do this:
Copy code
// namespaces is an array of kubernetes.core.v1.Namespace
const myNamespace = namespaces.find(
    ns => ns.metadata.name === 'mynamespace' // Usual Output<string> is not a string problem
);

// Use mynamespace as parent
new k8s.helm.v2.Chart(
    'myChart',
    {
        path: chartPath,
    },
    {
        parent: myNamespace
    }
);
t

tall-librarian-49374

03/03/2020, 8:17 AM
I’d say you’d have to return more information from the loop, e.g. not an array of namespaces but a map of namespaces by name. You can’t extract the name from outputs for the purpose of defining the parent.
25 Views