-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pulumi to the project to start deploying infrastructure
We're using Pulumi here to deploy two things - A Cloudfront distribution - An OIDC provider This required a small amount of reconfiguration of the linters to allow for the slightly different settings that Pulumi requires. We've added pulumi to the dev container so that it can be run from there. We're also adding a GitHub Actions workflow to deploy the infrastructure when the code is pushed to the main branch, using the OIDC provider (which has been applied manually to bootstrap the process).
- Loading branch information
Showing
18 changed files
with
1,560 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
on: | ||
pull_request: | ||
|
||
push: | ||
branches: | ||
- main | ||
|
||
name: Authenticate with AWS | ||
|
||
jobs: | ||
oidc: | ||
permissions: | ||
contents: read | ||
id-token: write | ||
pull-requests: write | ||
|
||
runs-on: ubuntu-latest | ||
|
||
env: | ||
AWS_REGION: eu-west-2 | ||
STATE_BUCKET: coldoutsi.de-pulumi-state | ||
|
||
steps: | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2 | ||
with: | ||
audience: coldoutsi.de-dev | ||
aws-region: ${{ env.AWS_REGION }} | ||
role-to-assume: arn:aws:iam::072248381277:role/oidcRole-715afe8 | ||
|
||
- name: Print session info | ||
run: aws sts get-caller-identity | ||
|
||
- name: Check out | ||
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 | ||
|
||
- name: Enable corepack | ||
run: | | ||
corepack enable | ||
- name: Set up Node.js | ||
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 | ||
with: | ||
node-version-file: "package.json" | ||
cache: "yarn" | ||
|
||
- name: Install dependencies | ||
run: yarn workspace pulumi install --immutable | ||
|
||
- name: Pulumi preview | ||
uses: pulumi/actions@18b5a33fc447ab919feb61f2bb41147a1b30ab40 # v5.2.4 | ||
with: | ||
cloud-url: | ||
s3://${{ env.STATE_BUCKET }}?region=${{ env.AWS_REGION }}&awssdk=v2 | ||
stack-name: organization/coldoutsi.de/dev | ||
command: preview | ||
comment-on-pr: true | ||
comment-on-summary: true | ||
work-dir: pulumi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ coverage/ | |
|
||
# Personal settings | ||
.vscode/settings.json | ||
.devcontainer/.env | ||
|
||
# Secrets in here | ||
.env* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ | |
"workspaces": { | ||
"packages": [ | ||
"app", | ||
"gen/*" | ||
"gen/*", | ||
"pulumi" | ||
] | ||
}, | ||
"type": "module", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bin/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
secretsprovider: awskms://12e131e6-2150-4361-913b-803c04bd5ed5?region=eu-west-2&awssdk=v2 | ||
encryptedkey: AQICAHhLE3kXzgyhKhfd8kMt7I2EBNdrJw7DPra9AQz3o1duvwFP5X23eeRpxqRKtjmP4VNoAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMDGX3lZXomIJHHVIMAgEQgDuk/UkIZt7A+8db7RGO9aWvexlDZxGmSK6m7Wda/LXX0gblOSKbjyYxW+cheqvz0Jvx8fkHNPep0dZgSA== | ||
config: | ||
gitHubRepo: iainlane/coldoutsi.de | ||
targetDomain: dev | ||
targetZone: coldoutsi.de |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: coldoutsi.de | ||
runtime: | ||
name: nodejs | ||
options: | ||
# https://github.com/TypeStrong/ts-node/issues/1007 | ||
nodeargs: "--loader ts-node/esm --no-warnings" | ||
description: Pulumi program for coldoutsi.de | ||
config: | ||
pulumi:tags: | ||
value: | ||
pulumi:template: typescript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import * as aws from "@pulumi/aws"; | ||
import * as aws_native from "@pulumi/aws-native"; | ||
import * as pulumi from "@pulumi/pulumi"; | ||
|
||
const config = new pulumi.Config(); | ||
|
||
const targetZone = config.require("targetZone"); | ||
const targetDomain = config.require("targetDomain"); | ||
|
||
const targetDomainFull = `${targetDomain}.${targetZone}`; | ||
|
||
const hostedZone = new aws.route53.Zone("zone", { | ||
name: targetZone, | ||
}); | ||
|
||
const logsBucket = new aws_native.s3.Bucket("requestLogs", { | ||
bucketName: `${targetDomainFull}-logs`, | ||
ownershipControls: { | ||
rules: [ | ||
{ | ||
objectOwnership: | ||
aws_native.s3.BucketOwnershipControlsRuleObjectOwnership | ||
.BucketOwnerPreferred, | ||
}, | ||
], | ||
}, | ||
publicAccessBlockConfiguration: { | ||
blockPublicAcls: true, | ||
blockPublicPolicy: true, | ||
ignorePublicAcls: true, | ||
restrictPublicBuckets: true, | ||
}, | ||
}); | ||
|
||
const awsUsEast = new aws.Provider("aws-us-east-1", { | ||
profile: aws_native.config.profile, | ||
region: "us-east-1", | ||
}); | ||
|
||
const certificate = new aws.acm.Certificate( | ||
`${targetDomain}-cert`, | ||
{ | ||
domainName: targetDomainFull, | ||
validationMethod: "DNS", | ||
}, | ||
{ | ||
provider: awsUsEast, | ||
}, | ||
); | ||
|
||
const certificateValidationDomain = new aws.route53.Record( | ||
`${targetDomain}-cert-validation`, | ||
{ | ||
name: certificate.domainValidationOptions[0].resourceRecordName, | ||
zoneId: hostedZone.zoneId, | ||
type: certificate.domainValidationOptions[0].resourceRecordType, | ||
records: [certificate.domainValidationOptions[0].resourceRecordValue], | ||
ttl: 60, | ||
}, | ||
); | ||
|
||
const certificateValidation = new aws.acm.CertificateValidation( | ||
"certificateValidation", | ||
{ | ||
certificateArn: certificate.arn, | ||
validationRecordFqdns: [certificateValidationDomain.fqdn], | ||
}, | ||
{ | ||
provider: awsUsEast, | ||
}, | ||
); | ||
|
||
const origin = { | ||
customOriginConfig: { | ||
originProtocolPolicy: "https-only", | ||
}, | ||
domainName: `api.${targetDomainFull}`, | ||
id: `api-${targetDomainFull}`, | ||
} satisfies aws_native.types.input.cloudfront.DistributionOriginArgs; | ||
|
||
const cachePolicy = new aws_native.cloudfront.CachePolicy( | ||
"coldoutsi.de-cache-policy", | ||
{ | ||
cachePolicyConfig: { | ||
name: "coldoutsi-de-cache-policy", | ||
defaultTtl: 60 * 60, // 1 hour | ||
minTtl: 60, // 1 minute | ||
maxTtl: 60 * 60 * 24, // 1 day | ||
parametersInCacheKeyAndForwardedToOrigin: { | ||
cookiesConfig: { | ||
cookieBehavior: "none", | ||
}, | ||
enableAcceptEncodingGzip: true, | ||
enableAcceptEncodingBrotli: true, | ||
headersConfig: { | ||
headerBehavior: "whitelist", | ||
headers: [ | ||
"Accept", | ||
"Accept-Language", | ||
"CloudFront-Viewer-Latitude", | ||
"CloudFront-Viewer-Longitude", | ||
"Content-Type", | ||
"If-None-Match", | ||
"Last-Modified", | ||
], | ||
}, | ||
queryStringsConfig: { | ||
queryStringBehavior: "whitelist", | ||
queryStrings: ["format"], | ||
}, | ||
}, | ||
}, | ||
}, | ||
); | ||
|
||
const cloudFrontDistribution = new aws_native.cloudfront.Distribution( | ||
"coldoutsi.de-dev", | ||
{ | ||
distributionConfig: { | ||
aliases: [targetDomainFull], | ||
defaultCacheBehavior: { | ||
cachePolicyId: cachePolicy.id, | ||
targetOriginId: origin.id, | ||
viewerProtocolPolicy: "redirect-to-https", | ||
}, | ||
enabled: true, | ||
httpVersion: "http3", | ||
ipv6Enabled: true, | ||
logging: { | ||
bucket: logsBucket.domainName, | ||
includeCookies: false, | ||
}, | ||
origins: [origin], | ||
// https://aws.amazon.com/cloudfront/pricing/ | ||
priceClass: "PriceClass_100", | ||
viewerCertificate: { | ||
acmCertificateArn: certificate.arn, | ||
sslSupportMethod: "sni-only", | ||
}, | ||
}, | ||
}, | ||
); | ||
|
||
const aliasRecord = new aws.route53.Record(`dns-${targetDomainFull}`, { | ||
name: targetDomainFull, | ||
zoneId: hostedZone.zoneId, | ||
type: "A", | ||
aliases: [ | ||
{ | ||
evaluateTargetHealth: true, | ||
name: cloudFrontDistribution.domainName, | ||
zoneId: "Z2FDTNDATAQYW2", // CloudFront zone ID | ||
}, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// TODO: why do we have to give the extension here? | ||
import "./cloudfront.ts"; | ||
export * from "./oidc.ts"; |
Oops, something went wrong.