All Projects → ematipico → Terraform Nextjs Plugin

ematipico / Terraform Nextjs Plugin

Licence: mit
A plugin to generate terraform configuration for Nextjs 8 and 9

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Terraform Nextjs Plugin

Serverless Next.js
⚡ Deploy your Next.js apps on AWS Lambda@Edge via Serverless Components
Stars: ✭ 2,977 (+7160.98%)
Mutual labels:  api-gateway, aws, serverless, lambda, nextjs
Aws Cli Cheatsheet
☁️ AWS CLI + JQ = Make life easier
Stars: ✭ 94 (+129.27%)
Mutual labels:  api-gateway, aws, lambda, cli
Workshop Donkeytracker
Workshop to build a serverless tracking application for your mobile device with an AWS backend
Stars: ✭ 27 (-34.15%)
Mutual labels:  api-gateway, aws, serverless, lambda
Aws Lambda Fastify
Insipired by aws-serverless-express to work with Fastify with inject functionality.
Stars: ✭ 190 (+363.41%)
Mutual labels:  api-gateway, aws, serverless, lambda
Aws Sam Cli
CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
Stars: ✭ 5,817 (+14087.8%)
Mutual labels:  api-gateway, aws, serverless, lambda
Serverless Es Logs
A Serverless plugin to transport logs to ElasticSearch
Stars: ✭ 51 (+24.39%)
Mutual labels:  api-gateway, aws, serverless, lambda
Hexaville
The modern serverless web application engine and framework for Swift
Stars: ✭ 123 (+200%)
Mutual labels:  api-gateway, aws, serverless, lambda
Zip It And Ship It
Intelligently prepare Node.js Lambda functions for deployment
Stars: ✭ 104 (+153.66%)
Mutual labels:  aws, serverless, lambda, cli
Terraform Aws Github Runner
Terraform module for scalable GitHub action runners on AWS
Stars: ✭ 326 (+695.12%)
Mutual labels:  aws, serverless, lambda, terraform
Lambdalogs
A CLI tool to trace AWS Lambda calls over multiple CloudWatch log groups.
Stars: ✭ 18 (-56.1%)
Mutual labels:  aws, serverless, lambda, cli
Shep
A framework for building JavaScript Applications with AWS API Gateway and Lambda
Stars: ✭ 376 (+817.07%)
Mutual labels:  api-gateway, aws, serverless, lambda
Aws Mobile React Sample
A React Starter App that displays how web developers can integrate their front end with AWS on the backend. The App interacts with AWS Cognito, API Gateway, Lambda and DynamoDB on the backend.
Stars: ✭ 650 (+1485.37%)
Mutual labels:  api-gateway, aws, serverless, lambda
Streamalert
StreamAlert is a serverless, realtime data analysis framework which empowers you to ingest, analyze, and alert on data from any environment, using datasources and alerting logic you define.
Stars: ✭ 2,634 (+6324.39%)
Mutual labels:  aws, serverless, lambda, terraform
Up
Up focuses on deploying "vanilla" HTTP servers so there's nothing new to learn, just develop with your favorite existing frameworks such as Express, Koa, Django, Golang net/http or others.
Stars: ✭ 8,439 (+20482.93%)
Mutual labels:  api-gateway, aws, serverless, lambda
Serverless Sam
Serverless framework plugin to export AWS SAM templates for a service
Stars: ✭ 143 (+248.78%)
Mutual labels:  aws, serverless, lambda, plugin
Aws Serverless Ecommerce Platform
Serverless Ecommerce Platform is a sample implementation of a serverless backend for an e-commerce website. This sample is not meant to be used as an e-commerce platform as-is, but as an inspiration on how to build event-driven serverless microservices on AWS.
Stars: ✭ 469 (+1043.9%)
Mutual labels:  api-gateway, aws, serverless, lambda
Binaryalert
BinaryAlert: Serverless, Real-time & Retroactive Malware Detection.
Stars: ✭ 1,125 (+2643.9%)
Mutual labels:  aws, serverless, lambda, terraform
Aws Mobile React Native Starter
AWS Mobile React Native Starter App https://aws.amazon.com/mobile
Stars: ✭ 2,247 (+5380.49%)
Mutual labels:  api-gateway, aws, serverless, lambda
Serverlessui
A command-line utility for deploying serverless applications to AWS. Complete with custom domains, deploy previews, TypeScript support, and more.
Stars: ✭ 434 (+958.54%)
Mutual labels:  aws, serverless, lambda, cli
Mangum
AWS Lambda & API Gateway support for ASGI
Stars: ✭ 475 (+1058.54%)
Mutual labels:  api-gateway, aws, serverless, lambda

Terraform nextjs plugin

