sdk-to-pf-migration
Guides migration of Terraform resources from Plugin SDK to Plugin Framework. Use when migrating SDK resources to PF, planning SDK-to-PF migrations, or when the user asks to migrate a resource to the Plugin Framework.
Best use case
sdk-to-pf-migration is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Guides migration of Terraform resources from Plugin SDK to Plugin Framework. Use when migrating SDK resources to PF, planning SDK-to-PF migrations, or when the user asks to migrate a resource to the Plugin Framework.
Teams using sdk-to-pf-migration should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/sdk-to-pf-migration/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How sdk-to-pf-migration Compares
| Feature / Agent | sdk-to-pf-migration | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Guides migration of Terraform resources from Plugin SDK to Plugin Framework. Use when migrating SDK resources to PF, planning SDK-to-PF migrations, or when the user asks to migrate a resource to the Plugin Framework.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# SDK to Plugin Framework Migration
Migrate Terraform resources from `terraform-plugin-sdk/v2` to `terraform-plugin-framework` while preserving behavior and avoiding breaking changes.
## Prerequisites
- Provider uses mux: `provider/factory.go` combines SDK and PF via `tf6muxserver`. PF resources take precedence when both define the same type.
- Shared clients: `internal/clients/elasticsearch` (and analogous client packages) plus `internal/models` are used by both SDK and PF.
## Client Diag Strategy
**Migrate client code to return PF diags** — do not introduce a compatibility layer in the PF resource.
1. **Client layer**: Change resource-specific client functions (CRUD helpers the resource calls) to return `fwdiag.Diagnostics` instead of SDK `diag.Diagnostics`. Use `diagutil.CheckErrorFromFW()` for HTTP errors, `fwdiag.NewErrorDiagnostic()` or `diagutil.FrameworkDiagFromError()` for other errors.
2. **PF resource**: Call the client directly; append returned diags to `resp.Diagnostics` with no conversion.
3. **SDK callers** (if any remain): Update them to use `diagutil.SDKDiagsFromFramework()` when calling the migrated client.
## Migration Workflow
### 1. Migrate Client (if resource-specific)
If the resource has dedicated client functions, migrate them to return `fwdiag.Diagnostics`:
- Change return type from `sdkdiag.Diagnostics` to `fwdiag.Diagnostics`
- Use `diagutil.CheckErrorFromFW()` instead of `diagutil.CheckError()` for HTTP responses
- Use `fwdiag.NewErrorDiagnostic()` / `diagutil.FrameworkDiagFromError()` for errors
Update any SDK callers to use `diagutil.SDKDiagsFromFramework()` when calling these functions.
*(Example: ILM used `PutIlm` / `GetIlm` / `DeleteIlm` — same pattern applies to any named CRUD helpers.)*
### 2. Create PF Package
Create `internal/<domain>/<resource>/` (path mirrors where the SDK resource lived). Typical layout:
| File | Purpose |
|------|---------|
| `resource.go` | Resource struct, Metadata, Configure, ImportState |
| `schema.go` | PF schema including the appropriate connection block for the backend |
| `models.go` | Plan/State model types |
| `create.go` | Create |
| `read.go` | Read |
| `update.go` | Update |
| `delete.go` | Delete |
| `resource-description.md` | Embedded description |
**Schema**: Use the same connection block helpers as other PF resources in this provider (e.g. `providerschema.GetEsFWConnectionBlock(false)` for Elasticsearch-backed resources). Replicate the SDK schema exactly; preserve attribute names, types, and validation.
**Critical behaviors to preserve** (audit the SDK implementation for each):
- **Optional vs absent**: Flatten/expand rules where the API distinguishes “not set” from “set to empty or disabled” — e.g. ILM phase actions where `readonly` / `freeze` / `unfollow` use `enabled: false` when absent in config.
- **Version gating**: Attributes that are only valid for certain stack versions must still be rejected or handled the same way in PF.
- **JSON / structured attributes**: If the SDK used normalized JSON types to avoid perpetual diffs, keep that approach (e.g. `jsontypes.NormalizedType` or the project’s equivalent for metadata-like blobs).
- **API defaults**: When the API omits fields that Terraform previously surfaced with sentinel defaults, preserve that mapping (e.g. ILM’s `total_shards_per_node: -1` when `ES < 7.16`).
### 3. Provider Wiring
- **Update**: `provider/plugin_framework.go` — register `NewResource` in `resources()` following the existing registration pattern.
- **Remove**: `provider/provider.go` — remove the type from `ResourcesMap`.
### 4. Move Acceptance Tests
- Create `internal/<domain>/<resource>/acc_test.go` with package `<resource>_test`.
- Move test functions and helpers such as `checkResourceDestroy` from the old `*_test.go`.
- Move testdata: `testdata/TestAccResourceX*/` into the new package.
- Update imports (version constants, etc.).
- Delete the old `*_test.go`.
### 5. SDK Upgrade Test
Add `TestAccResourceXFromSDK` to verify existing SDK-created state works after upgrade:
```go
//go:embed testdata/TestAccResourceXFromSDK/create/resource.tf
var sdkCreateConfig string
func TestAccResourceXFromSDK(t *testing.T) {
name := sdkacctest.RandStringFromCharSet(10, sdkacctest.CharSetAlphaNum)
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"elasticstack": {
Source: "elastic/elasticstack",
VersionConstraint: "0.14.3", // last SDK version for this resource
},
},
Config: sdkCreateConfig,
ConfigVariables: config.Variables{"name": config.StringVariable(name)},
Check: resource.ComposeTestCheckFunc(...),
},
{
ProtoV6ProviderFactories: acctest.Providers,
ConfigDirectory: acctest.NamedTestCaseDirectory("create"),
ConfigVariables: config.Variables{"name": config.StringVariable(name)},
Check: resource.ComposeTestCheckFunc(...),
},
},
})
}
```
Use the **last provider version where the resource was still SDK-based** for `VersionConstraint`.
### 6. Remove Old SDK Resource
- Delete the SDK resource implementation file(s).
- Move or update shared descriptions if they were only referenced from the old location.
### 7. Schema Coverage
Run schema-coverage analysis. Add tests for:
- Attributes with no coverage
- Nested blocks or phases never exercised
- Import (add `TestAccResourceX_importState` if missing)
- Update coverage for optional attributes
## Reference Implementations
Use these PF migrations as patterns (complexity varies):
- **Security user**: `internal/elasticsearch/security/user/` — includes `TestAccResourceSecurityUserFromSDK`
- **ILM**: `internal/elasticsearch/index/ilm/` — large schema, version gating, JSON normalization
- **Data stream lifecycle**: `internal/elasticsearch/index/datastreamlifecycle/` — smaller surface area
## Verification
1. `make build`
2. `go test ./internal/<domain>/<resource>/... -v`
3. Acceptance tests: `go test ./internal/<domain>/<resource>/... -v -count=1 -run TestAcc`. Follow [testing](dev-docs/high-level/testing.md) for environment requirements.
4. **Downstream resources**: Run tests for any resource that references the migrated type (e.g. resources that attach to ILM policies reference `elasticstack_elasticsearch_index_lifecycle`).
## Breaking Changes
Avoid unless unavoidable. Preserve:
- Resource type name (e.g. `elasticstack_elasticsearch_index_lifecycle` for ILM)
- Attribute paths and types
- State/ID format (composite ID, import passthrough)Related Skills
schema-coverage
Analyzes a Terraform resource schema and compares it to attributes used in the acceptance test suite (configs + assertions). Produces a prioritized report of missing and poor coverage (set-only assertions, single-value coverage, missing unset/empty cases, missing update coverage). Use when the user asks about schema coverage, test coverage gaps, or improving Terraform acceptance tests for a resource.
requirements-verification
Analyzes an OpenSpec requirements spec for internal consistency, implementation compliance, and test opportunities; when a shell is available, run openspec validate first for structural checks. Use when reviewing specs, verifying implementation against requirements, or identifying test gaps.
openspec-verify-change
Verify implementation matches change artifacts. Use when the user wants to validate that implementation is complete, correct, and coherent before archiving.
openspec-sync-specs
Sync delta specs from a change to main specs. Use when the user wants to update main specs with changes from a delta spec, without archiving the change.
openspec-propose
Propose a new change with all artifacts generated in one step. Use when the user wants to quickly describe what they want to build and get a complete proposal with design, specs, and tasks ready for implementation.
openspec-new-change
Start a new OpenSpec change using the experimental artifact workflow. Use when the user wants to create a new feature, fix, or modification with a structured step-by-step approach.
openspec-implementation-loop
Orchestrates an end-to-end implementation loop for a single OpenSpec change: select a change, delegate implementation to a dedicated subagent, run review and verification subagents, feed findings back for fixes, push to origin, and watch GitHub Actions until the branch is green or blocked. Use when the user wants to implement an approved OpenSpec proposal/change with iterative review and CI feedback.
openspec-explore
Enter explore mode - a thinking partner for exploring ideas, investigating problems, and clarifying requirements. Use when the user wants to think through something before or during a change.
openspec-continue-change
Continue working on an OpenSpec change by creating the next artifact. Use when the user wants to progress their change, create the next artifact, or continue their workflow.
openspec-archive-change
Archive a completed change in the experimental workflow. Use when the user wants to finalize and archive a change after implementation is complete.
openspec-apply-change
Implement tasks from an OpenSpec change. Use when the user wants to start implementing, continue implementation, or work through tasks.
new-entity-requirements
Gathers initial requirements for a new Terraform resource or data source by examining API clients (go-elasticsearch, generated kbapi), Elastic API docs (Elastic docs MCP server and/or web), then interviewing the user for gaps. Produces an OpenSpec proposal (change with proposal, design, tasks, and delta specs)—not a hand-written spec under openspec/specs/ alone. Use when designing a new entity, drafting requirements from an API, or before implementing a new resource/data source.