Skip to content

Add support for identity attribute in import blocks (Terraform 1.12.0+) #471

@AdamTylerLynch

Description

@AdamTylerLynch

Terraform 1.12.0 introduced a new identity attribute for import blocks as an alternative to the traditional id attribute. This allows resources to be imported using a structured object of key-value pairs instead of a single ID string.

Current Behavior

The terraform-schema library currently only recognizes the id attribute for import blocks and treats identity as an unexpected attribute, resulting in validation errors:

Unexpected attribute: An attribute named "identity" is not expected here
Required attribute "id" not specified: An attribute named "id" is required here

Expected Behavior

The schema for import blocks should accept either id OR identity attributes (mutually exclusive), matching Terraform 1.12.0+ behavior.

Example

# Should be valid in Terraform 1.12.0+
import {
  to = aws_instance.example
  identity = {
    instance_id = "i-1234567890abcdef0"
    region      = "us-west-2"
  }
}

References

Impact

This affects all tools that rely on terraform-schema for validation, including:

  • terraform-ls (Terraform Language Server)
  • VS Code Terraform extension
  • Other IDE integrations

Proposed Solution

Update the import block schema to support both id and identity attributes as mutually exclusive options, with version constraints to ensure compatibility (identity only available for Terraform >= 1.12.0).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions