Provider Framework Migration
HashiCorpOfficialPublished by HashiCorp
- Skill
- Workflow
- Cloud and DevOps
- MPL-2.0
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a structured, incremental workflow for migrating Terraform provider resources and data sources from the legacy Plugin SDKv2 to the modern Plugin Framework. It emphasizes a safe, per-resource migration strategy using provider muxing to allow both SDK versions to coexist. The guide covers the technical requirements for setting up a muxed server, mapping schemas and behaviors, handling critical null-versus-zero-value differences, and ensuring state compatibility to prevent breaking changes for end users.
What it does
- Provides a step-by-step procedure for muxing SDKv2 and Framework servers.
- Offers a comprehensive translation reference for schema types and resource behaviors.
- Defines criteria for determining which resources are safe to migrate.
- Details the verification process to ensure state and configuration compatibility.
- Highlights common pitfalls like null-versus-zero value handling and block-to-attribute mapping.
- Outlines the necessary testing patterns to validate migration success.
When to use it
- When you need to modernize a Terraform provider by migrating resources to the Plugin Framework.
- When you need to implement new features that require the Plugin Framework while maintaining existing resources.
- When you need to debug plan diffs or state errors that occur during or after a migration.
- When you are setting up a muxed provider to support incremental migration.
Advantages
- Enables incremental, low-risk migration without requiring a full rewrite.
- Maintains backward compatibility for existing user configurations and state.
- Provides clear guidance on avoiding breaking changes during translation.
- Includes a robust verification workflow to ensure the migrated resource is indistinguishable from the original.
Usage examples
- “How do I set up a muxed provider server to support both SDKv2 and Framework resources?”
- The skill provides a code template for main.go using tf5to6server and tf6muxserver to combine both plugin servers into a single provider binary.
- “What should I watch out for when mapping SDKv2 schemas to the Framework?”
- The skill warns about preserving block structures, keeping the id attribute, and handling null versus zero-value differences to avoid breaking user configurations.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/hashicorp/provider-framework-migration/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip provider-framework-migration.zip -d .agents/skills
Documentation by HashiCorp
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.
Files
- ATTRIBUTION.mdAdded by AutoGineer889 B
- LICENSELicence file added by AutoGineer16.3 KiB
- SKILL.md8.6 KiB
- references/schema-mapping.md6.1 KiB
references/schema-mapping.md
SDKv2 → Plugin Framework Translation Reference
Mechanical mappings for porting a resource. Every row preserves the user's configuration syntax and state layout — the invariant of a safe migration.
Schema: types
| SDKv2 | Framework |
|---|---|
Type: schema.TypeString | schema.StringAttribute |
Type: schema.TypeBool | schema.BoolAttribute |
Type: schema.TypeInt | schema.Int64Attribute |
Type: schema.TypeFloat | schema.Float64Attribute |
Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString} | schema.ListAttribute{ElementType: types.StringType} |
Type: schema.TypeSet, Elem: &schema.Schema{...} | schema.SetAttribute{ElementType: ...} |
Type: schema.TypeMap, Elem: &schema.Schema{...} | schema.MapAttribute{ElementType: ...} |
Type: schema.TypeList, Elem: &schema.Resource{...} (block syntax in configs) | schema.ListNestedBlock under Blocks: — not a nested attribute (attribute syntax would break existing configs) |
Type: schema.TypeSet, Elem: &schema.Resource{...} | schema.SetNestedBlock under Blocks: |
MaxItems: 1 block used as a pseudo-object | ListNestedBlock + listvalidator.SizeAtMost(1) for migrations; SingleNestedAttribute only for net-new schema |
Schema: behaviors
| SDKv2 | Framework |
|---|---|
Required: true / Optional: true / Computed: true | Same fields, same meanings |
ForceNew: true | PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()} |
Default: "foo" | Default: stringdefault.StaticString("foo") (from resource/schema/stringdefault; requires Computed: true alongside Optional) |
ValidateFunc / ValidateDiagFunc | Validators: []validator.String{...} (from terraform-plugin-framework-validators) |
ConflictsWith / ExactlyOneOf / AtLeastOneOf / RequiredWith | stringvalidator.ConflictsWith(path.Expressions...), ExactlyOneOf(...), AtLeastOneOf(...), AlsoRequires(...) |
Sensitive: true | Same field |
Deprecated: "..." | DeprecationMessage: "..." |
Description | Description / MarkdownDescription |
DiffSuppressFunc | No direct equivalent. Use a custom type with semantic equality (preferred; e.g. case-insensitive or JSON-normalized string types) or a plan modifier. If the suppression logic is intricate, reconsider migrating this resource |
StateFunc | No equivalent — normalize in Create/Read before setting state, or use a custom type |
CustomizeDiff | Resource-level plan modification: ResourceWithModifyPlan.ModifyPlan, or per-attribute plan modifiers |
Timeouts in schema | timeouts block via terraform-plugin-framework-timeouts; read with data.Timeouts.Create(ctx, defaultTimeout) |
Resource shape
| SDKv2 | Framework |
|---|---|
func resourceWidget() *schema.Resource returning struct of funcs | Struct implementing resource.Resource (+ ResourceWithConfigure, ResourceWithImportState) |
CreateWithoutTimeout: resourceWidgetCreate | func (r *widgetResource) Create(ctx, req resource.CreateRequest, resp *resource.CreateResponse) |
meta.(*Client) in every CRUD func | Client stored once by Configure(req.ProviderData) |
Importer: &schema.ResourceImporter{StateContext: schema.ImportStatePassthroughContext} | func (r *widgetResource) ImportState(...) calling resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) |
Registration in ResourcesMap: map[string]*schema.Resource | Constructor listed in the provider's Resources() []func() resource.Resource |
Data access inside CRUD
| SDKv2 | Framework |
|---|---|
d.Get("name").(string) | Typed model: data.Name.ValueString() after req.Plan.Get(ctx, &data) |
d.GetOk("name") | !data.Name.IsNull() — and decide unknown handling explicitly (IsUnknown()) |
d.Set("name", v) | Assign model field (data.Name = types.StringPointerValue(v)), then resp.State.Set(ctx, &data) |
d.SetId(id) | Set the id model field like any attribute |
d.SetId("") in Read (gone) | resp.State.RemoveResource(ctx) |
d.Id() | data.ID.ValueString() from req.State.Get |
d.HasChange("field") | Compare plan vs state models: !plan.Field.Equal(state.Field) |
d.IsNewResource() | Does not exist — Create simply is the new-resource path; post-create read-retry logic moves into Create |
diag.Diagnostics returns | resp.Diagnostics.AddError/AddWarning/Append |
The null/zero trap (the migration's main behavioral risk)
SDKv2 collapses "not set" into Go zero values: d.Get on an unset string
returns "", an unset int 0, an unset bool false. The Framework keeps
null, unknown, and zero distinct. Consequences:
// SDKv2 — unset and "" are the same thing:
if v, ok := d.GetOk("description"); ok {
input.Description = aws.String(v.(string))
}
// Framework — express the same "omit when not set" explicitly:
if !data.Description.IsNull() {
input.Description = data.Description.ValueStringPointer()
}Audit every attribute for three cases: user set a value, user set the zero
value ("", 0, false — SDKv2 could not tell this apart from unset;
users may depend on either interpretation), and user omitted it. The API
must receive exactly what the SDKv2 version sent in each case, or existing
configurations change behavior. ImportStateVerify and empty-plan upgrade
tests catch most, not all, of these — grep for GetOk and zero-value
comparisons and reason through each.
What does not change
retry.StateChangeConfwaiters andretry.NotFoundErrorfinders — thehelper/retrypackage works from Framework code; port them untouched.Acceptance tests —
terraform-plugin-testingruns against the muxed provider; existing tests must pass unchanged (switch factories toProtoV6ProviderFactoriesserving the muxed server).API client code, expand/flatten helpers operating on API types.
Tooling
Some providers script the first pass (terraform-provider-aws has an
internal tfsdk2fw scaffolder). No public tool produces a safe migration
end-to-end — treat any generated port as a draft to audit against this
reference, especially the null/zero table above.
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Published by
- HashiCorp
- Publisher
- HashiCorp (Official)
- Source
- hashicorp/agent-skills · plugins/terraform/skills/provider-framework-migration · commit 5e30fa5
- Licence
- Mozilla Public License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by HashiCorp or HashiCorp.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download provider-framework-migration.zip