Terraform example on how to use Cloud API
Question
How can I use API to manage clusters on ClickHouse Cloud?
Answer
We will use Terraform to configure our infra and ClickHouse Provider
Steps:
1). Create an API Key on Cloud. Follow the docs here - https://clickhouse.com/docs/en/cloud/manage/openapi
Save the creds locally.
2). Install Terraform using - https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli
You can use Homebrew package manager if you're on Mac.
3). Create a directory anywhere you like:
4). Create 2 files: main.tf
and secret.tfvars
Copy the following:
main.tf
file would be:
You can replace your own parameters like service name, region etc.. in the resources section above.
secret.tfvars
is where you'll put all the API Key related info that you downloaded earlier. The idea behind this file is that all your secret credentials will be hidden from the main config file.
It would be something like (replace these parameters):
5). Run terraform init
from this directory
Expected output:
6). Run terraform apply -var-file=secret.tfvars
command.
Something like:
Type yes
and hit enter
Side note: Notice it says password = (sensitive value)
above.
This is because we set sensitive = true
for the password in the main.tf file.
7). It will take a couple of mins to create the service but eventually it should come up like:
8). Check Cloud Console, you should be able to see the service created.
9). To clean up/destroy the service again, run terraform destroy -var-file=secret.tfvars
Something like:
Type yes and hit enter
10).
And it should be gone from the Cloud Console.
More details about the Cloud API can be found here - https://clickhouse.com/docs/en/cloud/manage/api/api-overview