forked from AviatrixSystems/terraform-modules-copilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
variables.tf
204 lines (168 loc) · 5.23 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
variable "availability_zone" {
type = string
description = "Availability zone"
default = ""
}
variable "vpc_cidr" {
type = string
description = "VPC in which you want launch Aviatrix Copilot"
default = "10.0.0.0/16"
}
variable "subnet_cidr" {
type = string
description = "Subnet in which you want launch Aviatrix Copilot"
default = "10.0.1.0/24"
}
variable "use_existing_vpc" {
type = bool
description = "Flag to indicate whether to use an existing VPC"
default = false
}
variable "vpc_id" {
type = string
description = "VPC ID, required when use_existing_vpc is true"
default = ""
}
variable "subnet_id" {
type = string
description = "Subnet ID, only required when use_existing_vpc is true"
default = ""
}
variable "use_existing_keypair" {
type = bool
description = "Flag to indicate whether to use an existing key pair"
default = false
}
variable "keypair" {
type = string
description = "Key pair which should be used by Aviatrix Copilot"
}
variable "tags" {
type = map(string)
description = "Map of common tags which should be used for module resources"
default = {}
}
variable "type" {
type = string
description = "Type of billing, can be 'Copilot' or 'CopilotARM'"
default = "Copilot"
}
variable "root_volume_size" {
type = number
description = "Root volume size for copilot"
default = 30
validation {
condition = var.root_volume_size >= 30
error_message = "The minimum root volume size is 30G."
}
}
variable "root_volume_type" {
type = string
description = "Root volume type for copilot"
default = "gp2"
}
variable "allowed_cidrs" {
type = map(object({
protocol = string,
port = number,
cidrs = set(string),
}))
}
variable "instance_type" {
type = string
description = "Copilot instance size"
default = ""
}
variable "name_prefix" {
type = string
description = "Additional name prefix for your environment resources"
default = ""
}
variable "copilot_name" {
default = ""
type = string
description = "Name of copilot that will be launched"
}
variable "default_data_volume_name" {
default = ""
type = string
description = "Name of default data volume. If not set, no default data volume will be created"
}
variable "default_data_volume_size" {
default = 50
type = number
description = "Size of default data volume"
}
variable "additional_volumes" {
default = {}
type = map(object({
device_name = string,
volume_id = string,
}))
}
variable "private_mode" {
type = bool
description = "Flag to indicate whether the copilot is for private mode"
default = false
}
variable "is_cluster" {
type = bool
description = "Flag to indicate whether the copilot is for a cluster"
default = false
}
variable "controller_public_ip" {
type = string
description = "Controller public IP"
default = "0.0.0.0"
}
variable "controller_private_ip" {
type = string
description = "Controller private IP"
}
variable "root_volume_encrypted" {
type = bool
description = "Whether the root volume is encrypted"
default = true
}
variable "root_volume_kms_key_id" {
type = string
description = "ARN for the key used to encrypt the root volume"
default = ""
}
data "aws_region" "current" {}
data "http" "copilot_iam_id" {
url = "https://cdn.prod.sre.aviatrix.com/image-details/aws_copilot_image_details.json"
request_headers = {
"Accept" = "application/json"
}
}
data "aws_availability_zones" "all" {}
data "aws_ec2_instance_type_offering" "offering" {
for_each = toset(data.aws_availability_zones.all.names)
filter {
name = "instance-type"
values = ["t2.micro", "t3.micro", local.instance_type]
}
filter {
name = "location"
values = [each.value]
}
location_type = "availability-zone"
preferred_instance_types = [local.instance_type, "t3.micro", "t2.micro"]
}
locals {
name_prefix = var.name_prefix != "" ? "${var.name_prefix}_" : ""
images_copilot = jsondecode(data.http.copilot_iam_id.response_body).Copilot
images_copilotarm = jsondecode(data.http.copilot_iam_id.response_body).CopilotARM
ami_id = var.type == "Copilot" ? local.images_copilot[data.aws_region.current.name] : local.images_copilotarm[data.aws_region.current.name]
instance_type = var.instance_type != "" ? var.instance_type : (var.type == "Copilot" ? "m5.2xlarge" : "t4g.2xlarge")
default_az = keys({ for az, details in data.aws_ec2_instance_type_offering.offering : az => details.instance_type if details.instance_type == local.instance_type })[0]
availability_zone = var.availability_zone != "" ? var.availability_zone : local.default_az
controller_ip = var.private_mode ? var.controller_private_ip : var.controller_public_ip
validate_public_ips = (var.private_mode == false && var.controller_public_ip == "0.0.0.0") ? tobool("Please pass in valid controller_public_ip when private_mode is false.") : true
common_tags = merge(
var.tags, {
module = "aviatrix-copilot-aws"
Createdby = "Terraform+Aviatrix"
})
}