terraform-cdk
terraform-cdk copied to clipboard
TerraformAsset: support lazy / token value for path
Description
Support lazy string values for the "path" option in TerraformAsset.
Today it's possible to provide a concrete string path to TerraformAsset, but if you provide a token string, you'll get an error like Error: ENOENT: no such file or directory, stat '${TfToken[TOKEN.0]}':
class MyStack extends TerraformStack {
constructor(scope: Construct, id: string) {
super(scope, id);
let lazyStr = Lazy.stringValue({ produce: () => path.join(__dirname, "setup.js") });
new TerraformAsset(this, "MyAsset1", {
path: path.join(__dirname, "main.js"), // ok
})
new TerraformAsset(this, "MyAsset2", {
path: lazyStr, // error!
})
}
}
I think supporting token values as shown in the example above should be straightforward to support since the implementation of TerraformAsset does not appear to use the path functionally (i.e. reading it, copying it, or zipping it) until the app is actually synthesized with _onSynthesize().
The value of the type option in TerraformAsset is currently inferred based on the file type, but a token string, we could simply throw an error requiring that the user specifies which kind it is in advance (or perhaps change onSynthesize to figure it out adhoc).
References
No response
Help Wanted
- [X] I'm interested in contributing a fix myself
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
I'd be okay with throwing an error if the type is not specified if a token is passed. Seems like a good trade-off to me.