Adding Resource Import Support#
Adding import support for Terraform resources will allow existing infrastructure to be managed within Terraform. This type of enhancement generally requires a small to moderate amount of code changes. Comprehensive code examples and information about resource import support can be found in the Terraform Plugin Framework documentation.
- Resource Code: In the resource code (e.g.,
internal/service/{service}/{thing}.go
),- Plugin Framework (Preferred) Implement the
ImportState
method on the resource struct. When possible, prefer using theresource.ImportStatePassthroughID
function. - Plugin SDK V2: Implement an
Importer
State
function. When possible, prefer usingschema.ImportStatePassthroughContext
.
- Plugin Framework (Preferred) Implement the
- Resource Acceptance Tests: In the resource acceptance tests (e.g.,
internal/service/{service}/{thing}_test.go
), implement one or more tests containing aTestStep
withImportState: true
. - Resource Documentation: In the resource documentation (e.g.,
website/docs/r/service_thing.html.markdown
), add anImport
section at the bottom of the page.