green-oyster-88467
02/18/2025, 12:44 AMpulumi up --diff
.
Code:
export const hostedZoneAppARecord = new aws.route53.Record(
'hostedZoneAppARecord',
{
name: `app.${config.require('hosted_zone_domain')}`,
type: aws.route53.RecordType.A,
zoneId: hostedZone.zoneId,
aliases: [
{
name: distribution.domainName.apply((domainName) => domainName),
evaluateTargetHealth: false,
zoneId: distribution.hostedZoneId.apply(
(hostedZoneId) => hostedZoneId
)
}
]
},
{ dependsOn: [distribution] }
);
Error:
[urn=urn:pulumi:dev::redacted::pulumi:pulumi:Stack::redacted] error: Running program 'redacted/index.ts' failed with an unhandled exception:
TypeError: Cannot read properties of undefined (reading 'domainName')
The undefined thing it complains about is distribution
.
I'm loading everything via barrel files. (export * from './file'). Distribution is loaded before the DNS record in the index.
Does anyone have any ideas?little-cartoon-10569
02/18/2025, 1:34 AMgreen-oyster-88467
02/18/2025, 1:46 AMexport const distribution = new cloudfront.Distribution(
'Distribution',
{
aliases: [domain, `app.${domain}`],
defaultCacheBehavior: {
allowedMethods: ['GET', 'HEAD'],
cachePolicyId: '658327ea-f89d-4fab-a63d-7e88639e58f6',
cachedMethods: ['GET', 'HEAD'],
compress: true,
targetOriginId: 'bucket',
viewerProtocolPolicy: 'redirect-to-https',
functionAssociations: [
{
eventType: 'viewer-request',
functionArn: redirectFunction.arn
}
]
},
defaultRootObject: 'index.html',
enabled: true,
isIpv6Enabled: false,
orderedCacheBehaviors: [
{
allowedMethods: ['POST', 'GET', 'HEAD', 'PATCH', 'DELETE', 'OPTIONS', 'PUT'],
cachePolicyId: '4135ea2d-6df8-44a3-9df3-4b5a84be39ad',
cachedMethods: ['GET', 'HEAD'],
compress: true,
originRequestPolicyId: '216adef6-5c7f-47e4-b989-5492eafa07d3',
pathPattern: '/api/*',
targetOriginId: 'load-balancer',
viewerProtocolPolicy: 'redirect-to-https'
},
{
cachePolicyId: '658327ea-f89d-4fab-a63d-7e88639e58f6',
pathPattern: '/files/*',
allowedMethods: ['GET', 'HEAD'],
targetOriginId: fileBucket.bucketDomainName,
cachedMethods: ['GET', 'HEAD'],
viewerProtocolPolicy: 'redirect-to-https',
compress: true,
trustedKeyGroups: [fileBucketKeyGroup.id]
}
],
origins: [
{
domainName: frontendBucket.bucketDomainName,
originId: 'origin-id',
s3OriginConfig: {
originAccessIdentity: originAccessIdentity.cloudfrontAccessIdentityPath
}
},
{
domainName: fileBucket.bucketDomainName,
originId: fileBucket.bucketDomainName,
originAccessControlId: originAccessControl.id
},
{
customOriginConfig: {
httpPort: 80,
httpsPort: 443,
originProtocolPolicy: 'match-viewer',
originSslProtocols: ['TLSv1.2']
},
domainName: ingressALB.status.loadBalancer.ingress.apply(([x]) => x.hostname),
originId: 'load-balancer',
customHeaders: [
{
name: 'X-Custom-Header',
value: 'redacted'
}
]
}
],
restrictions: {
geoRestriction: {
restrictionType: 'none'
}
},
viewerCertificate: {
acmCertificateArn: certificateArn,
minimumProtocolVersion: 'TLSv1.2_2021',
sslSupportMethod: 'sni-only'
}
},
{
protect: true
}
);
I then have several index files. which look like this:
distribution/index.ts: export * from './distribution'
route53/index.ts: export * from './domain'
Then in my main index:
export * from './distribution'
export * from './route53'
It can deploy and work fine, so long as I don't try to reference it with the route 53 code. At the moment the distribution is deployed as it had a lot of manual assistance with creating the domains initially. I'm trying to make things more maintainable by moving the route 53 things into pulumi given that we are changing domains now.little-cartoon-10569
02/18/2025, 1:53 AMlittle-cartoon-10569
02/18/2025, 1:54 AMdistribution
value?green-oyster-88467
02/18/2025, 1:55 AMimport { distribution } from '../cloudfront';
little-cartoon-10569
02/18/2025, 1:59 AMdistribution
from distribution.ts and then importing it from cloudfront.ts? That might be the problem. I would certainly be investigating that value of distribution
at various points. Given the code you've posted, there's no problem with the Pulumi parts. The only problem is that distribution
is null when you're trying to dereference it.green-oyster-88467
02/18/2025, 2:09 AMThat might be the problemTurns out it was the problem. I removed the index files and directly imported the things as needed and it worked. Thank you for your help 🙂
little-cartoon-10569
02/18/2025, 2:14 AM