Cloudflare_r2_custom_domain Can't Be Used With Buckets That Have A Jurisdiction
Introduction
Cloudflare R2 is a highly scalable and secure object storage service that allows users to store and serve large amounts of data. However, when trying to create a custom domain for an R2 bucket, users may encounter an error if the bucket has a jurisdiction. In this article, we will explore this issue and provide a solution.
Problem Statement
When creating a custom domain for an R2 bucket using the cloudflare_r2_custom_domain
resource, users may encounter a 404 Not Found error if the bucket has a jurisdiction. This error occurs because the Cloudflare API does not support creating custom domains for buckets with a jurisdiction.
Terraform Configuration
The following Terraform configuration creates an R2 bucket with a jurisdiction and attempts to create a custom domain for it:
resource "cloudflare_r2_bucket" "media_bucket" {
account_id = local.amine_account_id
name = "zaman-media"
location = local.media_bucket_location
jurisdiction = local.media_bucket_jurisdiction
storage_class = "Standard"
}
resource "cloudflare_r2_custom_domain" "media_bucket_public_domain" {
account_id = local.amine_account_id
bucket_name = cloudflare_r2_bucket.media_bucket.name
domain = "media.zaman.app"
enabled = true
zone_id = data.cloudflare_zone.zaman.zone_id
min_tls = "1.2" // Recommended to use at least TLS 1.2 for security
depends_on = [ cloudflare_r2_bucket.media_bucket ]
}
Error Message
The error message returned by the Cloudflare API is:
{
"success": false,
"errors": [
{
"code": 10006,
"message": "The specified bucket does not exist."
}
],
"messages": [],
"result": null
}
Steps to Reproduce
To reproduce this issue, follow these steps:
- Create an R2 bucket with a jurisdiction using the
cloudflare_r2_bucket
resource. - Attempt to create a custom domain for the bucket using the
cloudflare_r2_custom_domain
resource.
Additional Factoids
To illustrate how the Cloudflare API is behaving, the following curl
commands can be used:
# This will fail
curl -X GET "https://api.cloudflare.com/client/v4/accounts/<redacted_account_id>/r2/buckets/my-bucket" \
-H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}"
# This will succeed
curl -X GET "https://api.cloudflare.com/client/v4/accounts/<redacted_account_id>/r2/buckets" \
-H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \
-H "cf-r2-jurisdiction: eu"
References
For more information on the Cloudflare R2 API, please refer to the following documentation:
Conclusion
In conclusion, the cloudflare_r2_custom_domain
resource cannot be used with buckets that have a jurisdiction. This is due to a limitation in the Cloudflare API. To resolve this issue, users can create a custom domain for a bucket without a jurisdiction or use a different resource, such as the cloudflare_r2_bucket
resource, to manage the bucket.
Workaround
One possible workaround is to create a custom domain for a bucket without a jurisdiction. This can be achieved by removing the jurisdiction
attribute from the cloudflare_r2_bucket
resource.
resource "cloudflare_r2_bucket" "media_bucket" {
account_id = local.amine_account_id
name = "zaman-media"
location = local.media_bucket_location
storage_class = "Standard"
}
resource "cloudflare_r2_custom_domain" "media_bucket_public_domain" {
account_id = local.amine_account_id
bucket_name = cloudflare_r2_bucket.media_bucket.name
domain = "media.zaman.app"
enabled = true
zone_id = data.cloudflare_zone.zaman.zone_id
min_tls = "1.2" // Recommended to use at least TLS 1.2 for security
depends_on = [ cloudflare_r2_bucket.media_bucket ]
}
Introduction
In our previous article, we explored the issue of creating a custom domain for an R2 bucket using the cloudflare_r2_custom_domain
resource when the bucket has a jurisdiction. In this article, we will provide a Q&A section to address some of the most frequently asked questions related to this issue.
Q: What is the cause of this issue?
A: The cause of this issue is a limitation in the Cloudflare API. The API does not support creating custom domains for buckets with a jurisdiction.
Q: Can I create a custom domain for a bucket with a jurisdiction using the Cloudflare API?
A: No, you cannot create a custom domain for a bucket with a jurisdiction using the Cloudflare API. The API will return a 404 Not Found error if you attempt to do so.
Q: What is the workaround for this issue?
A: One possible workaround is to create a custom domain for a bucket without a jurisdiction. This can be achieved by removing the jurisdiction
attribute from the cloudflare_r2_bucket
resource.
Q: Will this workaround affect my existing buckets?
A: No, this workaround will not affect your existing buckets. You can create a new bucket without a jurisdiction and use the cloudflare_r2_custom_domain
resource to create a custom domain for it.
Q: Can I use a different resource to manage my bucket?
A: Yes, you can use a different resource, such as the cloudflare_r2_bucket
resource, to manage your bucket. This will allow you to create a custom domain for your bucket without a jurisdiction.
Q: What are the implications of using a workaround?
A: Using a workaround may have implications for your use case. You should carefully evaluate the implications before implementing a workaround.
Q: Can I report this issue to Cloudflare?
A: Yes, you can report this issue to Cloudflare. You can submit a support ticket or contact your account team to report the issue.
Q: Will Cloudflare fix this issue?
A: Cloudflare may fix this issue in a future release. However, there is no guarantee that the issue will be fixed.
Q: Can I use a different object storage service?
A: Yes, you can use a different object storage service that supports creating custom domains for buckets with a jurisdiction.
Conclusion
In conclusion, the cloudflare_r2_custom_domain
resource cannot be used with buckets that have a jurisdiction. However, there are workarounds available, such as creating a custom domain for a bucket without a jurisdiction or using a different resource to manage the bucket. It is essential to carefully evaluate the implications of using a workaround before implementing it.
Additional Resources
For more information on the Cloudflare R2 API, please refer to the following documentation:
Support
If you have any questions or need further assistance, please don't hesitate to contact us. We are here to help.