Skip to content

Disallow null resource identities #1193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Disallow null resource identities #1193

wants to merge 6 commits into from

Conversation

bbasata
Copy link
Contributor

@bbasata bbasata commented Jul 24, 2025

Related Issue

Fixes #1184. Depends on hashicorp/terraform-plugin-go#541.

Description

This pull request updates the ReadResource and ApplyResourceChange RPCs to return an error diagnostic on the Create, Read, and Update paths when a null resource identity would be returned for a resource that has an identity schema.

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 marked this pull request as ready for review July 28, 2025 17:52
@bbasata bbasata requested a review from a team as a code owner July 28, 2025 17:52
@@ -198,6 +198,17 @@ func (s *Server) ReadResource(ctx context.Context, req *ReadResourceRequest, res
}
}

if req.IdentitySchema != nil {
if resp.NewIdentity.Raw.IsFullyNull() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

💭 Thinking about whether or not we need to make an exception for readFollowingImport here. I think we still expect the provider to return a proper resource identity in order for the resource to be valid 🧐.

Copy link
Member

Choose a reason for hiding this comment

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

I think you're right. To repeat it back, I'd say what we're enforcing here is that if the provider indicates it supports identity (by providing a schema), it must be able to return said identity from a read, even if it was recently imported. Which sounds correct to me

readFollowingImport was introduced specifically to avoid validating the mutation of an identity due to the Terraform import methods using ReadResource with a stub state/identity. After the read is complete, the entire identity should be present or a diagnostic should be returned 👍🏻 . The same reason why we don't need an "updateFollowingImport", since the identity should be fully populated prior to that

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.

Code LGTM, as you mentioned, should probably point to the GH ref of terraform-plugin-go after that is merged.

Also looks like one of the corner resource's needs to be updated to actually set identity, a good catch! 👍🏻 (Also looks like there is an extra log statement in there 😆 )

@@ -198,6 +198,17 @@ func (s *Server) ReadResource(ctx context.Context, req *ReadResourceRequest, res
}
}

if req.IdentitySchema != nil {
if resp.NewIdentity.Raw.IsFullyNull() {
Copy link
Member

Choose a reason for hiding this comment

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

I think you're right. To repeat it back, I'd say what we're enforcing here is that if the provider indicates it supports identity (by providing a schema), it must be able to return said identity from a read, even if it was recently imported. Which sounds correct to me

readFollowingImport was introduced specifically to avoid validating the mutation of an identity due to the Terraform import methods using ReadResource with a stub state/identity. After the read is complete, the entire identity should be present or a diagnostic should be returned 👍🏻 . The same reason why we don't need an "updateFollowingImport", since the identity should be fully populated prior to that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Framework allows resource identities to be set to null, eventually triggering mutable identity error
2 participants