nuxt-terraform

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Nuxt + Terraform Scaffold Skill

Nuxt + Terraform 脚手架 Skill

Generate files for Nuxt + AWS infrastructure projects. This skill replaces the CLI — generate all files directly.
为 Nuxt + AWS 基础设施项目生成所需文件。该 Skill 可替代 CLI,直接生成全部所需文件。

Pre-Requisites

前置要求

Read
terraform-scaffold.config.ts
for
functionPrefix
(PascalCase),
environments
, and custom paths. If no config exists, ask the user for these values.
读取
terraform-scaffold.config.ts
中的
functionPrefix
(PascalCase 格式)、
environments
以及自定义路径。如果不存在配置文件,需向用户询问这些参数值。

Naming Conventions

命名约定

ConceptConventionExample
Function prefixPascalCase
MyApp
Full Lambda name
<prefix><PascalSuffix>
MyAppRedeemNow
Resolver namecamelCase
productById
GraphQL constantSCREAMING_SNAKE_CASE
PRODUCT_BY_ID
TF module name
appsync_function_<camelName>
appsync_function_productById
TF lambda module
lambda_function_<camelName>
lambda_function_productById
Composable file
use<Model>.ts
useProduct.ts
GraphQL file
<model>.ts
(lcfirst)
product.ts
TF file per model
<model>.tf
(lcfirst)
product.tf
DynamoDB datasource
appsync_datasource_<modelLower>
appsync_datasource_product
DynamoDB table
dynamodb_<modelLower>s
dynamodb_products
Query index
by<Field>
byUserId
String conversions:
toScreamingSnake
splits on uppercase, joins with
_
, uppercases.
toPascal
capitalizes first letter.
lcfirst
lowercases first letter.
概念约定规则示例
函数前缀PascalCase
MyApp
Lambda完整名称
<prefix><PascalSuffix>
MyAppRedeemNow
解析器名称camelCase
productById
GraphQL常量SCREAMING_SNAKE_CASE
PRODUCT_BY_ID
TF模块名称
appsync_function_<camelName>
appsync_function_productById
TF Lambda模块
lambda_function_<camelName>
lambda_function_productById
可组合函数文件
use<Model>.ts
useProduct.ts
GraphQL文件
<model>.ts
(lcfirst)
product.ts
单模型对应的TF文件
<model>.tf
(lcfirst)
product.tf
DynamoDB数据源
appsync_datasource_<modelLower>
appsync_datasource_product
DynamoDB表
dynamodb_<modelLower>s
dynamodb_products
查询索引
by<Field>
byUserId
字符串转换规则:
toScreamingSnake
按大写字母拆分,用
_
拼接后全部转为大写;
toPascal
将首字母大写;
lcfirst
将首字母小写。

Command 1: Init

命令1:初始化

Ask user for: project name, function prefix (PascalCase), AWS profile, AWS region (default:
ap-southeast-2
), S3 state bucket, DynamoDB lock table.
AWS Profile Selection: Parse
~/.aws/credentials
and
~/.aws/config
for profile names. Present numbered list. Allow "add new" via
aws configure --profile <name>
.
Read references/init-workflow.md for directory structure, template placeholders, static files, scripts, and package.json entries. Consult references/terraform-modules.md for all 18 reusable module signatures.
需要向用户询问以下信息:项目名称、函数前缀(PascalCase格式)、AWS配置文件、AWS区域(默认值:
ap-southeast-2
)、S3状态存储桶、DynamoDB锁表。
AWS配置文件选择:解析
~/.aws/credentials
~/.aws/config
中的配置文件名称,展示编号列表,允许用户通过
aws configure --profile <名称>
添加新配置。
阅读 references/init-workflow.md 了解目录结构、模板占位符、静态文件、脚本和package.json配置项。参考 references/terraform-modules.md 查看全部18个可复用模块的签名。

Command 2: GraphQL Resolver

命令2:GraphQL 解析器

