Skip to content

Instantly share code, notes, and snippets.

@chriswahl
Last active June 22, 2020 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriswahl/551ccdb3e3c2b7ff3e745aaa4c842327 to your computer and use it in GitHub Desktop.
Save chriswahl/551ccdb3e3c2b7ff3e745aaa4c842327 to your computer and use it in GitHub Desktop.
Terraform for Cloudflare Firewall Rule
provider "cloudflare" {
version = "~> 2.7"
api_token = "TOKEN"
}
data "cloudflare_zones" "wordpress" {
filter {
name = "wahlnetwork.com"
status = "active"
paused = false
}
}
resource "cloudflare_filter" "wordpress" {
zone_id = data.cloudflare_zones.wordpress.zones[0].id
description = "Block wp-admin by IP"
expression = "(not ip.src in {PUBLIC_IP_ADDRESS} and http.request.uri.path contains \"/wp-admin\")"
}
resource "cloudflare_firewall_rule" "wordpress" {
zone_id = data.cloudflare_zones.wordpress.zones[0].id
description = cloudflare_filter.wordpress.description
filter_id = cloudflare_filter.wordpress.id
action = "block"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment