Using Terraform to manage firewall rules and filters

I’m trying to move from managing firewall rules for multiple domains in the UI to managing them with Terraform. I’m having problems with duplicate filters when replacing the firewall rule.

First I created the firewall rule in the UI to compose the filter expression and test it out. Then when I wanted to add the firewall rule and filter to the code I deleted the rule and let Terraform recreate it. It appears that when deleting the firewall rule in the UI it does not also delete the related filter. When I ran terraform apply and it tried to create the filter I got the following error.

"code": 10102,
"message": "config duplicates an already existing config",

So is it the case that I can’t create another filter with the same expression?

This time I ended up deleting the existing filter by calling the API but this isn’t ideal.

Is there some better way to accomplish this?


What I’ve noticed when codifying our Cloudflare configuration to Terraform is that filter expressions are a different entity from firewall rules that use them.

See Cloudflare API v4 Documentation for instance. I think the UI doesn’t show this difference, but both the API & Terraform do. You probably didn’t delete the filter expression directly?