Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
75 lines (61 sloc) 1.62 KB
# A piece of randomization that gets consumed by the
# `google_sql_database_instance` resources.
#
# This is needed in order to facilitate creating and recreating instances
# without waiting for the whole period that GCP requires to name reusal.
#
#
#
resource "random_id" "instance-name" {
byte_length = 4
}
resource "google_sql_database_instance" "main" {
name = "${var.name}-${random_id.instance-name.hex}"
region = "${var.region}"
database_version = "POSTGRES_9_6"
settings {
availability_type = "ZONAL"
disk_autoresize = true
disk_size = "${var.disk_size_gb}"
disk_type = "PD_SSD"
tier = "db-custom-${var.cpus}-${var.memory_mb}"
database_flags {
name = "log_min_duration_statement"
value = "-1"
}
ip_configuration {
ipv4_enabled = "true"
require_ssl = "true"
authorized_networks {
name = "all"
value = "0.0.0.0/0"
}
}
backup_configuration {
enabled = true
start_time = "23:00"
}
location_preference {
zone = "${var.zone}"
}
}
}
resource "google_sql_database" "atc" {
name = "atc"
instance = "${google_sql_database_instance.main.name}"
charset = "UTF8"
collation = "en_US.UTF8"
}
resource "random_string" "password" {
length = 32
special = true
}
resource "google_sql_user" "user" {
name = "atc"
instance = "${google_sql_database_instance.main.name}"
password = "${random_string.password.result}"
}
resource "google_sql_ssl_cert" "cert" {
common_name = "atc"
instance = "${google_sql_database_instance.main.name}"
}
You can’t perform that action at this time.