-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
294 additions
and
137 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,42 @@ | ||
# Local .terraform directories | ||
**/.terraform/* | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# Crash log files | ||
crash.log | ||
# production | ||
/build | ||
|
||
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most | ||
# .tfvars files are managed as part of configuration and so should be included in | ||
# version control. | ||
# | ||
# example.tfvars | ||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# Ignore override files as they are usually used to override resources locally and so | ||
# are not checked in | ||
override.tf | ||
override.tf.json | ||
*_override.tf | ||
*_override.tf.json | ||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Include override files you do wish to add to version control using negated pattern | ||
# | ||
# !example_override.tf | ||
# local env files | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# Terraform | ||
**/.terraform/* | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan | ||
# example: *tfplan* | ||
# tf-next | ||
/.tf-next/ |
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 |
---|---|---|
@@ -1,15 +1,51 @@ | ||
# Terraform Next.js complete example | ||
|
||
Install it and run: | ||
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. | ||
|
||
You can find the full example code on [GitHub](https://github.com/dealmore/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 | ||
|
||
cd my-app | ||
``` | ||
|
||
## Build | ||
|
||
Prepare the Next.js application to be deployed with Terraform: | ||
|
||
```sh | ||
# Build | ||
yarn | ||
yarn tf-next | ||
``` | ||
|
||
# Terraform | ||
cd terraform | ||
terraform init | ||
terraform plan | ||
terraform apply | ||
## Deploy | ||
|
||
Use Terraform to deploy the Next.js app to your AWS account: | ||
|
||
```sh | ||
# Expose your AWS Access Keys to the current terminal session | ||
# Only needed when running Terraform commands | ||
export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE | ||
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY | ||
|
||
terraform init # Only needed on the first time running Terraform | ||
|
||
terraform plan # (Optional) See what resources Terraform will create | ||
terraform apply # Deploy the Next.js app to your AWS account | ||
``` | ||
|
||
After the deployment was successful, you should see the following output: | ||
|
||
```sh | ||
> Apply complete! | ||
> | ||
> Outputs: | ||
> | ||
> cloudfront_domain_name = "<distribution-id>.cloudfront.net" | ||
``` | ||
|
||
You can now access your Next.js app in the browser under the [https://<distribution-id>.cloudfront.net](https://<distribution-id>.cloudfront.net) domain. |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,29 +1,42 @@ | ||
# Local .terraform directories | ||
**/.terraform/* | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# Crash log files | ||
crash.log | ||
# production | ||
/build | ||
|
||
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most | ||
# .tfvars files are managed as part of configuration and so should be included in | ||
# version control. | ||
# | ||
# example.tfvars | ||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# Ignore override files as they are usually used to override resources locally and so | ||
# are not checked in | ||
override.tf | ||
override.tf.json | ||
*_override.tf | ||
*_override.tf.json | ||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Include override files you do wish to add to version control using negated pattern | ||
# | ||
# !example_override.tf | ||
# local env files | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# Terraform | ||
**/.terraform/* | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan | ||
# example: *tfplan* | ||
# tf-next | ||
/.tf-next/ |
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 |
---|---|---|
@@ -1,17 +1,70 @@ | ||
# Terraform Next.js static example | ||
# Terraform Next.js custom domain example | ||
|
||
Demonstrates how to use a custom domain with AWS Next.js Terraform module. | ||
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). | ||
|
||
Install it and run: | ||
You can find the full example code on [GitHub](https://github.com/dealmore/terraform-aws-next-js/tree/main/examples/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/custom-domain my-app | ||
|
||
cd my-app | ||
``` | ||
|
||
## Build | ||
|
||
Prepare the Next.js application to be deployed with Terraform: | ||
|
||
```sh | ||
# Build | ||
yarn | ||
yarn tf-next | ||
``` | ||
|
||
## Setting the domain | ||
|
||
Open the `main.tf` file in the root of the Next.js app, and change the following: | ||
|
||
```tf | ||
# main.tf | ||
... | ||
locals { | ||
# Your custom domain | ||
custom_domain = "example.com" | ||
} | ||
# Terraform | ||
cd terraform | ||
terraform init | ||
terraform plan | ||
terraform apply | ||
... | ||
``` | ||
|
||
You can change `example.com` to every domain that is associated with Route 53 in your AWS account. | ||
|
||
## Deploy | ||
|
||
Use Terraform to deploy the Next.js app to your AWS account: | ||
|
||
```sh | ||
# Expose your AWS Access Keys to the current terminal session | ||
# Only needed when running Terraform commands | ||
export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE | ||
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY | ||
|
||
terraform init # Only needed on the first time running Terraform | ||
|
||
terraform plan # (Optional) See what resources Terraform will create | ||
terraform apply # Deploy the Next.js app to your AWS account | ||
``` | ||
|
||
After the deployment was successful, you should see the following output: | ||
|
||
```sh | ||
> Apply complete! | ||
> | ||
> Outputs: | ||
> | ||
> cloudfront_domain_name = "<distribution-id>.cloudfront.net" | ||
> custom_domain_name = "example.com" | ||
``` | ||
|
||
You can now access your Next.js app in the browser under the [example.com](https://example.com) or [https://<distribution-id>.cloudfront.net](https://<distribution-id>.cloudfront.net) domain. |
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
Oops, something went wrong.