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 Aug 21, 2023
1 parent ab6acf6 commit ceb8aa7
Show file tree
Hide file tree
Showing 15 changed files with 1,255 additions and 2 deletions.
46 changes: 46 additions & 0 deletions packages/whook-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,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 @@ -16,7 +16,12 @@
"ignore": [
"dist",
"builds",
"lambdas"
"lambdas",
".bin",
".terraform",
"*.plan",
"*.tfstate.d",
"*.credentials.json"
],
"bundleFiles": [
"bin",
Expand Down
3 changes: 2 additions & 1 deletion packages/whook-example/src/__snapshots__/cli.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ exports[`commands should work with ls 1`] = `
",
"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 ceb8aa7

Please sign in to comment.