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

Native Terraform/OpenTofu function templatestring() does not work in Terragrunt as a builtin function. #3242

Open
Jpk518 opened this issue Jul 4, 2024 · 5 comments
Assignees
Labels
bug Something isn't working terragrunt

Comments

@Jpk518
Copy link

Jpk518 commented Jul 4, 2024

Describe the bug

A new function templatestring() was added in Terraform 1.9 and Opentofu 1.7. This New function does not work when attempting to use in terragrunt as a built-in function https://terragrunt.gruntwork.io/docs/reference/built-in-functions/#terraform-built-in-functions, both when using the Terraform binary and the OpenTofu binary.

Steps To Reproduce

Define locals block that uses function templatestring().

example/terragrunt.hcl:

locals {
  template = "$${stage}-test"
  name = templatestring(local.template, { stage = "staging" } )
}

inputs = {
  name = local.name
}

example/main.tf:

variable "name" {}

resource "aws_sqs_queue" "example" {
  name  = var.name
}

Expected behavior

Here is the expected behaviour

$ terragrunt init

OpenTofu has been successfully initialized!

Here is the actual behaviour

$ terragrunt init

ERRO[0000]   on /.../example/terragrunt.hcl line 7, in locals: 
ERRO[0000]    7:   name     = templatestring(local.template, { stage = "staging" }) 
ERRO[0000]                                              
ERRO[0000] with                                         
ERRO[0000] local.template as "${stage}-test"  

ERRO[0000] There is no function named "templatestring".

Versions

  • Terragrunt version: v0.59.6
  • OpenTofu Version: v1.7.2
  • Terraform version: v1.9.2

Additional context

Function works properly when defined directly in .tf file using opentofu/terraform

example/main.tf:

locals {
  template = "$${stage}-test"
  name = templatestring(local.template, { stage = "staging" } )
}

resource "aws_sqs_queue" "test" {
  name = local.name
}
$ terragrunt init

OpenTofu has been successfully initialized!
@Jpk518 Jpk518 added the bug Something isn't working label Jul 4, 2024
@ZachGoldberg ZachGoldberg added the terragrunt label Jul 9, 2024 — with Linear
@levkohimins levkohimins self-assigned this Jul 9, 2024
@begemotik
Copy link

@levkohimins would be wonderful to get it supported in Terragrunt. Do you have an estimation?

@yhakbar
Copy link
Collaborator

yhakbar commented Oct 17, 2024

Hey @begemotik , this is a good request, but not a priority right now.

Could you provide any reasons why this should be prioritized higher? I imagine most folks needing this functionality would simply use run_cmd right now.

@Jpk518
Copy link
Author

Jpk518 commented Oct 17, 2024

Hey @begemotik , this is a good request, but not a priority right now.

Could you provide any reasons why this should be prioritized higher? I imagine most folks needing this functionality would simply use run_cmd right now.

Is it possible to update the documentation if going forward Terragrunt doesn't plan to support all built in Opentofu/Terraform functions. Can lead to a little confusion https://terragrunt.gruntwork.io/docs/reference/built-in-functions/#opentofuterraform-built-in-functions

@yhakbar
Copy link
Collaborator

yhakbar commented Oct 17, 2024

Is it possible to update the documentation if going forward Terragrunt doesn't plan to support all built in Opentofu/Terraform functions.

Sure thing, I can update that.

To be clear, we're not refusing to support this, we're just trying to prioritize effectively. If there's a use-case that requires this behavior, we can look at prioritizing it.

@begemotik
Copy link

Could you provide any reasons why this should be prioritized higher? I imagine most folks needing this functionality would simply use run_cmd right now.

We manage multiple ASGs within one TF state and need to be able to re-use one config template for different cases.
There is another case I can imagine with "generate" block and dynamic providers rendering.

We haven't tried run_cmd, I might be mistaken but it occurs to be that run_cmd would be hard to re-use across many states as it references local file.

run_cmd(command, arg1, arg2…​) runs a shell command and returns the stdout as the result of the interpolation. The command is executed at the same folder as the terragrunt.hcl file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working terragrunt
Projects
None yet
Development

No branches or pull requests

5 participants