Enable Tencent Cloud Serverless Support via a Terraform-like Engine in ServerlessInsight
Summary
This Epic proposes extending ServerlessInsight with a Terraform-like infrastructure engine to enable first-class support for Tencent Cloud serverless resources, while laying a solid foundation for multi-cloud, stateful, and repeatable Infrastructure-as-Code (IaC) workflows.
The goal is not only to add a Tencent Cloud provider, but to introduce core IaC capabilities—state, plan, and deterministic apply—so ServerlessInsight can safely manage serverless infrastructure across providers (Aliyun today, Tencent Cloud next, others later).
Architecture
Problem Statement
Currently, ServerlessInsight:
- Supports declarative YAML-based infrastructure definitions
- Can deploy serverless resources via
si deploy
- Has an initial provider implementation for Aliyun (based on ROS)
However, it does not:
- Track deployed infrastructure state
- Detect drift between desired and actual resources
- Provide a preview (
plan) before applying changes
- Support Tencent Cloud (SCF, API Gateway, COS) as a backend provider
As a result:
- Users cannot safely manage the full lifecycle of serverless infrastructure on Tencent Cloud
- Multi-cloud workflows lack consistency and predictability
- Re-running deployments risks unintended changes
Proposed Solution
Introduce a Terraform-like engine inside ServerlessInsight and use it to implement Tencent Cloud serverless support.
This engine will:
- Parse declarative YAML (existing capability - refer parser)
- Track deployed infrastructure using a state store
- Compute diffs between desired and actual infrastructure (plan)
- Apply changes in correct dependency order (reuse
si deploy)
- Enable idempotent create / update / delete workflows
- Remain backward-compatible with existing providers (e.g., Aliyun ROS)
Core Design Principles
- Declarative-first: YAML remains the source of truth
- Provider-agnostic: No provider-specific syntax leaks into YAML
- Stateful & safe: Always know what exists before changing it
- Incremental adoption: Reuse existing parser and deploy logic
- Extensible: Future Tencent Cloud resources (VPC, DB, MQ) fit naturally
Core Components
1. Configuration Parsing (Existing)
- Parse
serverlessinsight.yml
- Convert YAML into an internal resource model (functions, buckets, APIs, databases, etc.)
- Already implemented and reused as-is
2. Resource Representation (scfStack)
Define TypeScript abstractions for each resource type, such as:
functions
events(apigateway should under)
bucket
Each resource:
- Encapsulates its properties (runtime, memory, handler, bucket name, etc.)
- Implements lifecycle operations:
create()
read()
update()
delete()
import() (future)
refresh()
Tencent Cloud resources will be implemented using:
3. Dependency Graph
Build a dependency graph to ensure correct execution order.
Dependencies can be:
- Inferred from YAML references
- Example: API Gateway event referencing a function
- Explicit, via
dependsOn
This ensures:
- Functions exist before API Gateways
- Buckets exist before website configs
- Safe parallelism where possible
4. State Management (New)
Introduce a Terraform-like state store:
- Initial implementation: local JSON file
- Designed to support remote backends in the future
- Maps logical resources → physical cloud resource IDs
State responsibilities:
- Track created resources
- Enable drift detection
- Ensure idempotent operations
Before planning or applying, the engine should:
- Refresh state by querying cloud APIs
- Reconcile state with real-world infrastructure
5. Planning Phase (si diff) — New Command
Introduce a new command:
Responsibilities:
- Compare desired state (YAML) vs current state
- Produce a plan without making changes
The plan identifies:
- Resources to create
- Resources to update
- Resources to delete
Planning flow:
- Load existing state
- Refresh state from cloud
- Diff against YAML
- Produce an ordered execution plan
6. Apply / Execution (si deploy) — Reuse Existing Command
Reuse and enhance the existing si deploy command to:
- Consume the generated plan
- Apply actions in dependency order
- Call provider SDKs (Tencent Cloud, Aliyun, etc.)
- Persist state after each successful operation
Execution behavior:
- Create / update resources via provider SDK
- Delete obsolete resources
- Stop dependent operations on failure
- Leave partial state intact for recovery
7. State Updates
After apply:
- Persist updated state
- Ensure next
si diff starts from a correct baseline
- Enable drift detection on future runs
Tencent Cloud Support Scope
Initial Tencent Cloud resources:
- SCF (Serverless Cloud Functions)
- API Gateway
- COS (Cloud Object Storage)
YAML syntax:
- Follows ServerlessInsight’s existing provider-agnostic conventions
- Does not copy Terraform or serverless-framework syntax
- Supports variables, stages, and references
Example YAML (excerpt):
version: 0.0.1
provider:
name: tencent
region: cn-hangzhou
vars:
testv: testVarValue
handler: index.handler
stages:
default:
region: ${vars.region}
node_env: default
dev:
region: ${vars.region}
node_env: development
prod:
region: cn-shanghai
service: insight-poc-api
tags:
owner: geek-fun
functions:
insight_poc_fn:
name: insight-poc-api-fn
code:
runtime: nodejs18
handler: ${vars.handler}
path: tests/fixtures/artifacts/artifact.zip
memory: 512
timeout: 10
environment:
NODE_ENV: ${stages.node_env}
TEST_VAR: ${vars.testv}
TEST_VAR_EXTRA: abcds-${vars.testv}-andyou
events:
gateway_event:
type: API_GATEWAY
name: insight-poc-gateway
triggers:
- method: GET
path: /api/hello
backend: ${functions.insight_poc_fn}
domain:
domain_name: insight-api.serverlessinsight.com
buckets:
insight_poc_bucket:
name: insight-poc-bucket
website:
code: dist
index: index.html
error_page: 404.html
error_code: 404
Cross-Provider Compatibility
- Aliyun (ROS-based) remains unchanged
- Tencent Cloud uses the new stateful engine
- Engine abstracts differences between providers
- No breaking changes to existing users
Implementation Outline (TypeScript)
some coding style guidance:
- Tries to use functional programing style for TypeScript implementation,
- use less keywords
function, dfine function as const xxx = xxx or export const xxx = xxx
- use type, enum rather than interface as possible
- create index.ts for a module, manage the exports in index.ts so outeside module can import from index.ts rather than expose the file name inside module
Key modules:
parser — YAML parsing & validation
scfStack — CRUD lifecycle
dependencies — DAG construction
state — local JSON state (future backend support)
planner — diff & execution plan
executor — apply plan using si deploy
- CLI extensions:
Expected Outcomes
By implementing this Epic, ServerlessInsight gains:
- Terraform-like plan/apply safety
- First-class Tencent Cloud serverless support
- Drift detection & idempotent deployments
- A scalable foundation for multi-cloud expansion
- Improved reliability for multi-tenant environments
References
Enable Tencent Cloud Serverless Support via a Terraform-like Engine in ServerlessInsight
Summary
This Epic proposes extending ServerlessInsight with a Terraform-like infrastructure engine to enable first-class support for Tencent Cloud serverless resources, while laying a solid foundation for multi-cloud, stateful, and repeatable Infrastructure-as-Code (IaC) workflows.
The goal is not only to add a Tencent Cloud provider, but to introduce core IaC capabilities—state, plan, and deterministic apply—so ServerlessInsight can safely manage serverless infrastructure across providers (Aliyun today, Tencent Cloud next, others later).
Architecture
Problem Statement
Currently, ServerlessInsight:
si deployHowever, it does not:
plan) before applying changesAs a result:
Proposed Solution
Introduce a Terraform-like engine inside ServerlessInsight and use it to implement Tencent Cloud serverless support.
This engine will:
si deploy)Core Design Principles
Core Components
1. Configuration Parsing (Existing)
serverlessinsight.yml2. Resource Representation (
scfStack)Define TypeScript abstractions for each resource type, such as:
functionsevents(apigateway should under)bucketEach resource:
create()read()update()delete()import()(future)refresh()Tencent Cloud resources will be implemented using:
[tencentcloud-sdk-nodejs](https://github.com/TencentCloud/tencentcloud-sdk-nodejs)3. Dependency Graph
Build a dependency graph to ensure correct execution order.
Dependencies can be:
dependsOnThis ensures:
4. State Management (New)
Introduce a Terraform-like state store:
State responsibilities:
Before planning or applying, the engine should:
5. Planning Phase (
si diff) — New CommandIntroduce a new command:
Responsibilities:
The plan identifies:
Planning flow:
6. Apply / Execution (
si deploy) — Reuse Existing CommandReuse and enhance the existing
si deploycommand to:Execution behavior:
7. State Updates
After apply:
si diffstarts from a correct baselineTencent Cloud Support Scope
Initial Tencent Cloud resources:
YAML syntax:
Example YAML (excerpt):
Cross-Provider Compatibility
Implementation Outline (TypeScript)
some coding style guidance:
function, dfine function asconst xxx = xxxorexport const xxx = xxxKey modules:
parser— YAML parsing & validationscfStack— CRUD lifecycledependencies— DAG constructionstate— local JSON state (future backend support)planner— diff & execution planexecutor— apply plan usingsi deploysi plansi deployExpected Outcomes
By implementing this Epic, ServerlessInsight gains:
References
https://developer.hashicorp.com/terraform/internals/graph
https://developer.hashicorp.com/terraform/language/state
https://developer.hashicorp.com/terraform/cli/commands/plan
https://github.com/Serverlesstencent/serverless-cloud-framework