Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(object storage): add OVHcloud provider to create bucket #7703

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ OVHcloud console GUI (also called "Control Panel" or "Manager") hides some backg
| --- | --- | --- |
| Block Storage | openstack | [blockstorage_volume_v3](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/blockstorage_volume_v3)|
| Object Storage (Swift) | openstack | [objectstorage_object_v1](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/objectstorage_object_v1) |
| Object Storage | Hashicorp aws | [aws_s3_bucket](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket)|
| Object Storage | ovh | [cloud_project_storage](https://registry.terraform.io/providers/ovh/ovh/latest/docs/resources/cloud_project_storage)|
| Object Storage users | ovh | [ovh_cloud_project_user](https://registry.terraform.io/providers/ovh/ovh/latest/docs/resources/cloud_project_user) with *objectstore_operator* role|
| Cloud Archive | openstack | [objectstorage_object_v1](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/objectstorage_object_v1) with [storage_policy](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/objectstorage_container_v1#storage_policy) set to “PCA” in order to create an “archive” swift container |
| Cold Archive | Hashicorp aws | [aws_s3_bucket](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket)|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ OVHcloud console GUI (also called "Control Panel" or "Manager") hides some backg
| --- | --- | --- |
| Block Storage | openstack | [blockstorage_volume_v3](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/blockstorage_volume_v3)|
| Object Storage (Swift) | openstack | [objectstorage_object_v1](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/objectstorage_object_v1) |
| Object Storage | Hashicorp aws | [aws_s3_bucket](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket)|
| Object Storage | ovh | [cloud_project_storage](https://registry.terraform.io/providers/ovh/ovh/latest/docs/resources/cloud_project_storage)|
| Object Storage users | ovh | [ovh_cloud_project_user](https://registry.terraform.io/providers/ovh/ovh/latest/docs/resources/cloud_project_user) with *objectstore_operator* role|
| Cloud Archive | openstack | [objectstorage_object_v1](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/objectstorage_object_v1) with [storage_policy](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/objectstorage_container_v1#storage_policy) set to “PCA” in order to create an “archive” swift container |
| Cold Archive | Hashicorp aws | [aws_s3_bucket](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket)|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Object Storage - Getting started with Object Storage
excerpt: This guide is designed to familiarise you with the management of your containers/objects
updated: 2025-03-17
updated: 2025-04-02
---

<style>
Expand Down Expand Up @@ -42,6 +42,11 @@ This guide is designed to familiarise you with the management of your containers

## Instructions

> [!primary]
>
> If you wish to use the OVHcloud Terraform provider, you can follow [this guide](/pages/storage_and_backup/object_storage/s3_terraform).
>

### Preparation

/// details | To use the AWS CLI
Expand Down Expand Up @@ -284,6 +289,7 @@ To manage an Object Storage bucket, first log in to your [OVHcloud Control Panel
>> Congratulations, your bucket is created:
>>
>> ![Result](images/01-object-storage-bucket-listing.png)
>>

#### Uploading your files as objects in your bucket

Expand Down Expand Up @@ -428,23 +434,6 @@ To manage an Object Storage bucket, first log in to your [OVHcloud Control Panel
>

> [!tabs]
> Via the OVHcloud Control Panel
>> **Deleting a bucket:**
>>
>> In the list of object storage containers, click on the `...`{.action} button on the containers line, then click `Delete`{.action}.
>>
>> ![Delete bucket](images/delete-bucket.png){.thumbnail}
>>
>> Click on `Confirm`{.action}.
>>
>> **Deleting objects:**
>>
>> Go to the relevant bucket and click on the `...`{.action} button on the object line, then click `Delete`{.action}.
>>
>> ![Delete file](images/delete-file.png){.thumbnail}
>>
>> Click on `Confirm`{.action}.
>>
> Via AWS CLI
>> /// details | **Via AWS s3**
>>
Expand Down Expand Up @@ -516,6 +505,24 @@ To manage an Object Storage bucket, first log in to your [OVHcloud Control Panel
>> > If your bucket has Object Lock enabled, you will not be able to permanently delete your objects. See our [documentation](/pages/storage_and_backup/object_storage/s3_managing_object_lock) to learn more about Object Lock.
>> > If you use Object Lock in GOVERNANCE mode and have the permission to bypass GOVERNANCE mode, you will have to add the `--bypass-governance-retention` option to your delete commands.
>> >
>>
> Via the OVHcloud Control Panel
>> **Deleting a bucket:**
>>
>> In the list of object storage containers, click on the `...`{.action} button on the containers line, then click `Delete`{.action}.
>>
>> ![Delete bucket](images/delete-bucket.png){.thumbnail}
>>
>> Click on `Confirm`{.action}.
>>
>> **Deleting objects:**
>>
>> Go to the relevant bucket and click on the `...`{.action} button on the object line, then click `Delete`{.action}.
>>
>> ![Delete file](images/delete-file.png){.thumbnail}
>>
>> Click on `Confirm`{.action}.
>>

**Manage tags**

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Object Storage - Premiers pas avec Object Storage
excerpt: Ce guide a pour objectif de vous familiariser avec la gestion de vos conteneurs / objets
updated: 2025-03-17
updated: 2025-04-02
---

<style>
Expand Down Expand Up @@ -42,6 +42,11 @@ Ce guide a pour objectif de vous familiariser avec la gestion de vos conteneurs/

## En pratique

> [!primary]
>
> Si vous souhaitez utiliser le provider Terraform OVHcloud, vous pouvez suivre [ce guide](/pages/storage_and_backup/object_storage/s3_terraform).
>

### Préparation

/// details | Pour utiliser l'AWS CLI
Expand Down Expand Up @@ -283,6 +288,7 @@ Pour gérer un bucket Object Storage, connectez-vous d'abord à votre [espace cl
>> Félicitations, votre bucket est créé :
>>
>> ![Result](images/01-object-storage-bucket-listing.png)
>>

#### Télécharger vos fichiers en tant qu'objets dans votre bucket

Expand Down Expand Up @@ -422,23 +428,6 @@ Pour gérer un bucket Object Storage, connectez-vous d'abord à votre [espace cl
>

> [!tabs]
> Via l'espace client OVHcloud
>> **Suppression d'un bucket**
>>
>> Dans la liste des conteneurs Object Storage, cliquez sur le bouton `...`{.action} sur la ligne des conteneurs, puis sur `Supprimer`{.action}.
>>
>> ![Delete bucket](images/delete-bucket.png){.thumbnail}
>>
>> Cliquez sur `Confirmer`{.action}.
>>
>> **Suppression d'objets**
>>
>> Allez dans le bucket concerné et cliquez sur le bouton `...`{.action} sur la ligne de l'objet, puis sur `Supprimer`{.action}.
>>
>> ![Delete file](images/delete-file.png){.thumbnail}
>>
>> Cliquez sur `Confirmer`{.action}.
>>
> Via AWS CLI
>>
>> /// details | **Avec AWS s3**
Expand Down Expand Up @@ -511,6 +500,24 @@ Pour gérer un bucket Object Storage, connectez-vous d'abord à votre [espace cl
>> > Si le verrouillage d'objet est activé dans votre bucket, vous ne pourrez pas supprimer définitivement vos objets. Consultez notre [documentation](/pages/storage_and_backup/object_storage/s3_managing_object_lock) pour en savoir plus sur le verrouillage d'objet.
>> > Si vous utilisez le verrouillage d'objet en mode GOUVERNANCE et que vous avez la permission de contourner le mode GOUVERNANCE, vous devrez ajouter l'option `--bypass-governance-retention` à vos commandes de suppression.
>> >
>>
> Via l'espace client OVHcloud
>> **Suppression d'un bucket**
>>
>> Dans la liste des conteneurs Object Storage, cliquez sur le bouton `...`{.action} sur la ligne des conteneurs, puis sur `Supprimer`{.action}.
>>
>> ![Delete bucket](images/delete-bucket.png){.thumbnail}
>>
>> Cliquez sur `Confirmer`{.action}.
>>
>> **Suppression d'objets**
>>
>> Allez dans le bucket concerné et cliquez sur le bouton `...`{.action} sur la ligne de l'objet, puis sur `Supprimer`{.action}.
>>
>> ![Delete file](images/delete-file.png){.thumbnail}
>>
>> Cliquez sur `Confirmer`{.action}.
>>

**Gérer les tags**

Expand Down
159 changes: 61 additions & 98 deletions pages/storage_and_backup/object_storage/s3_terraform/guide.en-gb.md
Original file line number Diff line number Diff line change
@@ -1,145 +1,108 @@
---
title: Object Storage - Manage an Object Storage bucket with Terraform
updated: 2024-08-27
updated: 2025-04-10
---

## Objective

This tutorial will show you how to automate some actions on Object Storage with Terraform which is an open source tool to automate infrastructure provisioning. The following actions will be automated:

- Object Storage user creation
- bucket creation
- file copy into the bucket
- S3 **\*** policies and assignment
This tutorial will help you automate and orchestrate actions to use the Object Storage - S3 API with Terraform. Terraform is an open source tool for orchestrating the provisioning and provisioning of resources.

## Requirements

- Have terraform command line installed (see this [tutorial](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli) from Hashicorp, the company behind Terraform). 
- Have git command line installed
- You will need to have set up an account to interact with the OVHcloud API (see this [tutorial](/pages/manage_and_operate/api/first-steps)). Depending on your needs in terms of permissions (http verbs PUT/GET/POST/DELETE), enter the route `/cloud/project/{serviceName}/region/{regionName}/storage/` to target object storage where *{serviceName}* corresponds to your Public Cloud project id and *{regionName}* corresponds to the region where your resources will be located. From the application keys created, you will need to export the 4 environment variables :

```bash
$ export OVH_ENDPOINT=ovh-eu
$ export OVH_APPLICATION_KEY=Your_key_application_OVH(or_AK)
$ export OVH_APPLICATION_SECRET=Your_secret_application_key_OVH(or_AS)
$ export OVH_CONSUMER_KEY=Your_token(or_CK)
```
- Installation of the [Terraform CLI](https://www.terraform.io/downloads.html){.external}
- Access to the [OVHcloud API](/links/api) (create your login by consulting [this guide](/pages/manage_and_operate/api/first-steps))
- A [Public Cloud project](/links/public-cloud/public-cloud) in your OVHcloud account.
- OVHcloud provides a [Terraform provider](https://registry.terraform.io/providers/ovh/ovh/latest){.external} which is available in the official Terraform registry. You must have installed a version >= 2.0. You can follow this guide [How to use Terraform on the OVHcloud Public Cloud](/pages/public_cloud/compute/how_to_use_terraform).

- A Public Cloud project, with the ID exported as the variable `TF_VAR_OVH_PUBLIC_CLOUD_PROJECT_ID`

```bash
$ export TF_VAR_OVH_PUBLIC_CLOUD_PROJECT_ID=Your_public_cloud_project_id
```
## Getting information on your cluster/API tokens

**If you do not have your AWS CLI** configured, you should set dummy values with the following. This is due to a limitation in Terraform dependency graph for providers initialization (see this long lasting terraform [issue)](https://github.com/hashicorp/terraform/issues/2430)):
The “OVH provider” must be configured with a set of credentials:

```bash
$ export AWS_ACCESS_KEY_ID="no_need_to_define_an_access_key"
$ export AWS_SECRET_ACCESS_KEY="no_need_to_define_a_secret_key"
```
- an `application_key`
- an `application_secret`
- a `consumer_key`

## Instructions
Why?

### Manage an Object Storage bucket with terraform @OVHcloud
Because, behind the scenes, the OVH Terraform provider makes requests to the OVHcloud APIs.

#### Initialize
To retrieve this necessary information, please follow the tutorial [First steps with the OVHcloud APIs](/pages/manage_and_operate/api/first-steps).

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

```bash
git clone https://github.com/yomovh/tf-at-ovhcloud && cd tf-at-ovhcloud/s3_bucket_only
```
The last piece of information you'll need is the `service_name`: this is the ID of your Public Cloud project.

Initialize Terraform:
How do I get it?

```bash
$ terraform init
```
In the Public Cloud section, you can retrieve your service name ID using the `Copy to clipboard`{.action} button.

#### Plan
![Copy paste service name](images/get-service-name.png){.thumbnail}

With the following command, you will see what are the actions that Terraform is going to perform:
You can also use this information in Terraform resource definition files.

```bash
$ terraform plan
```
## Instructions

Now let's have a look at the content of the `main.tf` file:
### Configuration

- The *variable* block defines the region and s3 endpoint that are used to create the bucket. You can update it according to your needs : check this [page](/pages/storage_and_backup/object_storage/s3_location) to know what region / endpoints are available.
- The *Providers* block defines 2 providers : ovh and Hashicorp AWS one. The first one is necessary to create the user whose identity / credentials will be used for the latest.
- The *User / Credential* block defines the user & credential that are visible in the Settings > Users & Roles tab. They are needed to configure the Hashicorp AWS provider.
- The Bucket block defines the bucket itself.
- The Output defines the access & secret key that may be useful for CLI usage.
First, create a `provider.tf` file with the minimum version, the European endpoint (“ovh-eu”) and the keys you obtained in this guide.

#### Run
Terraform:

```bash
$ terraform apply
```

Now you can go in the Console and check the "Object Storage" tab. Your bucket is created.

#### Destroy

With the following command you will be back to your original state: Terraform will destroy all the resources that were previously created.

```bash
$ terraform destroy
terraform {
required_providers {
ovh = {
source = "ovh/ovh"
version = "2.1.0" # greater than or equal to 2.0
}
}
}

provider "ovh" {
endpoint = "ovh-eu"
application_key = "<your_access_key>"
application_secret = "<your_application_secret>"
consumer_key = "<your_consumer_key>"
}
```

> [!primary]
>
> - This script does not follow Terraform best practices to split the project in multiple files e.g. **`provider.tf`, `main.tf`, `variables.tf`, `outputs.tf`**, ... This has been done intentionnaly to avoid switching into multiples files for what is a really simple example.
> - The secret that is created by this script is stored in the [local](https://developer.hashicorp.com/terraform/language/settings/backends/local) state back-end. If you use this back-end in production, make sure to consider the state file as a secret.

### Automating Object Storage policies with Terraform
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:

#### Initialize
- `ovh-eu` pour OVHcloud Europe API
- `ovh-us` pour OVHcloud US API
- `ovh-ca` pour OVHcloud North-America API

Clone the repository:
### Create a bucket

```bash
git clone https://github.com/yomovh/tf-at-ovhcloud && cd tf-at-ovhcloud/s3_policy
```

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

```bash
$ terraform init
```python
# Create an Object Storage bucket
resource "ovh_cloud_project_storage" "my-bucket" {
service_name = "my_service_name" # Replace with your OVHcloud project ID
region_name = "GRA" # Replace with the desired region in uppercase.
name = "object-storage-simple"
}
```

#### Plan

With the following command, you will see what are the actions that Terraform is going to perform:
You can create your resource by entering the following command:

```bash
$ terraform plan
terraform apply
```

Now let's have a look at the content of the `main.tf` file and compare it with the previous example:
### Delete a bucket

- The *User / Credential* block defines 3 users and credentials : one user will be administrator of the bucket and create it, the two others will have read/write & read-only access.
- In the *Bucket* block we have added the creation of a file into the bucket
- The *Policy* block defines 2 policies, one for read/write and the other for read-only on the bucket.

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

```bash
$ terraform apply
terraform destroy
```

Now you can go in the Console and check the "Object Storage" tab. You will see the bucket and the file.

You can also check the access right by using the AWS CLI with the 2 users that have the read / write & read-only access

#### Destroy

With the following command you will be back to your original state: Terraform will destroy all the resources that were previously created.

```bash
$ terraform destroy
```
> [!primary]
>
> 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

Expand Down
Loading