pulumi / pulumi-ai

222 stars 15 forks source link

AI is suggesting resources that don't exist in AWSx package #69

Open pierskarsenbarg opened 5 months ago

pierskarsenbarg commented 5 months ago

What happened?

Conversation: https://www.pulumi.com/ai/conversations/5c667f81-e6c0-4af6-81db-92e898e5f30c

Output:

import * as awsx from "@pulumi/awsx";

// Create an ECS Fargate cluster.
const cluster = new awsx.ecs.Cluster("my-cluster");

// Define the volume to mount.
const volume: awsx.ecs.Volume = {
    name: "my-volume",
    efsVolumeConfiguration: {
        fileSystemId: "fs-xxxxxxxx", // Replace with the actual file system ID of your EFS storage
    },
};

// Create a Fargate service with a task that has a durable EFS volume mounted.
const service = new awsx.ecs.FargateService("my-service", {
    cluster,
    taskDefinitionArgs: {
        containers: {
            my_container: {
                image: "nginx", // Replace with your preferred container image
                // Set the CPU and memory based on the required Graviton2 processor configuration.
                cpu: 256, // Quarter vCPU
                memory: 512, // 0.5GB memory
                portMappings: [{ containerPort: 80 }],
                mountPoints: [{ containerPath: "/srv", sourceVolume: volume.name }],
                environment: [
                    // Environment variables required by the container can be listed here.
                ],
            },
        },
        volumes: [volume],
        // Specify the platform version, for Fargate use 'LATEST'
        runtimePlatform: {
            cpuArchitecture: 'ARM64', // To use Graviton processors
        },
    },
    // Desired count specifies the number of tasks to run.
    desiredCount: 1,
    // If you need to specify an IAM role for the Fargate execution role, you can do so here.
});

// Export the URL of the service.
export const url = service.endpoint.apply(ep => `http://${ep.hostname}`);

Example

n/a

Output of pulumi about

n/a

Additional context

No response

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).

wongstein commented 5 months ago

Dirty notes:

Piers:

  1. Reason:
    1. Reading an article from an AWS SE in the container space.
      1. Doing an infra as code: it needs to be better
      2. What if I could do : It was that exact phrasing and put it in pulumi.ai
    2. It didn’t quite work.
  2. There’s a couple of bits:
    1. Wanted to build everything to get setup from scratch.
      1. We are using aws provider.
      2. Have awsx (that’s what it suggested using, it did it anyways)
        1. crosswalk: It’s built on top of base aws provider and we can simplify a lot of tasks for you
          1. Ex: vpc = new awsx.ec2.Vpc(“
            1. Not what pulumi.ai gave but piers wanted to show a section and expectations of what to do.
    2. VPC networking in AWS:
      1. To set this up without using crosswalk, you set up a vpc, a gateway, a subnet, route tables, nat gateways
        1. It’s a pain
      2. awsx.ec2.vpc does all that for you.
    3. There are a couple of eco things.
      1. Fargate is an all in 1.
        1. Normally for eco you have a service and task definition
          1. Task definition: This is the container.
          2. Service: how do I run the container and make it available to the outside world.
        2. Fargate has the two thing sin 1.
  3. The things in the issue:
    1. It mentions the clusters:
      1. Awsx before version 1 is typescript only.
        1. In newer version it’s a direct translation, so the product team said we don’t need it in awsx (awsx.ecs.Cluster not existing post version 1, aws.ecs.Cluster is correct)
    2. Awsx.ecs.volume doesn’t exist
      1. aws.types.input.ecs.TaskDefintionVolume does (from base provider
    3. Declaring FargateService
      1. Did a good job mostly
      2. Except: cluster: cluster
        1. Needs to be cluster: cluster.arn
        2. It was correct in version 1, we are on version 2
          1. Here’s schema: https://github.com/pulumi/pulumi-awsx/blob/master/schema.json
          2. Went to V2: October 2023
  4. Is awsx being deprecated?
    1. Awsx is a concept for a long time. Only in typescript/javascript
      1. There was no schema for sdks
      2. It was just an npm package.
      3. This was v0
    2. In v1 it became a multi language component.
    3. Because there were severe breaking changes, kept the node version
      1. There’s a aws classic as a submodule of awsx.
        1. That will be deprecated at some point.
    4. Awsx will be around for awhile.
      1. There hasn’t been a lot of love for it but that might be changing.
  5. Some of the stuff coming out of pulumi.ai is plain wrong or might have been in the classic version
  6. Const volume type :
    1. Didn’t need to have the type in declaration and it would have worked.
    2. The type it did make was wrong
  7. What else needs to be fixed?
    1. We create the filesystem, vpc, security group, then mount target (mount this in this network and security group)
      1. Everything from that up (as long as you got the valid id), then the rest of the Clust + Margate service would be right
      2. The shape is correct
        1. They are correct enough that they will be in older versions of the package
          1. They might not be in the registry
  8. There would have been examples historically that had awsx cluster
AaronFriel commented 3 months ago

@pierskarsenbarg what would you expect the result here with "durable storage volume" - an EBS disk?

pierskarsenbarg commented 3 months ago

I had some long conversations with @wongstein an out this. I think it was assuming a lot from an older version of this example: https://github.com/pulumi/examples/blob/master/aws-ts-lambda-efs/index.ts

I’ve now updated the example with up to date versions of the packages, but when I googled for similar statements as in the AI response it looked like an older version of the example.

It wasn’t exactly the same but close enough

lukehoban commented 1 week ago

I am not able to get it to make up awsx.ecs.Volume - but it does make a lot of mistakes it shouldn't still. A few more recent examples: