Skip to content

Evaluate list resources #37070

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 23 commits into
base: main
Choose a base branch
from
Open

Evaluate list resources #37070

wants to merge 23 commits into from

Conversation

dsa0x
Copy link
Member

@dsa0x dsa0x commented May 16, 2025

This PR implements the evaluation of list resources, then collects the results and stores them in the plan changes. It also

  • Added a new Query boolean parameter to PlanOpts to indicate when a plan is being generated for a query operation
  • Removed the dedicated walkQuery operation and integrated list resource execution into the standard walkPlan operation, but still being filtered out for now unless in query plan mode.
  • The implementation leverages the existing planning infrastructure but modifies it to specifically target list-mode resources when in query plan mode.
  • Added tests that verify various aspects of list resource operations, including validation, reference handling, state management, and errors.

Target Release

1.13.x

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

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@dsa0x dsa0x added the no-changelog-needed Add this to your PR if the change does not require a changelog entry label May 16, 2025
@dsa0x dsa0x force-pushed the sams/tfquery-execute branch from cf9cbde to 43ba8dd Compare May 16, 2025 06:39
@dsa0x dsa0x force-pushed the sams/tfquery-evaluation branch 4 times, most recently from c6a67de to 583b873 Compare May 16, 2025 19:45
@dsa0x dsa0x force-pushed the sams/tfquery-execute branch from 43ba8dd to afe811e Compare May 16, 2025 20:06
@dsa0x dsa0x force-pushed the sams/tfquery-evaluation branch from 583b873 to 1eba6dd Compare May 19, 2025 08:22
@dsa0x dsa0x force-pushed the sams/tfquery-execute branch from afe811e to 9e48802 Compare May 19, 2025 09:04
@dsa0x dsa0x force-pushed the sams/tfquery-execute branch from 9e48802 to 922d04c Compare May 20, 2025 14:20
Base automatically changed from sams/tfquery-evaluation to main May 20, 2025 17:45
@dsa0x dsa0x force-pushed the sams/tfquery-execute branch 3 times, most recently from 3816305 to 9da5b55 Compare May 20, 2025 17:57
@dsa0x dsa0x changed the base branch from main to dbanck/list-rpc May 20, 2025 17:57
@dbanck dbanck force-pushed the dbanck/list-rpc branch 5 times, most recently from 2e75a38 to 4465326 Compare May 21, 2025 16:07
@dsa0x dsa0x force-pushed the sams/tfquery-execute branch from f8b1551 to 593d752 Compare May 21, 2025 16:26
Before: cty.DynamicVal,
After: vals,
BeforeIdentity: cty.DynamicVal,
AfterIdentity: ids,
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if we should be overloading this for list or not. In fact I wonder if these should be combined into the list object that also contains the resource objects, that way they are directly paired and we can choose to expose those via configuration for import.

Change: plans.Change{
Action: plans.Read,
Before: cty.DynamicVal,
After: vals,
Copy link
Member

Choose a reason for hiding this comment

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

If we start evaluating this into normal configuration, I think we're going to want the vals to correspond to the same type as the list block object, rather than a tuple. That object could also give us a place to store the identities, which so have not been exposed in the configuration at all. This is why I mentioned that we need to complete the design of the configuration first, since the object type we use will follow that type.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we're going to want the vals to correspond to the same type as the list block object

I think what is being said here is to move the list block object construction from

func (d *evaluationStateData) wrapListResourceValues(ident, obj cty.Value) cty.Value {
ret := make([]cty.Value, 0)
objIter := obj.ElementIterator()
identIter := ident.ElementIterator()
for objIter.Next() && identIter.Next() {
objKey, objVal := objIter.Element()
identKey, identVal := identIter.Element()
if objKey.Equals(identKey).False() {
panic(fmt.Sprintf("List resource has mismatched keys %s and %s", objKey, identKey))
}
ret = append(ret, cty.ObjectVal(map[string]cty.Value{
"state": objVal,
"identity": identVal,
}))
}
return cty.ObjectVal(map[string]cty.Value{
"data": cty.TupleVal(ret),
})
}

and do that here instead. Based on my understanding, either way would be fine. Is there any reason why the plan changes requires the exact type of the list result?

@dsa0x dsa0x force-pushed the dbanck/list-rpc branch from 4038d33 to 2f3e0f1 Compare June 3, 2025 13:36
Base automatically changed from dbanck/list-rpc to main June 4, 2025 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog-needed Add this to your PR if the change does not require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants