Connecting To The Database
Now that we have a database it is time to connect Etherpad to it.
We see in the Hands on Guide to Google Cloud that the way to achieve this is by setting some environment variables to be read by Etherpad when it starts. Lets have a look how to do that.
Adding Environment Variables
Once again this is set up by the cloud run app module. which as I noted before is the basis of my webapp.
The boilerplate webapp module contains the following environment variable setting
|
|
This sets the EXTRA_SETTINGS_URLS
variable which is used by Django webapps written by
the University such as the
Lecture Capture Preferences webapp.
While Etherpad won’t understand this, it is instructive to
see how this works so we can set up the variables it does understand.
As we saw in an earlier post
the cloud run app module uses the Google Cloud Run Service
It notes that the environment variables are set in the env block, name
being the name
of the variable, and value
is it’s value. These are set by the cloud run app module
So I can simply add the variables in as per the hands on guide:
|
|
Great! But… These are what the hands on guide says to use. The SQL user we set up in terraform is webapp, so maybe we should change it to that. But there is already a variable in locals - we should obviously use that. Actually all the above are wrong, apart from the db_type.
Asking Terraform for Values
Can we get them out of terraform?
|
|
That’s better, but now we are passing the password in plain text.
Creating a Secret to hold the Password
The hands on guide explains how to use a secrets manager to create a secret. In fact the extra settings URL parameter is managed as a secret, but it contains a JSON document, which isn’t what we want. Lets add another secret just containing the password.
|
|
Granting Access to the Secret
I added access as well, again taking a cue from the webapp_secret_settings:
|
|
Passing the secret to the application
Once we have changed the Etherpad container to use Berglas, we can pass the URL of the secret, rather than the secret itself. So the environment variables section is changed as follows:
|
|
That is to say we pass the URL of the secret in the Google Secrets Manager that contains the password rather than the password itself. Then Berglas can fetch the secret.
Running Terraform
Running terraform plan
says
Running terraform init
followed by terraform plan
seemed to fix this problem.
What if it doesn’t work? That is the focus of the next post.