-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Create terraform-example for bulk redirect #22416
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0e0e2e1
Create terraform-example for bulk redirect
keefetangcf ce67f97
PCX update (based on SME review)
pedrosousa 54d7e27
Merge branch 'production' into patch-6
pedrosousa 9a08f7d
Update page order
pedrosousa fa799b3
Add required permissions
pedrosousa 7b66777
Update permissions description
pedrosousa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
src/content/docs/rules/url-forwarding/bulk-redirects/terraform-example.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| --- | ||
| title: Create a bulk redirect rule using Terraform | ||
| pcx_content_type: configuration | ||
| sidebar: | ||
| order: 6 | ||
| label: Create bulk redirect using Terraform | ||
| --- | ||
|
|
||
| import { Render } from "~/components"; | ||
|
|
||
| <Render file="v4-code-snippets" product="terraform" /> | ||
|
|
||
| The following example defines bulk redirect rules for an account using Terraform. The rule creates a redirect list item and a bulk URL redirect rule from the list to visitors based on the defined redirect list. | ||
pedrosousa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```tf | ||
| # Cloudflare account ID | ||
| variable "cloudflare_account_id" { | ||
| default = "<ACCOUNT_ID>" | ||
| } | ||
|
|
||
| # 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 | ||
| 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 | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| <Render file="terraform-additional-resources" /> | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.