Skip to content

Conversation

austinvalle
Copy link
Member

Related Issue

N/A

Description

This PR introduces new methods on schema.Resource that return the protocol v5 schema and identity schema. This can be useful for other Go modules that need the schema to decode/encode data for a managed resource. The logic is the same as what is returned from GetProviderSchema and GetResourceIdentitySchemas RPCs:

  • resp.ResourceSchemas[typ] = &tfprotov5.Schema{
    Version: int64(res.SchemaVersion),
    Block: convert.ConfigSchemaToProto(ctx, res.CoreConfigSchema()),
    }
  • if res.Identity != nil {
    idschema, err := res.CoreIdentitySchema()
    if err != nil {
    resp.Diagnostics = convert.AppendProtoDiag(ctx, resp.Diagnostics, fmt.Errorf("getting identity schema failed for resource '%s': %w", typ, err))
    return resp, nil
    }
    resp.IdentitySchemas[typ] = &tfprotov5.ResourceIdentitySchema{
    Version: res.Identity.Version,
    IdentityAttributes: convert.ConfigIdentitySchemaToProto(ctx, idschema),
    }
    }

Both methods return a function, which allows consuming Go modules to defer retrieving the schema until needed.

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

No

@austinvalle austinvalle requested a review from a team as a code owner August 7, 2025 22:07
Comment on lines -37 to -44
// these are global so if new tests are written we should probably employ a mutex
DescriptionKind = StringMarkdown
SchemaDescriptionBuilder = func(s *Schema) string {
if s.Required && s.Description != "" {
return fmt.Sprintf("**Required** %s", s.Description)
}
return s.Description
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically reducing the coverage of this test, but it's so specific that I don't think we're losing too much 😆

Copy link
Member

@stephybun stephybun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks reasonable to me, LGTM 🦒

Copy link
Contributor

@SBGoods SBGoods left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Great job documenting some of the SDK schema edge cases in the tests.

@austinvalle austinvalle merged commit d6f94a2 into main Aug 11, 2025
24 checks passed
@austinvalle austinvalle deleted the av/schema-method branch August 11, 2025 12:50
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 10, 2025
@austinvalle austinvalle added this to the v2.38.0 milestone Sep 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants