Terraform (AWS)
Terraform scaffolding for AWS with S3 backend, per-environment configs, and common tagging.
What create-faster adds
A complete infra/ directory with AWS provider configuration, S3 remote state backend, and per-environment variable files. No npm dependencies are added -- Terraform is installed separately.
Files created:
infra/
├── providers.tf # AWS provider ~> 6.0, required_version >= 1.10, common tags
├── backend.tf # S3 backend declaration
├── variables.tf # project_name, env (dev/staging/prod validation)
├── variables.auto.tfvars # Defaults pre-filled with project name
├── secrets.auto.tfvars # Placeholder for sensitive values (gitignored)
├── outputs.tf # Empty placeholder for resource outputs
├── main.tf # Empty placeholder for your resources
└── backend/
├── dev.hcl # Dev environment S3 backend config
└── prod.hcl # Prod environment S3 backend configproviders.tf
Configures the AWS provider with:
- AWS provider
~> 6.0 - Terraform
>= 1.10.0(required for native state locking) local.resource_namecomputed as{project_name}-{env}local.common_tagsapplied to all resources viadefault_tags(Project, Env, ManagedBy)
backend.tf
Declares an empty S3 backend. Configuration is injected at init time via -backend-config (a partial configuration):
terraform init -backend-config=backend/dev.hclvariables.tf
Two variables:
project_name-- used in resource naming and tagsenv-- validated todev,staging, orprod
variables.auto.tfvars
Pre-filled with the project name and env = "dev". There is no region: see Profile and region.
secrets.auto.tfvars
Empty placeholder for sensitive values. Gitignored so secrets never reach the repository.
backend/ configs
Per-environment S3 backend configs with use_lockfile = true (Terraform >= 1.10 native file locking, no DynamoDB table needed). Fill in the <BUCKET_NAME> placeholder before first use, with a bucket you created: Terraform cannot create its own state bucket.
main.tf
Empty file where you add your infrastructure resources.
.gitignore
.terraform/, .build/ (where the Lambda module of the Lambda (Terraform) blueprint writes its zips), *.tfstate*, and secrets.auto.tfvars are added to .gitignore.
Profile and region
The backend files and the provider name neither an AWS profile nor a region. Terraform reads them from the environment: the S3 backend takes AWS_PROFILE and AWS_REGION (S3 backend configuration), and so does the AWS provider (provider configuration). The same files therefore work on a laptop and in CI:
- Locally, export
AWS_PROFILEandAWS_REGIONin the shell. - In a GitHub Actions workflow,
aws-actions/configure-aws-credentialsassumes an IAM role through OIDC and exports temporary credentials andAWS_REGION(itsaws-regioninput). The workflow of the Lambda blueprint reads that region from theAWS_REGIONGitHub variable.
A profile in a backend file would break CI, which has no profile.
First deploy
The generated README.md has a "Deploying to AWS (Terraform)" section, in order: the AWS credentials and region, the state bucket (aws s3 mb, with versioning), the <BUCKET_NAME> placeholder of both backend files, then terraform -chdir=infra init -backend-config=backend/dev.hcl. With the Lambda (Terraform) blueprint it continues with the build, apply, the live URL and the GitHub Actions setup.
TanStack Start on Lambda
infra/ provisions no resource for any stack, TanStack Start included. When the project has a TanStack Start app, the generated AGENTS.md documents how to run it on AWS Lambda with Nitro's aws-lambda preset:
- Select the preset for the deploy build only (
NITRO_PRESET=aws-lambda npm run build, or thebun/pnpmequivalent, run from the app directory). Anaws-lambdabuild does not listen, so keep it out ofvite.config.tsand out of thebuildscript thatstartrelies on. - Zip
.output/serverand set the Lambda handler toindex.handler. - The preset does not serve
.output/public: serve it from S3 behind CloudFront, or embed it withserveStatic: 'inline'. - A buffered Lambda response is capped at 6 MB, so inlined assets suit a starter, not large media.
To get the function, bucket and CloudFront provisioned for you, use the SST deployment instead.
NODE_ENV on Lambda
A Lambda you create never runs the app's start script. Next.js and TanStack Start builds already replace process.env.NODE_ENV with production in their server bundle. A Hono or Node app has to get it from the way you bundle it:
-
With
bun build, Bun inlinesprocess.env.NODE_ENVat build time, and a plainbun buildinlinesdevelopment. With PostgreSQL that compiles the generated client's TLS default to off, whatever the Lambda environment says. Build with--production(which also minifies) or withNODE_ENV=productionin the build environment:bun build src/index.ts --target node --production --outfile dist/index.mjs # or, unminified NODE_ENV=production bun build src/index.ts --target node --outfile dist/index.mjs -
A bundler that leaves
process.env.NODE_ENVto runtime reads the function environment: setNODE_ENV=productionin itsenvironmentblock.
Otherwise the DATABASE_URL must set sslmode=verify-full (see PostgreSQL).
CLI usage
bunx create-faster myproject \
--app myproject:nextjs \
--deployment terraform-aws \
--pm bunCreate the state bucket and fill in <BUCKET_NAME> as the README says, then initialize and plan:
export AWS_PROFILE=my-profile AWS_REGION=eu-west-3
cd infra
terraform init -backend-config=backend/dev.hcl
terraform plan
