Skip to content

Commit 19c1476

Browse files
[Logs & Terraform] Recreates PR 15964 (#16790)
* Recreates PR 15964 * Apply suggestions from code review Co-authored-by: Pedro Sousa <[email protected]> * Correct placeholder for consistency --------- Co-authored-by: Pedro Sousa <[email protected]>
1 parent de43b5e commit 19c1476

File tree

6 files changed

+208
-38
lines changed

6 files changed

+208
-38
lines changed

src/content/docs/logs/logpull/enabling-log-retention/index.mdx

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,72 +5,54 @@ sidebar:
55
order: 13
66
---
77

8+
import { Render } from "~/components";
9+
810
By default, your HTTP request logs are not retained. When using the Logpull API for the first time, you will need to enable retention. You can also turn off retention at any time. Note that after retention is turned off, previously saved logs will be available until the retention period expires (refer to [Data retention period](/logs/logpull/understanding-the-basics/#data-retention-period)).
911

1012
## Endpoints
1113

1214
There are two endpoints for managing log retention:
1315

14-
- `GET /logs/control/retention/flag` - returns whether retention is on
16+
- `GET /logs/control/retention/flag` - returns the current status of retention
1517
- `POST /logs/control/retention/flag` - turns retention on or off
1618

1719
:::note[Note]
1820

19-
To make a `POST` call, you must have zone-scoped `edit` permissions, such as Super Administrator, Administrator, or Log Share.
21+
In the Linux examples below we use the optional [jq](/logs/tutorials/parsing-json-log-data/) tool to help parse the response data.
22+
23+
To make a `POST` call, you must have zone-scoped `edit` permissions, such as Super Administrator, Administrator, or Log Share. Refer to [Make API calls](/fundamentals/api/how-to/make-api-calls/) for more information.
2024

2125
:::
2226

2327
## Example API requests using cURL
2428

25-
### Check whether log retention is turned on:
29+
### Check log retention status
2630

27-
```sh
28-
curl -s -H "X-Auth-Email: <EMAIL>" -H "X-Auth-Key: <API_KEY>" -X GET "https://api.cloudflare.com/client/v4/zones/<ZONE_ID>/logs/control/retention/flag" | jq .
29-
```
31+
<Render file="check-log-retention" />
3032

31-
#### Response:
33+
If the zone has log retention [enabled](/logs/logpull/enabling-log-retention/#enabled-response) you get the value `true`, whereas a value of `false` is returned when it is [disabled](/logs/logpull/enabling-log-retention/#disabled-response).
3234

33-
```json
34-
{
35-
"errors": [],
36-
"messages": [],
37-
"result": {
38-
"flag": false
39-
},
40-
"success": true
41-
}
42-
```
35+
### Turn on log retention
4336

44-
### Turn on log retention:
37+
<Render file="enable-log-retention" />
4538

46-
On Linux or macOS:
39+
#### Enabled response
4740

48-
```bash
49-
curl -s -H "X-Auth-Email: <EMAIL>" -H "X-Auth-Key: <API_KEY>" -X POST "https://api.cloudflare.com/client/v4/zones/<ZONE_ID>/logs/control/retention/flag" -d'{"flag":true}' | jq .
50-
```
51-
52-
On Windows in Command Prompt:
53-
54-
```
55-
curl.exe -s -H "X-Auth-Email: <EMAIL>" -H "X-Auth-Key: <API_KEY>" POST "https://api.cloudflare.com/client/v4/zones/<ZONE_ID>/logs/control/retention/flag" -d "{""flag"":true}"
41+
```json
42+
{
43+
"flag": true
44+
}
5645
```
5746

58-
For further help with API calls on Windows, refer to [Making API calls on Windows](/fundamentals/api/how-to/make-api-calls/#making-api-calls-on-windows).
59-
60-
#### Parameters
47+
### Turn off log retention
6148

62-
- _flag_ - can be either `true` or `false`
49+
<Render file="disable-log-retention" />
6350

64-
#### Response:
51+
#### Disabled response
6552

6653
```json
6754
{
68-
"errors": [],
69-
"messages": [],
70-
"result": {
71-
"flag": true
72-
},
73-
"success": true
55+
"flag": false
7456
}
7557
```
7658

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
pcx_content_type: reference
3+
title: Remote R2 backend
4+
---
5+
6+
import { Render } from "~/components";
7+
8+
[Cloudflare R2](/r2/) and [Terraform remote backends](https://developer.hashicorp.com/terraform/language/settings/backends/remote) can interact with each other to provide a seamless experience for Terraform state management.
9+
10+
Cloudflare R2 is an object storage service that provides a highly available, scalable, and secure way to store and serve static assets, such as images, videos, and static websites. R2 has [S3 API compatibility](/r2/api/s3/api/) making it easy to integrate with existing cloud infrastructure and applications.
11+
12+
## Prerequisites
13+
14+
### Create R2 bucket
15+
16+
Using [Wrangler](/workers/wrangler/install-and-update/), [API](/api/operations/r2-create-bucket), or [Account View Dashboard](https://dash.cloudflare.com/?to=/:account/r2/new) create an [R2 Bucket](/r2/buckets/create-buckets/).
17+
18+
<Render file="create-r2-buckets" />
19+
20+
:::note
21+
Bucket names can only contain lowercase letters (`a-z`), numbers (`0-9`), and hyphens (`-`).
22+
:::
23+
24+
### Create scoped bucket API keys
25+
26+
Next you will need to create a [bucket scoped R2 API token](/r2/api/s3/tokens/) with `Object Read & Write` permissions. To create an API token, do the following:
27+
28+
1. In **Account Home**, select **R2**.
29+
2. Under **Account details**, select **Manage R2 API tokens**.
30+
3. Select [**Create API token**](https://dash.cloudflare.com/?to=/:account/r2/api-tokens).
31+
4. Select the **R2 Token** text to edit your API token name.
32+
5. Under **Permissions**, select the **Object Read and Write** permissions, then scope your token to your `<YOUR_BUCKET_NAME>` bucket.
33+
6. Select **Create API Token**.
34+
35+
After your token has been successfully created, review your **Secret Access Key** and **Access Key ID** values.
36+
37+
## Define R2 backend
38+
39+
Update your [`cloudflare.tf`](/terraform/tutorial/initialize-terraform/) file to include a [backend](https://developer.hashicorp.com/terraform/language/settings/backends/configuration) for the `<YOUR_BUCKET_NAME>` bucket you created above.
40+
41+
```tf
42+
terraform {
43+
backend "s3" {
44+
bucket = "<YOUR_BUCKET_NAME>"
45+
key = "/some/key/terraform.tfstate"
46+
region = "auto"
47+
skip_credentials_validation = true
48+
skip_metadata_api_check = true
49+
skip_region_validation = true
50+
skip_requesting_account_id = true
51+
skip_s3_checksum = true
52+
use_path_style = true
53+
access_key = "<YOUR_R2_ACCESS_KEY>"
54+
secret_key = "<YOUR_R2_ACCESS_SECRET>"
55+
endpoints = { s3 = "https://<YOUR_ACCOUNT_ID>.r2.cloudflarestorage.com" }
56+
}
57+
required_providers {
58+
cloudflare = {
59+
source = "cloudflare/cloudflare"
60+
version = "~> 4"
61+
}
62+
}
63+
}
64+
provider "cloudflare" {
65+
# token pulled from $CLOUDFLARE_API_TOKEN
66+
}
67+
variable "account_id" { default = "<YOUR_ACCOUNT_ID>" }
68+
```
69+
70+
## Migrate state file to R2 backend
71+
72+
After updating your `cloudflare.tf` file you can issue the `terraform init -reconfigure` command to migrate from a local state to [remote state](https://developer.hashicorp.com/terraform/language/state/remote).
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
{}
3+
4+
---
5+
6+
import { TabItem, Tabs } from "~/components";
7+
8+
<Tabs> <TabItem label="Linux">
9+
10+
```bash
11+
curl https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag \
12+
--header "Authorization: Bearer <API_TOKEN>"
13+
```
14+
15+
</TabItem> <TabItem label="CMD">
16+
17+
```txt
18+
curl.exe "https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag" --header "Authorization: Bearer <API_TOKEN>"
19+
```
20+
21+
</TabItem> <TabItem label="PowerShell">
22+
23+
```powershell
24+
$uri = "https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag"
25+
$headers = @{"Authorization" = "Bearer <API_TOKEN>"}
26+
Invoke-RestMethod -Uri $uri -Method Get -Headers $headers
27+
```
28+
29+
</TabItem> </Tabs>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
{}
3+
4+
---
5+
6+
import { TabItem, Tabs } from "~/components";
7+
8+
<Tabs> <TabItem label="Linux">
9+
10+
```bash
11+
curl https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag \
12+
--header "Authorization: Bearer <API_TOKEN>" \
13+
--header "Content-Type: application/json" \
14+
--data '{"flag": false}'
15+
```
16+
17+
</TabItem> <TabItem label="CMD">
18+
19+
```txt
20+
curl.exe "https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag" --header "Authorization: Bearer <API_TOKEN>" --data "{""flag"": false}"
21+
```
22+
23+
</TabItem> <TabItem label="PowerShell">
24+
25+
```powershell
26+
$uri = "https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag"
27+
$headers = @{"Authorization" = "Bearer <API_TOKEN>"}
28+
$bodyFlag = @{flag = $false} | ConvertTo-Json
29+
Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $bodyFlag -ContentType "application/json"
30+
```
31+
32+
</TabItem> </Tabs>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
{}
3+
4+
---
5+
6+
import { TabItem, Tabs } from "~/components";
7+
8+
<Tabs> <TabItem label="Linux">
9+
10+
```bash
11+
curl https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag \
12+
--header "Authorization: Bearer <API_TOKEN>" \
13+
--header "Content-Type: application/json" \
14+
--data '{"flag": true}'
15+
```
16+
17+
</TabItem> <TabItem label="CMD">
18+
19+
```txt
20+
curl.exe "https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag" --header "Authorization: Bearer <API_TOKEN>" --data "{""flag"": true}"
21+
```
22+
23+
</TabItem> <TabItem label="PowerShell">
24+
25+
```powershell
26+
$uri = "https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag"
27+
$headers = @{"Authorization" = "Bearer <API_TOKEN>"}
28+
$bodyFlag = @{flag = $true} | ConvertTo-Json
29+
Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $bodyFlag -ContentType "application/json"
30+
```
31+
32+
</TabItem> </Tabs>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
{}
3+
4+
---
5+
6+
import { TabItem, Tabs } from "~/components";
7+
8+
<Tabs> <TabItem label="Wrangler">
9+
10+
```sh
11+
wrangler r2 bucket create <YOUR_BUCKET_NAME>
12+
```
13+
14+
</TabItem> <TabItem label="API">
15+
16+
```bash
17+
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/r2/buckets \
18+
--header "Authorization: Bearer <API_TOKEN>" \
19+
--header "Content-Type: application/json" \
20+
--data '{"name": "<YOUR_BUCKET_NAME>"}'
21+
```
22+
23+
</TabItem> </Tabs>

0 commit comments

Comments
 (0)