Stop the resource validate node transforming the original config #34026
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, the validate resource node merges the base resource connection with any connection defined within the provisioner block. It then applies that merged result back into the original config. The value returned by the merge function contains both of the supplied configs. In a single execution this doesn't particularly matter, but in the testing framework this causes severe problems as the original config is shared and reused by all the run blocks. The current behaviour essentially causes the size of the connection config to double every time, so with 20 or 30 or 40 run blocks we getting larger and larger wait times for the validate node to execute, and then all subsequent nodes that use the modified config.
This PR updates the validate node so that it doesn't copy the merged config back into the original config, but just uses the merged config directly. I think this change is okay, as there is nothing downstream that is relying on the config being merged by the validate node.
An alternative solution here would be to do this merge in the configs package as soon as the configs are read initially. I don't think this is a good idea, as we may want to be able to deal with the config exactly as the user defined it, and by merging early we hide the actual written config. A second approach would be to stop the testing framework sharing the same config between the run blocks. In terms of performance, I think the implemented solution is preferable as we'd have to write complex Copy() logic to make duplicates of the original config to be used within the run blocks, or even re-read the config from scratch for each run block. Overall, I think the implemented solution is just much simpler.
Metanote: I don't know if we have lots of hidden places where the config is being transformed within the Terraform graph that makes the chosen approach for the testing framework somewhat dangerous. If it turns out that we regularly transform the supplied config within the graph, then maybe revisiting the approach of copying or reloading the original configuration for each run block would be preferable.
Fixes #34009
Target Release
1.6.1
Draft CHANGELOG entry
BUG FIXES
terraform test
: Fix performance issues when usingprovisioners
within configs being tested.