https://pulumi.com logo
d

dazzling-sundown-39670

05/27/2020, 11:32 AM
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

broad-dog-22463

05/27/2020, 11:34 AM
The vpc should have a func to get the Private subnets - does it not?
like vpc.privateSubnetIds as a property
d

dazzling-sundown-39670

05/27/2020, 11:36 AM
@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

broad-dog-22463

05/27/2020, 11:37 AM
can you wrap vpc.privateSubnetIds in pulumi.output() to get the correct type here? (please note, I've not tried this specific example)
d

dazzling-sundown-39670

05/27/2020, 11:38 AM
Seems like it's the wrong way:
Type 'Output<UnwrappedArray<Output<string>>>' is not assignable to type 'Input<string>'.
b

broad-dog-22463

05/27/2020, 11:40 AM
this may give you thoughts on how to achieve this
d

dazzling-sundown-39670

05/27/2020, 11:46 AM
@broad-dog-22463 thanks, but I don't really understand how to resolve it 🤔
b

broad-dog-22463

05/27/2020, 11:50 AM
I am looking for an example for you
❤️ 1
stay put 🙂
d

dazzling-sundown-39670

05/27/2020, 11:52 AM
Thanks 🙏
b

broad-dog-22463

05/27/2020, 12:10 PM
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

dazzling-sundown-39670

05/27/2020, 12:11 PM
@broad-dog-22463 🙏 thank you so much!
b

broad-dog-22463

05/27/2020, 12:12 PM
try it out and let me know if there are any issues 🙂
sorry that was confusing!
d

dazzling-sundown-39670

05/27/2020, 12:13 PM
Didn't realise I could use then() inline like that, cool!
Thanks! Now I have redis up and running 😎
b

broad-dog-22463

05/27/2020, 12:20 PM
ah great news 🙂
d

dazzling-sundown-39670

05/27/2020, 12:23 PM
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

broad-dog-22463

05/27/2020, 12:25 PM
configurationEndpoint is memcached only
I think you may need to use cacheNodes and then grab what's in there?
d

dazzling-sundown-39670

05/27/2020, 1:02 PM
@broad-dog-22463 thanks!
2 Views