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

freezing-artist-36980

09/09/2022, 3:23 AM
Hi! I'm trying to create a bastion host to connect my private (subnet) RDS. I created a VPC with
awsx
and it throws an error at assigning public subnet ID from newly created VPC to a new EC2 instance. Please help me.
Copy code
const vpc = new awsx.ec2.Vpc("my-vpc");

// Create bastion host
const bastionHost = new awsc.ec2.Instance("bastion-host", {
  ami: ami.id,
  instanceType: awsc.ec2.InstanceTypes.T2_Micro,
  associatePublicIpAddress: true,
  // Reference the public subnet from the custom vpc above
  subnetId: vpc.publicSubnetIds.apply(x => x![0]), // ! Property apply does not exist on type ...
  vpcSecurityGroupIds: [ec2SecurityGroup.id],
  keyName: sshKey.keyName,
});
l

little-cartoon-10569

09/09/2022, 5:30 AM
The publicSubnetIds array is automatically lifted. Don't use
apply()
.
subnetId: vpc.publicSubnetIds[0]
works fine.
f

freezing-artist-36980

09/09/2022, 6:01 AM
I tried but it says
1. Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'Promise<Output<string>[]>'.
Property '0' does not exist on type 'Promise<Output<string>[]>'.
l

little-cartoon-10569

09/09/2022, 7:15 AM
Ah, that's awsx for you. Promises instead of outputs. Is there an equivalent method / member that gives outputs?
If not, then you can wrap the value in an output. That'll allow Pulumi to lift the values correctly.
I think this should do it?
Copy code
subnetId: pulumi.output(vpc.publicSubnetIds)[0]
f

freezing-artist-36980

09/09/2022, 4:59 PM
It works! Thanks, brother.
2 Views