# OVHcloud FOCUS export

OVHcloud can write your bill as a FOCUS file into an Object Storage bucket of yours every day, and
Costfluent reads that bucket as a [FOCUS bucket](/connect/focus-bucket). It is the optional second
path: [Connect OVHcloud](/connect/ovhcloud) reads the same cost through an API key, with nothing to
set up in a bucket. Connect one of the two, because each imports the same cost and the second counts
it twice.

## Before you start

- The Costfluent access under [Prerequisites](/connect/focus-bucket#prerequisites).
- A Public Cloud project with an Object Storage bucket for the export.
- An OVHcloud API token allowed to call the `/finops` routes. OVHcloud documents setting up the
  export through its API only.

## Turn on the export

OVHcloud writes into your bucket with an access key you give it, so the export needs a user that may
write there. Costfluent gets a different user under **Create a read-only key**.

<Stepper>

1. In the Public Cloud project, open "Object Storage" under "Storage", and on the "Users" tab select
   "Create a user". Save its access key and secret key: OVHcloud shows the secret key once.
2. On the "Containers" tab, open the "..." menu of the bucket, select "Add S3 user", choose that user
   and the Role "Read and write".
3. Send `POST /v2/finops/bucketExport` to your account's API endpoint, `https://api.eu.ovhcloud.com`
   for an account in Europe, with the writing user's keys and the bucket:

   ```json
   {
     "targetSpec": {
       "exportHour": 6,
       "period": "DAILY",
       "filePolicy": "REPLACE",
       "bucketConfiguration": {
         "accessKey": "<writing user's access key>",
         "secretKey": "<writing user's secret key>",
         "bucketName": "<bucket>",
         "endpointURL": "s3.<region>.io.cloud.ovh.net",
         "region": "<region>",
         "pathPrefix": "./"
       }
     }
   }
   ```

   `exportHour` is the hour of the daily run in UTC. `filePolicy` `REPLACE` keeps one file per month,
   overwritten on every run; `CREATE` keeps one file per run. `endpointURL` is the host alone, without
   `https://`. `pathPrefix` `./` writes at the bucket's top; another value is a folder the files go
   under.
4. Note the `id` in the answer, and call `GET /v2/finops/bucketExport/{id}` until `resourceStatus` is
   `READY`. OVHcloud first lists the bucket and writes to it with the keys; when that fails, the
   status is `ERROR`.

</Stepper>

## Create a read-only key

Costfluent reads the bucket with a user of its own whose policy allows only listing the bucket and
reading its objects.

<Stepper>

1. On the "Users" tab of "Object Storage", select "Create a user", and save its access key and secret
   key.
2. Open the "..." menu of that user, select "Import a policy", and import this policy with your
   bucket's name. It replaces the user's current policy.

   ```json
   {
     "Statement": [{
       "Sid": "ROContainer",
       "Effect": "Allow",
       "Action": ["s3:GetObject", "s3:ListBucket", "s3:ListMultipartUploadParts", "s3:ListBucketMultipartUploads"],
       "Resource": ["arn:aws:s3:::<bucket>", "arn:aws:s3:::<bucket>/*"]
     }]
   }
   ```

</Stepper>

:::caution
Use a user that did not create the bucket and that the export does not write with. OVHcloud lets the
user who created a bucket do anything in it, whatever that user's policy says.
:::

## Connect in Costfluent

<Stepper>

1. Open **Settings**, then **Integrations**, select **FOCUS bucket**, open the **Connect** tab and
   select **Add access key**.
2. Choose OVHcloud as the **Provider**, and enter the bucket's region in lower case in **Region**,
   such as `gra`, `sbg`, `de` or `eu-west-par`: the export's `region`.
3. Enter the bucket's name in **Bucket**. In **Prefix**, enter the export's `pathPrefix`, or leave it
   empty when the `pathPrefix` is `./`.
4. Enter the read-only user's access key in **Access key ID** and its secret key in
   **Secret access key**.
5. Select **Test connection** to see each check, or **Connect** to save.

</Stepper>

You can connect before the first run: Costfluent accepts a prefix that holds no file yet.

## How it behaves

- OVHcloud writes a file every day at `exportHour` UTC, or every hour when `period` is `HOURLY`. Each
  file holds the month so far, in FOCUS 1.3, as a CSV file named `focus.csv` under a folder of your
  OVHcloud account's identifier.
- Costfluent reads the newest file of each month in each sync's window
  ([Data and freshness](/connect/focus-bucket#data-and-freshness)), so the `CREATE` and `REPLACE`
  policies import the same cost. `CREATE` leaves one file per day in the bucket.
- OVHcloud writes from its next run on and describes no export of earlier months.
- `DELETE /v2/finops/bucketExport/{id}` stops the export. The files it wrote stay in the bucket.

## Troubleshooting

- **The export stays in `ERROR`.** `GET /v2/finops/bucketExport/{id}/task` names the cause. Most
  often `endpointURL` starts with `https://`, the writing user may not list the bucket or write to
  it, or `bucketName` or `region` is wrong. Send the whole corrected `targetSpec` with
  `PUT /v2/finops/bucketExport/{id}`, the secret key included, which OVHcloud never returns.
- **No file appears.** The export is not `READY`, or its first run has not come yet: the next
  `exportHour` in UTC.
- **OVHcloud cost is counted twice.** An [OVHcloud](/connect/ovhcloud) API key connection imports the
  same cost. Remove one of the two connections.
- Every other message: [Troubleshooting](/connect/focus-bucket#troubleshooting) on the FOCUS bucket
  page.

## Related

- [Connect a FOCUS bucket](/connect/focus-bucket)
- [Connect OVHcloud](/connect/ovhcloud)
- [Manage connections](/connect/manage-connections)
