Cannot use typescript template literals with terraform interpolation
See original GitHub issueCommunity 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:
npx cdktf get
tsc
npx cdktf diff
Important Factoids
None that I can think of
References
Issue Analytics
- State:
- Created a year ago
- Comments:11 (6 by maintainers)
You can now express
url: \${${eksCluster.fqn}.identity[0].oidc[0].issuer},
asurl: eksCluster.identity.get(0).oidc.get(0).issuer
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