From 463d0c3c0cdeed9579666e255cbe67585acc4053 Mon Sep 17 00:00:00 2001 From: Hubert Cornet Date: Mon, 17 Nov 2025 14:55:15 +0100 Subject: [PATCH] Update gateway_policy.tf --- gateway_policy.tf | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/gateway_policy.tf b/gateway_policy.tf index 9420a82..9ca8933 100644 --- a/gateway_policy.tf +++ b/gateway_policy.tf @@ -25,15 +25,15 @@ resource "cloudflare_zero_trust_gateway_policy" "block_malware" { # POLICY: Block Ads locals { - # Iterate through each pihole_domain_list resource and extract its ID - pihole_domain_lists = [for k, v in cloudflare_teams_list.pihole_domain_lists : v.id] + # Iterate through each ads_domain_list resource and extract its ID + ads_domain_lists = [for k, v in cloudflare_teams_list.ads_domain_lists : v.id] # Format the values: remove dashes and prepend $ - pihole_domain_lists_formatted = [for v in local.pihole_domain_lists : format("$%s", replace(v, "-", ""))] + ads_domain_lists_formatted = [for v in local.ads_domain_lists : format("$%s", replace(v, "-", ""))] # Create filters to use in the policy - pihole_ad_filters = formatlist("any(dns.domains[*] in %s)", local.pihole_domain_lists_formatted) - pihole_ad_filter = join(" or ", local.pihole_ad_filters) + ads_ad_filters = formatlist("any(dns.domains[*] in %s)", local.ads_domain_lists_formatted) + ads_ad_filter = join(" or ", local.ads_ad_filters) } resource "cloudflare_zero_trust_gateway_policy" "block_ads" { @@ -48,7 +48,7 @@ resource "cloudflare_zero_trust_gateway_policy" "block_ads" { # Block domain belonging to lists (defined below) filters = ["dns"] action = "block" - traffic = local.pihole_ad_filter + traffic = local.ads_ad_filter rule_settings { block_page_enabled = false @@ -57,31 +57,31 @@ resource "cloudflare_zero_trust_gateway_policy" "block_ads" { locals { # The full path of the list holding the domain list - pihole_domain_list_file = "${path.module}/lists/pihole_domain_list.txt" + ads_domain_list_file = "${path.module}/lists/pihole_domain_list.txt" # Parse the file and create a list, one item per line - pihole_domain_list = split("\n", file(local.pihole_domain_list_file)) + ads_domain_list = split("\n", file(local.ads_domain_list_file)) # Remove empty lines - pihole_domain_list_clean = [for x in local.pihole_domain_list : x if x != ""] + ads_domain_list_clean = [for x in local.ads_domain_list : x if x != ""] # Use chunklist to split a list into fixed-size chunks # It returns a list of lists - pihole_aggregated_lists = chunklist(local.pihole_domain_list_clean, 1000) + ads_aggregated_lists = chunklist(local.ads_domain_list_clean, 1000) # Get the number of lists (chunks) created - pihole_list_count = length(local.pihole_aggregated_lists) + ads_list_count = length(local.ads_aggregated_lists) } -resource "cloudflare_zero_trust_list" "pihole_domain_lists" { +resource "cloudflare_zero_trust_list" "ads_domain_lists" { account_id = local.cloudflare_account_id for_each = { - for i in range(0, local.pihole_list_count) : - i => element(local.pihole_aggregated_lists, i) + for i in range(0, local.ads_list_count) : + i => element(local.ads_aggregated_lists, i) } - name = "pihole_domain_list_${each.key}" + name = "ads_domain_list_${each.key}" type = "DOMAIN" items = each.value }