Manage your OVHcloud privateSQL databases as code with Terraform:
- order an instance
- mariadb
- mysql
- postgresql
- redis
- create databases
- create users
- manage grants
- Whitelist IP address to restrict access to your instance (sftp or service port)
If your instance was ordered manually from the OVHCloud control panel, a datasource will allow you to manage your privateSQL the same way you ordered it "as code".
Read the Terraform registry documentation
-
terraform binary
-
An OVHCloud account
-
A private APIv6 tokens
-
A billing account (or your admin account). This account has rights to order privateSQL instances.
-
A technical account. This one will be able to manage your privateSQL and will not be able to terminate your service.
First your need to export your OVHCloud APIv6 variables then initialize your environnement:
cd env/mariadb
terraform init
- Create a custom
variables.tfvars
file to add your configuration.
order = {
name = "terraform-mariadb"
tech_account = "nictec-instanceid"
plan_code = "private-sql-512-instance"
datacenter = "gra3"
engine = "mariadb_10.3"
}
databases = [
"admin",
]
users = [{
name = "admin"
password = "changeme"
}
]
grants = [{
database = "admin"
user = "admin"
grant = "admin"
}
]
whitelists = [{
ip = "1.2.3.4"
name = "My personal public IP address"
service = true
sftp = true
}
]
The following arguments are required:
-
order
- Order detailsname
- Name of your instance displayed on the OVHcloud Control Paneltech_account
- Use a technical account instead of your admin/billing account to manage your instanceplan_code
- Plan code. Values can beprivate-sql-512-instance
,private-sql-1024-instance
,private-sql-2048-instance
,private-sql-4096-instance
datacenter
- OVHCloud datacenter. Values can begra3
(better thangra1
orgra2
for network considerations) orbhs1
engine
- Database engine. Values can bemariadb_10.2
mariadb_10.3
mariadb_10.4
mariadb_10.5
mysql_5.7
mysql_8.0
postgresql_9.5
postgresql_9.6
postgresql_10
postgresql_11
postgresql_12
redis_6.0
-
databases
- A list of string -
users
- a list of objects -
grants
- a list of objects. Grants value can beadmin
,ro
,rw
-
whitelists
- a list of objects
Then, check the terraform speculative plan:
terraform plan -var-file=variables.tfvars
If no errors let's deploy our instance and configurations in one terraform run:
terraform apply -var-file=variables.tfvars
For now APIv6 only allow us to handle whitelists.
Databases, users, grants are not available. We cannot update user's password once the instance is deployed.
You will need to change it from the OVHCloud control panel