This repository has been archived by the owner on Mar 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cloud_sql.tf
73 lines (62 loc) · 1.88 KB
/
cloud_sql.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
resource "random_id" "main-default-name-suffix" {
byte_length = 4
}
resource "google_sql_database_instance" "main-default" {
name = "main-default-${random_id.main-default-name-suffix.hex}"
region = var.gcp_default_region
database_version = "MYSQL_5_7"
settings {
tier = "db-n1-standard-1"
disk_size = 10
disk_type = "PD_SSD"
activation_policy = "ALWAYS"
disk_autoresize = true
replication_type = "SYNCHRONOUS"
backup_configuration {
enabled = true
binary_log_enabled = true
start_time = "00:00"
}
ip_configuration {
ipv4_enabled = true
require_ssl = true
dynamic "authorized_networks" {
for_each = google_compute_instance.step
iterator = step
content {
name = step.value.name
value = step.value.network_interface.0.access_config.0.nat_ip
}
}
dynamic "authorized_networks" {
for_each = google_compute_instance.app
iterator = app
content {
name = app.value.name
value = app.value.network_interface.0.access_config.0.nat_ip
}
}
}
location_preference {
zone = "${var.gcp_default_region}-a"
}
}
}
resource "google_sql_user" "main-default-root" {
name = "root"
instance = google_sql_database_instance.main-default.name
host = "%"
password = var.cloud_sql_root_password
}
resource "google_sql_user" "main-default-writer" {
name = var.cloud_sql_writer_username
instance = google_sql_database_instance.main-default.name
host = "%"
password = var.cloud_sql_writer_password
}
resource "google_sql_user" "main-default-reader" {
name = var.cloud_sql_reader_username
instance = google_sql_database_instance.main-default.name
host = "%"
password = var.cloud_sql_reader_password
}