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 Extending Terraform documentation.
- Uses Context-Aware Import Function: The context-aware
StateContext
function should be used over the deprecatedState
function. - Supports Optional Project ID In Import Identifier: If the resource has multi-project support, there should be an optional
{project_id}:
prefix for the import identifier. If the user does not provide a project ID explicitly,client.Config.ProjectID
should be used to retrieve the implied project ID from the provider. The user may provide aproject_id
to the provider, otherwise the provider uses the authentication scope to determine the oldest accessible project. This prevents the user from needing to locate and provide their project ID for single-project organizations. - Uses Passthrough If Possible: If the import identifier can match the
id
of the resource, and this does not violate any other guidelines, theImportStatePassthroughContext
passthrough should be used. - Specifies Minimal Import Identifier: If more than one value needs to be specified in the import identifier, the minimal number of values should be used, and those values should be colon (
:
) separated. - Includes Import Documentation: There should be an import example at
examples/resources/<resource>/import.sh
, which will be used when generating the docs. The docs should then be regenerated usinggo generate
, which will update files in thedocs/
directory.