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

breezy-butcher-78604

11/04/2019, 3:18 AM
hi all, trying to create some resources inside an AWS VPC defined by another stack. I’m using the
awsx.ec2.Vpc.fromExistingIds()
method but can’t quite figure out how to supply the right IDs. here’s what I’ve got so far:
Copy code
function toArray<T>(v: T | T[]) {
    return Array.isArray(v) ? v : [v];
}

const cfg = new pulumi.Config();

// Grab the VPC ID from the existing VPC stack
const vpcStack = new pulumi.StackReference(cfg.require("vpcStack"));

// Now create a VPC object from the id
const vpc = awsx.ec2.Vpc.fromExistingIds("vpc", {
    vpcId: vpcStack.getOutput("vpcId"),
    publicSubnetIds: toArray(vpcStack.getOutput("publicSubnetIds"))
});
however when running pulumi up, i get the below error message. I’m pretty new to typescript so my guess is I’m not handling the
Output<T>
type returned from
getOutput()
properly. the output should be an array of subnet IDs, eg:
Copy code
[
    "subnet-abcdefg123456",
    "subnet-foobah12345",
    "subnet-blahblahblah"
]
however it appears its not making it through properly.
t

tall-librarian-49374

11/04/2019, 7:31 AM
Try
Copy code
vpcStack.getOutput("publicSubnetIds").apply(toArray)
b

breezy-butcher-78604

11/04/2019, 7:37 AM
that gives me a compiler error
t

tall-librarian-49374

11/04/2019, 7:46 AM
That's a good error in a sense that it shows the problem at compile time. It looks like the type of
publicSubnetIds
is not great - it doesn't allow an
Output
. Try
toArray(vpcStack.getOutputSync("publicSubnetIds"))
?
b

breezy-butcher-78604

11/04/2019, 7:53 AM
that appears to be working… thanks! I’ll keep going and see what happens