Loading...
Loading...
Use when the user wants Terraform HCL for Alibaba Cloud (Alicloud) infrastructure — new project or extending an existing one. Covers VPC, ECS, ApsaraDB RDS, OSS, SLB / ALB, Function Compute v3, ACK, and any other `alicloud_*` resource via the provider's own documentation fetched at generation time. For AWS → Alicloud migration or importing existing resources into state, use a different skill. Triggers: "write terraform for alicloud", "generate alibaba cloud terraform", "alicloud HCL", "create alibaba cloud vpc/ecs/rds", "生成阿里云 Terraform", "阿里云 HCL", "用 Terraform 部署阿里云", "alicloud provider", "aliyun/alicloud", "terraform-provider-alicloud".
npx skill4agent add aliyun/alibabacloud-aiops-skills alibabacloud-terraform-code-generationaliyun/alicloudconfig.jsonreferences/auth-and-network.mdALICLOUD_*ALIBABACLOUD_*ALIBABA_CLOUD_ACCESS_KEY_ID_ACCESS_KEY_SECRET_SECURITY_TOKENfmt: okvalidate: okplan: okterraform applyterraform applyplanapplyterraformregioncn-hangzhouresources[]{ alicloud_type, quantity, attributes }<target-dir>myshop-infra/fmtinitvalidate.tfmkdir -p <target-dir><target-dir>/outputs/ls -R <target-dir>| resource | depends on | AZ / placement |
|---|
resources[]alicloud_*references/alicloud-providers.mdReadgrepgrep "alicloud_<name>" references/alicloud-providers.md[doc](<url>)⚠️ 弃用 → ** → switch the plan to and re-lookup. NEVER emit the deprecated name. Common catch:→alicloud_<guess>references/resource-patterns.mdzone_id_slave_a# Quick check whether a relevant pattern exists, then Read only the section:
grep -in "<keyword>" references/resource-patterns.mddocwebsite/docs/r/website/docs/d/https://raw.githubusercontent.com/aliyun/terraform-provider-alicloud/master/website/docs/{r|d}/<doc_name>.html.markdownreferences/alicloud-providers.mddoc unreachable: used local catalogno example availablereferences/deprecated-fields.mdgrep '`alicloud_<resource>`' references/deprecated-fields.mdreferences/resource-patterns.mddatazone_iddata "alicloud_zones"available_resource_creationimage_iddata "alicloud_images"name_regexowners = "system"most_recent = trueinstance_typedata "alicloud_instance_types"cpu_core_countmemory_size*.tf*.tfterraform { required_providers {} }terraform {
required_version = ">= 1.5"
required_providers {
alicloud = {
source = "aliyun/alicloud"
version = "~> 1.274"
}
}
}aliyun/alicloud1.278.0~> 1.278https://registry.terraform.io/v1/providers/aliyun/alicloud/versionshttps://registry.terraform.io/providers/aliyun/alicloud/latesthttps://github.com/aliyun/terraform-provider-alicloud/releaseshttps://github.com/aliyun/terraform-provider-alicloud/tags~> 1.274~> 1.<minor>>= 1.x>= 1.239.0provider "alicloud" {}region = var.regionconfiguration_sourceprovider "alicloud" {
region = var.region
configuration_source = "AlibabaCloud-Agent-Skills/alibabacloud-terraform-code-generation"
}configuration_sourceregionvar.regionterraform.tfproviders.tfversions.tfmain.tf*.tf# 1. required_providers has aliyun/alicloud with a ~> 1.<minor> version
awk '
/required_providers[[:space:]]*{/ { in_req=1 }
in_req && /alicloud[[:space:]]*=[[:space:]]*{/ { in_ali=1 }
in_ali && /source[[:space:]]*=[[:space:]]*"aliyun\/alicloud"/ { source=1 }
in_ali && /version[[:space:]]*=[[:space:]]*"~>[[:space:]]*1\.[0-9]+"/ { version=1 }
in_ali && /^[[:space:]]*}/ { in_ali=0 }
END { exit(source && version ? 0 : 1) }
' <target-dir>/*.tf \
&& echo OK_VERSION || echo BAD_OR_MISSING_VERSION
# 2. configuration_source attribution present somewhere
grep -Rq 'configuration_source = "AlibabaCloud-Agent-Skills/alibabacloud-terraform-code-generation"' \
<target-dir>/*.tf \
&& echo OK_CFG_SOURCE || echo MISSING_CFG_SOURCE
# 3. region uses variable, not hardcoded
grep -Rq 'region\s*=\s*var\.region' <target-dir>/*.tf \
&& echo OK_REGION_VAR || echo HARDCODED_REGION=alicloud_vswitch.app_avsw1tagsManagedByProjectEnvironmentCreatedByterraformreferences/deprecated-fields.mdalicloud_ram_rolenamerole_namedocumentassume_role_policy_documentalicloud_security_groupnamesecurity_group_namealicloud_db_databasenamedata_base_namereferences/resource-patterns.mdalicloud_oss_bucket_aclprivate# Walk deprecated-fields.md row by row and check whether any deprecated
# field that applies to a generated resource is still in use.
# Uses awk to extract individual resource blocks before field matching,
# so that short field names (name, document) don't falsely match
# substrings in compound field names (role_name, policy_document).
grep '| `alicloud_' references/deprecated-fields.md | while IFS='|' read _ resource field kind _; do
resource=$(echo "$resource" | tr -d ' `')
field=$(echo "$field" | tr -d ' ')
kind=$(echo "$kind" | tr -d ' ')
# Only check if this resource exists in the generated HCL
if grep -Rq "resource \"$resource\"" <target-dir>/*.tf; then
case "$kind" in
rename|deprecated-no-replacement)
awk -v res="$resource" -v fld="$field" '
$0 ~ "resource \"" res "\"" { in_block=1; next }
in_block && /^}/ { in_block=0 }
in_block && $0 ~ "(^|[^_[:alnum:]])" fld "([^_[:alnum:]]|$)" { found=1; exit }
END { exit found ? 0 : 1 }
' <target-dir>/*.tf \
&& echo "DEPRECATED: $resource.$field" || echo "OK: $resource.$field"
;;
split|soft-split)
grep -q "\b$field\b\s*=" <target-dir>/*.tf \
&& echo "DEPRECATED: $resource.$field (inline — use standalone sub-resource)" \
|| echo "OK: $resource.$field (not inline)"
;;
esac
fi
doneDEPRECATED:DEPRECATED:references/deprecated-fields.mdOK:DEPRECATED:OK:terraform(cd <target-dir> \
&& terraform fmt -recursive \
&& terraform init -backend=false \
&& terraform validate -json)validate -jsonvalidate -jsondiagnostics[].summary[DEPRECATED]"document": "[DEPRECATED] … New field 'assume_role_policy_document' instead."cd <target-dir> && terraform validate -json[DEPRECATED]Validation: FAILED (<diagnostic excerpt>)initregistry.terraform.ioreferences/auth-and-network.mdValidation: SKIPPED (init failed — network/unreachable)~/.terraformrcterraformValidation: SKIPPED (terraform binary not on PATH)Files written:Validation:<bracketed>Files written:Validation:Files written:
<path/to/file1>
<path/to/file2>
...
Validation: <one-of-four-exact-strings-below>
Deprecation routing: <If re-routed: `<original_name>` → `<new_name>`; else: None>
<optional: architecture notes, design decisions, deploy hints — free-form
here is fine, but NOT inside the lines above>Validation:Validation: terraform fmt+validate: okValidation: SKIPPED (terraform binary not on PATH)Validation: SKIPPED (<reason>)Validation: FAILED (<diagnostic excerpt>)Validation: FAILED (init timed out — provider installation exceeded time limit)Validation: SKIPPED (init failed — network/unreachable)terraform planreferences/auth-and-network.md(
[[ -n "${ALIBABA_CLOUD_ACCESS_KEY_ID:-}" ]] && [[ -n "${ALIBABA_CLOUD_ACCESS_KEY_SECRET:-}" ]] && echo "ready:env-ak-sk"
[[ -f "$HOME/.aliyun/config.json" ]] && echo "ready:shared-config"
{ [[ -n "${ALIBABA_CLOUD_CREDENTIALS_FILE:-}" ]] && [[ -f "${ALIBABA_CLOUD_CREDENTIALS_FILE}" ]]; } && echo "ready:custom-credentials-file"
[[ -n "${ALIBABA_CLOUD_ECS_METADATA:-}" ]] && echo "ready:ecs-ram-role"
[[ -n "${ALIBABA_CLOUD_ROLE_ARN:-}" ]] && echo "ready:assume-role"
[[ -n "${ALIBABA_CLOUD_CREDENTIALS_URI:-}" ]] && echo "ready:sidecar"
) | head -1(cd <target-dir> && terraform init && terraform plan -out=tfplan)NO_CREDENTIALS~/.aliyun/config.jsonALIBABA_CLOUD_PROFILEreferences/auth-and-network.md| Source | When to read |
|---|---|
| Step 4.1 — resource existence, deprecation mark, doc URL |
| Provider doc (WebFetch of the URL from 4.1) | Step 4.2 — authoritative Required / Optional per resource |
| Step 5.1 — known field-level renames not flagged by |
| Step 5.1 — product-specific idioms not emphasized by the provider doc (RDS HA, …) |
| Step 6 failure branch — mirror-source config; Step 8 pre-flight — full credential chain |
alicloud_*[doc](<url>)⚠️ 弃用 → scripts/build_alicloud_providers.pyaliyun/alicloud