-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
79 lines (67 loc) · 1.5 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
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
terraform {
required_version = "1.2.7"
required_providers {
google = {
# see https://registry.terraform.io/providers/hashicorp/google
source = "hashicorp/google"
version = "4.31.0"
}
}
}
provider "google" {
project = var.project
region = var.region
}
variable "project" {
}
variable "region" {
}
output "ca" {
value = google_sql_database_instance.example.server_ca_cert.0.cert
}
output "ip_address" {
value = google_sql_database_instance.example.public_ip_address
}
output "password" {
value = google_sql_user.postgres.password
sensitive = true
}
output "key" {
value = google_sql_ssl_cert.postgres.private_key
sensitive = true
}
output "crt" {
value = google_sql_ssl_cert.postgres.cert
}
resource "random_password" "postgres" {
length = 16
}
resource "google_sql_database_instance" "example" {
name = "example"
database_version = "POSTGRES_14"
deletion_protection = true
settings {
tier = "db-f1-micro"
ip_configuration {
ipv4_enabled = true
require_ssl = true
authorized_networks {
name = "all"
value = "0.0.0.0/0"
}
}
backup_configuration {
enabled = true
point_in_time_recovery_enabled = true
}
}
}
resource "google_sql_ssl_cert" "postgres" {
common_name = "postgres"
instance = google_sql_database_instance.example.name
}
resource "google_sql_user" "postgres" {
name = "postgres"
password = random_password.postgres.result
instance = google_sql_database_instance.example.name
}