square-hair-965
08/25/2022, 8:37 PMOutput<string>
to play nice with the aws.ec2.LaunchTemplate
userData
attribute. I've tried quite a few different approaches but I always seem to wind up with this in my aws console:
Calling [toString] on an [Output<T>] is not supported.
To get the value of an Output<T> as an Output<string> consider either:
1: o.apply(v => `prefix${v}suffix`)
2: pulumi.interpolate `prefix${v}suffix`
See <https://pulumi.io/help/outputs> for more details.
This function may throw in a future version of @pulumi/pulumi.
The userData script is a fairly large bash script that is created by interpolating numerous outputs from other resources. When I export it it's correct in the Pulumi console.
Full component code to follow in the thread ->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;
}
}
steep-toddler-94095
08/25/2022, 8:44 PMargs.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)
userData: args.userData.apply(userData => Buffer.from(userData, 'utf8').toString('base64'),
square-hair-965
08/25/2022, 8:53 PMbillowy-army-68599
08/25/2022, 9:00 PMsquare-hair-965
08/25/2022, 9:05 PMbreezy-airplane-94478
09/09/2022, 4:00 AM