# Azure FOCUS export

Azure Cost Management can export your cost as FOCUS files into a storage container of yours every
day, and Costfluent reads that container as a [FOCUS bucket](/connect/focus-bucket) on Azure Blob
Storage. It is the optional second path: [Connect Azure](/connect/azure) is the recommended one,
with no file export to run. Connect one of the two for a subscription. When both carry the same
subscription, Costfluent warns **Cost counted twice**: on the FOCUS bucket connection's page once the
export's first rows arrive, or when the Azure connection is made after it.

## Before you start

- The Costfluent access under [Prerequisites](/connect/focus-bucket#prerequisites).
- An Enterprise Agreement, a Microsoft Customer Agreement or a Microsoft Partner Agreement. Azure
  offers no FOCUS export for pay-as-you-go subscriptions.
- A role that may create exports at the scope you export, such as Owner or Contributor, and a
  storage account you may write to, or the right to create one.
- A storage account Costfluent can reach from the public internet: it reads the container from
  outside Azure.

## Turn on the export

<Stepper>

1. In the Azure portal, open "Cost Management", select the scope to export, such as the billing
   account for every subscription it pays, and select "Exports", then "+ Create".
2. On "Basics", select "Create your own export", then "Next".
3. On "Datasets", select "+ Add export". Choose "Cost and usage details (FOCUS)" as the "Type of
   data", the newest "Dataset version", and "Daily export of month-to-date costs" as the
   "Frequency". Enter an "Export name", note it, and select "Add".
4. On the destination tab, keep "Azure blob storage" as the "Storage type", and choose the
   subscription, the resource group and the storage account. Enter a container that already exists,
   or create it first under the storage account's "Containers", and a directory, such as `focus`, and
   note both. Azure would create a new container only at the export's first run, and the SAS and the
   connection need it before then.
5. Choose "CSV" as the "Format" with "Gzip" as the "Compression type", and leave "Overwrite data"
   on.
6. Select "Review + create", then "Create". To have the first run now instead of at the next
   scheduled one, open the export and select "Run now".

</Stepper>

CSV lets **Test connection** sample the rows before you save. Parquet with Snappy imports as well,
but the report then only counts its files.

## Create a read-only key

Costfluent reads the container with a SAS that grants only Read and List, the rules the FOCUS bucket
page sets under [Create a read-only key](/connect/focus-bucket#create-a-read-only-key).

<Stepper>

1. In the Azure portal, open the storage account, then "Containers".
2. Select the export's container, open its "..." menu, and select "Generate SAS".
3. Choose "Account key" as the "Signing method", one of the account's keys as the "Signing key",
   and "None" as the "Stored access policy".
4. Under "Permissions", select only "Read" and "List".
5. Set the "Expiry", and keep "Allowed protocols" at HTTPS only.
6. Select "Generate SAS token and URL", and copy the "Blob SAS token", not the "Blob SAS URL". Azure
   shows it once.

</Stepper>

With the Azure CLI:

```bash
az storage container generate-sas \
  --account-name <storage account> \
  --name <container> \
  --permissions rl \
  --https-only \
  --expiry <YYYY-MM-DDTHH:MMZ> \
  --auth-mode key \
  --output tsv
```

## Connect in Costfluent

<Stepper>

1. Open **Settings**, then **Integrations**, select **FOCUS bucket**, open the **Connect** tab and
   select **Add access key**.
2. Choose **Azure Blob Storage** as the **Provider**, and enter the storage account's name in
   **Storage account**.
3. Enter the container in **Container**, and in **Prefix** the directory and the export's name, such
   as `focus/<export name>`.
4. Paste the "Blob SAS token" in **SAS token**.
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

- Azure exports every day into a folder per month, named for the month's first and last day, such
  as `20261201-20261231`. Each run holds the month so far, and with "Overwrite data" on, a month's
  folder keeps only the newest run.
- Costfluent reads the newest run of each month in each sync's window
  ([Data and freshness](/connect/focus-bucket#data-and-freshness)). The `manifest.json` Azure writes
  beside each run's files is skipped, never read.
- In the first five days of a month, Azure also exports the month before again, and Costfluent
  collects that month again.
- To import months from before the export, select "Export selected dates" on the export, one month
  at a time.
- The SAS's expiry is the connection's: replace it in time, as
  [Rotating or removing access](/connect/focus-bucket#rotating-or-removing-access) describes.

## Troubleshooting

- **"Cost and usage details (FOCUS)" is not offered.** The scope is a pay-as-you-go subscription or
  a management group, which Azure cannot export FOCUS for. Choose a billing account, a billing
  profile, an enrollment or a subscription under one of the agreements above.
- **No file arrives.** A run can take up to 24 hours. Select "Run now" on the export, and check
  its run history.
- **The connection saves, but no cost arrives.** The **Prefix** is not the folder above the monthly
  folders, so Costfluent finds no file it reads there. A connection keeps its location, so remove it
  and connect again with the directory and the export's name, such as `focus/<export name>`.
- **"There is no container … in the storage account …".** The container does not exist yet. Create
  it under the storage account's "Containers", or wait for the export's first run.
- **Azure cost is counted twice.** An [Azure](/connect/azure) connection carries the same
  subscription. Remove one of the two connections.
- Every other message, the SAS messages included: [Troubleshooting](/connect/focus-bucket#troubleshooting)
  on the FOCUS bucket page.

## Related

- [Connect a FOCUS bucket](/connect/focus-bucket)
- [Connect Azure](/connect/azure)
- [Manage connections](/connect/manage-connections)
