Skip to content

Commit 790328d

Browse files
committed
init commit
0 parents  commit 790328d

26 files changed

+4358
-0
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
node_modules
3+
.eslintrc.js

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ["@eunchurn/eslint-config"],
3+
};

.gitignore

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# Snowpack dependency directory (https://snowpack.dev/)
46+
web_modules/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Optional stylelint cache
58+
.stylelintcache
59+
60+
# Microbundle cache
61+
.rpt2_cache/
62+
.rts2_cache_cjs/
63+
.rts2_cache_es/
64+
.rts2_cache_umd/
65+
66+
# Optional REPL history
67+
.node_repl_history
68+
69+
# Output of 'npm pack'
70+
*.tgz
71+
72+
# Yarn Integrity file
73+
.yarn-integrity
74+
75+
# dotenv environment variable files
76+
.env
77+
.env.development.local
78+
.env.test.local
79+
.env.production.local
80+
.env.local
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
dist
93+
94+
# Gatsby files
95+
.cache/
96+
# Comment in the public line in if your project uses Gatsby and not Next.js
97+
# https://nextjs.org/blog/next-9-1#public-directory-support
98+
# public
99+
100+
# vuepress build output
101+
.vuepress/dist
102+
103+
# vuepress v2.x temp and cache directory
104+
.temp
105+
.cache
106+
107+
# Docusaurus cache and generated files
108+
.docusaurus
109+
110+
# Serverless directories
111+
.serverless/
112+
113+
# FuseBox cache
114+
.fusebox/
115+
116+
# DynamoDB Local files
117+
.dynamodb/
118+
119+
# TernJS port file
120+
.tern-port
121+
122+
# Stores VSCode versions used for testing VSCode extensions
123+
.vscode-test
124+
125+
# yarn v2
126+
.yarn/cache
127+
.yarn/unplugged
128+
.yarn/build-state.yml
129+
.yarn/install-state.gz
130+
.pnp.*
131+
# Local .terraform directories
132+
**/.terraform/*
133+
134+
# .tfstate files
135+
*.tfstate
136+
*.tfstate.*
137+
138+
# Crash log files
139+
crash.log
140+
crash.*.log
141+
142+
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
143+
# password, private keys, and other secrets. These should not be part of version
144+
# control as they are data points which are potentially sensitive and subject
145+
# to change depending on the environment.
146+
# *.tfvars
147+
*.tfvars.json
148+
149+
# Ignore override files as they are usually used to override resources locally and so
150+
# are not checked in
151+
override.tf
152+
override.tf.json
153+
*_override.tf
154+
*_override.tf.json
155+
156+
# Include override files you do wish to add to version control using negated pattern
157+
# !example_override.tf
158+
159+
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
160+
# example: *tfplan*
161+
162+
# Ignore CLI configuration files
163+
.terraformrc
164+
terraform.rc

.jest/setupEnv.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
console.log("Testing environment", process.env.NODE_ENV);
3+

.prettierignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
dist
3+
.next
4+
node_modules
5+
.docker
6+
.github
7+
.jest
8+
.vscode
9+
coverage

.prettierrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
...require("@eunchurn/prettier-config"),
3+
};

.vscode/settings.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"typescript.tsdk": "./node_modules/typescript/lib",
3+
"typescript.referencesCodeLens.enabled": true,
4+
"typescript.disableAutomaticTypeAcquisition": true,
5+
"eslint.validate": [
6+
"typescript"
7+
],
8+
"editor.defaultFormatter": "esbenp.prettier-vscode",
9+
"[javascript]": {
10+
"editor.defaultFormatter": "esbenp.prettier-vscode"
11+
},
12+
"[typescript]": {
13+
"editor.defaultFormatter": "esbenp.prettier-vscode"
14+
},
15+
"[prisma]": {
16+
"editor.defaultFormatter": "esbenp.prettier-vscode"
17+
},
18+
"editor.formatOnSave": true,
19+
"eslint.alwaysShowStatus": true,
20+
"editor.codeActionsOnSave": {
21+
"source.fixAll": false
22+
},
23+
"[terraform]": {
24+
"editor.defaultFormatter": "hashicorp.terraform"
25+
}
26+
}

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Terraform TypeScript Lambda & API Gateway Infrastructure
2+
3+
TypeScript Lambda handler deployment and API Gateway v2 public endpoint
4+
5+
![infra](infra.png)
6+
7+
[Blog post](https://www.eunchurn.com/blog/development/2022-10-23-tWIL)
8+
9+
## Prerequisite
10+
11+
- NodeJS 16
12+
- [Terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli)
13+
14+
### Terraform install for Apple Silicon
15+
16+
[Reference](https://discuss.hashicorp.com/t/template-v2-2-0-does-not-have-a-package-available-mac-m1/35099/4)
17+
18+
- 1. Remove any existing Terraform binary (/usr/bin/terraform and/or /usr/local/bin/terraform)
19+
- 2. Install [m1-terraform-provider-helper](https://github.com/kreuzwerker/m1-terraform-provider-helper)
20+
- 2.1. `brew install kreuzwerker/taps/m1-terraform-provider-helper`
21+
- 3. Install Terraform
22+
- 3.1. `brew tap hashicorp/tap`
23+
- 3.2. `brew install hashicorp/tap/terraform`
24+
- 4. Install the hashicorp/template version v2.2.0
25+
- 4.1. `m1-terraform-provider-helper activate`
26+
- 4.2. `m1-terraform-provider-helper install hashicorp/template -v v2.2.0`
27+
28+
```
29+
➜ ~ terraform --version
30+
Terraform v1.3.1
31+
on darwin_arm64
32+
+ provider registry.terraform.io/hashicorp/aws v4.33.0
33+
+ provider registry.terraform.io/hashicorp/random v3.4.3
34+
+ provider registry.terraform.io/hashicorp/template v2.2.0
35+
```
36+
### Project
37+
38+
- Change your Lambda function name `terraform/locals.tf`
39+
- `name = "{your app name}"`
40+
- Change your API Gateway info `terraform/apiGateway.tf`
41+
- `aws_route53_zone`
42+
- `aws_route53_zone` sub
43+
- `aws_acm_certificate`: domain_name, subject_alternative_names
44+
- `aws_apigatewayv2_domain_name`: domain_name
45+
46+
## Usage
47+
48+
- `yarn tf:init`
49+
- `yarn tf:plan`
50+
- `yarn tf:apply`
51+
52+
### Destory
53+
54+
- `yarn destroy:all`
55+
56+
### Update All
57+
58+
- `yarn update:all`
59+
60+
- Check outputs

infra.png

186 KB
Loading

jest.config.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { pathsToModuleNameMapper, GlobalConfigTsJest } from "ts-jest";
2+
import type { InitialOptionsTsJest } from "ts-jest/dist/types";
3+
import ts from "typescript";
4+
5+
const compilerOptionsPaths = (() => {
6+
const configFileName = ts.findConfigFile(
7+
"../",
8+
ts.sys.fileExists,
9+
"tsconfig.json",
10+
);
11+
if (configFileName) {
12+
const configFile = ts.readConfigFile(configFileName, ts.sys.readFile);
13+
const option = ts.parseJsonConfigFileContent(
14+
configFile.config,
15+
ts.sys,
16+
"./",
17+
);
18+
return option.raw.compilerOptions.paths;
19+
}
20+
return {};
21+
})();
22+
23+
const globals: GlobalConfigTsJest = {
24+
"ts-jest": {
25+
tsconfig: "tsconfig.json",
26+
compiler: "typescript",
27+
},
28+
};
29+
30+
const moduleNameMapper = pathsToModuleNameMapper(compilerOptionsPaths, {
31+
prefix: "<rootDir>",
32+
});
33+
34+
const jestSetting: InitialOptionsTsJest = {
35+
setupFiles: ["<rootDir>/.jest/setupEnv.js"],
36+
globals,
37+
moduleFileExtensions: ["ts", "tsx", "js", "json"],
38+
rootDir: ".",
39+
roots: ["<rootDir>"],
40+
modulePaths: ["<rootDir>"],
41+
moduleNameMapper,
42+
modulePathIgnorePatterns: ["dist"],
43+
testRegex: ".spec|.test.ts$",
44+
transform: {
45+
"^.+.ts$": "ts-jest",
46+
},
47+
};
48+
49+
export default jestSetting;

0 commit comments

Comments
 (0)