diff --git a/src/content/docs/rules/url-forwarding/bulk-redirects/terraform-example.mdx b/src/content/docs/rules/url-forwarding/bulk-redirects/terraform-example.mdx new file mode 100644 index 000000000000000..bd4d4e66cb01a51 --- /dev/null +++ b/src/content/docs/rules/url-forwarding/bulk-redirects/terraform-example.mdx @@ -0,0 +1,128 @@ +--- +title: Configure Bulk Redirects using Terraform +pcx_content_type: configuration +sidebar: + order: 8 + label: Configure using Terraform +--- + +import { Render, Tabs, TabItem } from "~/components"; + + + +This Terraform example configures account-level Bulk Redirects. It creates a [Bulk Redirect List](/rules/url-forwarding/bulk-redirects/concepts/#bulk-redirect-lists) populated with [URL redirects](/rules/url-forwarding/bulk-redirects/concepts/#url-redirects) and a corresponding [Bulk Redirect Rule](/rules/url-forwarding/bulk-redirects/concepts/#bulk-redirect-rules) to activate them. + +```tf +# Cloudflare account ID +variable "cloudflare_account_id" { + default = "" +} + +# Bulk redirect list description +variable "bulk_redirect_list_description" { + default = "my bulk redirect description" +} + +# Bulk redirect list name +variable "bulk_redirect_list_name" { + default = "my_bulk_redirect_list_name" +} + +# Bulk redirect list item (URL redirect) +variable "bulk_redirects" { + type = map(object({ + source_url = string + target_url = string + status_code = number + })) + + default = { + "redirect1" = { + source_url = "https://source.url/redirect/1" + target_url = "https://target.url/?redirect=1" + status_code = 301 + } + "redirect2" = { + source_url = "https://source.url/redirect/2" + target_url = "https://target.url/?redirect=2" + status_code = 302 + } + "redirect3" = { + source_url = "https://source.url/redirect/3" + target_url = "https://target.url/?redirect=3" + status_code = 307 + } + } +} + +# Create redirect list +resource "cloudflare_list" "bulk_redirect_to_id" { + account_id = var.cloudflare_account_id + name = var.bulk_redirect_list_name + description = var.bulk_redirect_list_description + kind = "redirect" +} + +# Add redirect item into the redirect list +resource "cloudflare_list_item" "bulk_redirect_to_id_item" { + for_each = { for redirect in var.bulk_redirects : "${redirect.source_url}" => redirect } + + account_id = var.cloudflare_account_id + list_id = cloudflare_list.bulk_redirect_to_id.id + + redirect { + source_url = each.value.source_url + target_url = each.value.target_url + status_code = each.value.status_code + } + + depends_on = [ + cloudflare_list.bulk_redirect_to_id + ] + +} + +# Create bulk redirect and attach redirect list +resource "cloudflare_ruleset" "bulk_root_redirect_to_id" { + account_id = var.cloudflare_account_id + name = var.bulk_redirect_list_name + description = var.bulk_redirect_list_description + kind = "root" + phase = "http_request_redirect" + + rules { + action = "redirect" + action_parameters { + from_list { + name = var.bulk_redirect_list_name + key = "http.request.full_uri" + } + } + expression = "http.request.full_uri in ${"$"}${var.bulk_redirect_list_name}" + description = var.bulk_redirect_list_description + enabled = true + } + + depends_on = [ + cloudflare_list_item.bulk_redirect_to_id_item + ] +} +``` + +## Required token permissions + +Your API token must have at least the following [permissions](/fundamentals/api/reference/permissions/): + + + +- Account Filter Lists > Edit +- Bulk URL Redirects > Edit + + + +- Account Rule Lists Write +- Bulk URL Redirects Write + + + + diff --git a/src/content/partials/fundamentals/account-permissions-table.mdx b/src/content/partials/fundamentals/account-permissions-table.mdx index ac75ee15c9ca8b9..4f270c3a4b77a0b 100644 --- a/src/content/partials/fundamentals/account-permissions-table.mdx +++ b/src/content/partials/fundamentals/account-permissions-table.mdx @@ -47,8 +47,8 @@ import { Markdown } from "~/components"; | { props.src === "api" && "Account" } API Gateway {props.editWord} | Grants write access to [API Gateway (including API Shield)](/api-shield/) for all domains in an account. | | Billing Read | Grants read access to [billing profile, subscriptions, and access to fetch invoices](/billing/) and entitlements. | | Billing {props.editWord} | Grants write access to [billing profile, subscriptions, and access to fetch invoices and entitlements](/billing/). | -| Bulk URL Redirects Read | Grants read access to [Bulk URL Redirects](/rules/url-forwarding/bulk-redirects/). | -| Bulk URL Redirects {props.editWord} | Grants write access to [Bulk URL Redirects](/rules/url-forwarding/bulk-redirects/). | +| Bulk URL Redirects Read | Grants read access to [Bulk Redirects](/rules/url-forwarding/bulk-redirects/). | +| Bulk URL Redirects {props.editWord} | Grants write access to [Bulk Redirects](/rules/url-forwarding/bulk-redirects/). | | China Network Steering Read | Grants read access to [China Network Steering](/china-network/). | | China Network Steering {props.editWord} | Grants write access to [China Network Steering](/china-network/). | | Cloudchamber Read | Grants read access to Cloudchamber deployments. |