Skip to content

OVHcloud Terraform provider

The OVH provider is the entry point to interact with the resources provided by OVHcloud.

Latest releasev2.22.0GitHub

Agent setup
# OAuth2terraform {  required_providers {    ovh = {      source = "ovh/ovh"    }  }} provider "ovh" {  endpoint      = "ovh-eu"  client_id     = "xxxxxxxxx"  client_secret = "yyyyyyyyy"}

Quoted from the provider's documentation

Configure

The provider needs to be configured with the proper credentials before it can be used. Three forms of authentication are supported:

OAuth2

OAuth2, using scoped service accounts, and compatible with OVHcloud IAM. First, generate a pair of valid client_id and client_secret. Create a service account.

Terraform
terraform { required_providers { ovh = { source = "ovh/ovh" } }} provider "ovh" { endpoint = "ovh-eu" client_id = "xxxxxxxxx" client_secret = "yyyyyyyyy"}

Access token

A short-lived access token received from the OVHcloud API. The provider looks for it in the OVH_ACCESS_TOKEN environment variable, or in the access_token argument; the endpoint is set the same way.

Terraform
provider "ovh" { endpoint = "ovh-eu" access_token = "xxxxxxxxx"}

Application key

An application key, an application secret and a consumer key, generated on the OVHcloud token generation page. Create the keys.

Terraform
terraform { required_providers { ovh = { source = "ovh/ovh" } }} provider "ovh" { endpoint = "ovh-eu" application_key = "xxxxxxxxx" application_secret = "yyyyyyyyy" consumer_key = "zzzzzzzzzzzzzz"}

The endpoint: ovh-eu for the OVHcloud Europe API, ovh-ca for Canada, ovh-us for the US.

Credentials

Rather than in the code, the same code may run in several environments: the provider first looks for direct parameters, then for environment variables, then for a configuration file.

  • OAuth2: OVH_ENDPOINT, OVH_CLIENT_ID and OVH_CLIENT_SECRET
  • Access token: OVH_ENDPOINT and OVH_ACCESS_TOKEN
  • Application key: OVH_ENDPOINT, OVH_APPLICATION_KEY, OVH_APPLICATION_SECRET and OVH_CONSUMER_KEY

The configuration file, for OAuth2:

[default]
; general configuration: default endpoint
endpoint=ovh-eu

[ovh-eu]
; configuration specific to 'ovh-eu' endpoint
client_id=my_client_id
client_secret=my_client_secret

Looked for in ./ovh.conf, ~/.ovh.conf, then /etc/ovh.conf.

Example

A Managed Kubernetes cluster and its node pool:

Terraform
variable "service_name" { default = "wwwwwww"} # Create an OVHcloud Managed Kubernetes clusterresource "ovh_cloud_project_kube" "my_kube_cluster" { service_name = var.service_name name = "my-super-kube-cluster" region = "GRA5" version = "1.22"} # Create a Node Pool for our Kubernetes clusterresource "ovh_cloud_project_kube_nodepool" "node_pool" { service_name = var.service_name kube_id = ovh_cloud_project_kube.my_kube_cluster.id name = "my-pool" //Warning: "_" char is not allowed! flavor_name = "b3-8" desired_nodes = 3 max_nodes = 3 min_nodes = 3}

Every resource and data source: the provider's documentation; which provider and resource stand for what in the Control Panel: Terraform at OVHcloud.

Configuration reference

Every argument is optional; each has its environment variable.

ArgumentWhat it sets
endpointWhich API endpoint to use, e.g. ovh-eu or ovh-ca. OVH_ENDPOINT.
client_idThe OAuth2 client ID. OVH_CLIENT_ID.
client_secretThe OAuth2 client secret. OVH_CLIENT_SECRET.
access_tokenThe OVH API access token. OVH_ACCESS_TOKEN.
application_keyThe API application key. OVH_APPLICATION_KEY.
application_secretThe API application secret. OVH_APPLICATION_SECRET.
consumer_keyThe API consumer key. OVH_CONSUMER_KEY.
user_agent_extraExtra information to append at the end of the user-agent used when making API calls.
http_headersA map of extra HTTP headers to add to every request made to the OVH API.
api_rate_limitThe API request rate limit, X operations by second. If omitted, unlimited.

State storage

To keep your Terraform states on a High Performance (S3) OVHcloud Object Storage, follow the guide.

Guides