Nested tokens are not escaped when `Fn.format` is used on them
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
- NodeJS 16
- cdktf 0.10.1
Affected Resource(s)
Probably any, but I just tested with StringResource
from @cdktf/provider-random
Debug Output
debug output
yarn run v1.22.18
$ CDKTF_LOG_LEVEL=debug cdktf synth
[2022-04-04T17:41:21.284] [DEBUG] default - {
"terraform_version": "1.1.7",
"platform": "darwin_amd64",
"provider_selections": {},
"terraform_outdated": false
}
[2022-04-04T17:41:21.320] [DEBUG] default - v17.8.0
[2022-04-04T17:41:21.357] [DEBUG] default - Terraform v1.1.7
on darwin_amd64
Generated Terraform code for the stacks: stage
✨ Done in 8.33s.
Expected Behavior
Outputs should escape all tokens:
"output": {
"additional_output": {
"value": "${random_string.id.result}"
},
"direct_output": {
"value": "${random_string.id.result}"
},
"formatted_output": {
"value": "${format(\"%s\", random_string.id.result)}"
}
},
Actual Behavior
One token is not escaped (see line 3):
"output": {
"additional_output": {
"value": "random_string.id.result"
},
"direct_output": {
"value": "${random_string.id.result}"
},
"formatted_output": {
"value": "${format(\"%s\", random_string.id.result)}"
}
},
Steps to Reproduce
Here’s a snippet for typescript:
// @ts-ignore
import { Fn, TerraformOutput, TerraformStack } from 'cdktf';
import { Construct } from 'constructs';
import { RandomProvider, StringResource } from '@cdktf/provider-random';
export class MyStack extends TerraformStack {
constructor(scope: Construct, name: string) {
super(scope, name);
new RandomProvider(this, 'random');
const resource = new StringResource(this, 'id', { length: 1 });
const nested = { value: resource.result };
new TerraformOutput(this, 'direct_output', {
value: resource.result,
});
new TerraformOutput(this, 'additional_output', {
value: nested.value,
});
new TerraformOutput(this, 'formatted_output', {
// if you replace the Fn.format call with a static string, everything works
// value: 'static',
value: Fn.format('%s', [nested.value]),
});
}
}
If it is run as above, the additional_output
will not be escaped in the json output. Interestingly this happens only for the mapped/nested variable (i.e. the one that’s wrapped in an object). It probably has something to do with the new token handling since 0.9.0
, because the exact same code works with 0.8.*
. I hope I didn’t overlook something obvious when I attempted to upgrade our code to the newer version. Also, if the title doesn’t fit, please feel free to adjust it.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, you’re right! I missed the versions 😅 Weird that it worked in 0.8 for you… Maybe we introduced the issue in some patch version of 0.8 🤔 Nevertheless, I don’t think it makes sense to figure out why exactly that worked in 0.8 if it is broken in more recent versions as we already know why it’s broken 😄 (It has to do with how inner expressions are resolved and we have to find a good solution / refactor this quite a bit, but yeah, those are details)
I’m going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you’ve found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.