-
Notifications
You must be signed in to change notification settings - Fork 15
/
variables.tf
159 lines (158 loc) · 6.53 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
variable "name" {
description = "A unique name of RDS instance"
}
variable "disk_size" {
description = "The allocated storage in gigabytes."
default = "20"
}
variable "db_subnets" {
description = "A list of VPC subnet IDs"
type = list(string)
}
variable "password" {
description = "Password for the master DB user. Leave empty to generate."
default = ""
}
variable "username" {
description = "Username for the master DB user. Leave empty to generate."
default = ""
}
variable "database" {
description = "The name of the database to create when the DB instance is created."
default = ""
}
variable "multi_az" {
description = "Specifies if the RDS instance is multi-AZ"
default = false
}
variable "publicly_accessible" {
description = "Bool to control if instance is publicly accessible. Default is false."
default = false
}
variable "backup_retention_period" {
description = "The days to retain backups for"
default = 3
}
variable "enable_audit_log" {
description = "Enable audit log."
default = false
}
variable "enable_error_log" {
description = "Enable error log."
default = true
}
variable "enable_general_log" {
description = "Enable general log."
default = true
}
variable "enable_slowquery_log" {
description = "Enable slowquery log."
default = true
}
variable "enhanced_monitoring_interval" {
description = "Enable Enhanced Monitoring by specifying its interval. Allowed values are 0, 1, 5, 10, 15, 30, 60."
default = 0
}
variable "performance_insights_enabled" {
description = "Enable Performance Insights."
default = false
}
variable "backup_window" {
description = "The daily time range (in UTC) during which automated backups are created if they are enabled."
default = "05:00-07:00"
}
variable "trusted_cidr_blocks" {
description = "A list of trusted external IP. You may specify office IPs f.e. Of course, RDS should be public accessible."
type = list(string)
default = []
}
variable "instance_type" {
description = "The instance type of the RDS instance"
default = "db.t2.small"
}
data "aws_subnet" "default" {
id = var.db_subnets[0]
}
variable "engine_version" {
description = "MySQL version. Default is 8.0"
default = 8.0
}
variable "apply_immediately" {
description = "Specifies whether any database modifications are applied immediately, or during the next maintenance window."
default = true
}
variable "parameter_group_name" {
description = "Name of the DB parameter group to associate."
default = ""
}
variable "tags" {
description = "Tags."
type = map(string)
}
variable "parameter_prefix" {
description = "Prefix for module params to store in SSM Parameter Store."
default = ""
}
variable "deletion_protection" {
description = "The database can't be deleted when this value is set to true."
default = false
}
variable "storage_type" {
description = "One of 'standard', 'gp2', 'gp3' (new generation of general purpose SSD), or 'io1'."
default = "gp3"
}
variable "identifier" {
description = "The name of the RDS instance"
default = ""
}
variable "iam_database_authentication_enabled" {
description = "Specifies whether or mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled"
default = true
}
locals {
name = var.name
id = length(var.identifier) > 0 ? var.identifier : lower(replace(var.name, " ", "-"))
subnet_group_name = lower(replace(var.name, " ", "-"))
username = var.username == "" ? random_pet.username.id : var.username
password = var.password == "" ? random_password.password.result : var.password
database = var.database == "" ? random_pet.db_name.id : var.database
parameter_group_name = var.parameter_group_name
rds_with_param_group = local.parameter_group_name == "" ? 0 : 1
rds_without_param_group = local.parameter_group_name == "" ? 1 : 0
parameter_prefix = var.parameter_prefix == "" ? "" : "${var.parameter_prefix}/${local.id}"
store_parameters = var.parameter_prefix == "" ? 0 : 1
instance_type = var.instance_type
engine_version = var.engine_version
family = "mysql${var.engine_version}"
disk_size = var.disk_size
multi_az = var.multi_az
backup_window = var.backup_window
backup_retention_period = var.backup_retention_period
publicly_accessible = var.publicly_accessible
apply_immediately = var.apply_immediately
deletion_protection = var.deletion_protection
trusted_cidr_blocks = var.trusted_cidr_blocks
db_subnets = var.db_subnets
vpc_id = data.aws_subnet.default.vpc_id
address = local.parameter_group_name == "" ? join("", aws_db_instance.default.*.address) : join("", aws_db_instance.parameterized.*.address)
hosted_zone_id = local.parameter_group_name == "" ? join("", aws_db_instance.default.*.hosted_zone_id) : join("", aws_db_instance.parameterized.*.hosted_zone_id)
resource_id = local.parameter_group_name == "" ? join("", aws_db_instance.default.*.id) : join("", aws_db_instance.parameterized.*.id)
identifier = local.parameter_group_name == "" ? join("", aws_db_instance.default.*.identifier) : join("", aws_db_instance.parameterized.*.identifier)
arn = local.parameter_group_name == "" ? join("", aws_db_instance.default.*.arn) : join("", aws_db_instance.parameterized.*.arn)
storage_type = var.storage_type
iam_database_authentication_enabled = var.iam_database_authentication_enabled
logs_set = compact([
var.enable_audit_log ? "audit" : "",
var.enable_error_log ? "error" : "",
var.enable_general_log ? "general" : "",
var.enable_slowquery_log ? "slowquery" : "",
])
enhanced_monitoring_interval = var.enhanced_monitoring_interval
performance_insights_enabled = var.performance_insights_enabled
tags = merge({
Name = var.name,
Module = "RDS MySQL"
ModuleVersion = "v0.5.1"
ModuleSource = "https://github.com/jetbrains-infra/terraform-aws-rds-mysql"
}, var.tags)
}