Skip to content
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

Add support to retrieve ruleset ids to successfully import custom cloudflare_ruleset #2804

Closed
jbmartino opened this issue Sep 28, 2023 · 5 comments
Labels
kind/support Categorizes issue or PR as related to user support.

Comments

@jbmartino
Copy link

Current Terraform and Cloudflare provider version

Terraform v1.4.6
Cloudflare v4.15.0

Description

The following curl request only returns kind: managed/zone rulesets and never returns custom rulesets so it's impossible to get the ruleset id in order to import custom cloudflare_ruleset
curl --request GET
--url https://api.cloudflare.com/client/v4/accounts/zone_id/rulesets
--header 'Authorization: Bearer api_token'
--header 'Content-Type: application/json'

Use cases

Unless we are able to obtain ruleset ids for kind: custom cloudflare_ruleset we are unable to import existing custom rulesets into terraform.

Potential Terraform configuration

resource "cloudflare_ruleset" "videos" {
  account_id = local.account_id
  name       = "Videos"
  kind       = "custom"
  phase      = "http_request_firewall_custom"
  rules {
    action     = "log"
    expression = "(http.request.uri.path eq \"*.mov\" or http.request.uri.path eq \"*.mp4\")"
    enabled    = true
  }
}

References

https://github.com/cloudflare/terraform-provider-cloudflare/pull/2054/files this solves import for cloudflare_ruleset however it's currently not possible to retrieve ruleset ids for custom rulesets

@jbmartino jbmartino added kind/enhancement Categorizes issue or PR as related to improving an existing feature. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Sep 28, 2023
@github-actions
Copy link
Contributor

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@jacobbednarz
Copy link
Member

jacobbednarz commented Sep 28, 2023

have you tried using the cloudflare_ruleset data source? https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/data-sources/rulesets#filter

that has worked for me in the past to get any rule type.

@jbmartino
Copy link
Author

jbmartino commented Sep 29, 2023

@jacobbednarz Thanks for the suggestion. I created a few different data sources for various custom rules we have. They all return the same ruleset id and when I try to run a zone import for our cloudflare_ruleset.videos resource for example I get the following error:

| While attempting to import an existing object to "cloudflare_ruleset.videos", 
| the provider detected that no object exists with the given id. Only pre-existing objects
| can be imported; check that the id is correct and that it is associated 
| with the provider's configured region or endpoint, or use "terraform apply" 
| to create a new remote object for this resource.

After further digging maybe the issue lies in the fact that I'm trying to import custom "rules" rather than custom "rulesets"
https://developers.cloudflare.com/waf/custom-rules/
https://developers.cloudflare.com/waf/custom-rulesets/create-dashboard/

@jacobbednarz
Copy link
Member

you don't import rules; you import the entire ruleset and the rules are a part of that.

@jacobbednarz jacobbednarz added triage/needs-information Indicates an issue needs more information in order to work on it. kind/support Categorizes issue or PR as related to user support. and removed kind/enhancement Categorizes issue or PR as related to improving an existing feature. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. triage/needs-information Indicates an issue needs more information in order to work on it. labels Oct 11, 2023
@jacobbednarz
Copy link
Member

closing this off as a misunderstanding of how the cloudflare_ruleset resource currently works. if you manage to find a bug or something missing, please open a new issue following the issue template.

@jacobbednarz jacobbednarz closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Categorizes issue or PR as related to user support.
Projects
None yet
Development

No branches or pull requests

2 participants