Does anyone have any advice on debugging the follo...
# typescript
w
Does anyone have any advice on debugging the following
TypeError: Cannot read property 'arn' of undefined
? To work around it I replace the resource output ARN with a static string but this is not ideal.
w
Are you able to share the lb.ts code? A gut feeling is it might be a case where you need to use
.apply()
to resolve the arn value before using it. https://www.pulumi.com/docs/intro/concepts/inputs-outputs/
☝️ 1
l
That error message implies that the thing you're calling
arn
on doesn't exist. I think
apply()
is unlikely to help in this case.
Apologies for pet peeve: pictures of text preclude copying text out of the picture. Real text versions of messages are much more helpful.
w
Apologies,
Copy code
Previewing update (demo-inf):
     Type                          Name                                    Plan       Info
     pulumi:pulumi:Stack           immersify-inf-demo-inf                             1 error
 +   ├─ pulumi:providers:aws       eu-west-1                               create     
 +   ├─ aws:s3:Bucket              crud-service-logs-bucket                create     
 +   ├─ aws:lb:TargetGroup         crud-service-http-tg                    create     
 +   ├─ aws:ec2:SecurityGroup      crud-service-ec2-sg                     create     
 +   ├─ aws:ec2:SecurityGroup      crud-service-alb-sg                     create     
 +   ├─ aws:ec2:SecurityGroupRule  events-rds-instance-allow-crud-service  create     
 +   ├─ aws:ec2:SecurityGroupRule  crud-service-alb-allow-http             create     
 +   ├─ aws:ec2:SecurityGroupRule  crud-service-alb-allow-healthcheck      create     
 +   ├─ aws:ec2:SecurityGroupRule  crud-service-alb-allow-https            create     
 +   ├─ aws:lb:LoadBalancer        crud-service-loadbalancer               create     
 +   └─ aws:lb:Listener            crud-service-http-redirect-listener     create     
 
Diagnostics:
  pulumi:pulumi:Stack (immersify-inf-demo-inf):
    error: Running program '/Users/mikaelallison/workspace/gdsgroup/immersify-inf' failed with an unhandled exception:
    TypeError: Cannot read property 'arn' of undefined
        at Object.<anonymous> (/Users/mikaelallison/workspace/gdsgroup/immersify-inf/lb.ts:62:34)
        at Module._compile (internal/modules/cjs/loader.js:1085:14)
        at Module.m._compile (/Users/mikaelallison/workspace/gdsgroup/immersify-inf/node_modules/ts-node/src/index.ts:439:23)
        at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
        at Object.require.extensions.<computed> [as .ts] (/Users/mikaelallison/workspace/gdsgroup/immersify-inf/node_modules/ts-node/src/index.ts:442:12)
        at Module.load (internal/modules/cjs/loader.js:950:32)
        at Function.Module._load (internal/modules/cjs/loader.js:790:12)
        at Module.require (internal/modules/cjs/loader.js:974:19)
        at require (internal/modules/cjs/helpers.js:93:18)
        at Object.<anonymous> (/Users/mikaelallison/workspace/gdsgroup/immersify-inf/route53.ts:5:1)
The error is pointing to a cert I have passed to a listener for an application loadbalancer.
acmCertIreland.arn
Copy code
new lb.Listener(`${crudService}-http-listener`, {
  loadBalancerArn: crudServiceLoadBalancer.arn,
  port: 443,
  protocol: 'HTTPS',
  sslPolicy: 'ELBSecurityPolicy-2016-08',
  certificateArn: acmCertIreland.arn,

  defaultActions: [
    {
      type: 'forward',
      targetGroupArn: crudServiceHttpTargetGroup.arn,
    },
  ],
}, { dependsOn: acmCertIreland })
The cert definitely exists. I'm using the cert elsewhere in the code base. I suspect that maybe there is a dependency issue in the new resources I am trying to create and that this message might be a red herring. However, pasting the ARN in makes the error go away
l
It's not saying that the certificate doesn't exist. It's saying that
arn
is being called on
undefined
. If you're using the
acmCertIreland
object elsewhere (in the same conditional branch?), then could it be crudServiceLoadBalancer or crudServiceHttpTargetGroup that is undefined?
w
Hi @little-cartoon-10569, Can you please clarify what you mean by "conditional branch"?
acmCertIreland
is being used elsewhere in the stack.
The
crudServiceLoadBalancer
and
crudServiceHttpTargetGroup
are to be created. See below:
Copy code
export const crudServiceLoadBalancer = new lb.LoadBalancer(`${crudService}-loadbalancer`, {
  name: crudService,
  internal: false,
  loadBalancerType: 'application',
  securityGroups: [ crudServiceAlbSg.id ],
  subnets: vpc.publicSubnetIds,
  enableDeletionProtection: true,

  accessLogs: {
    bucket: crudServiceLogsBucket.bucket,
    prefix: crudService,
    enabled: true
  }
})

export const crudServiceHttpTargetGroup = new lb.TargetGroup(`${crudService}-http-tg`, {
  vpcId: vpc.id,
  targetType: 'instance',
  protocol: 'HTTP',
  port: 8080,
  deregistrationDelay: 300,

  healthCheck: {
    interval: 10,
    timeout: 4,
    path: '/actuator/health',
    healthyThreshold: 2,
    unhealthyThreshold: 4,
  },
})

new lb.Listener(`${crudService}-http-redirect-listener`, {
  loadBalancerArn: crudServiceLoadBalancer.arn,
  port: 80,
  protocol: 'HTTP',

  defaultActions: [
    {
      type: 'redirect',
      redirect: {
        port: '443',
        protocol: 'HTTPS',
        statusCode: 'HTTP_301'
      },
    },
  ]
})

new lb.Listener(`${crudService}-http-listener`, {
  loadBalancerArn: crudServiceLoadBalancer.arn,
  port: 443,
  protocol: 'HTTPS',
  sslPolicy: 'ELBSecurityPolicy-2016-08',
  certificateArn: acmCertIreland.arn,

  defaultActions: [
    {
      type: 'forward',
      targetGroupArn: crudServiceHttpTargetGroup.arn,
    },
  ],
}, { dependsOn: acmCertIreland })
l
I was wondering if the code with the error is being called under one guard (e.g. "if stack is prod") and the certificate is being called under another (e.g. "if stack is staging"). Just grasping at straws...
w
Oh, I get you. No, no gates at present. As you can see I have tried with depends option on the resource.
Do you think it is worth raising an issue? Or am I lacking enough debug information??
l
I think more code is required to be sure. Can you make a single MCVE in a gist, or similar?