Skip to content

Commit 2c27b86

Browse files
authored
fix(sdk): defer hash calculation of api spec to terraform (#3974)
Makes the code simpler and doesn't require to build keep two identical versions of the openapi spec ## Checklist - [ ] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [ ] Description explains motivation and solution - [ ] Tests added (always) - [ ] Docs updated (only required for features) - [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
1 parent 2b2aa81 commit 2c27b86

16 files changed

+37
-44
lines changed

libs/wingsdk/src/target-tf-aws/api.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createHash } from "crypto";
22
import { join } from "path";
33

4-
import { Lazy } from "cdktf/lib/tokens";
4+
import { Fn, Lazy } from "cdktf";
55
import { Construct } from "constructs";
66
import { App } from "./app";
77
import { Function } from "./function";
@@ -398,14 +398,7 @@ class WingRestApi extends Construct {
398398
},
399399
triggers: {
400400
// Trigger redeployment when the api spec changes
401-
redeployment: Lazy.stringValue({
402-
produce: () => {
403-
const value = createHash("sha1")
404-
.update(JSON.stringify(props.apiSpec))
405-
.digest("hex");
406-
return value;
407-
},
408-
}),
401+
redeployment: Fn.sha256(this.api.body),
409402
},
410403
});
411404

libs/wingsdk/test/target-tf-aws/__snapshots__/tokens.test.ts.snap

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ return class Handler {
1313
}
1414
};
1515
})())({
16-
str: JSON.parse(process.env[\\"WING_TOKEN_TFTOKEN_TOKEN_7\\"]),
17-
num: JSON.parse(process.env[\\"WING_TOKEN_8_109562212591386E_298\\"]),
18-
list: JSON.parse(process.env[\\"WING_TOKEN_TFTOKEN_TOKEN_9\\"])
16+
str: JSON.parse(process.env[\\"WING_TOKEN_TFTOKEN_TOKEN_8\\"]),
17+
num: JSON.parse(process.env[\\"WING_TOKEN_8_109562212591387E_298\\"]),
18+
list: JSON.parse(process.env[\\"WING_TOKEN_TFTOKEN_TOKEN_10\\"])
1919
})"
2020
`;
2121

@@ -39,7 +39,7 @@ exports[`captures tokens 2`] = `
3939
},
4040
"rest_api_id": "\${aws_api_gateway_rest_api.Api_api_91C07D84.id}",
4141
"triggers": {
42-
"redeployment": "5c0f11f0478884e3d7859fa987b8b7ecf8f2f6bc",
42+
"redeployment": "\${sha256(aws_api_gateway_rest_api.Api_api_91C07D84.body)}",
4343
},
4444
},
4545
},
@@ -81,9 +81,9 @@ exports[`captures tokens 2`] = `
8181
"environment": {
8282
"variables": {
8383
"WING_FUNCTION_NAME": "Api-OnRequest-c5395e41-c8f26cae",
84-
"WING_TOKEN_8_109562212591386E_298": "\${jsonencode(var.Number)}",
85-
"WING_TOKEN_TFTOKEN_TOKEN_7": "\${jsonencode(aws_api_gateway_stage.Api_api_stage_E0FA39D6.invoke_url)}",
86-
"WING_TOKEN_TFTOKEN_TOKEN_9": "\${jsonencode(var.List)}",
84+
"WING_TOKEN_8_109562212591387E_298": "\${jsonencode(var.Number)}",
85+
"WING_TOKEN_TFTOKEN_TOKEN_10": "\${jsonencode(var.List)}",
86+
"WING_TOKEN_TFTOKEN_TOKEN_8": "\${jsonencode(aws_api_gateway_stage.Api_api_stage_E0FA39D6.invoke_url)}",
8787
},
8888
},
8989
"function_name": "Api-OnRequest-c5395e41-c8f26cae",

tools/hangar/__snapshots__/test_corpus/sdk_tests/api/delete.w_compile_tf-aws.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ module.exports = function({ $api_url, $http_HttpMethod, $http_Util }) {
103103
},
104104
"rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}",
105105
"triggers": {
106-
"redeployment": "3f2ed3e388571f5b15cbc06ba1b47979abe75776"
106+
"redeployment": "${sha256(aws_api_gateway_rest_api.cloudApi_api_2B334D75.body)}"
107107
}
108108
}
109109
},
@@ -240,7 +240,7 @@ module.exports = function({ $api_url, $http_HttpMethod, $http_Util }) {
240240
"variables": {
241241
"WING_FUNCTION_NAME": "Handler-c897cd38",
242242
"WING_TARGET": "tf-aws",
243-
"WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
243+
"WING_TOKEN_TFTOKEN_TOKEN_8": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
244244
}
245245
},
246246
"function_name": "Handler-c897cd38",

tools/hangar/__snapshots__/test_corpus/sdk_tests/api/get.w_compile_tf-aws.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ module.exports = function({ $api_url, $body, $http_HttpMethod, $http_Util }) {
107107
},
108108
"rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}",
109109
"triggers": {
110-
"redeployment": "10bb301799b13187f97edf464edbfe465c48a11e"
110+
"redeployment": "${sha256(aws_api_gateway_rest_api.cloudApi_api_2B334D75.body)}"
111111
}
112112
}
113113
},
@@ -244,7 +244,7 @@ module.exports = function({ $api_url, $body, $http_HttpMethod, $http_Util }) {
244244
"variables": {
245245
"WING_FUNCTION_NAME": "Handler-c838ce37",
246246
"WING_TARGET": "tf-aws",
247-
"WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
247+
"WING_TOKEN_TFTOKEN_TOKEN_8": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
248248
}
249249
},
250250
"function_name": "Handler-c838ce37",

tools/hangar/__snapshots__/test_corpus/sdk_tests/api/options.w_compile_tf-aws.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ module.exports = function({ $api_url, $http_HttpMethod, $http_Util, $path }) {
137137
},
138138
"rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}",
139139
"triggers": {
140-
"redeployment": "9bcd95d1a951f5b01da431cbc7b3eb0ab691fdeb"
140+
"redeployment": "${sha256(aws_api_gateway_rest_api.cloudApi_api_2B334D75.body)}"
141141
}
142142
}
143143
},
@@ -390,7 +390,7 @@ module.exports = function({ $api_url, $http_HttpMethod, $http_Util, $path }) {
390390
"variables": {
391391
"WING_FUNCTION_NAME": "Handler-c8f5c667",
392392
"WING_TARGET": "tf-aws",
393-
"WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
393+
"WING_TOKEN_TFTOKEN_TOKEN_8": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
394394
}
395395
},
396396
"function_name": "Handler-c8f5c667",

tools/hangar/__snapshots__/test_corpus/sdk_tests/api/patch.w_compile_tf-aws.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ module.exports = function({ $_id, $api_url, $body, $http_HttpMethod, $http_Util,
104104
},
105105
"rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}",
106106
"triggers": {
107-
"redeployment": "2afd05beaf27bcecd099e20f65c2990011bdae48"
107+
"redeployment": "${sha256(aws_api_gateway_rest_api.cloudApi_api_2B334D75.body)}"
108108
}
109109
}
110110
},
@@ -241,7 +241,7 @@ module.exports = function({ $_id, $api_url, $body, $http_HttpMethod, $http_Util,
241241
"variables": {
242242
"WING_FUNCTION_NAME": "Handler-c89df580",
243243
"WING_TARGET": "tf-aws",
244-
"WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
244+
"WING_TOKEN_TFTOKEN_TOKEN_8": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
245245
}
246246
},
247247
"function_name": "Handler-c89df580",

tools/hangar/__snapshots__/test_corpus/sdk_tests/api/post.w_compile_tf-aws.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ module.exports = function({ $api_url, $body, $http_HttpMethod, $http_Util, $std_
103103
},
104104
"rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}",
105105
"triggers": {
106-
"redeployment": "afb250682538f14812af9e01ecd4d6310c8cfb87"
106+
"redeployment": "${sha256(aws_api_gateway_rest_api.cloudApi_api_2B334D75.body)}"
107107
}
108108
}
109109
},
@@ -240,7 +240,7 @@ module.exports = function({ $api_url, $body, $http_HttpMethod, $http_Util, $std_
240240
"variables": {
241241
"WING_FUNCTION_NAME": "Handler-c88947b5",
242242
"WING_TARGET": "tf-aws",
243-
"WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
243+
"WING_TOKEN_TFTOKEN_TOKEN_8": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
244244
}
245245
},
246246
"function_name": "Handler-c88947b5",

tools/hangar/__snapshots__/test_corpus/sdk_tests/api/put.w_compile_tf-aws.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ module.exports = function({ $_id, $api_url, $body, $http_HttpMethod, $http_Util,
108108
},
109109
"rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}",
110110
"triggers": {
111-
"redeployment": "4c47cf4383648e8878b273255efa16fb8e65ec18"
111+
"redeployment": "${sha256(aws_api_gateway_rest_api.cloudApi_api_2B334D75.body)}"
112112
}
113113
}
114114
},
@@ -245,7 +245,7 @@ module.exports = function({ $_id, $api_url, $body, $http_HttpMethod, $http_Util,
245245
"variables": {
246246
"WING_FUNCTION_NAME": "Handler-c8e4b12f",
247247
"WING_TARGET": "tf-aws",
248-
"WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
248+
"WING_TOKEN_TFTOKEN_TOKEN_8": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
249249
}
250250
},
251251
"function_name": "Handler-c8e4b12f",

tools/hangar/__snapshots__/test_corpus/valid/api.w_compile_tf-aws.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ module.exports = function({ }) {
126126
},
127127
"rest_api_id": "${aws_api_gateway_rest_api.A_cloudApi_api_37FCEF91.id}",
128128
"triggers": {
129-
"redeployment": "66f9e4b69146527e1951e6308dc9128a3ca41abb"
129+
"redeployment": "${sha256(aws_api_gateway_rest_api.A_cloudApi_api_37FCEF91.body)}"
130130
}
131131
},
132132
"cloudApi_api_deployment_545514BF": {
@@ -141,7 +141,7 @@ module.exports = function({ }) {
141141
},
142142
"rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}",
143143
"triggers": {
144-
"redeployment": "d4a66f49086c55ef3890317ca607c501380327bb"
144+
"redeployment": "${sha256(aws_api_gateway_rest_api.cloudApi_api_2B334D75.body)}"
145145
}
146146
}
147147
},
@@ -318,7 +318,7 @@ module.exports = function({ }) {
318318
"variables": {
319319
"WING_FUNCTION_NAME": "cloud-Api-OnRequest-73c5308f-c85168bb",
320320
"WING_TARGET": "tf-aws",
321-
"WING_TOKEN_TFTOKEN_TOKEN_41": "${jsonencode(aws_api_gateway_stage.A_cloudApi_api_stage_6D822CCE.invoke_url)}"
321+
"WING_TOKEN_TFTOKEN_TOKEN_43": "${jsonencode(aws_api_gateway_stage.A_cloudApi_api_stage_6D822CCE.invoke_url)}"
322322
}
323323
},
324324
"function_name": "cloud-Api-OnRequest-73c5308f-c85168bb",
@@ -378,7 +378,7 @@ module.exports = function({ }) {
378378
"variables": {
379379
"WING_FUNCTION_NAME": "Handler-c8315524",
380380
"WING_TARGET": "tf-aws",
381-
"WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
381+
"WING_TOKEN_TFTOKEN_TOKEN_8": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
382382
}
383383
},
384384
"function_name": "Handler-c8315524",

tools/hangar/__snapshots__/test_corpus/valid/api_path_vars.w_compile_tf-aws.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ module.exports = function({ $api_url, $http_Util, $std_Json }) {
9494
},
9595
"rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}",
9696
"triggers": {
97-
"redeployment": "4ae1656762ef65f98b4b2e240588f473cd4e9469"
97+
"redeployment": "${sha256(aws_api_gateway_rest_api.cloudApi_api_2B334D75.body)}"
9898
}
9999
}
100100
},
@@ -231,7 +231,7 @@ module.exports = function({ $api_url, $http_Util, $std_Json }) {
231231
"variables": {
232232
"WING_FUNCTION_NAME": "Handler-c8f4f2a1",
233233
"WING_TARGET": "tf-aws",
234-
"WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
234+
"WING_TOKEN_TFTOKEN_TOKEN_8": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
235235
}
236236
},
237237
"function_name": "Handler-c8f4f2a1",

tools/hangar/__snapshots__/test_corpus/valid/api_valid_path.w_compile_tf-aws.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ module.exports = function({ }) {
7373
},
7474
"rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}",
7575
"triggers": {
76-
"redeployment": "ca397382abb9ec6fa6cdfa8a96c26d44013057ba"
76+
"redeployment": "${sha256(aws_api_gateway_rest_api.cloudApi_api_2B334D75.body)}"
7777
}
7878
}
7979
},

tools/hangar/__snapshots__/test_corpus/valid/capture_tokens.w_compile_tf-aws.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ module.exports = function({ }) {
113113
},
114114
"rest_api_id": "${aws_api_gateway_rest_api.MyResource_cloudApi_api_4CB9B8E3.id}",
115115
"triggers": {
116-
"redeployment": "6eb5a41974a89ebc5d63af9e7fe3ce6e1d6619c7"
116+
"redeployment": "${sha256(aws_api_gateway_rest_api.MyResource_cloudApi_api_4CB9B8E3.body)}"
117117
}
118118
},
119119
"cloudApi_api_deployment_545514BF": {
@@ -128,7 +128,7 @@ module.exports = function({ }) {
128128
},
129129
"rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}",
130130
"triggers": {
131-
"redeployment": "6eb5a41974a89ebc5d63af9e7fe3ce6e1d6619c7"
131+
"redeployment": "${sha256(aws_api_gateway_rest_api.cloudApi_api_2B334D75.body)}"
132132
}
133133
}
134134
},
@@ -257,7 +257,7 @@ module.exports = function({ }) {
257257
"variables": {
258258
"WING_FUNCTION_NAME": "Handler-c8ed8f29",
259259
"WING_TARGET": "tf-aws",
260-
"WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.MyResource_cloudApi_api_stage_A26656F9.invoke_url)}"
260+
"WING_TOKEN_TFTOKEN_TOKEN_8": "${jsonencode(aws_api_gateway_stage.MyResource_cloudApi_api_stage_A26656F9.invoke_url)}"
261261
}
262262
},
263263
"function_name": "Handler-c8ed8f29",
@@ -287,7 +287,7 @@ module.exports = function({ }) {
287287
"variables": {
288288
"WING_FUNCTION_NAME": "Handler-c8ecc6d5",
289289
"WING_TARGET": "tf-aws",
290-
"WING_TOKEN_TFTOKEN_TOKEN_30": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
290+
"WING_TOKEN_TFTOKEN_TOKEN_32": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
291291
}
292292
},
293293
"function_name": "Handler-c8ecc6d5",

tools/hangar/__snapshots__/test_corpus/valid/captures.w_compile_tf-aws.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ module.exports = function({ $headers }) {
105105
},
106106
"rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}",
107107
"triggers": {
108-
"redeployment": "273d559c5171243e931678d9387d60465c3b99de"
108+
"redeployment": "${sha256(aws_api_gateway_rest_api.cloudApi_api_2B334D75.body)}"
109109
}
110110
}
111111
},

tools/hangar/__snapshots__/test_corpus/valid/inference.w_compile_tf-aws.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ module.exports = function({ }) {
7373
},
7474
"rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}",
7575
"triggers": {
76-
"redeployment": "d4a66f49086c55ef3890317ca607c501380327bb"
76+
"redeployment": "${sha256(aws_api_gateway_rest_api.cloudApi_api_2B334D75.body)}"
7777
}
7878
}
7979
},

tools/hangar/__snapshots__/test_corpus/valid/issue_2889.w_compile_tf-aws.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ module.exports = function({ $api_url, $http_Util, $std_Json }) {
9595
},
9696
"rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}",
9797
"triggers": {
98-
"redeployment": "ca2771f24c2978f810a5a1a5c3373f4ac9d7d88c"
98+
"redeployment": "${sha256(aws_api_gateway_rest_api.cloudApi_api_2B334D75.body)}"
9999
}
100100
}
101101
},
@@ -232,7 +232,7 @@ module.exports = function({ $api_url, $http_Util, $std_Json }) {
232232
"variables": {
233233
"WING_FUNCTION_NAME": "Handler-c88c3aa2",
234234
"WING_TARGET": "tf-aws",
235-
"WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
235+
"WING_TOKEN_TFTOKEN_TOKEN_8": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}"
236236
}
237237
},
238238
"function_name": "Handler-c88c3aa2",

tools/hangar/__snapshots__/test_corpus/valid/website_with_api.w_compile_tf-aws.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ module.exports = function({ }) {
151151
},
152152
"rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}",
153153
"triggers": {
154-
"redeployment": "53d34a77ebc006529cbee88240e663619396c753"
154+
"redeployment": "${sha256(aws_api_gateway_rest_api.cloudApi_api_2B334D75.body)}"
155155
}
156156
}
157157
},

0 commit comments

Comments
 (0)