Skip to content

query: generate unique resource identifiers for results of expanded list resources#37681

Merged
dsa0x merged 4 commits intosams/validate-query-commandfrom
sams/query-genconfig-expanded-resource
Oct 1, 2025
Merged

query: generate unique resource identifiers for results of expanded list resources#37681
dsa0x merged 4 commits intosams/validate-query-commandfrom
sams/query-genconfig-expanded-resource

Conversation

@dsa0x
Copy link
Copy Markdown
Member

@dsa0x dsa0x commented Sep 26, 2025

This fixes a bug where duplicate resource addresses are generated for the results of each instance of an expanded list resource. While AbsResourceInstance is indeed unique, the uniqueness key is not a valid hcl identifier, so we are using the enum of the list resource instance as an additional key in the address name.

Target Release

1.15.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 force-pushed the sams/query-genconfig-expanded-resource branch 2 times, most recently from 8a16803 to 53a7fd4 Compare September 26, 2025 09:23
@dsa0x dsa0x force-pushed the sams/query-genconfig-expanded-resource branch from 53a7fd4 to f9e4d0d Compare September 26, 2025 09:34
@dsa0x dsa0x added no-changelog-needed Add this to your PR if the change does not require a changelog entry 1.14-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged and removed no-changelog-needed Add this to your PR if the change does not require a changelog entry labels Sep 26, 2025
@dsa0x dsa0x marked this pull request as ready for review September 26, 2025 10:14
@dsa0x dsa0x requested a review from a team as a code owner September 26, 2025 10:14
InstanceAddrs []addrs.AbsResourceInstance
}

func (t *ResourceCountTransformer) Transform(g *Graph) error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is leaning on some very old code that probably should have been refactored out (notice it only mentions count, as if there's no other possibility 😆) I wonder if there's another was to get a generated value here without having to hide it in the NodeAbstractResourceInstance.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The config generation abstraction for instances from a list resource is genconfig.ResourceListElement. Since config generation is the only place where this index value has meaning, perhaps we can insert it there while iterating over the list states?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh right 😄 . I think we could at least rename that to ResourceExpansionTransformer. From the call-sites, i believe it is used by both count and for_each.

// override is set by the graph itself, just before this node executes.
override *configs.Override

// expansionEnum tracks the index of the resource instance within the resource.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It doesn't really track the index, it only happens to coincide with the order that the expansion addresses were generated by the Expander (the fact they are even sorted isn't guaranteed, it's just there to make consistent tests easier)

Copy link
Copy Markdown
Member Author

@dsa0x dsa0x Sep 29, 2025

Choose a reason for hiding this comment

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

Yeah it really isnt the the index, but the enum. Having looked that the Expander closely, we could even get this value from it directly without having to store it with with NodeResourcePlanInstance.

On the note of sorting, even if the result of ExpandedResource is not guaranteed to be sorted, we can sort the addresses and get a valid enum ourselves. Right now, I have created a method that relies on ExpandedResource in 364f395, but if that method is not sorted, we can still sort the resource in the new method.

@dsa0x dsa0x force-pushed the sams/query-genconfig-expanded-resource branch from 4dc4eb1 to 364f395 Compare September 29, 2025 08:57
@dsa0x dsa0x requested a review from jbardin September 29, 2025 13:01
@dsa0x dsa0x merged commit f4bd337 into sams/validate-query-command Oct 1, 2025
7 checks passed
@dsa0x dsa0x deleted the sams/query-genconfig-expanded-resource branch October 1, 2025 08:46
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Nov 1, 2025

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 Nov 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

1.14-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants