infra_snippets/terraform/modules/cloudsql/cloudsql.tf

56 lines
1.2 KiB
Terraform
Raw Normal View History

2021-07-12 04:06:49 +00:00
variable "project" {
description = "Project ID."
type = string
}
variable "region" {
description = "Region."
type = string
}
variable "tier" {
description = "DB machine type."
type = string
default = "db-f1-micro"
}
variable "db_version" {
description = "Database version."
type = string
default = "POSTGRES_13"
}
variable "private_network_id" {
description = "Private network id."
type = string
}
2021-07-18 20:37:26 +00:00
output "connection_name" {
description = "The connection string for connecting to the cloudsql instance (for example, through cloudsql proxy)."
value = google_sql_database_instance.instance.connection_name
}
resource "random_id" "cloudsql" {
byte_length = 4
}
2021-07-12 04:06:49 +00:00
resource "google_sql_database_instance" "instance" {
project = var.project
region = var.region
name = "my-database-instance-${random_id.cloudsql.hex}"
2021-07-12 04:06:49 +00:00
database_version = var.db_version
settings {
tier = var.tier
ip_configuration {
ipv4_enabled = false
private_network = var.private_network_id
2021-07-18 20:37:26 +00:00
require_ssl = true
}
2021-07-12 04:06:49 +00:00
}
deletion_protection = "false"
# deletion_protection = "true"
2021-07-12 04:06:49 +00:00
}