Add sandbox for experimentation

This commit is contained in:
Petri Autero
2019-02-01 12:09:36 +02:00
parent 941c7c10f9
commit dfb4eb8538
6 changed files with 211 additions and 3 deletions

61
modules/cloud-sql/main.tf Normal file
View File

@@ -0,0 +1,61 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# DEPLOY A CLOUD SQL CLUSTER
# This module deploys an Cloud SQL cluster. The cluster is managed by Google and automatically handles leader
# election, replication, failover, backups, patching, and encryption.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ------------------------------------------------------------------------------
# CREATE THE CLOUD SQL CLUSTER
#
# NOTE: We have multiple google_sql_database_instance resources, based on
# HA, encryption and replication configuration options.
# ------------------------------------------------------------------------------
resource "google_sql_database_instance" "default" {
name = "${var.name}"
project = "${var.project}"
region = "${var.region}"
database_version = "${var.engine}"
master_instance_name = "${var.master_instance_name}"
settings {
tier = "${var.machine_type}"
activation_policy = "${var.activation_policy}"
authorized_gae_applications = ["${var.authorized_gae_applications}"]
disk_autoresize = "${var.disk_autoresize}"
backup_configuration = ["${var.backup_configuration}"]
ip_configuration = ["${var.ip_configuration}"]
location_preference = ["${var.location_preference}"]
maintenance_window = ["${var.maintenance_window}"]
disk_size = "${var.disk_size}"
disk_type = "${var.disk_type}"
pricing_plan = "${var.pricing_plan}"
replication_type = "${var.replication_type}"
database_flags = ["${var.flags}"]
availability_type = "${var.availability_type}"
}
replica_configuration = ["${var.replica_configuration}"]
}
# ------------------------------------------------------------------------------
# CREATE A DATABASE
# ------------------------------------------------------------------------------
resource "google_sql_database" "default" {
count = "${var.master_instance_name == "" ? 1 : 0}"
name = "${var.db_name}"
project = "${var.project}"
instance = "${google_sql_database_instance.default.name}"
charset = "${var.db_charset}"
collation = "${var.db_collation}"
}
resource "google_sql_user" "default" {
count = "${var.master_instance_name == "" ? 1 : 0}"
name = "${var.db_name}"
project = "${var.project}"
instance = "${google_sql_database_instance.default.name}"
host = "${var.db_user_host}"
password = "${var.db_password}"
}

View File

@@ -0,0 +1,19 @@
output instance_name {
description = "The name of the database instance"
value = "${google_sql_database_instance.default.name}"
}
output instance_address {
description = "The IPv4 address of the master database instance"
value = "${google_sql_database_instance.default.ip_address.0.ip_address}"
}
output instance_address_time_to_retire {
description = "The time the master instance IP address will be reitred. RFC 3339 format."
value = "${google_sql_database_instance.default.ip_address.0.time_to_retire}"
}
output self_link {
description = "Self link to the master instance"
value = "${google_sql_database_instance.default.self_link}"
}

View File

@@ -29,6 +29,11 @@ variable "machine_type" {
default = "db-f1-micro"
}
variable "availability_type" {
description = "This specifies whether a PostgreSQL instance should be set up for high availability (REGIONAL) or single zone (ZONAL)."
default = "ZONAL"
}
variable "db_name" {
description = "Name of the default database to create"
default = "default"
@@ -44,17 +49,17 @@ variable "db_collation" {
default = ""
}
variable "master_user_name" {
variable "db_user" {
description = "The name of the default user"
default = "default"
}
variable "master_user_host" {
variable "db_user_host" {
description = "The host for the default user"
default = "%"
}
variable "master_user_password" {
variable "db_password" {
description = "The password for the default user."
default = ""
}