Can anyone explain to me why <https://github.com/p...
# aws
g
Can anyone explain to me why https://github.com/pulumi/pulumi-awsx/blob/v0.40.1/nodejs/awsx/lb/application.ts#L67 can create multiple pulumi resources
awsx.lb.Listener
but in the end, they all have the same
arn
and in AWS exist as a single listener?
m
Can you share a minimal example of this?
g
simply create a listener in a loop like this, I'd expect this to blow up but it went through which confused me.
Copy code
publicServicePorts.forEach((port) => {
       
        const targetGroup = alb.createTargetGroup(
          `alb-tg-${port}`,
          {
            deregistrationDelay: 10,
            port,
            protocol: "HTTP",
            healthCheck: {
              path: args.healthCheckPath ?? DefaultHealthCheckPath,
              interval: 21,
              timeout: 20,
              unhealthyThreshold: 5,
            },
            slowStart: 30,
            stickiness: {
              cookieDuration: 3600,
              enabled: true,
              type: "lb_cookie",
            },
          },
        );

        portApplicationMappingPublic[port] = {
          targetGroup,
          listener: targetGroup.createListener(
            `lis-https-${port}`,
            {
              certificateArn,
              defaultAction: {
                type: "fixed-response",
                fixedResponse: {
                  contentType: "text/plain",
                  statusCode: "403",
                  messageBody: "403 Forbidden",
                },
              },
              external: false,
              name: `${lbPrefix}-public-${port}`,
              port: 443,
              protocol: "HTTPS",
              sslPolicy: args.publicAccess?.sslPolicy || "ELBSecurityPolicy-TLS13-1-2-2021-06",
            },
          ),
        };
m
Can you share a full example, stripped down to the essential bits?
w
The code that does this is all in that same file - see for example https://github.com/pulumi/pulumi-awsx/blob/bec86712d61b7494104106f01886e81c2976d502/nodejs/awsx/lb/application.ts#L211. It is creating multiple instances of the component, but Bose instances share an underlying default listener instance in AWS via the logic there.
g
Thanks Luke, it starting to make sense! I wish I could just run the code in debug and go through step by step. this magic with object instances is not very obvious because in my case there were 3 items in the state but on one Listener and awsx made it look like there are multiple listeneres
w
I wish I could just run the code in debug and go through step by step.
Yes indeed! You technically can already - see comments on https://github.com/pulumi/pulumi/issues/1372 with suggestions. But we are also working on some improvements to make this more "push button" so you can directly debug a Pulumi program and automatically attach to the processes running any of the components it uses (like AWSX in this case).
g
This is amazing, I remember reading that issue long time ago it has gotten way easier! I am slowly working towards removing AWSX from the codebase. The magic behind finding the
"defaultListener"
which is actually a
targetGroup
is crazy, I feel like an Alice going down the rabbit hole. It is bizarre how the code can create 3 Listeners in the state referring to the same AWS object. I am trying to track down where is the reference to the original kept and how it is propagated to the pulumi resource in the state. So that result is: 3 different
URNs
but the same AWS
id
. And then looping over
createRule
is smart enough to merge all rules into a single listener without causing duplicates