-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariables.tf
109 lines (94 loc) · 3.3 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
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
## NAMING
variable "name" {
description = "Name of the Security Group and Prefix."
type = string
}
variable "name_prefix" {
description = "Whether to use the name as prefix or regular name."
default = true
type = bool
}
variable "description" {
description = "Description of the Security Group."
default = null
type = string
}
variable "tags" {
description = "Tags to add to the Security Group."
default = {}
type = map(any)
}
## Security Group
variable "vpc_id" {
description = "The VPC ID where resources are created."
type = string
}
variable "revoke_rules_on_delete" {
description = "Instruct Terraform to revoke all of the Security Groups attached ingress and egress rules before deleting the rule itself. This is normally not needed."
default = false
type = bool
}
variable "ingress_rules" {
description = "Ingress rules to add to the Security Group. See examples for usage."
default = []
type = list(object({
protocol = string
description = optional(string)
port = optional(number)
to_port = optional(number)
from_port = optional(number)
cidr_blocks = optional(list(string))
prefix_list_ids = optional(list(string))
source_security_group_id = optional(string)
self = optional(bool)
}))
validation {
# Only one of these can be set. Filter out null values and check if the length is greater than 1.
condition = alltrue([
for rule in var.ingress_rules :
false
if length([for k, v in [rule.self, rule.cidr_blocks, rule.source_security_group_id, rule.prefix_list_ids] : k if v != null]) > 1
])
error_message = "A rule can either have 'cidr_blocks', 'prefix_list_ids', 'source_security_group_id' or 'self'."
}
validation {
condition = alltrue([
for rule in var.ingress_rules :
false
if rule.port != null && (rule.to_port != null || rule.from_port != null)
])
error_message = "A rule can either have 'port' or 'to_port'|'from_port' but not both."
}
}
variable "egress_rules" {
description = "Egress rules to add to the Security Group. See examples for usage."
default = []
type = list(object({
protocol = string
description = optional(string)
port = optional(number)
to_port = optional(number)
from_port = optional(number)
cidr_blocks = optional(list(string))
prefix_list_ids = optional(list(string))
source_security_group_id = optional(string)
self = optional(bool)
}))
validation {
# Only one of these can be set. Filter out null values and check if the length is greater than 1.
condition = alltrue([
for rule in var.egress_rules :
false
if length([for k, v in [rule.self, rule.cidr_blocks, rule.source_security_group_id, rule.prefix_list_ids] : k if v != null]) > 1
])
error_message = "A rule can either have 'cidr_blocks', 'prefix_list_ids', 'source_security_group_id' or 'self'."
}
validation {
condition = alltrue([
for rule in var.egress_rules :
false
if rule.port != null && (rule.to_port != null || rule.from_port != null)
])
error_message = "A rule can either have 'port' or 'to_port'|'from_port' but not both."
}
}