2
2
3
3
import * as aws from "@pulumi/aws" ;
4
4
import * as pulumi from "@pulumi/pulumi" ;
5
-
6
5
import * as fs from "fs" ;
7
6
import * as mime from "mime" ;
8
7
import * as path from "path" ;
9
8
9
+
10
10
// Load the Pulumi program configuration. These act as the "parameters" to the Pulumi program,
11
11
// so that different Pulumi Stacks can be brought up using the same code.
12
12
@@ -19,10 +19,10 @@ const config = {
19
19
targetDomain : stackConfig . require ( "targetDomain" ) ,
20
20
// (Optional) ACM certificate ARN for the target domain; must be in the us-east-1 region. If omitted, an ACM certificate will be created.
21
21
certificateArn : stackConfig . get ( "certificateArn" ) ,
22
- // If true create an A record for the www subdomain of targetDomain pointing to the generated cloudfront distribution.
22
+ // If true create an A record for the www subdomain of targetDomain pointing to the generated cloudfront distribution.
23
23
// If a certificate was generated it will support this subdomain.
24
- // default: true
25
- includeWWW : stackConfig . getBoolean ( "includeWWW" ) || true
24
+ // default: true
25
+ includeWWW : stackConfig . getBoolean ( "includeWWW" ) || true ,
26
26
} ;
27
27
28
28
// contentBucket is the S3 bucket that the website's contents will be stored in.
@@ -98,11 +98,11 @@ if (config.certificateArn === undefined) {
98
98
} ) ;
99
99
100
100
// if config.includeWWW include required subjectAlternativeNames to support the www subdomain
101
- let certificateConfig :aws . acm . CertificateArgs = {
101
+ const certificateConfig : aws . acm . CertificateArgs = {
102
102
domainName : config . targetDomain ,
103
- validationMethod : "DNS" ,
104
- subjectAlternativeNames : config . includeWWW ? [ `www.${ config . targetDomain } ` ] : [ ]
105
- }
103
+ validationMethod : "DNS" ,
104
+ subjectAlternativeNames : config . includeWWW ? [ `www.${ config . targetDomain } ` ] : [ ] ,
105
+ } ;
106
106
107
107
const certificate = new aws . acm . Certificate ( "certificate" , certificateConfig , { provider : eastRegion } ) ;
108
108
@@ -122,7 +122,7 @@ if (config.certificateArn === undefined) {
122
122
} ) ;
123
123
124
124
// if config.includeWWW ensure we validate the www subdomain as well
125
- var subdomainCertificateValidationDomain ;
125
+ let subdomainCertificateValidationDomain ;
126
126
if ( config . includeWWW ) {
127
127
subdomainCertificateValidationDomain = new aws . route53 . Record ( `${ config . targetDomain } -validation2` , {
128
128
name : certificate . domainValidationOptions [ 1 ] . resourceRecordName ,
@@ -134,8 +134,8 @@ if (config.certificateArn === undefined) {
134
134
}
135
135
136
136
// if config.includeWWW include the validation record for the www subdomain
137
- const validationRecordFqdns = subdomainCertificateValidationDomain === undefined ?
138
- [ certificateValidationDomain . fqdn ] : [ certificateValidationDomain . fqdn , subdomainCertificateValidationDomain . fqdn ]
137
+ const validationRecordFqdns = subdomainCertificateValidationDomain === undefined ?
138
+ [ certificateValidationDomain . fqdn ] : [ certificateValidationDomain . fqdn , subdomainCertificateValidationDomain . fqdn ] ;
139
139
140
140
/**
141
141
* This is a _special_ resource that waits for ACM to complete validation via the DNS record
@@ -155,7 +155,7 @@ if (config.certificateArn === undefined) {
155
155
}
156
156
157
157
// if config.includeWWW include an alias for the www subdomain
158
- const distributionAliases = config . includeWWW ? [ config . targetDomain , `www.${ config . targetDomain } ` ] : [ config . targetDomain ]
158
+ const distributionAliases = config . includeWWW ? [ config . targetDomain , `www.${ config . targetDomain } ` ] : [ config . targetDomain ] ;
159
159
160
160
// distributionArgs configures the CloudFront distribution. Relevant documentation:
161
161
// https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html
@@ -279,11 +279,11 @@ function createWWWAliasRecord(targetDomain: string, distribution: aws.cloudfront
279
279
const domainParts = getDomainAndSubdomain ( targetDomain ) ;
280
280
const hostedZoneId = aws . route53 . getZone ( { name : domainParts . parentDomain } , { async : true } ) . then ( zone => zone . zoneId ) ;
281
281
282
- return new aws . route53 . Record (
283
- `${ targetDomain } -www-alias` ,
282
+ return new aws . route53 . Record (
283
+ `${ targetDomain } -www-alias` ,
284
284
{
285
- name : `www.${ targetDomain } ` ,
286
- zoneId : hostedZoneId ,
285
+ name : `www.${ targetDomain } ` ,
286
+ zoneId : hostedZoneId ,
287
287
type : "A" ,
288
288
aliases : [
289
289
{
@@ -292,18 +292,18 @@ function createWWWAliasRecord(targetDomain: string, distribution: aws.cloudfront
292
292
evaluateTargetHealth : true ,
293
293
} ,
294
294
] ,
295
- }
296
- )
295
+ } ,
296
+ ) ;
297
297
}
298
298
299
299
const aRecord = createAliasRecord ( config . targetDomain , cdn ) ;
300
- if ( config . includeWWW ) {
300
+ if ( config . includeWWW ) {
301
301
const cnameRecord = createWWWAliasRecord ( config . targetDomain , cdn ) ;
302
302
}
303
303
304
304
// Export properties from this stack. This prints them at the end of `pulumi up` and
305
305
// makes them easier to access from the pulumi.com.
306
- export const contentBucketUri = pulumi . interpolate `s3://${ contentBucket . bucket } ` ;
306
+ export const contentBucketUri = pulumi . interpolate `s3://${ contentBucket . bucket } ` ;
307
307
export const contentBucketWebsiteEndpoint = contentBucket . websiteEndpoint ;
308
308
export const cloudFrontDomain = cdn . domainName ;
309
309
export const targetDomainEndpoint = `https://${ config . targetDomain } /` ;
0 commit comments