For AI agents: the complete documentation index is available at https://docs.ovhcloud.com/en/llms.txt, the full documentation bundle is available at https://docs.ovhcloud.com/en/llms-full.txt, and this page is available as Markdown at https://docs.ovhcloud.com/en/guides/storage-and-backup/object-storage/s3-terraform.md.

Object Storage - Manage an Object Storage bucket with Terraform

View as Markdown

Objective

This tutorial shows you how to use the Object Storage - S31-compatible API with Terraform. Terraform is an open-source tool for orchestrating the provisioning of resources.

Requirements

Getting information about your API tokens

The “OVH provider” must 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 makes requests to the OVHcloud APIs.

To retrieve this necessary information, please follow the tutorial First steps with the OVHcloud APIs.

Once you've successfully generated your OVHcloud tokens, keep them. You'll need to set them in the next few minutes.

The last piece of information you'll need is the service_name: this is the ID of your Public Cloud project.

How do I get it?

In the Public Cloud section, you can retrieve your service name ID using the Copy to clipboard button.

Copy paste service name

You can also use this information in Terraform resource definition files.

Instructions

If you would like to access the provider's documentation on Object Storage, click here

Configuration

First, create a provider.tf file with the minimum version, the European endpoint (“ovh-eu”) and the keys you obtained in this guide.

Terraform:

terraform {
  required_providers {
    ovh = {
      source  = "ovh/ovh"
      version = "~> 2.1" # greater than or equal to 2.1
    }
  }
}

provider "ovh" {
  endpoint           = "ovh-eu"
  application_key    = "<application_key>"
  application_secret = "<application_secret>"
  consumer_key       = "<consumer_key>"
}

Here, we've defined the ovh-eu endpoint because we want to call the OVHcloud Europe API, but other endpoints exist, depending on your needs:

  • ovh-eu for the OVHcloud Europe API
  • ovh-us for the OVHcloud US API
  • ovh-ca for the OVHcloud North America API

Create a bucket

You can create a file named object_storage_simple.tf and write the following:

# Create an Object Storage bucket
resource "ovh_cloud_project_storage" "my_bucket" {
  service_name = "`<service_name>`" # Replace with your OVHcloud project ID
  region_name  = "GRA" # Replace with the desired region in uppercase.
  name         = "object-storage-simple"
  versioning = {
    status = "enabled"
  }
  encryption = {
    sse_algorithm = "AES256"
  }
}

You can create your resource by entering the following command:

terraform apply

Delete a bucket

You can delete your bucket and all the objects it contains by entering the following command:

terraform destroy
Info

This process may fail if the bucket contains locked objects. In this case, you'll need to delete these objects manually before you can run the command again.

Go further

For training or technical assistance implementing our solutions, contact your sales representative or visit our Professional Services page to request a quote and have your project analysed by our experts.

Join our community of users.

1: S3 is a trademark of Amazon Technologies, Inc. OVHcloud’s service is not sponsored by, endorsed by, or otherwise affiliated with Amazon Technologies, Inc.

Was this page helpful?