https://pulumi.com logo
#typescript
Title
# typescript
l

little-cartoon-10569

01/21/2021, 12:28 AM
Are there any plans to update the built-in typescript support?
According to https://www.pulumi.com/docs/intro/languages/javascript/#disabling-built-in-typescript-support we're stuck with target: es6 and module: commonjs for now.
I'd quite like top-level await, to help deal with the dreaded awsx.ec2.Vpc -> subnets issue.
But that requires target: es2017 and module: esnext.
b

bored-river-53178

01/21/2021, 12:48 AM
could you please provide more information about the subnets issue?
l

little-cartoon-10569

01/21/2021, 12:49 AM
It's impossible to export a subnetId from a stack, if you're starting from a vpcId.
awsx.ec2.Vpc.fromExistingIds()
gives double-wrapped subnet ids, and there's no way (afaik) to make one of those subnet IDs available to a top-level
export
.
Right now I'm dealing with needing an array of all private subnet IDs, and a single subnet ID, in the same block of code. I've gone back and forth countless times. I can't see how to do it, short of hardcoding a subnet ID in my config file.
I've even resorted to the rather-nasty
Copy code
declare module '@pulumi/pulumi' {
  export interface OutputInstance<T> {
    promise(withUnknowns?: boolean): Promise<T>;
  }
}
but that introduces all sorts of issues when pulumi.Input is used in the same file, because Outputs start auto-converting themselves to Promises...
b

bored-river-53178

01/21/2021, 1:08 AM
thank you
I use awsx.Vpc in one of my stacks and there are subnetIds in stack outputs, but maybe our use cases are quite different
not sure what does that mean > if you're starting from a vpcId
l

little-cartoon-10569

01/21/2021, 1:13 AM
I have a vpcId, imported from another stack. I want to pass a
pulumi.Input<pulumi.Input<string>[]>
of subnet IDs to the constructor of aws.alb.LoadBalancer, and I want to pass a
pulumi.Input<string>
to the constructor of aws.ec2.Instance. I don't want to call any constructors inside a then or apply, as per Pulumi recommendations. How do I do this?
b

bored-river-53178

01/21/2021, 1:15 AM
ah, it's imported, got it
could you also export subnetids in the same imported stack?
l

little-cartoon-10569

01/21/2021, 1:20 AM
Same problem though. At a single level, I can unwrap once, or I can unwrap twice, but not both. At least, not without repeating a significant chunk of code, verbosely and inelegantly.
Right now, I'm getting the
pulumi.Input<pulumi.Input<string>[]>
array of private subnet IDs from the VPC, and I'm passing the
pulumi.Input<string>
as a config parameter to the stack. This makes for the cleanest code, with no duplication. I'd like to improve that, because I could just pick a random subnet ID from that array.. but I haven't been able to find a way to do it.
b

bored-river-53178

01/21/2021, 1:33 AM
what I do: I export a vpc id and the associated networks ids in a stack which uses awsx.Vpc and use these values in other stacks, I don't seem to remember any code duplication related to that but probably I do not fully understand your problem, so I can't help you further
so here is a simplified output example
Copy code
vpcs   : {
                eu-central-1: [
                    [0]: {
                        id            : "vpc-xxx"
                        name          : "main"
                        subnetIds       : [
                            [0]: "subnet-xxx"
                            [1]: "subnet-yyy"
                            [2]: "subnet-zzz"
                        ]
                    }
                ]
            }
p

prehistoric-kite-30979

01/24/2021, 1:54 PM
@bored-river-53178 what does your import look like?