-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbs.tf
73 lines (63 loc) · 1.86 KB
/
dbs.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
#https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance
resource "google_sql_database_instance" "instance" {
for_each = {
for index, instance in local.values.sqlInstances :
instance.name => instance
}
name = each.value.name
region = local.values.vpc.region
database_version = "POSTGRES_14"
depends_on = [google_service_networking_connection.private_vpc_connection]
settings {
tier = each.value.machineType
disk_size = each.value.diskSizeGb
disk_autoresize = true
disk_autoresize_limit = 200
availability_type = "REGIONAL"
activation_policy = "ALWAYS"
ip_configuration {
ipv4_enabled = false
private_network = google_compute_network.main.id
enable_private_path_for_google_cloud_services = true
}
backup_configuration {
enabled = true
point_in_time_recovery_enabled = true
}
insights_config {
query_insights_enabled = true
}
}
lifecycle {
ignore_changes = [
maintenance_version,
]
}
}
resource "google_sql_database" "database" {
for_each = {
for index, instance in local.values.sqlInstances :
instance.name => instance
}
name = each.value.database
instance = each.value.name
charset = "utf8"
collation = "en_US.UTF8"
}
resource "google_sql_user" "users" {
for_each = {
for index, instance in local.values.sqlInstances :
instance.name => instance
}
name = each.value.username
instance = each.value.name
password = random_password.password[each.key].result
}
resource "random_password" "password" {
for_each = {
for index, instance in local.values.sqlInstances :
instance.name => instance
}
length = 30
special = false
}