Skip to content

Commit f426713

Browse files
Merge commit '4f47d40a33fcc372fd6e939347a400730bab0f5a' into release
2 parents bad1685 + 4f47d40 commit f426713

File tree

19 files changed

+136
-39
lines changed

19 files changed

+136
-39
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
## [1.0.0-canary.5] - 2022-07-12
6+
7+
- Adds alias for profile, improves error message ([#344](https://github.com/milliHQ/terraform-aws-next-js/pull/344))
8+
59
## [1.0.0-canary.4] - 2022-06-07
610

711
- Correctly increase version number of new packages

README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1+
<blockquote>
2+
<p align="center">
3+
<strong>Note</strong>
4+
<br />
5+
The main branch currently contains the atomic deployments alpha preview.
6+
<br />
7+
For the lastest stable release, check out the <a href="https://github.com/milliHQ/terraform-aws-next-js/tree/v0.x"><code>v0.x</code> branch</a>.
8+
</p>
9+
<p align="center">
10+
Please see our blog post <a href="https://milli.is/blog/the-road-to-atomic-deployments" target="_blank" rel="noopener">"The road to Atomic Deployments"</a><br />or watch the latest release review for more information:
11+
<br />
12+
<br />
13+
<a aria-label="Terraform Next.js for AWS: First look at the new atomic deployments feature" href="https://www.youtube.com/watch?v=NY3zKnIcLd4" target="_blank" rel="noopener">
14+
<img src="https://img.youtube.com/vi/NY3zKnIcLd4/0.jpg" height="260px">
15+
</a>
16+
17+
</p>
18+
</blockquote>
19+
20+
---
21+
122
# Terraform Next.js module for AWS
223

324
![CI status](https://github.com/milliHQ/terraform-aws-next-js/workflows/CI/badge.svg)
425

5-
> **Note:** The main branch currently contains the atomic deployments alpha preview.
6-
> For the lastest stable release, please see the [`v0.x` branch](https://github.com/milliHQ/terraform-aws-next-js/tree/v0.x).
7-
826
A zero-config Terraform module for self-hosting Next.js sites serverless on AWS Lambda.
927

1028
## Features
@@ -37,10 +55,10 @@ You should have the following tools installed:
3755
- [Node.js](https://nodejs.org)
3856
- [Bash](https://www.gnu.org/software/bash/) & [curl](https://curl.se/) (Should be available by default on many Linux based images or macOS)
3957

40-
> Additionally we assume here that you already have a public [Route53 Hosted Zone](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/AboutHZWorkingWith.html) associated with your AWS account.
58+
> **Note:** Additionally we assume here that you already have a public [Route53 Hosted Zone](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/AboutHZWorkingWith.html) associated with your AWS account.
4159
>
42-
> This is currently a requirement in the preview phase of atomic deployments to enable preview deployments, where each deployment gets a unique subdomain assigned.
43-
> This will change once atomic deployments become generally available.
60+
> This is a requirement in the preview phase of atomic deployments, where each deployment gets a unique subdomain assigned.
61+
> It will change once atomic deployments become generally available.
4462
4563
### Setup the Next.js Terraform module
4664

@@ -156,7 +174,7 @@ module "cloudfront_cert" {
156174
157175
module "tf_next" {
158176
source = "milliHQ/next-js/aws"
159-
version = "1.0.0-canary.3"
177+
version = "1.0.0-canary.4"
160178
161179
cloudfront_aliases = local.aliases
162180
cloudfront_acm_certificate_arn = module.cloudfront_cert.acm_certificate_arn

examples/atomic-deployments/README.md

Lines changed: 74 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,34 @@
22

33
This example shows how to use the atomic deployments feature with the [Next.js Terraform module for AWS](https://registry.terraform.io/modules/milliHQ/next-js/aws).
44

5+
To learn more about this feature, please see the blog post ["The road to Atomic Deployments"](https://milli.is/blog/the-road-to-atomic-deployments) or watch the release review: [First look at the new atomic deployments feature](https://youtu.be/NY3zKnIcLd4).
6+
57
## Features
68

7-
- Unlimited parallel deployments of Next.js with a single CloudFront distribution
8-
- Preview deployment subdomains, e.g. `<deployment-id>.example.com`
9+
- &nbsp;Unlimited parallel deployments of Next.js apps served by a single CloudFront distribution
10+
- &nbsp;Preview deployment subdomains, e.g. `<deployment-id>.example.com`
911

10-
> **Note:** You can find the full example code on [GitHub](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/atomic-deployments).
12+
> **Notice:** You can find the full example code on [GitHub](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/atomic-deployments).
1113
12-
## Setup
14+
## How to use
1315

14-
Download the files from the example app:
16+
> **Cost disclaimer**: All resources that are created in your AWS account are designed to be fully serverless.
17+
> This means it produces **no running costs** until it is actually used (e.g. by deploying a Next.js application or when your app starts receiving requests from the web).
18+
> Most of the resources created are also eligible for the [AWS always free tier](https://aws.amazon.com/free/).
19+
>
20+
> Highest cost factor in this example is the Route 53 hosted zone which can [produce costs of up to $0.50 / month](https://aws.amazon.com/route53/pricing/#Hosted_Zones_and_Records) when creating a new one.
1521
16-
```sh
17-
yarn create next-app --example https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/atomic-deployments my-app
22+
Run [`create-next-app`](https://www.npmjs.com/package/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [yarn](https://classic.yarnpkg.com/en/docs/cli/create/) or [pnpm](https://pnpm.io/cli/create) to bootstrap the example:
1823

19-
cd my-app
24+
```sh
25+
npx create-next-app --example https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/atomic-deployments atomic-deployments
26+
# or
27+
yarn create next-app --example https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/atomic-deployments atomic-deployments
28+
# or
29+
pnpm create next-app --example https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/atomic-deployments atomic-deployments
2030
```
2131

22-
## Setup
32+
### Terraform setup
2333

2434
Use Terraform to deploy the base system to your AWS account.
2535

@@ -49,8 +59,7 @@ You can change `example.com` to every domain (or subdomain) that is associated w
4959
Then deploy the base system.
5060

5161
```sh
52-
# Expose your AWS Access Keys to the current terminal session
53-
# Only needed when running Terraform commands
62+
# Expose your AWS Access Keys (administrator) to the current terminal session
5463
export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
5564
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
5665

@@ -71,24 +80,69 @@ After the deployment was successful, you should see the following output:
7180
> api_endpoint_access_policy_arn = "arn:aws:iam::123456789012:policy/access-api"
7281
```
7382

74-
## Build
83+
> For deploying your apps in the next step you can optionally [create a new IAM user](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html) and assign it the policy that you got from the `api_endpoint_access_policy_arn` output.
84+
> This is a security feature that prevents a full AWS account access during deployments. It only allows access to the internal API, but not to create, destroy or modify any resources in the AWS account directly.
85+
86+
### Build
7587

76-
Prepare the Next.js application to be deployed with Terraform:
88+
First, install the [`tf-next`](https://github.com/milliHQ/terraform-aws-next-js/tree/main/packages/tf-next) CLI by running:
89+
90+
```
91+
npm i -g tf-next@canary
92+
# or
93+
yarn global add tf-next@canary
94+
# or
95+
pnpm add -g tf-next@canary
96+
```
97+
98+
Then prepare your Next.js application for a serverless deployment:
7799

78100
```sh
79-
npm run tf-next
101+
tf-next build
80102
```
81103

82-
## Deploy
104+
### Deploy
83105

84-
Deploy the previously built Next.js app to the AWS infrastructure:
106+
Deploy the previously built Next.js app to your AWS infrastructure. For the `--endpoint` flag use the domain you got from the `api_endpoint` output in the previous [Terraform Setup](#terraform-setup) step.
85107

86108
```sh
87109
tf-next deploy --endpoint https://<api-id>.execute-api.<region>.amazonaws.com
88110

89-
> ✅ Upload complete.
90-
> Deployment complete.
91-
> Available at: https://<deployment-id>.example.com
111+
> success Deployment package uploaded.
112+
> success Deployment ready
113+
> Available at: https://<deployment-id>.example.com/ (copied to clipboard)
92114
```
93115

94-
You can now access your Next.js app in the browser under the `https://<deployment-id>.example.com` domain.
116+
You can now access your Next.js app in the browser at the `https://<deployment-id>.example.com` domain.
117+
Repeat the [build](#build) & [deploy](#deploy) step for each new app or deployment you want to push to the system.
118+
119+
## Cleanup
120+
121+
To delete all resources from your AWS account that were created in this examples follow this steps:
122+
123+
1. **Cleanup all deployments with the `tf-next` CLI**
124+
First, get all active deployments through the CLI
125+
126+
```
127+
tf-next deployment ls
128+
129+
> age ▼ deployment-id status
130+
> 5m 59ec3b01f4325c906af8573efe0d75ba ready
131+
```
132+
133+
Then remove each deployment by its id:
134+
135+
```
136+
tf-next deployment rm 59ec3b01f4325c906af8573efe0d75ba
137+
```
138+
139+
Repeat this until `tf-next deployment ls` shows no more active deployments.
140+
141+
2. **Remove the Terraform module**
142+
To remove the deployment system (with it's global resources like CloudFront, S3 etc.) that were created with Terraform:
143+
144+
```
145+
terraform destroy
146+
```
147+
148+
> **Note:** The destroy command could fail on the first execution since [Lambda@Edge functions cannot be deleted in a synchronous way](https://github.com/hashicorp/terraform-provider-aws/issues/1721). You can workaround this by simply wait ~30 minutes and then run `terraform destroy` again.

examples/atomic-deployments/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ module "cloudfront_cert" {
103103
##########################
104104

105105
module "tf_next" {
106-
source = "milliHQ/next-js/aws"
106+
source = "milliHQ/next-js/aws"
107+
version = "1.0.0-canary.5"
107108

108109
cloudfront_aliases = local.aliases
109110
cloudfront_acm_certificate_arn = module.cloudfront_cert.acm_certificate_arn

examples/complete/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Terraform Next.js complete example
22

3+
> **Warning:** This example is not fully updated for the upcoming `v1.0.0` release.
4+
> We recommend following the [Atomic Deployments Example](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/atomic-deployments) instead until this example gets an update.
5+
36
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.
47

5-
You can find the full example code on [GitHub](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/complete).
8+
> **Notice:** You can find the full example code on [GitHub](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/complete).
69
710
## Setup
811

examples/complete/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ provider "aws" {
2121
}
2222

2323
module "tf_next" {
24-
source = "milliHQ/next-js/aws"
24+
source = "milliHQ/next-js/aws"
25+
version = "1.0.0-canary.5"
2526

2627
deployment_name = "tf-next-example-complete"
2728

examples/next-image/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Terraform Next.js Image component example
22

3+
> **Warning:** This example is not fully updated for the upcoming `v1.0.0` release.
4+
> We recommend following the [Atomic Deployments Example](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/atomic-deployments) instead until this example gets an update.
5+
36
This example shows the usage of Next.js together with the `next/image` component.
47
You can find the full example code on [GitHub](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/next-image).
58

examples/next-image/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ provider "aws" {
2121
}
2222

2323
module "tf_next" {
24-
source = "milliHQ/next-js/aws"
24+
source = "milliHQ/next-js/aws"
25+
version = "1.0.0-canary.5"
2526

2627
deployment_name = "tf-next-example-image"
2728

examples/static/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Terraform Next.js static example
22

3+
> **Warning:** This example is not fully updated for the upcoming `v1.0.0` release.
4+
> We recommend following the [Atomic Deployments Example](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/atomic-deployments) instead until this example gets an update.
5+
36
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.
47

58
You can find the full example code on [GitHub](https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/static).

examples/static/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ provider "aws" {
2121
}
2222

2323
module "tf_next" {
24-
source = "milliHQ/next-js/aws"
24+
source = "milliHQ/next-js/aws"
25+
version = "1.0.0-canary.5"
2526

2627
deployment_name = "tf-next-example-static"
2728

0 commit comments

Comments
 (0)