Skip to content

Commit

Permalink
creating zip manually
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuf239 committed Oct 1, 2024
1 parent bc9b169 commit 4d4f09f
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 12 deletions.
4 changes: 3 additions & 1 deletion packages/@winglang/sdk/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 13 additions & 8 deletions packages/@winglang/sdk/src/target-tf-aws/function.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { AssetType, Lazy, TerraformAsset } from "cdktf";
import { join } from "path";
import { Lazy } from "cdktf";
import { Construct } from "constructs";
import { ensureDirSync } from "fs-extra";
import { App } from "./app";
import { CloudwatchLogGroup } from "../.gen/providers/aws/cloudwatch-log-group";
import { IamRole } from "../.gen/providers/aws/iam-role";
Expand All @@ -26,6 +28,7 @@ import {
import { makeAwsLambdaHandler } from "../shared-aws/function-util";
import { IInflightHost, Resource } from "../std";
import { Duration } from "../std/duration";
import AdmZip from "adm-zip";

/**
* Function names are limited to 64 characters.
Expand Down Expand Up @@ -284,15 +287,17 @@ export class Function extends cloud.Function implements IAwsFunction {

const bundle = createBundle(this.entrypoint, externalLibraries);

// would prefer to create TerraformAsset in the constructor, but using a CDKTF token for
// the "path" argument isn't supported
const asset = new TerraformAsset(this, "Asset", {
path: bundle.directory,
type: AssetType.ARCHIVE,
});
// we used to use terraformAsset- but it can't handle file paths that contain spaces- so we create the bundle zip manually.
const zip = new AdmZip();
zip.addLocalFolder(bundle.directory);

const folderPath = join(App.of(this).outdir, "assets");
const filename = `${this.node.addr}.zip`;
ensureDirSync(folderPath);
zip.writeZip(join(folderPath, filename));

this.assetPath = join("assets", filename);
this.bundleHash = bundle.hash;
this.assetPath = asset.path;
}

/** @internal */
Expand Down
23 changes: 20 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/valid/folder with spaces/main.test.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bring cloud;

let bucket = new cloud.Bucket();

test "Bucket is empty" {
assert(bucket.list().length == 0);
}
81 changes: 81 additions & 0 deletions tests/valid/folder with spaces/main.test.w.tf-aws.snap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# `main.test.w.tf-aws.snap.md`

## main.tf.json

```json
{
"//": {
"metadata": {
"backend": "local",
"stackName": "root",
"version": "0.20.7"
},
"outputs": {
}
},
"provider": {
"aws": [
{
}
]
},
"resource": {
"aws_s3_bucket": {
"Bucket": {
"//": {
"metadata": {
"path": "root/Default/Default/Bucket/Default",
"uniqueId": "Bucket"
}
},
"bucket_prefix": "bucket-c88fdc5f-",
"force_destroy": false
}
},
"aws_s3_bucket_cors_configuration": {
"Bucket_CorsConfiguration-1357ca3a_A4CCA40A": {
"//": {
"metadata": {
"path": "root/Default/Default/Bucket/CorsConfiguration-1357ca3a",
"uniqueId": "Bucket_CorsConfiguration-1357ca3a_A4CCA40A"
}
},
"bucket": "${aws_s3_bucket.Bucket.id}",
"cors_rule": [
{
"allowed_headers": [
"*"
],
"allowed_methods": [
"GET",
"POST",
"PUT",
"DELETE",
"HEAD"
],
"allowed_origins": [
"*"
],
"expose_headers": [
],
"max_age_seconds": 0
}
]
}
}
},
"terraform": {
"backend": {
"local": {
"path": "./terraform.tfstate"
}
},
"required_providers": {
"aws": {
"source": "aws",
"version": "5.56.1"
}
}
}
}
```

0 comments on commit 4d4f09f

Please sign in to comment.