Repository navigation
Expand file tree
/
Copy pathmain.tf
More file actions
133 lines (119 loc) · 3.63 KB
/
Copy pathmain.tf
File metadata and controls
133 lines (119 loc) · 3.63 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
resource "cloudflare_zone" "primary" {
account = {
id = var.account_id
}
name = var.zone_name
type = "full"
lifecycle {
prevent_destroy = true
}
}
resource "cloudflare_dns_record" "records" {
for_each = var.dns_records
zone_id = cloudflare_zone.primary.id
name = each.value.name
type = each.value.type
content = each.value.content
ttl = each.value.ttl
proxied = each.value.proxied
priority = each.value.priority
comment = each.value.comment
tags = each.value.tags
private_routing = each.value.private_routing
settings = each.value.settings
}
resource "cloudflare_r2_bucket" "buckets" {
for_each = var.r2_buckets
account_id = var.account_id
name = each.key
jurisdiction = each.value.jurisdiction
location = each.value.location
storage_class = each.value.storage_class
lifecycle {
prevent_destroy = true
}
}
resource "cloudflare_r2_bucket_lock" "retention" {
for_each = {
for name, bucket in var.r2_buckets : name => bucket
if bucket.retention_lock_days != null
}
account_id = var.account_id
bucket_name = cloudflare_r2_bucket.buckets[each.key].name
jurisdiction = cloudflare_r2_bucket.buckets[each.key].jurisdiction
rules = [{
id = "archive-retention"
enabled = true
prefix = ""
condition = {
type = "Age"
max_age_seconds = each.value.retention_lock_days * 86400
}
}]
lifecycle {
prevent_destroy = true
}
}
resource "cloudflare_r2_bucket_lifecycle" "rules" {
for_each = var.r2_lifecycle_rules
account_id = var.account_id
bucket_name = cloudflare_r2_bucket.buckets[each.key].name
jurisdiction = try(
cloudflare_r2_bucket.buckets[each.key].jurisdiction,
"default"
)
rules = [
for rule in each.value : {
id = rule.id
enabled = rule.enabled
conditions = {
prefix = rule.prefix
}
abort_multipart_uploads_transition = rule.abort_multipart_uploads_after_days == null ? null : {
condition = {
max_age = rule.abort_multipart_uploads_after_days * 86400
type = "Age"
}
}
delete_objects_transition = rule.delete_objects_after_days == null ? null : {
condition = {
max_age = rule.delete_objects_after_days * 86400
type = "Age"
}
}
storage_class_transitions = rule.transition_to_infrequent_access_after_days == null ? [] : [{
condition = {
max_age = rule.transition_to_infrequent_access_after_days * 86400
type = "Age"
}
storage_class = "InfrequentAccess"
}]
}
]
}
resource "cloudflare_account_token" "tokens" {
for_each = var.account_tokens
account_id = var.account_id
name = each.value.name
policies = [
for policy in each.value.policies : {
effect = policy.effect
permission_groups = [
for permission_group_id in policy.permission_group_ids : {
id = permission_group_id
}
]
resources = jsonencode(policy.resources)
}
]
condition = length(each.value.allowed_cidrs) == 0 && length(each.value.denied_cidrs) == 0 ? null : {
# An empty list is sent as null, not []: `in = []` would require the caller to
# belong to an empty allowed set and make a deny-only token unusable.
request_ip = {
in = length(each.value.allowed_cidrs) == 0 ? null : each.value.allowed_cidrs
not_in = length(each.value.denied_cidrs) == 0 ? null : each.value.denied_cidrs
}
}
not_before = each.value.not_before
expires_on = each.value.expires_on
}