1+ # ========================================
2+ # Variables
3+ # ========================================
14variable "cloudflare_account_id" {
25 description = " Cloudflare account ID"
36 type = string
@@ -12,6 +15,21 @@ variable "cloudflare_zone_id" {
1215# Worker URL: https://e2e-webhook-endpoint.terraform-testing-a09.workers.dev/
1316# This worker responds with 200 OK to all requests for webhook validation
1417
18+ # ========================================
19+ # Locals
20+ # ========================================
21+ locals {
22+ common_account = var. cloudflare_account_id
23+ name_prefix = " test-integration"
24+ webhook_base_url = " https://e2e-webhook-endpoint.terraform-testing-a09.workers.dev"
25+ enable_backup = true
26+ enable_test = false
27+ }
28+
29+ # ========================================
30+ # Basic Resources
31+ # ========================================
32+
1533# Test Case 1: Basic webhook with minimal fields
1634resource "cloudflare_notification_policy_webhooks" "basic_webhook" {
1735 account_id = var. cloudflare_account_id
@@ -27,16 +45,132 @@ resource "cloudflare_notification_policy_webhooks" "full_webhook" {
2745 secret = " webhook-secret-token-12345"
2846}
2947
30- # Test Case 3: Multiple webhooks
31- resource "cloudflare_notification_policy_webhooks" "primary" {
48+ # ========================================
49+ # for_each with Maps Pattern (3 resources)
50+ # ========================================
51+ resource "cloudflare_notification_policy_webhooks" "map_example" {
52+ for_each = {
53+ " alerts" = {
54+ name = " alerts-webhook"
55+ secret = " alerts-secret-123"
56+ }
57+ " monitoring" = {
58+ name = " monitoring-webhook"
59+ secret = " monitoring-secret-456"
60+ }
61+ " security" = {
62+ name = " security-webhook"
63+ secret = " security-secret-789"
64+ }
65+ }
66+
67+ account_id = local. common_account
68+ name = each. value . name
69+ url = " ${ local . webhook_base_url } /${ each . key } "
70+ secret = each. value . secret
71+ }
72+
73+ # ========================================
74+ # for_each with Sets Pattern (4 resources)
75+ # ========================================
76+ resource "cloudflare_notification_policy_webhooks" "set_example" {
77+ for_each = toset ([
78+ " alpha" ,
79+ " beta" ,
80+ " gamma" ,
81+ " delta"
82+ ])
83+
84+ account_id = var. cloudflare_account_id
85+ name = " set-${ each . value } "
86+ url = " ${ local . webhook_base_url } /set-${ each . value } "
87+ }
88+
89+ # ========================================
90+ # count-based Resources (3 resources)
91+ # ========================================
92+ resource "cloudflare_notification_policy_webhooks" "counted" {
93+ count = 3
94+
95+ account_id = var. cloudflare_account_id
96+ name = " webhook-${ count . index } "
97+ url = " ${ local . webhook_base_url } /counted-${ count . index } "
98+ }
99+
100+ # ========================================
101+ # Conditional Creation
102+ # ========================================
103+ resource "cloudflare_notification_policy_webhooks" "conditional_enabled" {
104+ count = local. enable_backup ? 1 : 0
105+
106+ account_id = var. cloudflare_account_id
107+ name = " conditional-enabled"
108+ url = " ${ local . webhook_base_url } /conditional-enabled"
109+ }
110+
111+ resource "cloudflare_notification_policy_webhooks" "conditional_disabled" {
112+ count = local. enable_test ? 1 : 0
113+
114+ account_id = var. cloudflare_account_id
115+ name = " conditional-disabled"
116+ url = " ${ local . webhook_base_url } /conditional-disabled"
117+ }
118+
119+ # ========================================
120+ # Terraform Functions
121+ # ========================================
122+ resource "cloudflare_notification_policy_webhooks" "with_functions" {
123+ account_id = local. common_account
124+ name = join (" -" , [local . name_prefix , " function" , " example" ])
125+ url = " ${ local . webhook_base_url } /function-test"
126+ secret = " function-test-secret"
127+ }
128+
129+ # ========================================
130+ # Lifecycle Meta-Arguments
131+ # ========================================
132+ resource "cloudflare_notification_policy_webhooks" "with_lifecycle" {
133+ account_id = var. cloudflare_account_id
134+ name = " lifecycle-test"
135+ url = " ${ local . webhook_base_url } /lifecycle"
136+
137+ lifecycle {
138+ create_before_destroy = true
139+ }
140+ }
141+
142+ resource "cloudflare_notification_policy_webhooks" "with_prevent_destroy" {
143+ account_id = var. cloudflare_account_id
144+ name = " prevent-destroy-test"
145+ url = " ${ local . webhook_base_url } /prevent-destroy"
146+
147+ lifecycle {
148+ prevent_destroy = false
149+ }
150+ }
151+
152+ # ========================================
153+ # Edge Cases
154+ # ========================================
155+
156+ # Minimal resource (only required fields)
157+ resource "cloudflare_notification_policy_webhooks" "minimal" {
158+ account_id = var. cloudflare_account_id
159+ name = " minimal"
160+ url = " ${ local . webhook_base_url } /minimal"
161+ }
162+
163+ # Maximal resource (all fields populated)
164+ resource "cloudflare_notification_policy_webhooks" "maximal" {
32165 account_id = var. cloudflare_account_id
33- name = " primary-webhook"
34- url = " https://e2e-webhook-endpoint.terraform-testing-a09.workers.dev/primary"
166+ name = " maximal-webhook-with-all-fields"
167+ url = " ${ local . webhook_base_url } /maximal?param=value&test=123"
168+ secret = " maximal-secret-token-with-special-chars-!@#$"
35169}
36170
37- resource "cloudflare_notification_policy_webhooks" "backup" {
171+ # URL with special characters
172+ resource "cloudflare_notification_policy_webhooks" "special_chars" {
38173 account_id = var. cloudflare_account_id
39- name = " backup-webhook"
40- url = " https://e2e-webhook-endpoint.terraform-testing-a09.workers.dev/backup"
41- secret = " backup-secret"
174+ name = " special-chars-test"
175+ url = " ${ local . webhook_base_url } /path?query=value¶m=test"
42176}
0 commit comments