Skip to content

Commit

Permalink
Many fixes to the pulumi policy. Unable to really know how wrong this…
Browse files Browse the repository at this point in the history
… is.
  • Loading branch information
Zemnmez committed Jun 5, 2023
1 parent 959017a commit cefc492
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions ts/pulumi/lib/website.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function relative(from: string, to: string): string {
throw new Error(errorMessage);
}

return t.slice(f.length);
return path.relative(f, t);
}

export interface Args {
Expand Down Expand Up @@ -76,8 +76,16 @@ export class Website extends pulumi.ComponentResource {
) {
super('ts:pulumi:lib:Website', name, args, opts);

/**
* The final subdomain that the website can be loaded from on the target domain.
*/
const targetDomain = args.zone.name.apply(zoneName =>
[args.subDomain, zoneName].filter(guard.isDefined).join('.')
);


const cert = new aws.acm.Certificate(`${name}_cert`, {
domainName: args.subDomain,
domainName: targetDomain,
validationMethod: 'DNS',
});

Expand Down Expand Up @@ -105,8 +113,7 @@ export class Website extends pulumi.ComponentResource {
? relative(args.directory, args.notFound)
: undefined;

const bucket = new aws.s3.Bucket(`${name}_bucket`, {
acl: 'public-read',
const bucket = new aws.s3.Bucket(`${name.replace(/[^a-z0-9\.]/g, "-")}-bucket`, {
website: {
indexDocument,
errorDocument,
Expand Down Expand Up @@ -139,8 +146,7 @@ export class Website extends pulumi.ComponentResource {
guard.isNotNull,
() => `couldn't get contentType of ${fPath}`
)(mime.getType(fPath)),
source: fPath,
acl: 'public-read',
source: fPath
})
);
}
Expand Down Expand Up @@ -169,13 +175,6 @@ export class Website extends pulumi.ComponentResource {

// create the cloudfront

/**
* The final subdomain that the website can be loaded from on the target domain.
*/
const targetDomain = args.zone.name.apply(zoneName =>
[args.subDomain, zoneName].filter(guard.isDefined).join('.')
);

const distribution = new aws.cloudfront.Distribution(
`${name}_cloudfront_distribution`,
{
Expand All @@ -200,7 +199,7 @@ export class Website extends pulumi.ComponentResource {
{
errorCode: 404,
responseCode: 404,
responsePagePath: errorDocumentObject.key,
responsePagePath: pulumi.interpolate`/${errorDocumentObject.key}`,
},
],
}
Expand All @@ -221,7 +220,7 @@ export class Website extends pulumi.ComponentResource {
// i'm fairly sure this is correct, but the docs kinda suck
// on which of AWS's many IDs this might be and sapling histgrep
// is broken.
targetOriginId: bucket.id,
targetOriginId: `${name}_cloudfront_distribution`,
forwardedValues: {
queryString: false,
// I'm not using cookies for anything yet.
Expand Down

0 comments on commit cefc492

Please sign in to comment.