pulumi / pulumi-ai

222 stars 15 forks source link

Generated program that uses, say, `pulumi.asset` module doesn't import the module in the program #87

Open MitchellGerdisch opened 1 month ago

MitchellGerdisch commented 1 month ago

What happened?

I asked AI the following:

I want a lambda hello-world function with the function code in the pulumi program and I want the program to output a link that can be used to test the lambda

The program it generates includes

// Define the inline code for the Lambda function
const lambdaCode = `exports.handler = async (event) => {
    console.log("Hello World");
    return {
        statusCode: 200,
        body: JSON.stringify('Hello World'),
    };
};`;

// Create the Lambda function with the inline code
const lambdaFunction = new aws.lambda.Function("helloWorldFunction", {
    code: new pulumi.asset.AssetArchive({
        "index.js": new pulumi.asset.StringAsset(lambdaCode),
    }),
    role: lambdaRole.arn,
    handler: "index.handler",
    runtime: aws.lambda.Runtime.NodeJS12dX,
});

As you can see it uses pulumi.asset.StringAsset but the generated program does not include `import * as pulumi from "@pulumi/pulumi";

This is especially vexing when using Pulumi AI in new project wizard since the deployment naturally fails.

Example

See above.

Output of pulumi about

N/A

Additional context

There is an additional problem in the above code in that it uses specifies node 12 for the lambda runtime but AWS no longer supports node 12 for lambda.

And FWIW, the following prompt generates usable code:

I want a lambda hello-world function with the function code in the pulumi program and I want the program to output a link that can be used to test the lambda and don't forget to include the pulumi/pulumi package and be sure to use node 18 for the lambda runtime

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).