square-ability-48831
08/17/2022, 3:34 AMStackReference
type conversion help, or maybe it's the standard Output/Input handling stuff that I need?
I'm accessing the details of a VPC from a StackReference, and I need the subnetId
as an Input
to an ec2
- whats the best way to be able to treat the subnet output from the StackReference into an array? Or even better - can I grab the full vpc Output object and then interrogate it to get the subnetId I need?
const devopsVpc = vpcStack.getOutput("devopsVpc"); // Full VPC output - can I get this and use it like it was created in this stack?
const devopsVpcPublicSubnetIds = vpcStack.getOutput("devopsVpcPublicSubnetIds"); // Output<any> - can I coerce this to an array?
// output in this stack is Array:
// Outputs:
// + subnetIds: [
// + [0]: "subnet-06a**********3fe0"
// + [1]: "subnet-036**********c6b7"
// ]
// but how to access as an array as input to EC2 creation?
// just need a single subnetId
const host = new ec2.Instance("bastionHost", {
ami: ubuntuAmi,
tags: { "Name": "hostthemost" },
instanceType: "t2.medium",
subnetId: devopsVpcPublicSubnetIds[0], // <-- throws since not an array type
// ...other props...
})
export const subnetIds = devopsVpcPublicSubnetIds; // show sup as an array Output (see above)
steep-toddler-94095
08/17/2022, 4:44 AMconst devopsVpcPublicSubnetIds = vpcStack.getOutput("devopsVpcPublicSubnetIds") as Output<Array<string>>
you can do something similar with the devopsVpc
objectsquare-ability-48831
08/17/2022, 5:04 AM