-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariables.tf
60 lines (53 loc) · 1.51 KB
/
variables.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
variable "additional_ports" {
type = list(number)
description = "Any additional tcp ports that should be addred to the egress rules"
default = []
}
variable "name" {
type = string
description = "The name of the security group"
default = ""
}
variable "tags" {
type = map(any)
description = "The tags to apply to the security group and rules"
default = {}
}
variable "vpc_id" {
type = string
description = "The ID of the VPC to place the security group within"
}
locals {
name = var.name == "" ? "CloudflareIngress-${var.vpc_id}" : var.name
ports = toset(length(var.additional_ports) == 0 ? ["443"] : concat(["443"], var.additional_ports))
ipv4_rules = merge(flatten(concat(
[
for port in local.ports : [
for cidr in data.cloudflare_ip_ranges.cloudflare.ipv4_cidr_blocks : [
{
"${cidr}:${port}" = {
port = port
cidr = cidr
description = "Allow ingress from Cloudflare (${cidr}) on port ${port}"
}
}
]
]
]
)[0])...)
ipv6_rules = merge(flatten(concat(
[
for port in local.ports : [
for cidr in data.cloudflare_ip_ranges.cloudflare.ipv6_cidr_blocks : [
{
"${cidr}:${port}" = {
port = port
cidr = cidr
description = "Allow ingress from Cloudflare (${cidr}) on port ${port}"
}
}
]
]
]
)[0])...)
}