@@ -8,11 +8,11 @@ export type StaticSiteArgs = {
88 * The domain which will be used to access the static site.
99 * The domain or subdomain must belong to the provided hostedZone.
1010 */
11- domain : pulumi . Input < string > ;
11+ domain ? : pulumi . Input < string > ;
1212 /**
1313 * The ID of the hosted zone.
1414 */
15- hostedZoneId : pulumi . Input < string > ;
15+ hostedZoneId ? : pulumi . Input < string > ;
1616 /**
1717 * A map of tags to assign to the resource.
1818 */
@@ -23,7 +23,7 @@ export type StaticSiteArgs = {
2323
2424export class StaticSite extends pulumi . ComponentResource {
2525 name : string ;
26- certificate : AcmCertificate ;
26+ certificate ? : AcmCertificate ;
2727 bucket : aws . s3 . Bucket ;
2828 cloudfront : aws . cloudfront . Distribution ;
2929
@@ -36,18 +36,28 @@ export class StaticSite extends pulumi.ComponentResource {
3636
3737 this . name = name ;
3838 const { domain, hostedZoneId, tags } = args ;
39- this . certificate = this . createTlsCertificate ( { domain, hostedZoneId } ) ;
39+ const hasCustomDomain = domain && hostedZoneId ;
40+ if ( domain && ! hostedZoneId ) {
41+ throw new Error (
42+ 'StaticSite:hostedZoneId must be provided when the domain is specified' ,
43+ ) ;
44+ }
45+ if ( hasCustomDomain ) {
46+ this . certificate = this . createTlsCertificate ( { domain, hostedZoneId } ) ;
47+ }
4048 this . bucket = this . createPublicBucket ( { tags } ) ;
4149 this . cloudfront = this . createCloudfrontDistribution ( { domain, tags } ) ;
42- this . createDnsRecord ( { domain, hostedZoneId } ) ;
50+ if ( hasCustomDomain ) {
51+ this . createDnsRecord ( { domain, hostedZoneId } ) ;
52+ }
4353
4454 this . registerOutputs ( ) ;
4555 }
4656
4757 private createTlsCertificate ( {
4858 domain,
4959 hostedZoneId,
50- } : Pick < StaticSiteArgs , 'domain' | 'hostedZoneId' > ) {
60+ } : Pick < Required < StaticSiteArgs > , 'domain' | 'hostedZoneId' > ) {
5161 const certificate = new AcmCertificate (
5262 `${ domain } -acm-certificate` ,
5363 {
@@ -120,14 +130,20 @@ export class StaticSite extends pulumi.ComponentResource {
120130 {
121131 enabled : true ,
122132 defaultRootObject : 'index.html' ,
123- aliases : [ domain ] ,
133+ ... ( domain && { aliases : [ domain ] } ) ,
124134 isIpv6Enabled : true ,
125135 waitForDeployment : true ,
126136 httpVersion : 'http2and3' ,
127137 viewerCertificate : {
128- acmCertificateArn : this . certificate . certificate . arn ,
129- sslSupportMethod : 'sni-only' ,
130- minimumProtocolVersion : 'TLSv1.2_2021' ,
138+ ...( this . certificate
139+ ? {
140+ acmCertificateArn : this . certificate . certificate . arn ,
141+ sslSupportMethod : 'sni-only' ,
142+ minimumProtocolVersion : 'TLSv1.2_2021' ,
143+ }
144+ : {
145+ cloudfrontDefaultCertificate : true ,
146+ } ) ,
131147 } ,
132148 origins : [
133149 {
@@ -171,7 +187,7 @@ export class StaticSite extends pulumi.ComponentResource {
171187 private createDnsRecord ( {
172188 domain,
173189 hostedZoneId,
174- } : Pick < StaticSiteArgs , 'domain' | 'hostedZoneId' > ) {
190+ } : Pick < Required < StaticSiteArgs > , 'domain' | 'hostedZoneId' > ) {
175191 const cdnAliasRecord = new aws . route53 . Record (
176192 `${ this . name } -cdn-route53-record` ,
177193 {
0 commit comments