diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..ced907ec --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 474e78ac..00000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,8 +0,0 @@ -version: 2 -updates: - - package-ecosystem: 'npm' - directory: '/' - schedule: - interval: 'daily' - allow: - - dependency-name: 'next' diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 00000000..c56777d7 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,187 @@ +name: CI + +on: + push: + branches: + - main + - v[0-9]+.[0-9x]+.x + pull_request: + +env: + NEXT_TELEMETRY_DISABLED: 1 + +jobs: + build: + runs-on: ubuntu-latest + container: registry.gitlab.com/dealmore/dealmore-build-images/lambda:nodejs14.x + + steps: + - uses: actions/checkout@v2 + + - name: Cache + uses: actions/cache@v2 + with: + path: | + .yarn + **/node_modules + key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }} + + - name: Install dependencies + run: yarn --frozen-lockfile --cache-folder .yarn + + - name: Build runtime + run: yarn workspace @millihq/tf-next-runtime build + + - name: Build tf-next + run: yarn workspace tf-next build + + - name: Build proxy + run: yarn workspace @millihq/terraform-next-proxy build + + - name: Build deploy-trigger + run: yarn workspace @millihq/terraform-next-deploy-trigger build + + - name: Upload build artifacts + uses: actions/upload-artifact@v2 + with: + name: dist + path: | + packages/runtime/dist/ + packages/tf-next/dist/ + packages/proxy/dist.zip + packages/deploy-trigger/dist.zip + if-no-files-found: error + + test-integration: + needs: build + runs-on: ubuntu-latest + container: registry.gitlab.com/dealmore/dealmore-build-images/lambda:nodejs14.x + services: + s3: + image: registry.gitlab.com/dealmore/dealmore-build-images:s3-emulator + env: + MINIO_ACCESS_KEY: test + MINIO_SECRET_KEY: testtest + + env: + MINIO_ACCESS_KEY: test + MINIO_SECRET_KEY: testtest + S3_ENDPOINT: s3:9000 + + steps: + - uses: actions/checkout@v2 + + - name: Cache + uses: actions/cache@v2 + with: + path: | + .yarn + **/node_modules + key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }} + + - name: Yarn install + run: yarn --frozen-lockfile --cache-folder .yarn + + - name: Download build artifacts + uses: actions/download-artifact@v2 + with: + name: dist + path: packages + + - name: Jest + run: yarn test + + test-e2e-prepare: + needs: build + runs-on: ubuntu-latest + container: registry.gitlab.com/dealmore/dealmore-build-images/lambda:nodejs14.x + steps: + - uses: actions/checkout@v2 + + - name: Cache + uses: actions/cache@v2 + with: + path: | + .yarn + **/node_modules + key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }} + + - name: Yarn install + run: yarn --frozen-lockfile --cache-folder .yarn + + - name: Download build artifacts + uses: actions/download-artifact@v2 + with: + name: dist + path: packages + + - name: Build e2e fixtures + run: yarn test:e2e:prepare + + - name: Upload e2e fixtures + uses: actions/upload-artifact@v2 + with: + name: e2e-fixtures + path: test/fixtures/**/.next-tf/**/* + if-no-files-found: error + + test-e2e: + needs: [build, test-e2e-prepare] + runs-on: ubuntu-latest + services: + s3: + image: registry.gitlab.com/dealmore/dealmore-build-images:s3-emulator + env: + MINIO_ACCESS_KEY: test + MINIO_SECRET_KEY: testtest + ports: + - 9000:9000 + env: + SAM_CLI_TELEMETRY: 0 + # Don't worry these are fake AWS credentials for AWS SAM + AWS_ACCESS_KEY_ID: ABIAZLJNBT8I3KFOU4NO + AWS_SECRET_ACCESS_KEY: 4Xt3Rbx4DO21MhK1IHXZXRvVRDuqaQ0Wo5lILA/h + MINIO_ACCESS_KEY: test + MINIO_SECRET_KEY: testtest + + steps: + - name: Setup AWS SAM + run: | + brew tap aws/tap + brew install aws-sam-cli + sam --version + + - uses: actions/checkout@v2 + + - name: Cache + uses: actions/cache@v2 + with: + path: | + .yarn + **/node_modules + key: ${{ runner.os }}-e2e-${{ hashFiles('yarn.lock') }} + + - name: Download build artifacts + uses: actions/download-artifact@v2 + with: + name: dist + path: packages + + - name: Download prebuilt e2e fixtures + uses: actions/download-artifact@v2 + with: + name: e2e-fixtures + path: test/fixtures + + - name: Install dependencies + run: yarn --frozen-lockfile --cache-folder .yarn + + - name: Run e2e-test + run: yarn test:e2e --runInBand + + - name: Output SAM logs + run: | + printf "\n\nOutput of sam-local.log:\n" + cat sam-local.log + printf "\n\nOutput of sam-api.log:\n" + cat sam-api.log diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d9fc3e46..3cd2f15b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - v[0-9]+.[0-9x]+.x pull_request: jobs: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b5073404..cb14e41a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,6 +6,10 @@ on: tag: description: 'Tag' required: true + releaseBranch: + description: 'Release branch' + required: true + default: 'release' jobs: release: @@ -16,9 +20,16 @@ jobs: with: fetch-depth: 0 - - uses: dealmore/gh-action-release-branch@v1.1.0 + - uses: milliHQ/gh-action-release-branch@v2.0.0 with: - upstream-branch: main - release-branch: release + release-branch: ${{ github.event.inputs.releaseBranch }} release-tag: ${{ github.event.inputs.tag }} - exclude: '["packages/**/*", "test/**/*", "package.json", "yarn.lock"]' + exclude: | + .vscode/**/* + packages/**/* + test/**/* + docker-compose.yml + jest.config.js + package.json + tsconfig.json + yarn.lock diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 85364c87..00000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,104 +0,0 @@ -name: CI - -on: - push: - branches: - - main - pull_request: - -env: - NEXT_TELEMETRY_DISABLED: 1 - -jobs: - test-integration: - runs-on: ubuntu-latest - container: registry.gitlab.com/dealmore/dealmore-build-images/lambda:nodejs14.x - services: - s3: - image: registry.gitlab.com/dealmore/dealmore-build-images:s3-emulator - env: - MINIO_ACCESS_KEY: test - MINIO_SECRET_KEY: testtest - - env: - MINIO_ACCESS_KEY: test - MINIO_SECRET_KEY: testtest - S3_ENDPOINT: s3:9000 - - steps: - - uses: actions/checkout@v2 - - - name: Cache - uses: actions/cache@v2 - with: - path: | - .yarn - **/node_modules - key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }} - - - name: Yarn install - run: yarn --frozen-lockfile --cache-folder .yarn - - - name: Build runtime - run: yarn --cwd packages/runtime build - - - name: Jest - run: yarn test - - test-e2e-prepare: - runs-on: ubuntu-latest - container: registry.gitlab.com/dealmore/dealmore-build-images/lambda:nodejs14.x - steps: - - uses: actions/checkout@v2 - - - name: Cache - uses: actions/cache@v2 - with: - path: | - .yarn - **/node_modules - key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }} - - - name: Yarn install - run: yarn --frozen-lockfile --cache-folder .yarn - - - name: Build runtime - run: yarn --cwd packages/runtime build - - - name: Build tf-next - run: yarn --cwd packages/tf-next build - - - name: Build e2e fixtures - run: yarn test:e2e:prepare - - - name: Upload e2e fixtures - uses: actions/upload-artifact@v2 - with: - name: e2e-fixtures - path: | - packages/proxy/dist.zip - test/**/.next-tf/**/* - if-no-files-found: error - - test-e2e: - needs: test-e2e-prepare - runs-on: ubuntu-latest - env: - SAM_CLI_TELEMETRY: 0 - # Don't worry these are fake AWS credentials for AWS SAM - AWS_ACCESS_KEY_ID: ABIAZLJNBT8I3KFOU4NO - AWS_SECRET_ACCESS_KEY: 4Xt3Rbx4DO21MhK1IHXZXRvVRDuqaQ0Wo5lILA/h - steps: - - name: Setup AWS SAM - run: | - brew tap aws/tap - brew install aws-sam-cli - sam --version - - uses: actions/checkout@v2 - - name: Download e2e fixtures - uses: actions/download-artifact@v2 - with: - name: e2e-fixtures - - run: yarn install --frozen-lockfile --check-files - - name: Run e2e-test - run: yarn test:e2e --runInBand diff --git a/.github/workflows/tf-docs.yml b/.github/workflows/tf-docs.yml index 448ff0a3..0da3da30 100644 --- a/.github/workflows/tf-docs.yml +++ b/.github/workflows/tf-docs.yml @@ -7,6 +7,7 @@ on: push: branches: - main + - v[0-9]+.[0-9x]+.x jobs: update-docs: @@ -14,8 +15,9 @@ jobs: steps: - uses: actions/checkout@v2 - name: Update Terraform docs in README - uses: Dirrk/terraform-docs@v1.0.8 + uses: terraform-docs/gh-actions@v0.10.0 with: - tf_docs_output_file: README.md - tf_docs_git_push: 'true' - tf_docs_git_commit_message: 'terraform-docs: Update' + config-file: '.terraform-docs.yml' + output-file: README.md + git-push: 'true' + git-commit-message: 'docs: Update Terraform docs' diff --git a/.gitignore b/.gitignore index 277d2aa1..57748138 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,11 @@ node_modules # Temp files *.swp* + +# Log files +*.log + +# direnv +.direnv +.envrc + diff --git a/.terraform-docs.yml b/.terraform-docs.yml new file mode 100644 index 00000000..a825e1e8 --- /dev/null +++ b/.terraform-docs.yml @@ -0,0 +1,10 @@ +formatter: 'markdown table' + +sections: + hide: + - 'data-sources' + - 'modules' + - 'resources' + +settings: + anchor: false diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 9e5e50a5..00000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "Debug Jest Tests", - "type": "node", - "request": "launch", - "runtimeArgs": ["--inspect-brk", "${workspaceRoot}/node_modules/.bin/jest", "--runInBand"], - "console": "integratedTerminal", - "internalConsoleOptions": "neverOpen", - "port": 9229 - }, - { - "name": "Debug Current Jest File", - "type": "node", - "request": "launch", - "runtimeArgs": [ - "--inspect-brk", - "${workspaceRoot}/node_modules/.bin/jest", - "--runInBand", - "${file}" - ], - "console": "integratedTerminal", - "internalConsoleOptions": "neverOpen", - "port": 9229 - }, - { - "name": "e2e: Debug Current Jest File", - "type": "node", - "request": "launch", - "runtimeArgs": [ - "--inspect-brk", - "${workspaceRoot}/node_modules/.bin/jest", - "--config", - "${workspaceRoot}/jest.e2e.config.js", - "--runInBand", - "${file}" - ], - "console": "integratedTerminal", - "internalConsoleOptions": "neverOpen", - "port": 9229 - } - ] -} diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 4c04a307..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "files.associations": { - "**/test/**/probes.json": "jsonc" - } -} diff --git a/CHANGELOG.md b/CHANGELOG.md index b18be296..a7c2da58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,35 @@ # Changelog -## 0.9.1 - (June 20, 2021) +## 0.9.2 (September 19, 2021) + +⚠️ Namespace changed ⚠️ + +We [recently changed](https://github.com/milliHQ/terraform-aws-next-js/issues/194) the namespace of this module from `dealmore` to `milliHQ`. Make sure to upgrade the source of the module accordingly: + +```diff +module "tf_next" { +- source = "dealmore/next-js/aws" ++ source = "milliHQ/next-js/aws" + + ... +} +``` + +--- + +Besides from the namespace change, this release has now an improved experience when using it with [custom domains](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/with-custom-domain) and some bugfixes to the proxy component when using the [`trailingSlash` option](https://nextjs.org/docs/api-reference/next.config.js/trailing-slash) from Next.js. + +### Terraform module + +- It's now possible to use domain aliases without creating an external CloudFront distribution ([#192](https://github.com/milliHQ/terraform-aws-next-js/pull/192)) +- Ensure `x-nextjs-page` header gets forwarded ([#190](https://github.com/milliHQ/terraform-aws-next-js/pull/190)) +- Bump `milliHQ/download/npm` from 1.1.0 to 2.0.0 ([#193](https://github.com/milliHQ/terraform-aws-next-js/pull/193)) + +### Proxy (0.8.0) + +- Improve filesystem routes for trailing slashes ([#162](https://github.com/milliHQ/terraform-aws-next-js/pull/162), [#180](https://github.com/milliHQ/terraform-aws-next-js/issues/180), [#182](https://github.com/milliHQ/terraform-aws-next-js/pull/182), [#191](https://github.com/milliHQ/terraform-aws-next-js/pull/191)) + +## 0.9.1 (June 20, 2021) This is a maintenance release which upgrades the image optimizer module to the latest version. We also changed the behavior of the proxy module so that the default root object in CloudFront is no longer necessary. @@ -9,17 +38,17 @@ No configuration changes should be necessary when upgrading from the `0.9.0` rel ### Terraform module -- Upgrades Proxy component to 0.7.0 ([#139](https://github.com/dealmore/terraform-aws-next-js/issues/139), [#141](https://github.com/dealmore/terraform-aws-next-js/pull/141)) -- Upgrades [Terraform Next.js Image Optimization module for AWS](https://github.com/dealmore/terraform-aws-next-js-image-optimization) to `11.x.x` release ([#142](https://github.com/dealmore/terraform-aws-next-js/issues/142), [#144](https://github.com/dealmore/terraform-aws-next-js/pull/144)) +- Upgrades Proxy component to 0.7.0 ([#139](https://github.com/milliHQ/terraform-aws-next-js/issues/139), [#141](https://github.com/milliHQ/terraform-aws-next-js/pull/141)) +- Upgrades [Terraform Next.js Image Optimization module for AWS](https://github.com/milliHQ/terraform-aws-next-js-image-optimization) to `11.x.x` release ([#142](https://github.com/milliHQ/terraform-aws-next-js/issues/142), [#144](https://github.com/milliHQ/terraform-aws-next-js/pull/144)) The image optimizer Lambda now uses `2048mb` RAM by default (from `1024mb`) to improve resizing speed. You can change that amount with the newly introduced variable `image_optimization_lambda_memory_size`. This has no effect on the Lambda functions that serve the Next.js pages or api routes (they remain at `1024mb` by default). -- Bump AWS Lambda Terraform module from 1.47.0 to 2.4.0 ([#145](https://github.com/dealmore/terraform-aws-next-js/pull/145)) -- Bump AWS API Gateway Terraform module from 0.11.0 to 1.1.0 ([#146](https://github.com/dealmore/terraform-aws-next-js/pull/146)) +- Bump AWS Lambda Terraform module from 1.47.0 to 2.4.0 ([#145](https://github.com/milliHQ/terraform-aws-next-js/pull/145)) +- Bump AWS API Gateway Terraform module from 0.11.0 to 1.1.0 ([#146](https://github.com/milliHQ/terraform-aws-next-js/pull/146)) -## Proxy (0.7.0) +### Proxy (0.7.0) -- Fix root route rewrites ([#139](https://github.com/dealmore/terraform-aws-next-js/issues/139), [#141](https://github.com/dealmore/terraform-aws-next-js/pull/141)) +- Fix root route rewrites ([#139](https://github.com/milliHQ/terraform-aws-next-js/issues/139), [#141](https://github.com/milliHQ/terraform-aws-next-js/pull/141)) ## 0.9.0 - (June 15, 2021) @@ -44,40 +73,40 @@ If you use one of the following input variables read below for more information If you are already using one of these input variables you should now create a new CloudFront resource in your `main.tf` file and link it with the Next.js module. -For more information please see the ["with existing CloudFront"](https://github.com/dealmore/terraform-aws-next-js/tree/main/examples/with-existing-cloudfront) and ["with custom domain"](https://github.com/dealmore/terraform-aws-next-js/tree/main/examples/with-custom-domain) examples. +For more information please see the ["with existing CloudFront"](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/with-existing-cloudfront) and ["with custom domain"](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/with-custom-domain) examples. ### Terraform module -- Enable usage of external CloudFront resource ([#55](https://github.com/dealmore/terraform-aws-next-js/issues/55), [#134](https://github.com/dealmore/terraform-aws-next-js/pull/134), [#137](https://github.com/dealmore/terraform-aws-next-js/pull/137)) -- Queue CloudFront invalidations ([#48](https://github.com/dealmore/terraform-aws-next-js/issues/48), [#125](https://github.com/dealmore/terraform-aws-next-js/pull/125)) -- Attaching Lambda to VPC ([#110](https://github.com/dealmore/terraform-aws-next-js/issues/110), [#111](https://github.com/dealmore/terraform-aws-next-js/pull/111)) +- Enable usage of external CloudFront resource ([#55](https://github.com/milliHQ/terraform-aws-next-js/issues/55), [#134](https://github.com/milliHQ/terraform-aws-next-js/pull/134), [#137](https://github.com/milliHQ/terraform-aws-next-js/pull/137)) +- Queue CloudFront invalidations ([#48](https://github.com/milliHQ/terraform-aws-next-js/issues/48), [#125](https://github.com/milliHQ/terraform-aws-next-js/pull/125)) +- Attaching Lambda to VPC ([#110](https://github.com/milliHQ/terraform-aws-next-js/issues/110), [#111](https://github.com/milliHQ/terraform-aws-next-js/pull/111)) Thanks to [@chamilad](https://github.com/chamilad) for contributing! -- Remove provider proxy from proxy-config module ([#102](https://github.com/dealmore/terraform-aws-next-js/issues/102), [#124](https://github.com/dealmore/terraform-aws-next-js/pull/124)) +- Remove provider proxy from proxy-config module ([#102](https://github.com/milliHQ/terraform-aws-next-js/issues/102), [#124](https://github.com/milliHQ/terraform-aws-next-js/pull/124)) ## Proxy (0.6.0) -- Support rewriting to an external URL ([#65](https://github.com/dealmore/terraform-aws-next-js/issues/65), [#120](https://github.com/dealmore/terraform-aws-next-js/pull/120)) -- Bump runtime from `nodejs12.x` to `nodejs14.x` ([#136](https://github.com/dealmore/terraform-aws-next-js/pull/136)) +- Support rewriting to an external URL ([#65](https://github.com/milliHQ/terraform-aws-next-js/issues/65), [#120](https://github.com/milliHQ/terraform-aws-next-js/pull/120)) +- Bump runtime from `nodejs12.x` to `nodejs14.x` ([#136](https://github.com/milliHQ/terraform-aws-next-js/pull/136)) ### Deploy trigger (0.4.0) -- Queue CloudFront invalidations ([#48](https://github.com/dealmore/terraform-aws-next-js/issues/48), [#125](https://github.com/dealmore/terraform-aws-next-js/pull/125)) +- Queue CloudFront invalidations ([#48](https://github.com/milliHQ/terraform-aws-next-js/issues/48), [#125](https://github.com/milliHQ/terraform-aws-next-js/pull/125)) ## tf-next (0.7.0) -- Adds support for yarn workspaces ([#93](https://github.com/dealmore/terraform-aws-next-js/issues/93), [#107](https://github.com/dealmore/terraform-aws-next-js/pull/107)) +- Adds support for yarn workspaces ([#93](https://github.com/milliHQ/terraform-aws-next-js/issues/93), [#107](https://github.com/milliHQ/terraform-aws-next-js/pull/107)) ### Runtime (1.1.0) -- Bump @vercel/nft from 0.9.5 to 0.10.0 ([#112](https://github.com/dealmore/terraform-aws-next-js/pull/112)) +- Bump @vercel/nft from 0.9.5 to 0.10.0 ([#112](https://github.com/milliHQ/terraform-aws-next-js/pull/112)) ## 0.8.1 - (April 27, 2021) ### Terraform module -- Fixes compatibility with Terraform 0.15 ([#115](https://github.com/dealmore/terraform-aws-next-js/issues/115), [#118](https://github.com/dealmore/terraform-aws-next-js/pull/118)) -- Bump AWS Lambda Terraform module from 1.34.0 to 1.47.0 ([#117](https://github.com/dealmore/terraform-aws-next-js/pull/117)) -- Bump Next.js Image Optimization module from 10.0.5 to 10.0.8 ([#116](https://github.com/dealmore/terraform-aws-next-js/pull/116)) +- Fixes compatibility with Terraform 0.15 ([#115](https://github.com/milliHQ/terraform-aws-next-js/issues/115), [#118](https://github.com/milliHQ/terraform-aws-next-js/pull/118)) +- Bump AWS Lambda Terraform module from 1.34.0 to 1.47.0 ([#117](https://github.com/milliHQ/terraform-aws-next-js/pull/117)) +- Bump Next.js Image Optimization module from 10.0.5 to 10.0.8 ([#116](https://github.com/milliHQ/terraform-aws-next-js/pull/116)) ## 0.8.0 - (April 05, 2021) @@ -110,73 +139,73 @@ module "tf_next" { ### Terraform module -- Removes internal AWS provider for `us-east-1` region ([#50](https://github.com/dealmore/terraform-aws-next-js/issues/50), [#101](https://github.com/dealmore/terraform-aws-next-js/pull/101)) -- Enable Brotli compression for CloudFront ([#8](https://github.com/dealmore/terraform-aws-next-js/issues/8), [#82](https://github.com/dealmore/terraform-aws-next-js/pull/82)) -- Adds `cloudfront_geo_restriction` variable ([#97](https://github.com/dealmore/terraform-aws-next-js/pull/97)) -- Use `nodejs14.x` as default runtime for Lambda ([#67](https://github.com/dealmore/terraform-aws-next-js/pull/67), [#80](https://github.com/dealmore/terraform-aws-next-js/issues/80), [#81](https://github.com/dealmore/terraform-aws-next-js/pull/81)) +- Removes internal AWS provider for `us-east-1` region ([#50](https://github.com/milliHQ/terraform-aws-next-js/issues/50), [#101](https://github.com/milliHQ/terraform-aws-next-js/pull/101)) +- Enable Brotli compression for CloudFront ([#8](https://github.com/milliHQ/terraform-aws-next-js/issues/8), [#82](https://github.com/milliHQ/terraform-aws-next-js/pull/82)) +- Adds `cloudfront_geo_restriction` variable ([#97](https://github.com/milliHQ/terraform-aws-next-js/pull/97)) +- Use `nodejs14.x` as default runtime for Lambda ([#67](https://github.com/milliHQ/terraform-aws-next-js/pull/67), [#80](https://github.com/milliHQ/terraform-aws-next-js/issues/80), [#81](https://github.com/milliHQ/terraform-aws-next-js/pull/81)) ### Deploy trigger (0.3.0) -- CloudFront invalidations for static files (e.g. static prerendered HTML or files from `public/`) are only issues if the eTag of the file changes ([#48](https://github.com/dealmore/terraform-aws-next-js/issues/48), [#91](https://github.com/dealmore/terraform-aws-next-js/pull/91)) +- CloudFront invalidations for static files (e.g. static prerendered HTML or files from `public/`) are only issues if the eTag of the file changes ([#48](https://github.com/milliHQ/terraform-aws-next-js/issues/48), [#91](https://github.com/milliHQ/terraform-aws-next-js/pull/91)) ### tf-next (0.6.1) -- Ensure that `INIT_CWD` environment variable is set to the correct working directory ([#87](https://github.com/dealmore/terraform-aws-next-js/pull/87)) +- Ensure that `INIT_CWD` environment variable is set to the correct working directory ([#87](https://github.com/milliHQ/terraform-aws-next-js/pull/87)) ### tf-next (0.6.0) -- Allows dependencies (e.g. Prisma & Blitz.js) to correctly detect the build environment ([#70](https://github.com/dealmore/terraform-aws-next-js/issues/70), [#73](https://github.com/dealmore/terraform-aws-next-js/issues/73), [#85](https://github.com/dealmore/terraform-aws-next-js/pull/85)) +- Allows dependencies (e.g. Prisma & Blitz.js) to correctly detect the build environment ([#70](https://github.com/milliHQ/terraform-aws-next-js/issues/70), [#73](https://github.com/milliHQ/terraform-aws-next-js/issues/73), [#85](https://github.com/milliHQ/terraform-aws-next-js/pull/85)) ## 0.7.4 (April 03, 2021) ### Terraform module -- Use `concat` instead of `merge` for custom CloudFront origins and cache behaviors ([#66](https://github.com/dealmore/terraform-aws-next-js/issues/66), [#105](https://github.com/dealmore/terraform-aws-next-js/pull/105)) +- Use `concat` instead of `merge` for custom CloudFront origins and cache behaviors ([#66](https://github.com/milliHQ/terraform-aws-next-js/issues/66), [#105](https://github.com/milliHQ/terraform-aws-next-js/pull/105)) ## 0.7.3 (March 08, 2021) ### Terraform module -- Bump internal module `terraform-aws-modules/apigateway-v2/aws` from `0.5.0` to `0.11.0` ([#68](https://github.com/dealmore/terraform-aws-next-js/pull/68)) -- Bump internal module `dealmore/next-js-image-optimization/aws` from `2.0.0` to `2.0.1` ([#68](https://github.com/dealmore/terraform-aws-next-js/pull/68)) +- Bump internal module `terraform-aws-modules/apigateway-v2/aws` from `0.5.0` to `0.11.0` ([#68](https://github.com/milliHQ/terraform-aws-next-js/pull/68)) +- Bump internal module `dealmore/next-js-image-optimization/aws` from `2.0.0` to `2.0.1` ([#68](https://github.com/milliHQ/terraform-aws-next-js/pull/68)) ## 0.7.2 (March 04, 2021) ### Terraform module -- Fix for invalid function argument error introduced by `0.7.1` release ([#59](https://github.com/dealmore/terraform-aws-next-js/issues/59)) +- Fix for invalid function argument error introduced by `0.7.1` release ([#59](https://github.com/milliHQ/terraform-aws-next-js/issues/59)) ## 0.7.1 (March 04, 2021) ### Terraform module -- Add option to set the image optimizer version ([#58](https://github.com/dealmore/terraform-aws-next-js/issues/58)) +- Add option to set the image optimizer version ([#58](https://github.com/milliHQ/terraform-aws-next-js/issues/58)) ## 0.7.0 (February 13, 2021) This release brings support for [Next.js image optimization](https://nextjs.org/docs/basic-features/image-optimization) 📸. No extra config is needed, simply update the Terraform module and the `tf-next` package to the latest version! -Check out our example for more information: [Next image component example](https://github.com/dealmore/terraform-aws-next-js/tree/main/examples/next-image) +Check out our example for more information: [Next image component example](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/next-image) You can always opt-out from creating resources for image optimization by setting `create_image_optimization = false`. ### Terraform module -- Adds support for `next/image` component ([#28](https://github.com/dealmore/terraform-aws-next-js/issues/28), [#51](https://github.com/dealmore/terraform-aws-next-js/pull/51)) +- Adds support for `next/image` component ([#28](https://github.com/milliHQ/terraform-aws-next-js/issues/28), [#51](https://github.com/milliHQ/terraform-aws-next-js/pull/51)) - Refactoring: Outsources a previously private Terraform module, that is now used across multiple projects. Is now avaiable here: [NPM Download Terraform module - ](https://registry.terraform.io/modules/dealmore/download/npm) ([#41](https://github.com/dealmore/terraform-aws-next-js/issues/41)) + ](https://registry.terraform.io/modules/milliHQ/download/npm) ([#41](https://github.com/milliHQ/terraform-aws-next-js/issues/41)) ### tf-next (0.5.0) -- Adds support for `next/image` component ([#28](https://github.com/dealmore/terraform-aws-next-js/issues/28), [#51](https://github.com/dealmore/terraform-aws-next-js/pull/51)) +- Adds support for `next/image` component ([#28](https://github.com/milliHQ/terraform-aws-next-js/issues/28), [#51](https://github.com/milliHQ/terraform-aws-next-js/pull/51)) ### Proxy (0.5.0) -- Internal refactoring which changes the way the module is bundled. No feature changes ([#43](https://github.com/dealmore/terraform-aws-next-js/issues/43)) +- Internal refactoring which changes the way the module is bundled. No feature changes ([#43](https://github.com/milliHQ/terraform-aws-next-js/issues/43)) ### Deploy trigger (0.2.0) -- Internal refactoring which changes the way the module is bundled. No feature changes ([#43](https://github.com/dealmore/terraform-aws-next-js/issues/43)) +- Internal refactoring which changes the way the module is bundled. No feature changes ([#43](https://github.com/milliHQ/terraform-aws-next-js/issues/43)) ## 0.6.2 (January 19, 2021) @@ -189,11 +218,11 @@ You can always opt-out from creating resources for image optimization by setting ### Terraform module -- Fix: Correctly propagate the permissions boundary (`lambda_role_permissions_boundary`) to all Lambda & Lambda@Edge functions ([#38](https://github.com/dealmore/terraform-aws-next-js/pull/38)) +- Fix: Correctly propagate the permissions boundary (`lambda_role_permissions_boundary`) to all Lambda & Lambda@Edge functions ([#38](https://github.com/milliHQ/terraform-aws-next-js/pull/38)) ### tf-next (0.4.1) -- Fix: Request cookie header should be semi-colon delimitated ([#39](https://github.com/dealmore/terraform-aws-next-js/pull/39)) +- Fix: Request cookie header should be semi-colon delimitated ([#39](https://github.com/milliHQ/terraform-aws-next-js/pull/39)) ## 0.6.0 (January 16, 2021) @@ -208,15 +237,15 @@ yarn upgrade tf-next@latest # yarn ### Terraform module -- Upgrade to API Gateway Payload V2.0 ([#29](https://github.com/dealmore/terraform-aws-next-js/issues/29), [#31](https://github.com/dealmore/terraform-aws-next-js/pull/31)) +- Upgrade to API Gateway Payload V2.0 ([#29](https://github.com/milliHQ/terraform-aws-next-js/issues/29), [#31](https://github.com/milliHQ/terraform-aws-next-js/pull/31)) This is only an upgrade of the internally API used by Lambda and API Gateway (Not the resource itself, since we already use API Gateway V2). See this [guide](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html) for a detailed look at the differences between the V1.0 and V2.0 format. It fixes a bug where no multi-value headers could be sent by a SSR or API page. -- Sends an error message when you try to use the Terraform module together with an old version of `tf-next` ([#5](https://github.com/dealmore/terraform-aws-next-js/issues/5), [#37](https://github.com/dealmore/terraform-aws-next-js/pull/37)) +- Sends an error message when you try to use the Terraform module together with an old version of `tf-next` ([#5](https://github.com/milliHQ/terraform-aws-next-js/issues/5), [#37](https://github.com/milliHQ/terraform-aws-next-js/pull/37)) - Upgrades proxy component to `v0.4.0` ### tf-next (0.4.0) -- Adds a version number to the config file, so that the Terraform module is able to warn about a possible version mismatch ([#5](https://github.com/dealmore/terraform-aws-next-js/issues/5), [#37](https://github.com/dealmore/terraform-aws-next-js/pull/37)) +- Adds a version number to the config file, so that the Terraform module is able to warn about a possible version mismatch ([#5](https://github.com/milliHQ/terraform-aws-next-js/issues/5), [#37](https://github.com/milliHQ/terraform-aws-next-js/pull/37)) ### Proxy (0.4.0) @@ -226,20 +255,20 @@ yarn upgrade tf-next@latest # yarn ### Terraform module -- Fix: Pass permissions boundary to edge proxy lambda ([#35](https://github.com/dealmore/terraform-aws-next-js/pull/35)) +- Fix: Pass permissions boundary to edge proxy lambda ([#35](https://github.com/milliHQ/terraform-aws-next-js/pull/35)) ## 0.5.2 (January 14, 2021) ### Terraform module -- Adds `tags` variable to set tags on supported AWS resources ([#34](https://github.com/dealmore/terraform-aws-next-js/pull/34)) -- Adds `lambda_role_permissions_boundary` variable for setting a permission boundary for the Lambda role ([#33](https://github.com/dealmore/terraform-aws-next-js/pull/33)) +- Adds `tags` variable to set tags on supported AWS resources ([#34](https://github.com/milliHQ/terraform-aws-next-js/pull/34)) +- Adds `lambda_role_permissions_boundary` variable for setting a permission boundary for the Lambda role ([#33](https://github.com/milliHQ/terraform-aws-next-js/pull/33)) ## 0.5.1 (January 13, 2021) ### Terraform module -- Adds `cloudfront_hosted_zone_id` output ([#30](https://github.com/dealmore/terraform-aws-next-js/pull/30)). +- Adds `cloudfront_hosted_zone_id` output ([#30](https://github.com/milliHQ/terraform-aws-next-js/pull/30)). ## 0.5.0 (January 03, 2021) @@ -248,7 +277,7 @@ With this release we bring native support for [redirects](https://nextjs.org/doc ### Proxy (0.3.0) -- Adds ability to handle redirects ([#10](https://github.com/dealmore/terraform-aws-next-js/issues/10), [#24](https://github.com/dealmore/terraform-aws-next-js/pull/24)). +- Adds ability to handle redirects ([#10](https://github.com/milliHQ/terraform-aws-next-js/issues/10), [#24](https://github.com/milliHQ/terraform-aws-next-js/pull/24)). ### tf-next (0.3.0) @@ -259,7 +288,7 @@ With this release we bring native support for [redirects](https://nextjs.org/doc ## 0.4.0 (December 30, 2020) -- Adds [new example](https://github.com/dealmore/terraform-aws-next-js/blob/main/examples/custom-domain) how to use custom domains. +- Adds [new example](https://github.com/milliHQ/terraform-aws-next-js/blob/main/examples/custom-domain) how to use custom domains. ### Terraform module @@ -282,17 +311,17 @@ With this release we bring native support for [redirects](https://nextjs.org/doc ## 0.2.0 (December 22, 2020) -> **Note:** This will be the last release with support for Terraform `v12.x`, see [#18](https://github.com/dealmore/terraform-aws-next-js/issues/18) for more information. +> **Note:** This will be the last release with support for Terraform `v12.x`, see [#18](https://github.com/milliHQ/terraform-aws-next-js/issues/18) for more information. ### Terraform module - Destroy non-empty S3 buckets on stack deletion -- Experimental support for pre-Rendered routes ([#16](https://github.com/dealmore/terraform-aws-next-js/issues/16)) +- Experimental support for pre-Rendered routes ([#16](https://github.com/milliHQ/terraform-aws-next-js/issues/16)) ### Terraform Next Build -- Experimental support for pre-Rendered routes ([#16](https://github.com/dealmore/terraform-aws-next-js/issues/16)) +- Experimental support for pre-Rendered routes ([#16](https://github.com/milliHQ/terraform-aws-next-js/issues/16)) ### Proxy -- Experimental support for pre-Rendered routes ([#16](https://github.com/dealmore/terraform-aws-next-js/issues/16)) +- Experimental support for pre-Rendered routes ([#16](https://github.com/milliHQ/terraform-aws-next-js/issues/16)) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..4f4be918 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,156 @@ +# Contributing + +Contributions are welcome! + +As a general advice it is always a good idea to raise an [issue](https://github.com/milliHQ/terraform-aws-next-js/issues) before creating a new pull request. +This ensures that we don't have to reject pull requests that are not aligning with our roadmap and not wasting your valuable time. + +## Contribution Prerequisites + +The project is a monorepo which contains both the Terraform module and the CLI (`tf-next`) that is used to prepare the Next.js to be served by AWS Lambda written in Node.js. +It also contains components (`proxy` and `deploy-trigger`) that are directly published to AWS Lambda. They are also written in Node.js. + +For the Terraform part you should have installed: + +- [Terraform CLI](https://www.terraform.io/downloads.html) at 0.13+ + +For the CLI and the components you should have installed: + +- [Node.js](https://nodejs.org/) at v14.0.0+ +- [Yarn 1](https://classic.yarnpkg.com/) at v1.2.0+ + +## Development Workflow + +### Terraform module + +> **Note:** You should not make changes to the documentation of the **Requirements**, **Providers**, **Inputs** and **Outputs** sections in the `README.md` when contributing. +> The values there are auto generated by a GitHub action task once a PR is merged. + +#### Codestyle + +We use a [GitHub Action](https://github.com/milliHQ/terraform-aws-next-js/actions/workflows/lint.yml) to make sure that the committed code is properly formatted. +Before submitting a PR, you should make sure that the code is properly formatted. + +You can do this by running the Terraform [`fmt` command](https://www.terraform.io/docs/cli/commands/fmt.html) in the root of the repository: + +```sh +terraform fmt -recursive +``` + +### CLI and components + +After cloning the repository, run `yarn` to fetch and install its dependencies. + +## Testing + +Automatic testing is only done for the worker component written in Node.js. +The Terraform module is **not** covered by automatic tests. + +### Testing Terraform module + +Since the Terraform module itself is not covered by automatic tests, testing has to be done manually. +The repository contains some examples in the [`examples/*`](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples) folder, that can be used to run a quick acceptance test against your own AWS account. + +You may need to change a few settings in the `main.tf` file in the root of the example: + +#### Use local development version of the module + +To use the local development version instead of downloading it from the Terraform registry you have to change the source to the local path of the module. +When working with one of the examples zou can simply use the relative path to the root of the cloned repository: + +```diff +module "tf_next" { +- source = "milliHQ/next-js/aws" ++ source = "../.." + ... +} +``` + +#### Use local build of the components + +Instead of downloading the components from npm you can also specify the `debug_use_local_packages` to use the local version. +To do so, make sure that the components are built by running the following commands: + +```sh +yarn --cwd packages/proxy build +yarn --cwd packages/deploy-trigger build +``` + +After that you should have a `dist.zip` file in the root of each package. + +To deploy the local built components, you also need to set `debug_use_local_packages = true`: + +```diff +module "tf_next" { + source = "../.." + ... ++ debug_use_local_packages = true +} +``` + +### End-to-end (e2e) testing (CLI + components) + +The end-to-end testing is only used for testing the the CLI (`tf-next`) and components (`proxy` and `deploy-trigger`). +A local environment of AWS Lambda is created for this to simulate a execution under the same conditions as it would run in a AWS data center. + +#### 0. Prerequisites + +- [Docker Desktop + Docker Compose](https://www.docker.com/products/docker-desktop) + (Docker Compose comes bundled with Docker Desktop on MacOS and Windows) +- [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) + +You should check after install if they are available from your command-line: + +```sh +docker --version +# > Docker version 20.10.2, build 2291f61 + +docker-compose --version +# > docker-compose version 1.27.4, build 40524192 + +sam --version +# > SAM CLI, version 1.17.0 +``` + +#### 1. Build the CLI & components + +Before running a e2e-test make sure that the CLI and the components are built: + +```sh +# CLI (Order is important here!) +yarn --cwd packages/runtime build +yarn --cwd packages/tf-next build + +# Components +yarn --cwd packages/proxy build +yarn --cwd packages/deploy-trigger build +``` + +#### 2. Build the fixtures + +The fixtures are real Next.js apps that need to be built with `tf-next build` before passing them to the e2e-test. +You can build all fixtures by running: + +```sh +yarn test:e2e:prepare +``` + +#### 3. Local S3 instance + +Before running the e2e-tests, make sure that the local S3 emulator from docker-compose is running. +From the root of the project run: + +```sh +docker-compose up -d +``` + +#### 4. Run tests + +After that you should be able to execute the e2e-tests locally by running the `test:e2e` task: + +```sh +yarn test:e2e +``` + +The e2e-tests are executed from the `test/routes.test.ts` file. +Each fixture in `test/fixtures/*` contains a `probes.json` file that contains the actual test cases. diff --git a/LICENSE b/LICENSE index fc2e88da..7cb3978a 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2020-present Felix Haus (DealMore) + Copyright 2020 Felix Haus (milliVolt infrastructure) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 83cd3745..a7e8b265 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Terraform Next.js module for AWS -![CI status](https://github.com/dealmore/terraform-aws-next-js/workflows/CI/badge.svg) +![CI status](https://github.com/milliHQ/terraform-aws-next-js/workflows/CI/badge.svg) A zero-config Terraform module for self-hosting Next.js sites serverless on AWS Lambda. @@ -21,7 +21,7 @@ Some features are still under development, here is a list of features that are c The Next.js Terraform module is designed as a full stack AWS app. It relies on multiple AWS services and connects them to work as a single application: -![Architecture overview diagram](https://github.com/dealmore/terraform-aws-next-js/blob/main/docs/assets/architecture.png?raw=true) +![Architecture overview diagram](https://github.com/milliHQ/terraform-aws-next-js/blob/main/docs/assets/architecture.png?raw=true) - **`I.` CloudFront** @@ -49,7 +49,7 @@ The Next.js Terraform module is designed as a full stack AWS app. It relies on m - **Terraform Next.js Image Optimization** The [image optimization](https://nextjs.org/docs/basic-features/image-optimization) is triggered by routes with the prefix `/_next/image/*`. - It is a serverless task provided by our [Terraform Next.js Image Optimization module for AWS](https://registry.terraform.io/modules/dealmore/next-js-image-optimization/aws). + It is a serverless task provided by our [Terraform Next.js Image Optimization module for AWS](https://registry.terraform.io/modules/milliHQ/next-js-image-optimization/aws). - **Static Content Deployment** @@ -133,7 +133,7 @@ provider "aws" { } module "tf_next" { - source = "dealmore/next-js/aws" + source = "milliHQ/next-js/aws" providers = { aws.global_region = aws.global_region @@ -182,15 +182,15 @@ You can create a `.terraformignore` in the root of your project and add the foll ## Examples -- [Complete](https://github.com/dealmore/terraform-aws-next-js/blob/main/examples/complete) +- [Complete](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/complete) Complete example with SSR, API and static pages. -- [Static](https://github.com/dealmore/terraform-aws-next-js/blob/main/examples/static) +- [Static](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/static) Example that uses static pages only (No SSR). -- [Next Image](https://github.com/dealmore/terraform-aws-next-js/blob/main/examples/next-image) +- [Next Image](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/next-image) Images are optimized on the fly by AWS Lambda. -- [Existing CloudFront](https://github.com/dealmore/terraform-aws-next-js/blob/main/examples/with-existing-cloudfront) +- [Existing CloudFront](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/with-existing-cloudfront) Use the module together with an existing CloudFront distribution that can be fully customized. -- [Custom Domain](https://github.com/dealmore/terraform-aws-next-js/blob/main/examples/with-custom-domain) +- [Custom Domain](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/with-custom-domain) Use the module with your own domain from Route 53. @@ -214,15 +214,19 @@ You can create a `.terraformignore` in the root of your project and add the foll | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| +| cloudfront\_acm\_certificate\_arn | ACM certificate arn for custom\_domain | `string` | `null` | no | +| cloudfront\_aliases | Aliases for custom\_domain | `list(string)` | `[]` | no | | cloudfront\_cache\_key\_headers | Header keys that should be used to calculate the cache key in CloudFront. | `list(string)` |
[| no | | cloudfront\_create\_distribution | Controls whether the main CloudFront distribution should be created. | `bool` | `true` | no | | cloudfront\_external\_arn | When using an external CloudFront distribution provide its arn. | `string` | `null` | no | | cloudfront\_external\_id | When using an external CloudFront distribution provide its id. | `string` | `null` | no | +| cloudfront\_minimum\_protocol\_version | The minimum version of the SSL protocol that you want CloudFront to use for HTTPS connections. One of SSLv3, TLSv1, TLSv1\_2016, TLSv1.1\_2016, TLSv1.2\_2018 or TLSv1.2\_2019. | `string` | `"TLSv1"` | no | | cloudfront\_origin\_headers | Header keys that should be sent to the S3 or Lambda origins. Should not contain any header that is defined via cloudfront\_cache\_key\_headers. | `list(string)` | `[]` | no | | cloudfront\_price\_class | Price class for the CloudFront distributions (main & proxy config). One of PriceClass\_All, PriceClass\_200, PriceClass\_100. | `string` | `"PriceClass_100"` | no | | create\_image\_optimization | Controls whether resources for image optimization support should be created or not. | `bool` | `true` | no | | debug\_use\_local\_packages | Use locally built packages rather than download them from npm. | `bool` | `false` | no | | deployment\_name | Identifier for the deployment group (alphanumeric characters, underscores, hyphens, slashes, hash signs and dots are allowed). | `string` | `"tf-next"` | no | +| domain\_name | This is used to figure out which preview deployment to route to. | `string` | `null` | no | | expire\_static\_assets | Number of days after which static assets from previous deployments should be removed from S3. Set to -1 to disable expiration. | `number` | `30` | no | | image\_optimization\_lambda\_memory\_size | Amount of memory in MB the worker Lambda Function for image optimization can use. Valid value between 128 MB to 10,240 MB, in 1 MB increments. | `number` | `2048` | no | | lambda\_attach\_to\_vpc | Set to true if the Lambda functions should be attached to a VPC. Use this setting if VPC resources should be accessed by the Lambda functions. When setting this to true, use vpc\_security\_group\_ids and vpc\_subnet\_ids to specify the VPC networking. Note that attaching to a VPC would introduce a delay on to cold starts | `bool` | `false` | no | @@ -232,6 +236,7 @@ You can create a `.terraformignore` in the root of your project and add the foll | lambda\_role\_permissions\_boundary | ARN of IAM policy that scopes aws\_iam\_role access for the lambda | `string` | `null` | no | | lambda\_runtime | Lambda Function runtime | `string` | `"nodejs14.x"` | no | | lambda\_timeout | Max amount of time a Lambda Function has to return a response in seconds. Should not be more than 30 (Limited by API Gateway). | `number` | `10` | no | +| multiple\_deployments | Have multiple deployments and domain aliases. | `bool` | `false` | no | | next\_tf\_dir | Relative path to the .next-tf dir. | `string` | `"./.next-tf"` | no | | tags | Tag metadata to label AWS resources that support tags. | `map(string)` | `{}` | no | | use\_awscli\_for\_static\_upload | Use AWS CLI when uploading static resources to S3 instead of default Bash script. Some cases may fail with 403 Forbidden when using the Bash script. | `bool` | `false` | no | @@ -269,7 +274,7 @@ So issues that exist on Vercel are likely to occur on this project too. After running the initial `terraform destroy` command (that failed) wait ~1 hour and run the command again. This time it should run successfully and delete the rest of the stack. -- Initial apply fails with error message `Error: error creating Lambda Event Source Mapping` ([#138](https://github.com/dealmore/terraform-aws-next-js/issues/138)) +- Initial apply fails with error message `Error: error creating Lambda Event Source Mapping` ([#138](https://github.com/milliHQ/terraform-aws-next-js/issues/138)) There is some race condition when the permissions are created for the static deployment Lambda. This should only happen on the first deployment. @@ -278,6 +283,11 @@ So issues that exist on Vercel are likely to occur on this project too. You should be able to run`terraform apply` again and the stack creation would progreed without this error. +## Contributing + +Contributions are welcome! +If you want to improve this module, please take a look at our [contributing guidelines](https://github.com/milliHQ/terraform-aws-next-js/tree/main/CONTRIBUTING.md) to get started. + ## License Apache-2.0 - see [LICENSE](./LICENSE) for details. diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 9dcd9674..00000000 --- a/docker-compose.yml +++ /dev/null @@ -1,20 +0,0 @@ -############## -# This docker-compose file is only meant for e2e testing packages that -# require an S3 connection: -# - deploy-trigger -############### - -version: '3.6' - -services: - s3-emulator: - image: registry.gitlab.com/dealmore/dealmore-build-images:s3-emulator - ports: - - '9000:9000' - volumes: - - data-volume:/data - env_file: - - ./test.env - -volumes: - data-volume: diff --git a/examples/complete/LICENSE b/examples/complete/LICENSE index de282fd7..c3dca6ec 100644 --- a/examples/complete/LICENSE +++ b/examples/complete/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2020 Felix Haus (DealMore) +Copyright (c) 2020 Felix Haus (milliVolt infrastructure) Copyright (c) 2020 Vercel, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/examples/complete/README.md b/examples/complete/README.md index 111c85ed..0b7a529a 100644 --- a/examples/complete/README.md +++ b/examples/complete/README.md @@ -1,15 +1,15 @@ # Terraform Next.js complete example -This example contains a fully featured Next.js app (Static files, API-Routes, SSR) that can be deployed using the [Terraform Next.js for AWS](https://registry.terraform.io/modules/dealmore/next-js/aws) module. +This example contains a fully featured Next.js app (Static files, API-Routes, SSR) that can be deployed using the [Terraform Next.js for AWS](https://registry.terraform.io/modules/milliHQ/next-js/aws) module. -You can find the full example code on [GitHub](https://github.com/dealmore/terraform-aws-next-js/tree/main/examples/complete). +You can find the full example code on [GitHub](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/complete). ## Setup Download the files from the example app: ```sh -yarn create next-app --example https://github.com/dealmore/terraform-aws-next-js/tree/main/examples/complete my-app +yarn create next-app --example https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/complete my-app cd my-app ``` diff --git a/examples/next-image/LICENSE b/examples/next-image/LICENSE index f5fbfe59..a32647f7 100644 --- a/examples/next-image/LICENSE +++ b/examples/next-image/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2021 Felix Haus (DealMore) +Copyright (c) 2021 Felix Haus (milliVolt infrastructure) Copyright (c) 2021 Vercel, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/examples/next-image/README.md b/examples/next-image/README.md index bcd00bfa..7f23aded 100644 --- a/examples/next-image/README.md +++ b/examples/next-image/README.md @@ -1,7 +1,7 @@ # Terraform Next.js Image component example This example shows the usage of Next.js together with the `next/image` component. -You can find the full example code on [GitHub](https://github.com/dealmore/terraform-aws-next-js/tree/main/examples/next-image). +You can find the full example code on [GitHub](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/next-image). > **Note:** Support for `next/image` component is enabled in the Terraform Next.js module by default and requires no extra config other than the standard setup! @@ -10,7 +10,7 @@ You can find the full example code on [GitHub](https://github.com/dealmore/terra Download the files from the example app: ```sh -yarn create next-app --example https://github.com/dealmore/terraform-aws-next-js/tree/main/examples/next-image my-app +yarn create next-app --example https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/next-image my-app cd my-app ``` diff --git a/examples/static/LICENSE b/examples/static/LICENSE index 02b696d7..3f5f2b32 100644 --- a/examples/static/LICENSE +++ b/examples/static/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2020 Felix Haus (DealMore) +Copyright (c) 2020 Felix Haus (milliVolt infrastructure) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/examples/static/README.md b/examples/static/README.md index 71f0e79f..ef2ac20d 100644 --- a/examples/static/README.md +++ b/examples/static/README.md @@ -1,15 +1,15 @@ # Terraform Next.js static example -This example shows a simple static Next.js app that is deployed to S3 without lambdas using the [Terraform Next.js for AWS](https://registry.terraform.io/modules/dealmore/next-js/aws) module. +This example shows a simple static Next.js app that is deployed to S3 without lambdas using the [Terraform Next.js for AWS](https://registry.terraform.io/modules/milliHQ/next-js/aws) module. -You can find the full example code on [GitHub](https://github.com/dealmore/terraform-aws-next-js/tree/main/examples/static). +You can find the full example code on [GitHub](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/static). ## Setup Download the files from the example app: ```sh -yarn create next-app --example https://github.com/dealmore/terraform-aws-next-js/tree/main/examples/static my-app +yarn create next-app --example https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/static my-app cd my-app ``` diff --git a/examples/with-custom-domain/LICENSE b/examples/with-custom-domain/LICENSE index 02b696d7..3f5f2b32 100644 --- a/examples/with-custom-domain/LICENSE +++ b/examples/with-custom-domain/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2020 Felix Haus (DealMore) +Copyright (c) 2020 Felix Haus (milliVolt infrastructure) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/examples/with-custom-domain/README.md b/examples/with-custom-domain/README.md index 2e3514ef..bba6027d 100644 --- a/examples/with-custom-domain/README.md +++ b/examples/with-custom-domain/README.md @@ -1,7 +1,7 @@ # Terraform Next.js custom domain example -This example shows how to use a custom domain with the [Next.js Terraform module for AWS](https://registry.terraform.io/modules/dealmore/next-js/aws). -The code is based on the [with existing CloudFront distribution example](https://github.com/dealmore/terraform-aws-next-js/tree/main/examples/with-existing-cloudfront). +This example shows how to use a custom domain with the [Next.js Terraform module for AWS](https://registry.terraform.io/modules/milliHQ/next-js/aws). +The code is based on the [with existing CloudFront distribution example](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/with-existing-cloudfront). ## Features @@ -9,14 +9,14 @@ The code is based on the [with existing CloudFront distribution example](https:/ - Provisions a free SSL certificate from the AWS Certificate Manager for the domain - Assigns the domain and the SSL certificate to the CloudFront distribution -> **Note:** You can find the full example code on [GitHub](https://github.com/dealmore/terraform-aws-next-js/tree/main/examples/with-custom-domain). +> **Note:** You can find the full example code on [GitHub](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/with-custom-domain). ## Setup Download the files from the example app: ```sh -yarn create next-app --example https://github.com/dealmore/terraform-aws-next-js/tree/main/examples/with-custom-domain my-app +yarn create next-app --example https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/with-custom-domain my-app cd my-app ``` diff --git a/examples/with-custom-domain/main.tf b/examples/with-custom-domain/main.tf index 9d1fa4b7..7610961e 100644 --- a/examples/with-custom-domain/main.tf +++ b/examples/with-custom-domain/main.tf @@ -27,8 +27,7 @@ provider "aws" { variable "custom_domain" { description = "Your custom domain" type = string - # default = "example.com" - default = "tf-next.dealmore.de" + default = "example.com" } # Assuming that the ZONE of your domain is already registrated in your AWS account (Route 53) @@ -39,6 +38,15 @@ variable "custom_domain_zone_name" { default = "example.com." } +########### +# Locals +########### + +locals { + aliases = [var.custom_domain] + # If you need a wildcard domain(ex: *.example.com), you can add it like this: + # aliases = [var.custom_domain, "*.${var.custom_domain}"] +} ####################### # Route53 Domain record @@ -51,13 +59,15 @@ data "aws_route53_zone" "custom_domain_zone" { # Create a new record in Route 53 for the domain resource "aws_route53_record" "cloudfront_alias_domain" { + for_each = toset(local.aliases) + zone_id = data.aws_route53_zone.custom_domain_zone.zone_id - name = var.custom_domain + name = each.key type = "A" alias { - name = aws_cloudfront_distribution.distribution.domain_name - zone_id = aws_cloudfront_distribution.distribution.hosted_zone_id + name = module.tf_next.cloudfront_domain_name + zone_id = module.tf_next.cloudfront_hosted_zone_id evaluate_target_health = false } } @@ -73,8 +83,9 @@ module "cloudfront_cert" { source = "terraform-aws-modules/acm/aws" version = "~> 3.0" - domain_name = var.custom_domain - zone_id = data.aws_route53_zone.custom_domain_zone.zone_id + domain_name = var.custom_domain + zone_id = data.aws_route53_zone.custom_domain_zone.zone_id + subject_alternative_names = slice(local.aliases, 1, length(local.aliases)) tags = { Name = "CloudFront ${var.custom_domain}" @@ -91,12 +102,10 @@ module "cloudfront_cert" { ########################## module "tf_next" { - # source = "dealmore/next-js/aws" + source = "dealmore/next-js/aws" - # Prevent creation of the main CloudFront distribution - cloudfront_create_distribution = false - cloudfront_external_id = aws_cloudfront_distribution.distribution.id - cloudfront_external_arn = aws_cloudfront_distribution.distribution.arn + cloudfront_aliases = local.aliases + cloudfront_acm_certificate_arn = module.cloudfront_cert.acm_certificate_arn deployment_name = "terraform-next-js-example-custom-domain" providers = { @@ -104,158 +113,10 @@ module "tf_next" { } # Uncomment when using in the cloned monorepo for tf-next development - source = "../.." + # source = "../.." # debug_use_local_packages = true } -################################## -# Existing CloudFront distribution -################################## - -# You can fully customize all the settings of the CloudFront distribution -# as described in the AWS Provider documentation: -# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_distribution -resource "aws_cloudfront_distribution" "distribution" { - enabled = true - is_ipv6_enabled = true - comment = "terraform-next-js-example-custom-domain" - aliases = [var.custom_domain] - default_root_object = module.tf_next.cloudfront_default_root_object - - # Default cache behavior - ######################## - # Inserts the preconfigured default cache behavior from the tf-next module - # No manual edits should be neccessary here - dynamic "default_cache_behavior" { - for_each = module.tf_next.cloudfront_default_cache_behavior - - content { - allowed_methods = default_cache_behavior.value["allowed_methods"] - cached_methods = default_cache_behavior.value["cached_methods"] - target_origin_id = default_cache_behavior.value["target_origin_id"] - - viewer_protocol_policy = default_cache_behavior.value["viewer_protocol_policy"] - compress = default_cache_behavior.value["compress"] - - origin_request_policy_id = default_cache_behavior.value["origin_request_policy_id"] - cache_policy_id = default_cache_behavior.value["cache_policy_id"] - - dynamic "lambda_function_association" { - for_each = [default_cache_behavior.value["lambda_function_association"]] - - content { - event_type = lambda_function_association.value["event_type"] - lambda_arn = lambda_function_association.value["lambda_arn"] - include_body = lambda_function_association.value["include_body"] - } - } - } - } - - # Ordered cache behaviors - ######################### - # Inserts the preconfigured ordered cache behaviors from the tf-next module - # No manual edits should be neccessary here - dynamic "ordered_cache_behavior" { - for_each = module.tf_next.cloudfront_ordered_cache_behaviors - - content { - path_pattern = ordered_cache_behavior.value["path_pattern"] - allowed_methods = ordered_cache_behavior.value["allowed_methods"] - cached_methods = ordered_cache_behavior.value["cached_methods"] - target_origin_id = ordered_cache_behavior.value["target_origin_id"] - - compress = ordered_cache_behavior.value["compress"] - viewer_protocol_policy = ordered_cache_behavior.value["viewer_protocol_policy"] - - origin_request_policy_id = ordered_cache_behavior.value["origin_request_policy_id"] - cache_policy_id = ordered_cache_behavior.value["cache_policy_id"] - } - } - - # Origins - ######### - # Adds the preconfigured origins from the tf-next module - # No manual edits should be neccessary here - dynamic "origin" { - for_each = module.tf_next.cloudfront_origins - - content { - domain_name = origin.value["domain_name"] - origin_id = origin.value["origin_id"] - - # Origin Shield - dynamic "origin_shield" { - for_each = lookup(origin.value, "origin_shield", null) != null ? [true] : [] - - content { - enabled = lookup(origin.value["origin_shield"], "enabled", false) - origin_shield_region = lookup(origin.value["origin_shield"], "origin_shield_region", null) - } - } - - # S3 origin - dynamic "s3_origin_config" { - for_each = lookup(origin.value, "s3_origin_config", null) != null ? [true] : [] - content { - origin_access_identity = lookup(origin.value["s3_origin_config"], "origin_access_identity", null) - } - } - - # Custom origin - dynamic "custom_origin_config" { - for_each = lookup(origin.value, "custom_origin_config", null) != null ? [true] : [] - - content { - http_port = lookup(origin.value["custom_origin_config"], "http_port", null) - https_port = lookup(origin.value["custom_origin_config"], "https_port", null) - origin_protocol_policy = lookup(origin.value["custom_origin_config"], "origin_protocol_policy", null) - origin_ssl_protocols = lookup(origin.value["custom_origin_config"], "origin_ssl_protocols", null) - origin_keepalive_timeout = lookup(origin.value["custom_origin_config"], "origin_keepalive_timeout", null) - origin_read_timeout = lookup(origin.value["custom_origin_config"], "origin_read_timeout", null) - } - } - - dynamic "custom_header" { - for_each = lookup(origin.value, "custom_header", null) != null ? origin.value["custom_header"] : [] - - content { - name = custom_header.value["name"] - value = custom_header.value["value"] - } - } - } - } - - # Custom Error response (S3 failover) - ##################################### - # Adds the preconfigured custom error response from the tf-next module - # No manual edits should be neccessary here - dynamic "custom_error_response" { - for_each = module.tf_next.cloudfront_custom_error_response - - content { - error_caching_min_ttl = custom_error_response.value["error_caching_min_ttl"] - error_code = custom_error_response.value["error_code"] - response_code = custom_error_response.value["response_code"] - response_page_path = custom_error_response.value["response_page_path"] - } - } - - viewer_certificate { - cloudfront_default_certificate = false - acm_certificate_arn = module.cloudfront_cert.acm_certificate_arn - ssl_support_method = "sni-only" - minimum_protocol_version = "TLSv1" - } - - restrictions { - geo_restriction { - restriction_type = "none" - } - } -} - ######### # Outputs ######### diff --git a/examples/with-existing-cloudfront/LICENSE b/examples/with-existing-cloudfront/LICENSE index b209ef1c..ce8d44cb 100644 --- a/examples/with-existing-cloudfront/LICENSE +++ b/examples/with-existing-cloudfront/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2021 Felix Haus (DealMore) +Copyright (c) 2021 Felix Haus (milliVolt infrastructure) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/examples/with-existing-cloudfront/README.md b/examples/with-existing-cloudfront/README.md index 067bb7cc..afdc1245 100644 --- a/examples/with-existing-cloudfront/README.md +++ b/examples/with-existing-cloudfront/README.md @@ -2,14 +2,14 @@ This example shows how to integrate the Terraform Next.js module for AWS into an existing CloudFront distribution (Without creating a new one). -> **Note:** The full example code is available on [GitHub](https://github.com/dealmore/terraform-aws-next-js/tree/main/examples/with-existing-cloudfront) +> **Note:** The full example code is available on [GitHub](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/with-existing-cloudfront) ## Setup Download the files from the example app: ```sh -yarn create next-app --example https://github.com/dealmore/terraform-aws-next-js/tree/main/examples/with-existing-cloudfront my-app +yarn create next-app --example https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/with-existing-cloudfront my-app cd my-app ``` diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index f62b6187..00000000 --- a/jest.config.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - preset: 'ts-jest', - testEnvironment: 'node', - rootDir: './', - globalSetup: '
"Authorization"
]