Related Posting: TerraformAsset: support lazy / token value for path · Issue #3429 · hashicorp/terraform-cdk · GitHub
Here is info about our technical development environment :
• Microsoft Visual Studio 2022
• .NET 6.0
• C# 10
• HashiCorp.Cdktf 0.16.3
• HashiCorp.Cdktf.Providers.Aws 14.0.4
• HashiCorp.Cdktf.Providers.Docker 7.0.1
• Amazon.Lambda.Core 2.1.0
• Amazon.Lambda.Serialization.SystemTextJson 2.3.1
• Amazon.Lambda.APIGatewayEvents 2.6.0
The AWS Lambda project contains the following:
• Amazon.Lambda.Core 2.1.0
• Amazon.Lambda.Serialization.SystemTextJson 2.3.1
• Amazon.Lambda.APIGatewayEvents 2.6.0
In my Windows Powershell window, I’ve run the following commands:
$Env:TF_VAR_blahLambdaAssetDirPath =“C:\Blah\Lambda\bin\Debug\net6.0\”
cdktf synth
Please keep in mind that the following code is coded in C#
TerraformVariable blahLambdaAssetDirPath = new TerraformVariable(this, nameof(blahLambdaAssetDirPath), new TerraformVariableConfig { Type = "string", Default = "ami-abcde123", Description = "Blah Lambda Asset Directory Path", }); ITerraformAssetConfig assetConfig = new TerraformAssetConfig() { Path = blahLambdaAssetDirPath.StringValue , Type = AssetType.ARCHIVE }; TerraformAsset lambdaAsset = new TerraformAsset(this, "lambda-asset", assetConfig);
When I run the following from the Windows Powershell commandline:
cdktf synth
Using Visual Studio 2022 debug breakpoints, I noticed that the Path value will be set to the following:
Path = “${TfToken[TOKEN.3]}”
However, when the point of execution reaches the following line of code:
TerraformAsset lambdaAsset = new TerraformAsset(this, "lambda-asset", assetConfig);
, the following error is thrown:
System.Exception: ‘ENOENT: no such file or directory, stat ‘${TfToken[TOKEN.3]}’’
The problem is that the TerraformAsset constructor processes the Path as a AssetType of Archive which is problematic as the value is a Token when the point of execution reaches the aforementioned code.
What modifications to the aforementioned code do I have to make in order to make the TerraformAsset constructor to process the Path as a Token for now? (During execution like terraform apply, I will ensure that the relevant environment variables are set to the proper Directory paths)