Ask user for:
  1. Model name
    @model
    type from
    schema.graphql
    (PascalCase)
  2. Resolver type
    query
    or
    mutation
  3. Resolver name — camelCase (e.g.
    productById
    )
  4. Runtime
    APPSYNC_JS
    or
    LAMBDA
  5. DynamoDB operation (APPSYNC_JS only) —
    GetItem
    ,
    Query
    ,
    PutItem
    ,
    UpdateItem
    ,
    Scan
    ,
    BatchDeleteItem
  6. Fields — model fields as arguments + optional extras (
    payload: AWSJSON
    ,
    filter: AWSJSON
    ,
    limit: Int
    ,
    nextToken: String
    )
Read references/resolver-workflow.md for all generation templates: schema injection, GraphQL constant, Terraform modules (APPSYNC_JS and LAMBDA), dependency modules, AppSync JS functions, Lambda source, and composable generation.
需要向用户询问以下信息:
  1. 模型名称
    schema.graphql
    中的
    @model
    类型(PascalCase格式)
  2. 解析器类型
    query
    mutation
  3. 解析器名称 — camelCase格式(例如
    productById
  4. 运行时
    APPSYNC_JS
    LAMBDA
  5. DynamoDB操作(仅APPSYNC_JS运行时需要) —
    GetItem
    Query
    PutItem
    UpdateItem
    Scan
    BatchDeleteItem
  6. 字段 — 作为参数的模型字段 + 可选额外字段(
    payload: AWSJSON
    filter: AWSJSON
    limit: Int
    nextToken: String
阅读 references/resolver-workflow.md 了解所有生成模板:schema注入、GraphQL常量、Terraform模块(APPSYNC_JS和LAMBDA两种)、依赖模块、AppSync JS函数、Lambda源码、可组合函数生成。

Command 3: Lambda Function

命令3:Lambda 函数

Ask user for:
  1. Name — PascalCase suffix (e.g.
    RedeemNow
    )
  2. Type
    standard
    or
    cron
  3. Schedule (cron only) — EventBridge expression (e.g.
    rate(5 minutes)
    )
Read references/lambda-workflow.md for Lambda source files, TF module block, cron resources, and dependency checks.
需要向用户询问以下信息:
  1. 名称 — PascalCase格式的后缀(例如
    RedeemNow
  2. 类型
    standard
    cron
  3. 调度规则(仅cron类型需要) — EventBridge表达式(例如
    rate(5 minutes)
阅读 references/lambda-workflow.md 了解Lambda源文件、TF模块块、cron资源和依赖检查规则。

Rules

规则

Idempotency — never overwrite existing files during init. Skip if TF module, schema field, GraphQL constant, composable function, or Lambda source already exists. When appending, trim trailing whitespace and add newline before new content.
Pre-generation checklist:
  • Read
    terraform-scaffold.config.ts
    for
    functionPrefix
  • Read
    schema.graphql
    for existing models and fields
  • Check TF files, graphql/ files, and composables for duplicates
  • Follow exact naming conventions from the table above
  • Verify module dependencies exist; generate if missing (see resolver-workflow.md dependency modules section)
Post-generation validation: Run
terraform fmt
on modified
.tf
files, then
terraform validate
. If providers not initialized, skip and inform user to run
terraform init
first.
幂等性 — 初始化过程中永远不要覆盖已有文件。如果TF模块、schema字段、GraphQL常量、可组合函数或Lambda源码已存在则跳过。追加内容时,修剪尾部空白,在新内容前添加换行符。
生成前检查清单
  • 读取
    terraform-scaffold.config.ts
    获取
    functionPrefix
  • 读取
    schema.graphql
    获取现有模型和字段
  • 检查TF文件、graphql/目录下文件、可组合函数是否有重复
  • 严格遵守上表中的命名约定
  • 验证模块依赖是否存在,缺失则生成(参考resolver-workflow.md的依赖模块章节)
生成后校验:对修改过的
.tf
文件执行
terraform fmt
,然后执行
terraform validate
。如果provider未初始化,跳过校验并告知用户先运行
terraform init