A plugin to generate terraform configuration from nextjs pages

Build Status Codacy Badge npm Conventional Commits codecov

The reason

Nextjs supports serverless pages, where it creates files that can be used by some lambdas to render the pages. Unfortunately, here you are left alone. So here a solution for your troubles.

Installation

npm i --save-dev @ematipico/terraform-nextjs-plugin

Or

yarn add --dev @ematipico/terraform-nextjs-plugin

This package requires at least Next v8.

Usage

terranext --provider=AWS

This library supports cosmiconfig: you just need to have a file called terranextrc that matches the criteria. This repository has one.

Via CLI

You can use the simple CLI available. At moment you can't pass the routes parameter, you will need to use the config object or use the API.

Using the CLI will automatically emit the configuration files.

Arguments passed via CLI will override the ones that are defined inside the config file.

terranext --provider=AWS --gateway-key=CustomKey --next-dir-app=../../nextjs-project/

Or you can use the aliases:

terranext --provider=AWS -g=CustomKey -p=../../nextjs-project/

Help section


Usage
  $ terranext

Options
  --gateway-key, -g     The API Gateway key of the project. Default is "Terranext"
  --next-app-dir, -d    The path that Terraform CLI has to follow to reach the nextjs project.
  --provider            The Cloud provider to use when exporting the configuration
  --env				    A way for passing environment variables to the lambdas


Examples
  $ terranext
  $ terranext --gateway-key=CustomKey --next-app-dir=../../nextjs-project/
  $ terranext --provider=AWS --next-app-dir=../../nextjs-project/
  $ terranext -g=CustomKey -d=../../nextjs-project/
  $ terranext --env="DEBUG,express:*" --env="API_KEY,1234"

Via API

const generateResources = require("@ematipico/terraform-nextjs-plugin");

const configuration = {
	gatewayKey: "AmazingWebsite",
	lambdaPath: "../../project/build",
	provider: "AWS",
	env: [
		{
			key: "KEY",
			value: "2940"
		}
	]
};

const resources = generateResources(configuration); // inside resources you have the terraform json configuration
generateResources(configuration, true); // it creates two files

If the second argument is a boolean and it's true, the library will create two files:

  • gateway.terraform.tf.json
  • lambdas.terraform.tf.json

Having a suffix with .tf. will tell automatically to terraform that should be validated and planned. It will be up to you to consume them in a proper way.

Configuration

Name Type Default Description
gatewayKey string Terranext A name that will be prefixed to your resources. Usually it's the project name. Default value: Terranext.
provider string Must be provided The Cloud Provider. Based on the value, a different configuration will be exported. Supported providers: AWS
nextAppDir string Must be provided This is the path where your Next.js project is. Usually you will run terraform CLI from a different project/folder. So you need to tell terraform where this folder is. The library will take care of the rest. Default value: "./"
routes Array<Mapping>, Mapping Optional This is the structure of the routes that describe your pages.
env Array<Env> Optional Environments passed via CLI have to be split using ,: --env="KEY,VALUE". When using the API, you always have to pass an array of objects { key: "MyKeyName", "value": "MyKeyValue" }. Environment variables are applied to all the lambdas
nodeVersion 10 or 12 10 Runtime to use

Mapping explained

These mappings are only needed if you have custom routes. If you don't, routes is not needed as this library is able to create mappings from the files that Nextjs generates.

Let's say we want to describe the following URLs:

  • /about-us/contacts
  • /about-us/the-company
  • /blog/first-blog-post
  • /blog/second-blog-post
  • /credits?hideComments: here, hideComments is not mandatory. If it is mandatory, it will be marked true in the configuration
const routes = [
	{
		prefix: "/about-us",
		mappings: [
			{
				route: "/contacts", // the URL
				page: "/companyContacts" // the nextjs file, inside pages folder, that is responsible to render this page
			},
			{
				route: "/the-company",
				page: "/aboutTheCompany"
			}
		]
	},
	{
		prefix: "",
		mappings: [
			{
				route: "/blog/:url",
				page: "/blogPost"
			},
			{
				route: "/credits",
				page: "/credits",
				params: {
					hideComments: false
				}
			}
		]
	}
];

Providers

At the moment the project supports only AWS but it's up to support more providers in the future.

AWS

Once you generate the resource files, you will need to consume them. Also, you will need to create the following resource:

resource "aws_api_gateway_rest_api" "CustomKey" {
  name        = "WebApi"
  description = "Web API"
}

locals {
  groupname = "WebApi"
  lambda_iam_role = "arn:aws:iam::202020202020:role/lambda_execution_role"
  aws_region = "${data.aws_region.current.name}"
}

Please check the integration testing to see how to consume the configuration.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].