mirror of
https://github.com/ryboe/private-ip-cloud-sql-db.git
synced 2025-12-19 18:14:59 -05:00
* terraform v1.0.0 -> v1.1.5 * hashicorp/google 3.80.0 -> 4.9.0 * hashicorp/tfe 0.25.3 -> 0.28.1 * postgres 13 -> 14
30 lines
845 B
HCL
30 lines
845 B
HCL
// db module
|
|
|
|
resource "google_sql_database" "main" {
|
|
name = "main"
|
|
instance = google_sql_database_instance.main_primary.name
|
|
}
|
|
|
|
resource "google_sql_database_instance" "main_primary" {
|
|
name = "main-primary"
|
|
database_version = "POSTGRES_14"
|
|
depends_on = [var.db_depends_on]
|
|
|
|
settings {
|
|
tier = var.instance_type
|
|
availability_type = "ZONAL" # use "REGIONAL" for prod to distribute data storage across zones
|
|
disk_size = var.disk_size
|
|
|
|
ip_configuration {
|
|
ipv4_enabled = false # don't give the db a public IPv4
|
|
private_network = var.vpc_link # the VPC where the db will be assigned a private IP
|
|
}
|
|
}
|
|
}
|
|
|
|
resource "google_sql_user" "db_user" {
|
|
name = var.user
|
|
instance = google_sql_database_instance.main_primary.name
|
|
password = var.password
|
|
}
|