Assets
In CDK for Terraform (CDKTF) v0.4+, asset constructs can manage assets for resources that need them, such as template_file, S3 bucket objects, or Lambda function archive files. You can use Terraform assets to move existing files or directories into your CDKTF application so that you can use them in resource definitions.
Assets are especially useful for:
- Copying over previously generated zip files with Lambda functions.
- Deploying static local files to S3.
Usage Example
Hands-on: Try the Deploy Multiple Lambda Functions with TypeScript tutorial. This tutorial guides you through using a
TerraformAsset
to archive a Lambda function, uploading the archive to an S3 bucket, then deploying the Lambda function.
The following example uses TerraformAsset
to upload the contents of the specified directory into an S3 Bucket. The TerraformAsset
is responsible for making sure the directory ends up in the correct output folder as a zip file that the S3BucketObject
can reference.
The stack output directory in cdktf.out
contains all of the assets that TerraformAsset
needs. This is important for workflows where you use synthesized configurations with Terraform directly. For example, you would only need to upload the contents of the stack output folder to HCP Terraform or Terraform Enterprise.
Paths
Assets support both absolute and relative paths. Relative paths are always considered to be relative to your project's cdktf.json
file.