-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
50 lines (40 loc) · 1.37 KB
/
main.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
locals {
instance_name = strcontains(var.deployment_id, "postgresql") ? var.deployment_id : "${var.deployment_id}-postgresql"
network_id = "projects/${var.project_id}/global/networks/${var.network}"
}
resource "google_sql_database_instance" "instance" {
name = local.instance_name
project = var.project_id
region = var.region
database_version = "POSTGRES_${var.postgres_version}"
root_password = random_password.postgres_password.result
settings {
tier = "db-custom-${var.cpu_count}-${var.ram_mb}"
edition = var.use_enterprise_plus ? "ENTERPRISE_PLUS" : "ENTERPRISE"
availability_type = "REGIONAL"
user_labels = {
deployment_id = var.deployment_id
}
deletion_protection_enabled = var.deletion_protection
data_cache_config {
data_cache_enabled = var.use_enterprise_plus
}
backup_configuration {
enabled = var.backup_enabled
point_in_time_recovery_enabled = var.backup_enabled
}
ip_configuration {
ipv4_enabled = false
private_network = local.network_id
enable_private_path_for_google_cloud_services = true
}
database_flags {
name = "cloudsql.iam_authentication"
value = "on"
}
}
deletion_protection = var.deletion_protection
}
resource "random_password" "postgres_password" {
length = 16
}