I've created a VPC with `awsx.ec2.Vpc`, how can I ...
# general
d
I've created a VPC with
awsx.ec2.Vpc
, how can I create a
aws.elasticache.SubnetGroup
based on the subnets in that VPC? I've tried some different things, code in thread:
Copy code
export const vpc = new awsx.ec2.Vpc("test-pulumi-vpc-2", {
    numberOfAvailabilityZones: 2,
    cidrBlock: "10.0.0.0/16",
    tags: {
        Name: "tf-test",
    },
});

const selectedVpc = pulumi.output(aws.ec2.getVpc({
    tags: {
        Name: vpc.id,
    },
}, { async: true }));
const selectedSubnetIds = selectedVpc.apply(selectedVpc => aws.ec2.getSubnetIds({
    tags: {
        Tier: "private",
    },
    vpcId: selectedVpc.id!,
}, { async: true }));

// const subnetGroup = selectedSubnetIds.apply(ids => {
//     return new aws.elasticache.SubnetGroup("subnetGroup", {
//         subnetIds: [ids], // how to use?
//     });
// })

// const subnetGroup = new aws.elasticache.SubnetGroup("subnetGroup", {
//     subnetIds: [selectedSubnetIds.apply], // how to use?
// });
b
The vpc should have a func to get the Private subnets - does it not?
like vpc.privateSubnetIds as a property
d
@broad-dog-22463
Type 'Promise<Output<string>[]>' is not assignable to type 'Input<string>'.
Copy code
const subnetGroup = new aws.elasticache.SubnetGroup("subnetGroup", {
    subnetIds: [vpc.privateSubnetIds],
});
when I do this
b
can you wrap vpc.privateSubnetIds in pulumi.output() to get the correct type here? (please note, I've not tried this specific example)
d
Seems like it's the wrong way:
Type 'Output<UnwrappedArray<Output<string>>>' is not assignable to type 'Input<string>'.
b
this may give you thoughts on how to achieve this
d
@broad-dog-22463 thanks, but I don't really understand how to resolve it 🤔
b
I am looking for an example for you
❤️ 1
stay put 🙂
d
Thanks 🙏
b
so I jsut tested this and it works
Copy code
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";

export const vpc = new awsx.ec2.Vpc("test-pulumi-vpc-2", {
    numberOfAvailabilityZones: 2,
    cidrBlock: "10.0.0.0/16",
    tags: {
        Name: "tf-test",
    },
});

const subnetGroup = new aws.elasticache.SubnetGroup("subnetGroup", {
    subnetIds: vpc.privateSubnetIds.then(),
}, {
    dependsOn: [vpc]
});
notice the use of
then()
as that resolves the promise
d
@broad-dog-22463 🙏 thank you so much!
b
try it out and let me know if there are any issues 🙂
sorry that was confusing!
d
Didn't realise I could use then() inline like that, cool!
Thanks! Now I have redis up and running 😎
b
ah great news 🙂
d
But it seems there's no way to get "Primary EndpointPrimary endpoint of the cluster" from the redis object I've created
Only
configurationEndpoint
b
configurationEndpoint is memcached only
I think you may need to use cacheNodes and then grab what's in there?
d
@broad-dog-22463 thanks!