question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot use typescript template literals with terraform interpolation

See original GitHub issue

Community Note

  • Please vote on this issue by adding a πŸ‘ reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave β€œ+1” or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

cdktf & Language Versions

From my package.json

  "dependencies": {
    "@cdktf/provider-aws": "^9.0.3",
    "@cdktf/provider-kubernetes": "^2.0.3",
    "@eryldor/cidr": "^1.0.5",
    "cdktf": "^0.12.0",
    "cdktf-cli": "^0.12.0",
    "constructs": "^10.0.9",
    "ejs": "^3.1.6"
  },

Affected Resource(s)

None in particular. This seems like a problem with typescript + terraform interpolation + cdktf

Debug Output

Expected Behavior

I expect that I should be able to use typescript template literals

Actual Behavior

Typescript template literals are not being evaluated (or are incorrectly evaluated). I get the following errors (note that in the terminal output the second $ in each error is underlined):

[2022-07-29T10:22:38.612] [ERROR] default - β•·
β”‚ Error: Invalid character
β”‚
β”‚   on cdk.tf.json line 191, in data.tls_certificate.certificate:
β”‚  191:         "url": "${${aws_eks_cluster.eksCluster}.identity[0].oidc[0].issuer}"
β”‚
β”‚ This character is not used within the language.
goldsky-infra-dev  β•·
                   β”‚ Error: Invalid character
                   β”‚
                   β”‚   on cdk.tf.json line 191, in data.tls_certificate.certificate (certificate):
                   β”‚  191:         "url": "${${aws_eks_cluster.eksCluster (eksCluster)}.identity[0].oidc[0].issuer}"
                   β”‚
                   β”‚ This character is not used within the language.
                   β•΅

β ™  Processing
[2022-07-29T10:22:38.628] [ERROR] default - β•·
β”‚ Error: Invalid expression
β”‚
β”‚   on cdk.tf.json line 191, in data.tls_certificate.certificate:
β”‚  191:         "url": "${${aws_eks_cluster.eksCluster}.identity[0].oidc[0].issuer}"
β”‚
β”‚ Expected the start of an expression, but found an invalid expression token.
goldsky-infra-dev  β•·
                   β”‚ Error: Invalid expression
                   β”‚
                   β”‚   on cdk.tf.json line 191, in data.tls_certificate.certificate (certificate):
                   β”‚  191:         "url": "${${aws_eks_cluster.eksCluster (eksCluster)}.identity[0].oidc[0].issuer}"
                   β”‚
                   β”‚ Expected the start of an expression, but found an invalid expression token.

Steps to Reproduce

This is happening during an upgrade from cdktf of 0.8.6 to 0.12.0.

Here’s the code which is causing the above issue:

    const dataTlsCertificateCertificate = new tls.DataTlsCertificate(
      this,
      "certificate",
      {
        url: `\${${eksCluster.fqn}.identity[0].oidc[0].issuer}`,
      }
    );

where eksCluster is a resource of type aws.eks.EksCluster.

It seems that I cannot use a javascript template literal when using terraform interpolation. Ninja edit: it seems that other uses of template literals are working well though, maybe something else is going on?

I’m using cdktf and the above issue happens when I run:

  1. npx cdktf get
  2. tsc
  3. npx cdktf diff

Important Factoids

None that I can think of

References

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
DanielMSchmidtcommented, Aug 12, 2022

You can now express url: \${${eksCluster.fqn}.identity[0].oidc[0].issuer}, as url: eksCluster.identity.get(0).oidc.get(0).issuer

1reaction
ansgarmcommented, Aug 1, 2022

Hi @paymog πŸ‘‹ This seems to be related to https://github.com/hashicorp/terraform-cdk/issues/1641. However, it seems to be a different result as it seems to render aws_eks_cluster.eksCluster (eksCluster) which probably originates from somewhere else (some .toString() method probably). The workaround that Daniel Schmidt posted in that other issue should work for you as well.

edit: What I’m trying to say is: We need to investigate this one as well as it is not exactly the same as #1641

Read more comments on GitHub >

github_iconTop Results From Across the Web

Template literals should not be nested - SonarSource Rules
Template literals (previously named "template strings") are an elegant way to build a string without using the + operator to make strings concatenation...
Read more >
typescript asking for template literal - javascript - Stack Overflow
Starts and ends with a backtick. Supports multiline strings. Expressions are interpolated with ${expression}. Share.
Read more >
How can I solve the error message I am receiving in my below ...
I am getting the below error when i run terraform apply : Invalid template interpolation value. var.oidc_condition_statement is list ofΒ ...
Read more >
JSON Configuration Syntax | Terraform - HashiCorp Developer
When a JSON string is encountered in a location where arbitrary expressions are expected, its value is first parsed as a string template...
Read more >
Pains with Terraform (again) - Jakub Holy
F.ex. the default value of a variable cannot use another variable etc. Sometimes you just have to provide a literal value because Terraform...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found