Skip to content

Conversation

@bbasata
Copy link
Contributor

@bbasata bbasata commented May 28, 2025

Description

To merge after #1151. This pull request adds list resource metadata to the protocol-independent framework server implementation of GetProviderSchema.

For a focused start, I have defined list.Schema.StringAttribute and no other attribute types or block types. Then, the remaining schema definition can follow in another focused pull request.

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

None

@bbasata bbasata changed the base branch from main to add-list-to-fwserver May 28, 2025 21:20
@bbasata bbasata changed the title Add list to fwserver part ii fwserver: add list resources to GetProviderSchema May 28, 2025
@bbasata bbasata added this to the v1.16.0 milestone May 28, 2025
@bbasata bbasata force-pushed the add-list-to-fwserver-part-ii branch from da1aba6 to 83f0604 Compare May 28, 2025 21:49
@bbasata bbasata marked this pull request as ready for review May 28, 2025 22:33
@bbasata bbasata requested a review from a team as a code owner May 28, 2025 22:33
@bbasata bbasata mentioned this pull request May 29, 2025
1 task
@bbasata bbasata force-pushed the add-list-to-fwserver branch from c57458a to 586bdca Compare May 29, 2025 16:37
@bbasata bbasata force-pushed the add-list-to-fwserver-part-ii branch from 1da956e to 70aac24 Compare May 29, 2025 16:37
@bbasata bbasata force-pushed the add-list-to-fwserver branch from 586bdca to f971285 Compare May 29, 2025 17:01
@bbasata bbasata force-pushed the add-list-to-fwserver-part-ii branch from 70aac24 to d6776b3 Compare May 29, 2025 17:03
@bbasata bbasata force-pushed the add-list-to-fwserver branch from 485abb7 to 4dd9564 Compare May 30, 2025 21:00
@bbasata bbasata force-pushed the add-list-to-fwserver branch from 4dd9564 to 7a0dfb3 Compare June 2, 2025 14:42
@bbasata bbasata force-pushed the add-list-to-fwserver-part-ii branch 4 times, most recently from b30df31 to be455ea Compare June 3, 2025 19:20
@bbasata bbasata force-pushed the add-list-to-fwserver-part-ii branch from be455ea to 7691bb8 Compare June 3, 2025 19:33
Base automatically changed from add-list-to-fwserver to main June 4, 2025 14:37
austinvalle
austinvalle previously approved these changes Jun 4, 2025
Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

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

LGTM as a first go, left some considerations for future PRs

continue
}

if _, ok := s.resourceFuncs[typeName]; !ok {
Copy link
Member

Choose a reason for hiding this comment

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

Is s.resourceFuncs guaranteed to be populated at this point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In a roundabout way, yes. The fwserver implementations of GetMetadata and GetProviderSchema both call Server.ResourceFuncs to prime that cache before Server.ListResourceFuncs.

There's room for improvement.

Copy link
Contributor Author

@bbasata bbasata Jun 5, 2025

Choose a reason for hiding this comment

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

Maybe we change this to s.ResourceFuncs(ctx)[typeName] ...

// also validated.
func (s *Server) ListResourceSchemas(ctx context.Context) (map[string]fwschema.Schema, diag.Diagnostics) {
listResourceSchemas := make(map[string]fwschema.Schema)
listResourceFuncs, diags := s.ListResourceFuncs(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

This will give us the list resource implementations actually defined in ListResources(), but couldn't there also be implementations in Resources() as well? Potentially conflicting 👀

same thought for metadata

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My current thinking on this is: Framework only needs to look at ListResources().

If a provider type implements both resource.Resource and list.ListResource, then they add a NewMyResource function in two places: Resources() and ListResources().

Example: https://github.com/hashicorp/terraform-provider-corner/pull/358/files#diff-8e71dd37ab963ab4edd62bcbc12cc75b0d4cee4e084f515bf239385c4d16b7e2

There's room for improvement...

Path: path.Root(attributeName),
}

diags.Append(fwschema.IsReservedResourceAttributeName(req.Name, req.Path)...)
Copy link
Member

Choose a reason for hiding this comment

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

Just a reminder (since it's also relevant for state storage), we should double check if there are any additional fields that should be protect from shadowing that aren't the same as managed resources.

For example, state_store blocks will only need to ensure there is no provider attribute in the schema.

@bbasata bbasata requested a review from austinvalle June 5, 2025 13:23
Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@bbasata bbasata merged commit b0bfc20 into main Jun 5, 2025
35 checks passed
@bbasata bbasata deleted the add-list-to-fwserver-part-ii branch June 5, 2025 14:53
@bbasata bbasata mentioned this pull request Jun 13, 2025
1 task
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 5, 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.

2 participants