forked from Madh93/cloudflare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
86 lines (71 loc) · 1.89 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
provider "cloudflare" {
api_token = var.cloudflare_api_token
}
########
# Zone #
########
resource "cloudflare_zone" "default" {
account_id = var.cloudflare_account_id
zone = var.domain_name
}
resource "cloudflare_zone_settings_override" "default" {
zone_id = cloudflare_zone.default.id
settings {
ssl = "full"
}
}
###############
# DNS Records #
###############
resource "cloudflare_record" "default" {
for_each = var.records
zone_id = cloudflare_zone.default.id
type = each.value.type
name = each.value.name
value = each.value.content
comment = lookup(each.value, "comment", null)
proxied = lookup(each.value, "proxied", true)
ttl = lookup(each.value, "ttl", 1)
}
##################
# Firewall Rules #
##################
resource "cloudflare_filter" "default" {
for_each = var.firewall_rules
zone_id = cloudflare_zone.default.id
expression = each.value.expression
}
resource "cloudflare_firewall_rule" "default" {
for_each = var.firewall_rules
zone_id = cloudflare_zone.default.id
filter_id = cloudflare_filter.default[each.key].id
description = lookup(each.value, "description", "")
action = lookup(each.value, "action", "block")
}
###################
# Transform Rules #
###################
resource "cloudflare_ruleset" "extra_security_headers" {
zone_id = cloudflare_zone.default.id
name = "default"
kind = "zone"
phase = "http_response_headers_transform"
rules {
description = "Extra Security Headers"
action = "rewrite"
expression = "(ssl)"
enabled = true
action_parameters {
headers {
name = "Permissions-Policy"
operation = "set"
value = "camera=(),microphone=(),usb=()"
}
headers {
name = "Strict-Transport-Security"
operation = "set"
value = "max-age=31536000; includeSubDomains"
}
}
}
}