This message was deleted.
# typescript
s
This message was deleted.
s
Copy code
import * as aws from "@pulumi/aws";
import * as pulumi from "@pulumi/pulumi";

const config = new pulumi.Config();

export interface WorkerLaunchTemplateArgs {
    stack: pulumi.Input<string>;
    instanceType: string;
    vpcSecurityGroupIds: pulumi.Output<any>[];
    userData: pulumi.Output<string>;
    ami: pulumi.Input<string>;
}

export default class WorkerLaunchTemplate extends pulumi.ComponentResource {

    launchTemplateId;

    constructor(name: string, args: WorkerLaunchTemplateArgs, opts?: pulumi.ResourceOptions) {

        super("pkg:index:WorkerLaunchTemplate", name, {}, opts);

        const launchTemplate = new aws.ec2.LaunchTemplate(`${args.stack}-${name}`, {
            imageId: args.ami,
            instanceType: args.instanceType,
            userData: Buffer.from(`${args.userData}`, 'utf8').toString('base64'),
            vpcSecurityGroupIds: args.vpcSecurityGroupIds,
            tagSpecifications: [{
                resourceType: "instance",
                tags: {
                    Name: `${args.stack}-${name}`
                },
            }],

        });

        this.launchTemplateId = launchTemplate.id;
    }

}
Let me know what you guys think. I've had similar issues before and worked around them by refactoring some code but nothing I try here seems to work.
s
args.userData
is an
Output<string>
so you cannot treat it like a string. Similarly to a
Promise
, you can only access its string value in a callback function within the
apply
method (`sort of like Promise's
then
method)
Copy code
userData: args.userData.apply(userData => Buffer.from(userData, 'utf8').toString('base64'),
🙌 1
s
awesome that worked Mike! Thanks so much. I did something similar (though not inline) earlier and I had thought it didn't work but now I wonder if I just forgot to check the latest version in console 😫
p 1
b
s
thanks jaxx, I've gotten my head around what Pulumi wants to do the past few weeks, I just couldn't quite figure out what I was doing wrong with the Buffer func here. I did something similar for my container definitions earlier in the week`.apply(([dbConnection, ...]) => JSON.stringify(...)` I probably should of referred back there. Thanks for the help, really do appreciate it.
b
@billowy-army-68599 thanks for the clarifications here, they helped me out this week. I'm actually learning typescript for the first time through pulumi (zero JS experience either) so I often struggle to even know what I'm supposed to google lol