Skip to content
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

deferred actions: allow unknown foreach attributes within import blocks #35311

Merged
merged 2 commits into from
Jun 12, 2024

Conversation

liamcervante
Copy link
Member

This PR adds support for unknown for_each values within import blocks when deferred actions is enabled.

This can result in the to argument being essentially unknown. To combat this we parse the to argument as a partial resource, and defer all resources that it might refer to once the unknown values are resolved.

Any resources that are already in state and might be targeted by a partial to address are not deferred. The behaviour of the import block when targeting a resource already in state is simply a no-op. So, when the unknown to is eventually resolved and would point to a resource already in state it doesn't matter.

This builds on the work in the previous PR allowing unknown id values: #35300. The way we mark a resource as being deferred due to an import block is to simply mark the target ID value as being unknown.

@liamcervante liamcervante requested a review from a team June 7, 2024 15:16

var typeName, name string
switch tt := remain[0].(type) {
case hcl.TraverseRoot:
Copy link
Member

Choose a reason for hiding this comment

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

Above should ensure that this is a TraverseRoot, and would also panic with RootName() if it weren't.

Copy link
Member Author

Choose a reason for hiding this comment

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

For a resource, this would definitely be TraverseRoot here. But we can (in theory) also handle data sources here. For a data source, the TraverseRoot is the data part of the traversal, and we skipped over that above meaning we would be processing a TraverseAttr here.

We're not actually processing data sources in this function yet, as the only user is the import functionality which can't target data sources, but I think it's okay to still support both here.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks. Now I see a key point we need to address, managed resources and data resources shouldn't be handled that differently. A managed resource can be prefixed with resource. just like a data source is prefixed with data.. I just checked though and while reference parsing works, the target addr parsing code was never updated, but we should probably start taking this into account to clean things up though.

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'll put a follow up PR together that fixes this both here and in the target parsing function.

switch tt := remain[0].(type) {
case hcl.TraverseRoot:
typeName = tt.Name
case hcl.TraverseAttr:
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we could have a TraverseAttr here, since there is only one resource address following a module, and we turned that into a TraverseRoot

Copy link
Member Author

Choose a reason for hiding this comment

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

As in the other comment, for a data source this would be TraverseAttr as we consumed the TraverseRoot when processing the data entry.


var typeName, name string
switch tt := remain[0].(type) {
case hcl.TraverseRoot:
Copy link
Member

Choose a reason for hiding this comment

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

Thanks. Now I see a key point we need to address, managed resources and data resources shouldn't be handled that differently. A managed resource can be prefixed with resource. just like a data source is prefixed with data.. I just checked though and while reference parsing works, the target addr parsing code was never updated, but we should probably start taking this into account to clean things up though.

Base automatically changed from liamcervante/deferred-actions/unknown-import-id to main June 12, 2024 10:59
@liamcervante liamcervante force-pushed the liamcervante/deferred-actions/unknown-import-to branch from 60bf04c to 8fd3bfa Compare June 12, 2024 11:07
@liamcervante liamcervante merged commit 5172cb5 into main Jun 12, 2024
6 checks passed
@liamcervante liamcervante deleted the liamcervante/deferred-actions/unknown-import-to branch June 12, 2024 11:14
Copy link

Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch.

Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 13, 2024
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