|
1 | 1 | import * as pulumi from "@pulumi/pulumi"; |
2 | 2 | import * as aws from "@pulumi/aws"; |
3 | 3 | import * as apigateway from "@pulumi/aws-apigateway"; |
| 4 | +import * as tailscale from "@pulumi/tailscale"; |
4 | 5 | import * as path from "path"; |
5 | 6 |
|
6 | 7 | import * as handler from "./handler"; |
7 | 8 |
|
8 | 9 | const name = `example-${path.basename(process.cwd())}`; |
9 | 10 | const pulumiConfig = new pulumi.Config(); |
| 11 | +const tailscaleOauthClientId = pulumiConfig.require("tailscaleOauthClientId"); |
| 12 | +const tailscaleOauthClientSecret = pulumiConfig.requireSecret("tailscaleOauthClientSecret"); |
| 13 | + |
| 14 | +const fn = new aws.lambda.CallbackFunction(`${name}-fn`, { |
| 15 | + environment: { |
| 16 | + variables: { |
| 17 | + [handler.ENV_TAILSCALE_OAUTH_CLIENT_ID]: tailscaleOauthClientId, |
| 18 | + [handler.ENV_TAILSCALE_OAUTH_CLIENT_SECRET]: tailscaleOauthClientSecret, |
| 19 | + }, |
| 20 | + }, |
| 21 | + runtime: "nodejs24.x", |
| 22 | + callback: async (ev: any, ctx) => { |
| 23 | + return handler.lambdaHandler(ev); |
| 24 | + }, |
| 25 | +}); |
10 | 26 |
|
11 | 27 | const api = new apigateway.RestAPI(name, { |
12 | | - stageName: "tailscale-device-approval", |
| 28 | + stageName: `${name}`, |
13 | 29 | binaryMediaTypes: ["application/json"], |
14 | 30 | routes: [ |
15 | 31 | { |
16 | 32 | path: "/", |
17 | 33 | method: "POST", |
18 | | - eventHandler: new aws.lambda.CallbackFunction(`${name}-fn`, { |
19 | | - environment: { |
20 | | - variables: { |
21 | | - [handler.ENV_TAILSCALE_OAUTH_CLIENT_ID]: pulumiConfig.require("tailscaleOauthClientId"), |
22 | | - [handler.ENV_TAILSCALE_OAUTH_CLIENT_SECRET]: pulumiConfig.requireSecret("tailscaleOauthClientSecret"), |
23 | | - }, |
24 | | - }, |
25 | | - runtime: "nodejs20.x", |
26 | | - callback: async (ev: any, ctx) => { |
27 | | - return handler.lambdaHandler(ev); |
28 | | - }, |
29 | | - }), |
| 34 | + eventHandler: fn, |
30 | 35 | }, |
31 | 36 | ], |
32 | 37 | }); |
33 | 38 |
|
34 | 39 | export const url = api.url; |
| 40 | +export const lambdaFunctionName = fn.name; |
| 41 | + |
| 42 | +const webhook = new tailscale.Webhook(`${name}-webhook`, { |
| 43 | + endpointUrl: api.url, |
| 44 | + subscriptions: ["nodeNeedsApproval"], |
| 45 | +}); |
| 46 | + |
| 47 | +// Only set at creation. Store it if you plan to verify webhook signatures in the handler. |
| 48 | +export const webhookSecret = pulumi.secret(webhook.secret); |
0 commit comments