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

Allow for templatefile recursion (up to 1024 depth default) #1250

Merged
merged 5 commits into from
Mar 11, 2024

Conversation

cam72cam
Copy link
Contributor

@cam72cam cam72cam commented Feb 12, 2024

This changes templatefile to track call depth when building templatefile functions. It works fine, even when nested inside other function calls.

As mentioned in #402, due to the lack of tail recursion it can be memory intensive during evaluation. In my opinion this is a reasonable trade off and the default max depth should prevent most OOM crashes during reasonable use.

Example:

main.tf 
locals {
        x = templatefile("rec.tmpl", {})
}

rec.tmpl 
${ base64encode(templatefile("other.tmpl", {})) }

other.tmpl 
${ templatefile("rec.tmpl", {}) }

image

With TF_LOG=debug
image

TODO:

  • Documentation changes to templatefile
  • Changelog entry

Resolves #402

Target Release

1.7.0

Copy link

Reminder for the PR assignee: If this is a user-visible change, please update the changelog as part of the PR.

@cam72cam cam72cam force-pushed the recursive_templatefile_implementation branch 2 times, most recently from 22e8e99 to 909a210 Compare February 28, 2024 16:39
@cam72cam cam72cam changed the title [DRAFT] Allow for templatefile recursion (up to 1024 depth) Allow for templatefile recursion (up to 1024 depth default) Feb 28, 2024
@cam72cam cam72cam marked this pull request as ready for review February 28, 2024 16:42
@cam72cam cam72cam requested a review from a team as a code owner February 28, 2024 16:42
internal/lang/funcs/filesystem.go Show resolved Hide resolved
internal/lang/funcs/filesystem.go Outdated Show resolved Hide resolved
cube2222
cube2222 previously approved these changes Mar 11, 2024
cube2222
cube2222 previously approved these changes Mar 11, 2024
cam72cam and others added 5 commits March 11, 2024 08:33
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Janos <86970079+janosdebugs@users.noreply.github.com>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
@cam72cam cam72cam merged commit b51396f into main Mar 11, 2024
8 checks passed
@cam72cam cam72cam deleted the recursive_templatefile_implementation branch March 11, 2024 14:00
IgnorantSapient pushed a commit to IgnorantSapient/opentofu that referenced this pull request Apr 1, 2024
…#1250)

Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Janos <86970079+janosdebugs@users.noreply.github.com>
Signed-off-by: Ashwin Annamalai <4549937+IgnorantSapient@users.noreply.github.com>
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.

Accept recursive calls to templatefile()
3 participants