I'm having some more Output fun. I've exported the...
# typescript
p
I'm having some more Output fun. I've exported the publicSubnetIds from an EKS stack with a line like:
export const publicSubnetIds = cluster.core.publicSubnetIds;
and then import them into another stack with
const pubsub = stackMon.getOutput("publicSubnetIds");
I then need to use them to annotate an ingress in a helm chart something like
Copy code
ingress: {
    annotations: {
        '<http://alb.ingress.kubernetes.io/subnets|alb.ingress.kubernetes.io/subnets>': `${pubsub[0]}, ${pubsub[1]}`
or
Copy code
'<http://alb.ingress.kubernetes.io/subnets|alb.ingress.kubernetes.io/subnets>': `${pubsub.join(',')}`
but this results in
Property 'join' does not exist on type 'OutputInstance<any>'.
or a similar error saying I can't index an Output<any> with 0 or 1 What am I getting wrong here? Can I not export an array? Do I need some apply magic on the gotten output before Typescript will accept it is and array and can be joined?
r
I believe
getOutput
returns an object of type
Output
You could either try using
getOutputValue
instead or do
pubsub.apply(value => { // your code that uses the value[0] here })
p
Copy code
const pubsub = stackMon.getOutput("publicSubnetIds");

const grafana = pulumi.all(pubsub).apply(([subnet1, subnet2])=> {
        return new k8s.helm.v3.Release("grafana", {
...
                values: {
...
                        ingress: {
...
                                annotations: {
...
                                        '<http://alb.ingress.kubernetes.io/subnets|alb.ingress.kubernetes.io/subnets>': `${subnet1}, ${subnet2}`,
                                },
                        },
I've removed some static config lines to make it clearer. Now pubsub is an Output<any> which contains and array of 2 strings, or will contain that at runtime when it's looked up. and when I try and run this I get
Copy code
index.ts(132,28): error TS2769: No overload matches this call.
      The last overload gave the following error.
        Argument of type 'Output<any>' is not assignable to parameter of type 'unknown[]'.
          Type 'OutputInstance<any>' is missing the following properties from type 'unknown[]': length, pop, push, concat, and 29 more.
    index.ts(132,44): error TS7031: Binding element 'subnet1' implicitly has an 'any' type.
    index.ts(132,53): error TS7031: Binding element 'subnet2' implicitly has an 'any' type.
any ideas?
const publicSubnetIds = pubsub.apply(list => list.join(','));
is what it took in the end.
Ah no, that gives me
Calling [toString] on an [Output<T>] is not supported.
Ok for the sake of anyone who ends up looking for the answer here:
Copy code
const pubsub = stackMon.getOutput("publicSubnetIds");
...
const pubsubId = pubsub.apply((l: Array<string>) => {
        return l.map(a => `${a}`).join(",");
});
const grafana = new k8s.helm.v3.Release("grafana", {
...
        values: {
                ingress: {
                        annotations: {
                                '<http://alb.ingress.kubernetes.io/subnets|alb.ingress.kubernetes.io/subnets>': pulumi.interpolate `${pubsubId}`,
Is what actually manages to get the annotation to work :D