Skip to content

Commit c6ad133

Browse files
committed
policies
1 parent 2624fa6 commit c6ad133

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

src/content/docs/learning-paths/replace-vpn/build-policies/create-policy.mdx

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,25 @@ curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules \
7777
}'
7878
```
7979

80-
</TabItem> </Tabs>
80+
</TabItem>
81+
<TabItem label="Terraform (v5)">
82+
83+
```tf
84+
resource "cloudflare_zero_trust_gateway_policy" "dns_allow_wiki_domains" {
85+
name = "Company Wiki DNS policy"
86+
enabled = true
87+
account_id = var.cloudflare_account_id
88+
description = "Managed by Terraform - Allow employees to access company wiki domains."
89+
precedence = 102
90+
action = "allow"
91+
filters = ["dns"]
92+
traffic = "any(dns.domains[*] in ${"$"}${cloudflare_zero_trust_list.wiki_domains.id})"
93+
identity = "identity.email matches \".*@example.com\""
94+
}
95+
```
96+
97+
</TabItem>
98+
</Tabs>
8199

82100
## Example network policy
83101

@@ -135,7 +153,25 @@ curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules \
135153
}'
136154
```
137155

138-
</TabItem> </Tabs>
156+
</TabItem>
157+
<TabItem label="Terraform (v5)">
158+
159+
```tf
160+
resource "cloudflare_zero_trust_gateway_policy" "network_allow_wiki_IPs" {
161+
name = "Company Wiki Network policy"
162+
enabled = true
163+
account_id = var.cloudflare_account_id
164+
description = "Managed by Terraform - Allow employees to access company wiki IPs."
165+
precedence = 103
166+
action = "allow"
167+
filters = ["l4"]
168+
traffic = "net.dst.ip in ${"$"}${cloudflare_zero_trust_list.wiki_IPs.id}"
169+
identity = "identity.email matches \".*@example.com\""
170+
}
171+
```
172+
173+
</TabItem>
174+
</Tabs>
139175

140176
### Catch-all policy
141177

@@ -197,7 +233,24 @@ curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules \
197233
}'
198234
```
199235

200-
</TabItem> </Tabs>
236+
</TabItem>
237+
<TabItem label="Terraform (v5)">
238+
239+
```tf
240+
resource "cloudflare_zero_trust_gateway_policy" "network_catch_all" {
241+
name = "Catch-all block policy"
242+
enabled = true
243+
account_id = var.cloudflare_account_id
244+
description = "Managed by Terraform - Block access to private network."
245+
precedence = 14002
246+
action = "block"
247+
filters = ["l4"]
248+
traffic = "net.dst.ip in ${"$"}${cloudflare_zero_trust_list.private_IPs.id} or any(net.sni.domains[*] in ${"$"}${cloudflare_zero_trust_list.private_domains.id})"
249+
}
250+
```
251+
252+
</TabItem>
253+
</Tabs>
201254

202255
Network policies are evaluated in [top-down order](/cloudflare-one/policies/gateway/order-of-enforcement/#order-of-precedence), so if a user does not match an explicitly defined policy for an application, they will be blocked.
203256
To learn how multiple policies interact, refer to [Order of enforcement](/cloudflare-one/policies/gateway/order-of-enforcement/).

0 commit comments

Comments
 (0)