SuperAPI AI 工具集

provider-actions

部署与运维

查看项目

更新于 10-15 22:12

技能介绍

用途:该技能用于在 Terraform 提供程序中实现 Actions(实验性功能),在创建、更新、销毁等生命周期事件时执行命令式操作。

主要能力:新增首个 Action 时需实现 ProviderWithActions 的 Actions() 方法、在 Configure 中设置 ActionData、创建 ActionWithConfigure 基类型与 action-schema 辅助变体;定义 Action Schema(属性说明、ElementType、校验器、Optional/Computed);编写 Invoke 方法处理配置读取、进度上报 resp.SendProgress、超时与错误诊断 resp.Diagnostics.AddError、异步轮询;通过 action_trigger 生命周期块触发(事件有 before_create、after_create、before_update、after_update,1.14 暂不支持 before/after_destroy);使用 terraform_data 作为空操作触发器;用 Acceptance Test 和 PostApplyFunc 验证副作用;用 tfplugindocs 生成文档并写变更日志。

使用方式:在 internal/provider 下按 <action_name>action.go 与测试文件组织代码;HCL 中动作参数写入 config {} 块,触发引用 action. 前缀。测试命令:go test -c -o /dev/null ./internal/provider 与 TF_ACC=1 go test ./internal/provider -run TestAccExampleAction -timeout 60m。

适用场景与限制:面向 Terraform 提供程序开发者。Actions 为实验特性,生命周期事件支持有限,销毁前后事件暂不可用;其他功能、收费、平台等资料暂未提供。