How to deploy the entire governance watchdog infrastructure from scratch.
- The Terraform State for this project lives in our shared Terraform Seed Project with the ID
mento-terraform-seed-ffac
- Deploying the project for the first time should automatically create a subfolder in the google storage bucket used for terraform state management in the seed project
The project is preconfigured to impersonate our shared terraform service account (see ./infra/versions.tf
).
The only permission you will need on your own gcloud user account is roles/iam.serviceAccountTokenCreator
to allow you to impersonate our shared terraform service account.
If for whatever reason service account impersonation doesn't work, you'll need at least the following permissions on your personal gcloud account to deploy this project with terraform:
roles/resourcemanager.folderViewer
on the folder that you want to create the project inroles/resourcemanager.organizationViewer
on the organizationroles/resourcemanager.projectCreator
on the organizationroles/billing.user
on the organizationroles/storage.admin
to allow creation of new storage buckets
-
Run
./bin/set-up-terraform.sh
to check required permissions and provision all required terraform providers and modules -
Create a
./infra/terraform.tfvars
file. This is like.env
for Terraform:touch ./infra/terraform.tfvars # This file is `.gitignore`d to avoid accidentally leaking sensitive data
-
Add Google Cloud Org ID and Billing Account to your local
terraform.tfvars
# Required for creating new GCP projects # Get it via `gcloud organizations list` org_id = "<our-org-id>" # Required for creating new GCP projects # Get it via `gcloud billing accounts list` (pick the GmbH account) billing_account = "<our-billing-account-id>"
-
Create a Discord Webhook URL for the channel you want to receive notifications in
-
Add the Discord Webhook URL to your local
terraform.tfvars
:# This will be stored in Google Secret Manager upon deployment via Terraform echo "discord_webhook_url = \"<discord-webhook-url>"" >> terraform.tfvars
-
Create a Telegram group and invite a new bot into it
-
Open a new telegram chat with @BotFather
-
Use the
/newbot
command to create a new bot -
Copy the API key printed out at the end of the prompt and store it in your
terraform.tfvars
telegram_bot_token = "<bot-api-key>"
-
Get the Chat ID by inviting @MissRose_bot to the group and then using the
/id
command -
Add the Chat ID to your
terraform.tfvars
telegram_chat_id = "<group-chat-id>"
-
Remove @MissRose_bot after you got the Chat ID
-
-
Get (or generate if non-existing) a QuickNode API key to enable Terraform to provision QuickAlerts
- Grab the API key from our QuickNode dashboard: https://dashboard.quicknode.com/api-keys
- Add it to
terraform.tfvars
quicknode_api_key = "<quicknode-api-key>"
-
Get a VictorOps webhook URL by copying the Service API Endpoint URL from the VictorOps Stackdriver Integration. The routing key can be founder under the
Settings
tab# Required to send on-call alerts to VictorOps victorops_webhook_url = "<victorops-webhook-url>/<victorops-routing-key>"
-
Generate an auth key to allow us to test the deployed function from our local machines
- You can use your password manager to generate a long and secure (url-compatible) key
- Add it to
terraform.tfvars
x_auth_token = "<x-auth-token>"
-
Deploy the entire project via
terraform apply
-
You will see an overview of all resources to be created. Review them if you like and then type "Yes" to confirm.
-
This command can take up to 10 minutes because it does a lot of work creating and configuring all defined Google Cloud Resources
-
❌ Given the complexity of setting up an entire Google Cloud Project incl. service accounts, permissions, etc., you might run into deployment errors with some components.
Often a simple retry of
terraform apply
helps. Sometimes a dependency of a resource has simply not finished creating when terraform already tried to deploy the next one, so waiting a few minutes for things to settle can help.
-
-
Set your local
gcloud
project ID to our freshly created one and populate your local cache with frequently used project values:npm run cache:clear
-
Check that everything worked as expected
# 1. Call the deployed function via: npm run test:prod # 2. Monitor the configured Discord channel for a message to appear open https://discord.com/channels/966739027782955068/1262714272476037212 # 3. Monitor the configured Telegram channel for a message to appear # 4. Check the function logs via: npm run logs # prints logs into your local terminal (with a few seconds of latency) # OR npm run logs:url # prints a URL to the cloud console logs in the browser
For most problems, you'll likely want to check the cloud function logs first.
npm run logs
will print the latest 50 staging log entries into your local terminal for quick and easy accessnpm run logs:url
will print the URL to the staging function logs in the Google Cloud Console for full access
- Run
npm run destroy
to delete the entire production environment from google cloud- You might run into permission issues here, especially around deleting the associated billing account resources
- I didn't have time to figure out the minimum set of permissions required to delete this project so the easiest would be to let an organization owner (i.e. Bogdan) run this with full permissions if you face any issues