Skip to content

Commit

Permalink
feat(deploy): add the terraform deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Dec 5, 2024
1 parent 230c0ec commit 9a2e26d
Show file tree
Hide file tree
Showing 19 changed files with 1,304 additions and 48 deletions.
46 changes: 46 additions & 0 deletions packages/whook-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,52 @@ APP_ENV=staging bin/lambdas_zip.sh
APP_ENV=staging bin/lambdas_push.sh
```

### Deploy with Terraform

Otherwise, here is a full step by step setup for you.

First install Terraform:

```sh
wget https://releases.hashicorp.com/terraform/1.2.2/terraform_1.2.2_linux_amd64.zip
mkdir .bin
unzip -d .bin terraform_1.2.2_linux_amd64.zip
rm terraform_1.2.2_linux_amd64.zip
```

Then initialize the Terraform configuration:

```sh
cd ./terraform
../.bin/terraform init;
```

Create a new workspace for each `APP_ENV`:

```sh
../.bin/terraform workspace new staging
```

Plan the deployment:

```sh
../.bin/terraform plan -out=terraform.plan -var "node_env=${NODE_ENV}"
```

Apply changes:

```sh
../.bin/terraform apply -var "node_env=${NODE_ENV}" terraform.plan
```

Finally retrieve the API URL and add and enjoy!

```sh
../.bin/terraform output api_url
curl "$(.bin/terraform output api_url)staging/v3/ping"
# {"pong":"pong"}
```

Generate API types:

```sh
Expand Down
7 changes: 6 additions & 1 deletion packages/whook-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
"distFiles": "'dist/**/*.js'",
"ignore": [
"dist",
"builds"
"builds",
".bin",
".terraform",
"*.plan",
"*.tfstate.d",
"*.credentials.json"
],
"bundleFiles": [
"bin",
Expand Down
9 changes: 5 additions & 4 deletions packages/whook-example/src/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ describe('commands should work', () => {
);

expect({
stdout: stdout.replace(/( |"|')([^ ]+)\/whook\//g, ' /whook/'),
stderr: stderr.replace(/( |"|')([^ ]+)\/whook\//g, ' /whook/'),
}).toMatchInlineSnapshot(`
stdout: stdout.replace(/( |"|')([^ ]+)\/whook\//g, ' /whook/'),
stderr: stderr.replace(/( |"|')([^ ]+)\/whook\//g, ' /whook/')
}).toMatchInlineSnapshot(`
{
"stderr": "⚡ - Loading configurations from /whook/packages/whook-example/dist/config/local/config.js".
🤖 - Initializing the \`$autoload\` service.
On air 🚀🌕
",
"stdout": "
# Provided by "@whook/example": 1 commands
# Provided by "@whook/example": 2 commands
- printEnv: A command printing every env values
- terraformValues: A command printing lambdas informations for Terraform
# Provided by "@whook/whook": 8 commands
Expand Down
Loading

0 comments on commit 9a2e26d

Please sign in to comment.