a0dc296ede
We sometimes need to test against cloud databases. Here, we add a Terraform module to start a new AlloyDB cluster and instance, which we can then use for testing purposes. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7002 GitOrigin-RevId: 2d661b5cc6d60e47485ea68b781e13426ed4f097 |
||
---|---|---|
.. | ||
alloydb | ||
.gitignore | ||
README.md |
Manual testing helpers
The code in this directory will help you spin up manual testing environments.
It uses Terraform, which you can install using your package manager.
You will need to specify your name to use these, so that you don't step on the toes of other developers. We recommend using the name portion of your Hasura email address, without any dots.
You can either specify your name by passing -var <name>
to each terraform
command, or by setting the TF_VAR_name
environment variable. If you do the latter, you might find it easiest to add it to .envrc.local in the repository root, and use direnv to load it automatically.
$ export TF_VAR_name='tanmaigopal'
Note that Terraform creates files locally to manage its internal state. Do not delete the state files or it will lose track of what you've created.
Once you've started something, it's your job to stop it too. Please don't leave it lying around.
Google Cloud
To spin up these resources, you will need a Google Cloud account and a project with billing enabled.
First, install the Google Cloud CLI.
Next, authenticate:
$ gcloud auth application-default login
Set your project (you can add this to .envrc.local if you want):
$ export GOOGLE_CLOUD_PROJECT='<project name>'
Then proceed.
AlloyDB
To spin up a test instance, cd
into the alloydb directory, and run:
$ terraform init
$ terraform apply -var password='<a strong password>'
(You can generate a strong password by running openssl rand 32 | base64
.)
If the plan looks good, type "yes".
You may have to wait a few minutes for things to start up, and then a couple more while the bastion instance comes online.
The URL can be found by running terraform output url
(be warned, it includes your super-secret password).
Once everything is up and running, you can connect to the AlloyDB proxy as follows:
$ psql "$(terraform output -raw url)"
Test all you like. When you're done, run:
$ terraform destroy
Troubleshooting
If you're having trouble, you may want to debug the Bastion instance. View the auth proxy logs by SSHing in and reading the log file.
First of all, enable SSH by uncommenting the "ssh" tag in bastion.tf, and running terraform apply
again.
Then take a peek:
$ gcloud compute ssh <name>-testing-alloydb-bastion
bastion$ cat /alloydb-auth-proxy.log
Modifying these files
You are advised to read the Terraform documentation.
When reading provider documentation, you might notice discrepancies between the pinned version here and the version documented. To mitigate this, upgrade first:
$ terraform get -update
Then fix any issues. After that, you can make your changes.
Once you're done, please run terraform fmt
before committing.