关于
This skill helps developers migrate Terraform provider resources from Plugin SDKv2 to the Plugin Framework. It covers muxing both SDKs, schema mapping, handling behavioral differences, and verifying state compatibility. Use it when converting SDKv2 resources, setting up a muxed provider, or debugging migration-related plan and state errors.
快速安装
Claude Code
推荐npx skills add hashicorp/agent-skills -a claude-code/plugin add https://github.com/hashicorp/agent-skillsgit clone https://github.com/hashicorp/agent-skills.git ~/.claude/skills/provider-framework-migration在 Claude Code 中复制并粘贴此命令以安装该技能
技能文档
Migrating from Plugin SDKv2 to the Plugin Framework
The Plugin Framework is required for net-new resources and data sources; SDKv2 is maintenance-only. Migration is per-resource and incremental: a muxed provider serves SDKv2 and Framework implementations side by side, so you never need a big-bang rewrite. This skill covers the mux setup, the per-resource workflow, and the behavioral traps that turn a mechanical translation into a silent breaking change.
Reference (load when needed):
references/schema-mapping.md— the full SDKv2 → Framework translation table with code pairs
Official guide: Framework migration.
Decide Whether to Migrate at All
Migration has real risk and little user-visible payoff, so triage first:
- Do not migrate complex or heavily-used resources without a driving need (a Framework-only feature, a bug that SDKv2 cannot fix). The two SDKs differ behaviorally — most importantly around null versus zero values — and those differences surface as breaking changes for existing users. This is the standing policy in large providers like terraform-provider-aws.
- Simple resources migrate safely: flat schemas, no
DiffSuppressFunc, noCustomizeDiff, noStateFunc, no complex nested blocks. - New capabilities never require migrating old code — mux and write the new resource in the Framework alongside the old ones.
To tell what mode a provider is in, check go.mod: terraform-plugin-mux
present means it already serves both; only terraform-plugin-sdk/v2 means
SDKv2-only (mux setup is your first step); only
terraform-plugin-framework means the migration is done.
Step 1: Mux the Provider
Combine both plugin servers in main.go. Serving protocol version 6
requires upgrading the SDKv2 server with tf5to6server (protocol 6 needs
Terraform CLI >= 1.0; if you must support 0.12+, mux at protocol 5 with
tf6to5server/tf5muxserver instead — but the Framework provider then
cannot use protocol-6-only features like nested attributes):
package main
import (
"context"
"flag"
"log"
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server"
"github.com/hashicorp/terraform-plugin-mux/tf5to6server"
"github.com/hashicorp/terraform-plugin-mux/tf6muxserver"
"example.org/terraform-provider-examplecloud/internal/provider"
sdkprovider "example.org/terraform-provider-examplecloud/internal/sdkprovider"
)
func main() {
var debug bool
flag.BoolVar(&debug, "debug", false, "run with support for debuggers")
flag.Parse()
ctx := context.Background()
upgradedSDKServer, err := tf5to6server.UpgradeServer(
ctx,
sdkprovider.Provider().GRPCProvider,
)
if err != nil {
log.Fatal(err)
}
providers := []func() tfprotov6.ProviderServer{
providerserver.NewProtocol6(provider.New(version)()),
func() tfprotov6.ProviderServer { return upgradedSDKServer },
}
muxServer, err := tf6muxserver.NewMuxServer(ctx, providers...)
if err != nil {
log.Fatal(err)
}
var serveOpts []tf6server.ServeOpt
if debug {
serveOpts = append(serveOpts, tf6server.WithManagedDebug())
}
err = tf6server.Serve("registry.terraform.io/example/examplecloud",
muxServer.ProviderServer, serveOpts...)
if err != nil {
log.Fatal(err)
}
}
Mux requirements that bite in practice:
- Provider schemas must match exactly across both plugins — same provider-level attributes, same types, same descriptions. Keep one source of truth for the provider configuration and mirror it.
- Each resource and data source may exist in only one of the two plugins. Migration's final step is deleting the SDKv2 registration.
- If publishing to the Registry with protocol 6, set
"metadata": {"protocol_versions": ["6.0"]}interraform-registry-manifest.json.
Step 2: Baseline Before You Touch Anything
The migrated resource must be indistinguishable to users. Prove it with tests that exist before the migration:
- Ensure the resource has passing acceptance coverage:
_basicwith an import step (ImportStateVerify: true),_disappears, and per-attribute update tests. If coverage is missing, write it against the SDKv2 implementation first — these tests are the migration's acceptance criteria and must pass unchanged afterward. - Note behaviors tests don't capture: attribute defaults, what happens
when optional attributes are omitted (null vs
""/0/falseis about to matter), and anyDiffSuppressFunc/StateFuncnormalization.
Step 3: Port the Resource
Translate schema and CRUD using the mapping table in
references/schema-mapping.md. The rules that prevent breaking changes:
- Blocks stay blocks. An SDKv2
Elem: &schema.Resource{...}written asblock { ... }syntax in user configs must become a Framework Block (schema.ListNestedBlock/SetNestedBlock) — converting it to a nested attribute changes the HCL syntax users must write, which is a breaking change. Nested attributes are for new schema only. - Null is not zero. SDKv2
d.Get("name")returned""for unset; the Framework model gives youtypes.Stringthat distinguishes null, unknown, and"". Everywhere the old code checked== ""or relied onGetOk, decide explicitly what null means, and make sure you send the API the same thing SDKv2 sent (usually: omit the field when null). - Keep the
idattribute. Net-new Framework resources may omit a redundantid, but a migrated resource must keep its exact schema — removing or renaming attributes breaks existing state and configs. - State must round-trip. The Framework reads the state SDKv2 wrote. If
every attribute keeps its name and type, no state upgrade is needed. If
the old schema stored a value the new types package normalizes
differently, you need a
StateUpgrader— treat that as a signal the resource may be in the do-not-migrate bucket.
Step 4: Move the Registration
Register the resource in the Framework provider's Resources() and delete
it from the SDKv2 provider's ResourcesMap in the same commit — mux errors
on duplicates.
Step 5: Verify
- The pre-existing acceptance tests pass without modification —
especially
ImportStateVerify, which diffs imported state against stored state and catches most null-vs-zero regressions. - Add a state-compatibility step: apply a config with the last released
(SDKv2) provider version, then plan with the migrated build — the plan
must be empty. In
terraform-plugin-testingthis is a two-step test usingExternalProvidersfor the old version, thenProtoV6ProviderFactorieswithConfigPlanChecksasserting an empty plan. Theprovider-test-patternsskill (if available) documents the pattern. terraform planagainst a real pre-migration state file shows no diff.
Checklist
- Resource is simple enough to migrate (no complex diff customization), or there's a driving need
- Mux serves both plugins; provider-level schemas identical in both
- Acceptance tests existed before migration and pass unchanged after
- Blocks remained blocks; attribute names and types unchanged;
idkept - Null/omitted semantics preserved (API receives what SDKv2 sent)
- SDKv2 registration removed in the same change
- Empty-plan verified against state written by the previous release
- Changelog entry added, if the repo tracks release notes
Related Skills
Use the provider-resources skill (if available) for Framework CRUD,
finder, and waiter patterns in the ported code, and provider-test-patterns
for the regression and version-upgrade test patterns.
GitHub 仓库
常见问题
什么是 provider-framework-migration Skill?
provider-framework-migration 是一个 Claude Skill,作者为 hashicorp。Skill 将 Claude 按需加载的说明和资源打包,让 Claude 无需额外提示即可执行与 provider-framework-migration 相关的任务。
如何安装 provider-framework-migration?
使用本页的安装命令:将 provider-framework-migration 作为插件添加到 Claude Code,或将其仓库克隆到 skills 目录,然后重启 Claude 以加载该 Skill。
provider-framework-migration 属于哪个分类?
provider-framework-migration 属于测试分类。
provider-framework-migration 可以免费使用吗?
可以。provider-framework-migration 已收录在 AIMCP,可免费安装。
相关推荐技能
该Skill通过60+个学术基准测试(如MMLU、GSM8K等)评估大语言模型质量,适用于模型对比、学术研究及训练进度追踪。它支持HuggingFace、vLLM和API接口,被EleutherAI等行业领先机构广泛采用。开发者可通过简单命令行快速对模型进行多任务批量评估。
这个Claude Skill提供了关于Cloudflare Cron Triggers的完整知识库,用于通过cron表达式定时执行Workers。它支持配置周期性任务、维护作业和自动化工作流,并能处理常见的cron触发错误。开发者可以用它来设置定时任务、测试cron处理器,并集成Workflows和Green Compute功能。
该Skill为开发者提供了基于Playwright的本地Web应用测试工具集,支持自动化测试前端功能、调试UI行为、捕获屏幕截图和查看浏览器日志。它包含管理服务器生命周期的辅助脚本,可直接作为黑盒工具运行而无需阅读源码。适用于需要快速验证本地Web应用界面和交互功能的开发场景。
这个Skill用于开发分支完成后的集成决策,当代码实现完成且测试通过时,它会引导开发者选择合适的工作流。它首先验证测试状态,然后提供合并、创建PR或清理等结构化选项。核心价值在于确保代码质量的同时,标准化分支收尾流程。
