/alibabacloud-core:alibabacloud-terraform-code-generationfrom alibabacloud-core
Generates validated Terraform HCL for Alibaba Cloud (Alicloud) infrastructure from natural language requirements. Covers VPC, ECS, RDS, OSS, SLB/ALB, Function Compute, ACK, and other alicloud_* resources via IaCService MCP.
Ships in alibabacloud-core. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Turn natural-language Alibaba Cloud infrastructure requirements into validated
Terraform for the current aliyun/alicloud provider. Resource schema and
validation are resolved through IaCService via MCP; Terraform provider docs and
local reference files are used for HCL argument shape, examples, deprecations,
and product-specific guardrails.
NEVER read, print, ask for, or write AK/SK values anywhere — HCL, comments, env
declarations, shell output, logs. The provider reads credentials itself from
env, shared config, RAM role, OIDC/RRSA, sidecar, or static HCL. Do NOT
recommend deprecated ALICLOUD_* or ALIBABACLOUD_* env names; current names
are ALIBABA_CLOUD_ACCESS_KEY_ID, _ACCESS_KEY_SECRET, and _SECURITY_TOKEN.
Never report fmt: ok / validate: ok / plan: ok unless the corresponding
command actually executed AND returned that status. When a step is skipped
(tool missing, user opt-out), state "SKIPPED" (or "FAILED") with a
reason. Paraphrasing real output is fine; fabricating it is not.
Never run terraform apply. Run terraform plan only when the user asks.
Validation uses IaCService MCP when available, otherwise local
terraform fmt/init/validate when the binary exists. Never claim validation
passed unless that exact path ran successfully.
alibabacloud-core MCP server for IaCService API calls. Tool names may be
namespace-prefixed by the host client; select the tool whose name ends with
AlibabaCloud___CallCLI or is documented by the installed plugin as CallCLI.
Do NOT call local aliyun or helper scripts for IaCService when that MCP tool
is available.--endpoint iac.cn-zhangjiakou.aliyuncs.com
for all IaCService commands. Do NOT derive endpoints from region.Extract:
region — default cn-hangzhou.resources[] — { alicloud_type, quantity, attributes }.If ambiguous (e.g. "搭个数据库"), ask at most one clarifying question.
Extract <target-dir> from the user's request (explicit path like
myshop-infra/ or current working directory if unspecified). All subsequent
file writes and static HCL checks operate in this directory. Remote validation
submits the files from this directory through MCP/IaCService.
Before writing any .tf file, MUST create the directory:
mkdir -p <target-dir>
All file writes MUST prefix paths with <target-dir>/ — never write to
the current working directory directly, never write to a generic outputs/
parent. After generation completes, verify the structure:
ls -R <target-dir>
Before any HCL, sketch a dependency table — one row per resource:
| resource | depends on | AZ / placement |
|---|
resources[] with implied infra (VPC → VSwitch → SecurityGroup
→ workload); user parse often skips these.For every distinct alicloud_* type from Step 3 (resources and data
sources), execute 4.1 → 4.2 → 4.3. Before running any lookup, build a
task-local lookup cache:
types[] — de-duplicated final resource/data-source names from Step 3.catalog[type] — local catalog row and provider doc URL.product[type] — IaCService product when it can be determined from
IaCService metadata or resource naming.resource_type[type] — IaCService schema response or failure.example[type] — selected IaCService example code, only when useful.provider_doc[type] — GetProviderDocument result or fallback doc, only when needed.Never repeat the same IaCService call, catalog grep, pattern lookup, or provider
doc fetch for the same key. Run independent lookups in parallel: list-products,
catalog grep, pattern grep; then parallelize per-type get-resource-type.
Run the live MCP metadata lookup and local targeted lookups before writing HCL. Optimize for one pass over each unique key:
(a) IaCService metadata via MCP — when a CallCLI-compatible MCP tool is
exposed in the session, you MUST attempt live metadata lookup. In most clients
the tool name ends with AlibabaCloud___CallCLI, but it may include a plugin or
server namespace prefix. Do NOT silently skip this step. Do NOT run these
commands in a local shell.
Use this de-duplicated call plan:
list-products once per generation task.get-resource-type once per final distinct alicloud_* type after
deprecation routing; this is mandatory when CallCLI is available.list-resource-types only when product/resource type cannot be inferred.aliyun iacservice list-products --endpoint iac.cn-zhangjiakou.aliyuncs.com
aliyun iacservice get-resource-type --resource-type alicloud_<name> --endpoint iac.cn-zhangjiakou.aliyuncs.com
# Conditional only:
aliyun iacservice list-resource-types --product <Product> --endpoint iac.cn-zhangjiakou.aliyuncs.com
aliyun iacservice list-resource-type-examples --resource-type alicloud_<name> --endpoint iac.cn-zhangjiakou.aliyuncs.com
aliyun iacservice get-resource-type-example --example-id <exampleId> --endpoint iac.cn-zhangjiakou.aliyuncs.com
Use metadata for product/resource availability, required attributes, enum values, defaults, sensitivity, ForceNew, and Computed constraints when present. For every distinct type, record one of these metadata statuses for Step 4.3 and Step 7:
ok — include the product/resource type and the schema source returned by
IaCService.failed — include the attempted command/API and the concise failure reason;
continue with provider docs plus the local catalog.skipped — only allowed when no CallCLI-compatible MCP tool is exposed in
the current session; include that exact reason.Never report metadata constraints: SKIPPED if a CallCLI-compatible MCP tool
was available but you did not try the IaCService command. That is a workflow
failure; go back and run the metadata lookup. If a CallCLI invocation fails,
record the failure as evidence and continue with provider docs plus the local
catalog; do not simulate API results.
Two local lookups; run them concurrently with the live metadata lookup:
(b) Catalog lookup — use the local generated catalog as a stale-tolerant
cache for common data source names plus deprecated resource/data-source routing
and doc URL fallback. Normal supported resources and non-common data sources are
intentionally omitted; IaCService metadata is authoritative for resource
availability. The catalog (references/alicloud-providers.md) is a compact
index; do NOT Read it whole. Use exact table-row grep per requested type;
avoid substring patterns such as alicloud_(vpc|instance) because they
overmatch:
for type in alicloud_vpc alicloud_vswitch alicloud_instance; do
grep -E '^\| (resource|data source) \| `'"$type"'` \|' references/alicloud-providers.md
done
If a single type or routed replacement needs a follow-up:
grep -E '^\| (resource|data source) \| `alicloud_<name>` \|' references/alicloud-providers.md
Three outcomes:
[doc](<url>) from the row and proceed to 4.2.DEPRECATED -> <new_name> → switch the plan to
<new_name> and re-lookup. NEVER emit the deprecated name. Common catch:
alicloud_fc_function → alicloud_fcv3_function.DEPRECATED without replacement → stop and ask for a
supported alternative; do not emit the deprecated resource/data source.get-resource-type succeeded → continue;
record normal resource omitted from catalog; IaCService metadata used.alicloud_<guess>.(c) Pattern lookup (conditional) — if the user's requirement matches a
product-specific idiom listed in references/resource-patterns.md (e.g.
RDS cross-AZ HA, OSS lifecycle noncurrent, VPC peering), read the
relevant section. These idioms are NOT in the provider doc's Required
list but are what the user actually wants (e.g. zone_id_slave_a for RDS
HA is optional per the doc but required for real cross-AZ placement).
Missing them produces "validates but silently wrong" output.
When a matching pattern section is found, ALL attributes listed in that section's "Required attributes" table MUST appear in the generated HCL — treat them as mandatory even if the provider doc marks them Optional.
# Quick check whether a relevant pattern exists, then Read only the section:
grep -inE "<keyword1>|<keyword2>" references/resource-patterns.md
Run one pattern grep for the user's product keywords, not one grep per resource, then cache any matching sections.
Do NOT fetch provider docs when IaCService metadata and selected official examples from 4.1 contain enough schema and usage shape for HCL generation. Provider doc fetch is not a default phase; running external documentation fetch on the fast path is a workflow failure.
Fetch provider docs only when metadata is unavailable/incomplete for the user's requirement, examples are absent/insufficient, Step 6 diagnostics cannot be fixed from metadata plus local references, or the user explicitly asks for docs.
When docs are needed, call IaCService get-provider-document through MCP first.
Use --endpoint iac.cn-zhangjiakou.aliyuncs.com, call once per distinct type,
and cache provider_doc[type].
If get-provider-document fails, fall back to the catalog GitHub URL/raw URL.
If all documentation channels fail, use the local catalog plus IaCService
metadata from 4.1 and prefix recitation with
doc unreachable: used metadata/local catalog.
Before writing HCL, emit a compact per-resource brief:
resource-patterns.md, if anymetadata constraints: SKIPPED (<reason>) / metadata constraints: FAILED (<reason>)ok, failed, or skipped). If this line is missing, Step 4 is
incomplete and HCL generation must not start.not fetched (metadata sufficient) on the fast path, or
the provider doc/raw URL when 4.2 fetched documentation.If Required or Optional params are missing, return to 4.2. Skipping or using a partial recitation is a hard failure; metadata/doc failure uses local catalog fallback, not memory.
Use ONLY the params established in 4.3. If you need a param that wasn't in the recited brief, re-fetch 4.2 with a deeper read; do not guess. Use the fastest batch write method allowed by the host client (single batch edit, script, or heredoc); avoid serial per-file writes unless required.
Before writing a field, look up the resource in
references/deprecated-fields.md for local fix actions (see §5.5):
grep '`alicloud_<resource>`' references/deprecated-fields.md
If the user's requirement touches a product with a specific usage pattern
(e.g. RDS cross-AZ HA, VPC peering, OSS lifecycle), also consult
references/resource-patterns.md for the non-obvious attributes.
Resolve via data blocks, never literals. These also pass Step 4's gate:
zone_id → data "alicloud_zones" (filter by available_resource_creation).image_id → data "alicloud_images" (filter by name_regex, owners = "system", most_recent = true).instance_type → data "alicloud_instance_types" (filter by cpu_core_count, memory_size, AZ).zone_id, image_id, or ECS
instance_type variables. Resource arguments must reference the data source
result, not a hardcoded ID or a variable default.Generate variables.tf for all variable blocks; every generated var.*
MUST have type and description. Generate outputs.tf for useful non-sensitive
resource IDs, endpoints, and names. Terraform merges all *.tf equivalently.
HARD GATE: must pass before Step 6. The provider contract is mandatory, not
stylistic. Any missing block, open-ended provider version, hardcoded region, or
missing configuration_source must be fixed before validation.
Two Terraform blocks must appear somewhere in the project's *.tf
files. Terraform merges all *.tf in a directory, so file organization
is a style choice, not a contract — see "File organization" below.
Block 1 — terraform { required_providers {} }:
terraform {
required_version = ">= 1.5"
required_providers {
alicloud = {
source = "aliyun/alicloud"
version = "~> 1.280"
}
}
}
aliyun/alicloud 1.x
version through IaCService metadata when available, then write a pessimistic
minor constraint (1.278.0 -> ~> 1.278).
Lookup sources, in order:
aliyun iacservice list-terraform-provider-versions
if supported by the installed MCP/proxy version.~> 1.280 (last reviewed 2026-07-02).
Accepted form is ~> 1.<minor> or ~> 1.<minor>.<patch>
from a confirmed or conservative stable 1.x release. Do NOT write open-ended
constraints (>= 1.x, >= 1.239.0) or bare version strings.Block 2 — provider "alicloud" {} with BOTH region = var.region
and configuration_source:
provider "alicloud" {
region = var.region
configuration_source = "AlibabaCloud-Agent-Skills/alibabacloud-terraform-code-generation/<32hex>"
}
configuration_source is required. Resolve one session id per task: use
SKILL_SESSION_ID only if it is exactly 32 hex characters; otherwise generate
one 32-character lowercase hex value once. Replace <32hex> with the real id.region MUST reference var.region, not a hardcoded literal.File organization (recommended, not required): conventional split is
terraform.tf (Block 1) + providers.tf (Block 2). Also acceptable:
a single versions.tf containing both blocks, or either block at the
top of main.tf. Pick what fits the project — Terraform merges all
*.tf equivalently. Do NOT add a filename check; run the content check
below instead.
Post-generation verification: run scripts/static_checks.sh provider <target-dir>. All lines must return OK_*. If any fails, fix the offending
content and re-run. Do NOT proceed to Step 6 with BAD_OR_MISSING_VERSION,
MISSING_CFG_SOURCE, or HARDCODED_REGION. Do NOT claim provider verification
unless the script emitted OK_VERSION, OK_CFG_SOURCE, and OK_REGION_VAR.
= aligned within a block; snake_case semantic resource labels
(alicloud_vswitch.app_a, not vsw1).tags block for ops
hygiene — pick reasonable keys for the scenario (common choices:
ManagedBy, Project, Environment, CreatedBy). Skill does not
prescribe specific tag keys or values.Run before terraform is needed — this is a pure-grep pass on the HCL you
just wrote. IaCService/provider diagnostics decide whether a field is currently
deprecated; references/deprecated-fields.md is a compact fix-action map for
high-risk fields whose replacement is not always returned by IaCService. For
every generated resource, grep the project against it and handle each row-kind:
alicloud_ram_role: name → role_name,
document → assume_role_policy_documentalicloud_security_group: name → security_group_namealicloud_db_database: name → data_base_namereferences/resource-patterns.md says the
sub-resource has an explicit safe default. Example: for OSS buckets,
alicloud_oss_bucket_acl defaults to private, but logging/CORS/website
sub-resources are omitted unless the user asks for those features.Applies only to files written in this generation — do NOT refactor pre-existing user files you weren't asked to touch.
HARD GATE: must pass before Step 6 — run scripts/static_checks.sh deprecated <target-dir>. If it produces any DEPRECATED: line, fix using the
Action column in references/deprecated-fields.md, then re-run until every line
returns OK:.
Before the audit, explicitly grep each generated resource type in
references/deprecated-fields.md; any rename row means the old field name is
forbidden in generated HCL.
Do NOT proceed to Step 6 with any DEPRECATED: output. Do NOT claim
"verified" unless the script produces all OK:.
Prefer IaCService remote validation through the available CallCLI-compatible MCP
tool, usually the tool whose name ends with AlibabaCloud___CallCLI, with
aliyun iacservice validate-module; use endpoint
--endpoint iac.cn-zhangjiakou.aliyuncs.com. Related commands are
list-products, get-resource-type, get-provider-document,
list-terraform-provider-versions, and validate-module --source Upload.
For validate-module, preserve real newlines in --code and generate a fresh
UUID --client-token.
Remote validation limits: IaCService validates uploaded Terraform in a remote sandbox. Do NOT introduce dependencies that require local filesystem access or unregistered providers before this step:
file(), filebase64(),
templatefile(), fileset(), archive_file, or source = "./..." module
references. Inline small generated artifacts when needed, or omit artifact
packaging from remote validation and explain that boundary.hashicorp/archive in generated modules.
The validation environment is intended for the Alibaba Cloud provider path;
if another provider is unavoidable, report Validation: SKIPPED or
FAILED with the exact IaCService diagnostic instead of adding local-only
workarounds.file://, relative zip/code paths, or machine-local
directories) in arguments that IaCService must evaluate.If CallCLI is unavailable or fails before validation starts, fall back to local Terraform when present:
(cd <target-dir> && terraform fmt -recursive && terraform init -backend=false && terraform validate -json)
If terraform is not on PATH, report exactly:
Validation: SKIPPED (terraform binary not on PATH).
Loop up to 3 fix attempts for either validation path:
error.[DEPRECATED] strings.MANDATORY — runs regardless of generation outcome. The Files written:,
IaCService metadata:, Validation:, and Deprecation routing: labels are
the final contract; do not skip or rename them.
Coverage check. Enumerate resource blocks in the generated HCL and compare with Step 3's sketch. If any row is missing, return to Step 5, add it, then rerun Step 5 checks and Step 6; do not skip implicit resources.
Summary template — print in the user's language, using this structure:
Files written:
<path/to/file1>
<path/to/file2>
...
IaCService metadata: <ok | SKIPPED (CallCLI-compatible MCP tool not exposed) | FAILED (<reason>)>
Validation: <iacservice validate-module: ok | terraform fmt+validate: ok | SKIPPED (...) | FAILED (...)>
Deprecation routing: <If re-routed: `<original_name>` → `<new_name>`; else: None>
<optional architecture notes, design decisions, deploy hints>
Allowed Validation: values:
Validation: iacservice validate-module: okValidation: terraform fmt+validate: okValidation: SKIPPED (terraform binary not on PATH)Validation: SKIPPED (<reason>)Validation: FAILED (<diagnostic excerpt>)IaCService metadata: summarizes Step 4.1 only. Use ok only when every
generated resource/data source had successful metadata lookup; use
SKIPPED (CallCLI-compatible MCP tool not exposed) only when no CallCLI-style
MCP tool is available; otherwise use FAILED (<reason>).
After Step 7, stop. Do not run plan/apply. Do not expose orchestration phrases
such as "returning control", "handoff", or "upstream caller". If the user asks
to deploy, point to their normal Terraform workflow or
alibabacloud-spec-ops:alibabacloud-executing-plans.
| Source | When to read |
|---|---|
references/alicloud-providers.md (local) | Step 4.1 — resource existence, deprecation mark, doc URL |
| OSS provider doc mirror, then catalog GitHub/raw URL | Step 4.2 — fallback docs for HCL argument shape and examples |
references/deprecated-fields.md (local) | Step 5.1 + Step 5.5 — fix actions for high-risk deprecated fields |
references/resource-patterns.md (local) | Step 5.1 — product-specific idioms not emphasized by the provider doc (RDS HA, …) |
scripts/static_checks.sh | Step 5.3 + Step 5.5 — provider block and deprecated-field verification |
references/alicloud-providers.md (opens in a new tab)references/auth-and-network.md (opens in a new tab)references/deprecated-fields.md (opens in a new tab)references/resource-patterns.md (opens in a new tab)references/static-checks.md (opens in a new tab)scripts/build_alicloud_providers.py (opens in a new tab)scripts/build_deprecated_fields.py (opens in a new tab)scripts/iacservice.py (opens in a new tab)scripts/static_checks.sh (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
alibaba-cloud, alicloud, terraform-generator, iac, hcl-generation
10 skills in this plugin
/alibabacloud-cli-cost-estimationPre-execution cost estimation for Alibaba Cloud CLI operations. Use this skill whenever a user asks "how much will this cost", before executing any chargeable operation (create / resize / renew / bandwidth change), or when planning a multi-step workflow whose total cost should be known up front. Covers the --estimate-cost flag (quote without executing), --estimate-cost-context (usage assumptions and future-state overrides for multi-step workflows), reading the quote JSON correctly (pricingMode, pricingUnit, delta amounts), and reconciling quotes against actual bills.
/alibabacloud-cli-guidanceGuide for Alibaba Cloud CLI (aliyun) command syntax, plugin system, parameter naming, and best practices. Use this skill to generate correct CLI commands, understand plugin vs built-in command differences, structured parameter syntax, output filtering, pagination, and error troubleshooting. This skill is a CLI knowledge reference — when MCP tools (AlibabaCloud___CallCLI, etc.) are available, always prefer MCP tools for execution rather than running aliyun commands locally in the shell.
/alibabacloud-find-skillsUse this skill when users want to search, discover, browse, or find Alibaba Cloud (阿里云) agent skills. Triggers include: "find a skill for X", "search alicloud skills", "阿里云有什么 skill","阿里云", "搜索阿里云技能", "有没有管理 ECS/RDS/OSS 的 skill", "阿里云 skills 有哪些类目", "帮我找一个 skill", "browse alicloud skills", "list alicloud skill categories", "is there an alicloud skill that can...", "what alicloud skills are available", "XX Skill 的内容是什么", "我想了解阿里云 XX Skill 具体做什么","帮我安装阿里云 Skill","使用阿里云相关的skill", "阿里云 agent skill 市场", "搜一下阿里云的 skill", "建一个数据分析项目有没有相关 skill".
npx claudepluginhub aliyun/alibabacloud-agent-toolkit --plugin alibabacloud-coreOther plugins' skills for the same job