Learn how to order a Cloud Database or Analytics service using Terraform.
Cloud Databases and Analytics allow you to focus on building and deploying cloud applications while OVHcloud takes care of the service infrastructure and maintenance.
Requirements
- Terraform >= 0.17.1 installed
- Access to the OVHcloud API (create your credentials by consulting this guide)
- A Public Cloud project in your OVHcloud account
Instructions
Step 1: Gather the OVHcloud required parameters
Getting your cluster/API tokens information
The "OVH provider" needs to be configured with a set of credentials:
- an
application_key
- an
application_secret
- a
consumer_key
Why?
Because, behind the scenes, the "OVH Terraform provider" is making requests to OVHcloud APIs.
To retrieve this necessary information, please follow our First Steps with the OVHcloud API tutorial.
Specifically, you have to generate these credentials via the OVHcloud token generation page with the following rights:
When you have successfully generated your OVHcloud tokens, please save them as you will have to use them very soon.
The last needed information is the service_name
: it is the ID of your Public Cloud project.
How to get it?
In the Public Cloud section, you can retrieve your service name ID thanks to the Copy to clipboard
button.
You will also use this information in Terraform resources definition files.
Step 2: Gather the set of required parameters
To create a new PostgreSQL cluster, you will need to specify at least:
- the version (e.g. "15")
- the region (e.g. "US-EAST-VA")
- the plan (e.g. "business")
- the flavor of the cluster (e.g. "db1-7")
Step 3: Create Terraform files
You may find it useful to have the Terraform documentation open while completing these steps.
First, create a main.tf
file defining the resources that will be created
Then, create a variables.tf
file defining the variables used in main.tf
:
This file will set default values that will be overwritten by the secrets.tfvars
file in the next step.
Here, we defined the ovh-us
endpoint because we want to call the OVHcloud US API.
Then, create a secrets.tfvars
file containing the required variables values:
Don't forget to replace <service_name>
, <application_key>
, <application_secret>
, <consumer_key>
, <ip_range>
with the real data.
Finally, create an outputs.tf
file defining the resources that will be exported:
Step 4: Run
Now we need to initialize Terraform, generate a plan, and apply it.
The init command will initialize your working directory which contains .tf
configuration files.
It’s the first command to execute for a new configuration, or after doing a checkout of an existing configuration in a given git repository for example.
The init
command will:
- Download and install Terraform providers/plugins
- Initialize backend (if defined)
- Download and install modules (if defined)
Now, we can generate our plan:
Thanks to the plan command, we can check what Terraform wants to create, modify, or remove.
The plan is OK for us, so let's apply it:
NOTE: If executing this command with a pre-existing user name, you may receive an error message stating that the user already exists. Despite this error, your database should have successfully been created.
To avoid this error, run the command below with a new user name.
Finally, export the user credentials and the URI.
Congratulations! The PostgreSQL cluster is created.
How to deploy with other engines
In this guide, we explained how to deploy a PostgreSQL service but you can find examples for other engines in our GitHub repository by selecting the folder for your engine and the terrform/hello-world
folder.
Go further
For more information and tutorials, please see our other Managed Databases & Analytics or Platform as a Service guides. You can also explore the guides for other OVHcloud products and services.