Add first example
This commit is contained in:
@@ -9,70 +9,44 @@ terraform {
|
||||
required_version = ">= 0.10.3"
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
default = "europe-north1"
|
||||
}
|
||||
module "mysql" {
|
||||
source = "../../modules/mysql"
|
||||
|
||||
variable "project" {
|
||||
default = "dev-sandbox-228703"
|
||||
}
|
||||
|
||||
|
||||
variable "zone" {
|
||||
default = "europe-north1-a"
|
||||
}
|
||||
|
||||
variable "mysql_version" {
|
||||
default = "MYSQL_5_6"
|
||||
}
|
||||
|
||||
resource "random_id" "name" {
|
||||
byte_length = 2
|
||||
}
|
||||
|
||||
resource "google_compute_network" "private_network" {
|
||||
provider = "google-beta"
|
||||
name = "private-network"
|
||||
}
|
||||
|
||||
resource "google_compute_global_address" "private_ip_address" {
|
||||
provider = "google-beta"
|
||||
name = "private-ip-address"
|
||||
purpose = "VPC_PEERING"
|
||||
address_type = "INTERNAL"
|
||||
prefix_length = 16
|
||||
network = "${google_compute_network.private_network.self_link}"
|
||||
}
|
||||
|
||||
resource "google_service_networking_connection" "private_vpc_connection" {
|
||||
provider = "google-beta"
|
||||
network = "${google_compute_network.private_network.self_link}"
|
||||
service = "servicenetworking.googleapis.com"
|
||||
reserved_peering_ranges = ["${google_compute_global_address.private_ip_address.name}"]
|
||||
}
|
||||
|
||||
|
||||
module "mysql-db" {
|
||||
source = "../../modules/cloud-sql"
|
||||
name = "example-mysql-${random_id.name.hex}"
|
||||
region = "${var.region}"
|
||||
engine = "${var.mysql_version}"
|
||||
project = "${var.project}"
|
||||
machine_type = "db-f1-micro"
|
||||
region = "${var.region}"
|
||||
name = "${var.name}"
|
||||
db_name = "${var.db_name}"
|
||||
|
||||
ip_configuration = [
|
||||
engine = "${var.mysql_version}"
|
||||
machine_type = "${var.machine_type}"
|
||||
|
||||
master_password = "${var.master_password}"
|
||||
master_username = "${var.master_username}"
|
||||
|
||||
master_host = "%"
|
||||
publicly_accessible = "${var.publicly_accessible}"
|
||||
|
||||
# Never do this in production!
|
||||
# We're setting permissive network rules to make
|
||||
# it easier to test the instance
|
||||
authorized_networks = [
|
||||
{
|
||||
ipv4_enabled = "true"
|
||||
private_network = "${google_compute_network.private_network.self_link}"
|
||||
name = "allow-all-inbound",
|
||||
value = "0.0.0.0/0"
|
||||
}
|
||||
]
|
||||
|
||||
# https://cloud.google.com/sql/docs/mysql/flags
|
||||
flags = [
|
||||
# Set auto-increment flags to test the
|
||||
# feature in during automated testing
|
||||
database_flags = [
|
||||
{
|
||||
name = "auto_increment_increment"
|
||||
value = "10"
|
||||
},
|
||||
{
|
||||
name = "auto_increment_offset"
|
||||
value = "5"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
output "mysql_conn" {
|
||||
value = "${var.project}:${var.region}:${module.mysql-db.instance_name}"
|
||||
}
|
||||
|
||||
|
||||
29
examples/cloud-sql-mysql/outputs.tf
Normal file
29
examples/cloud-sql-mysql/outputs.tf
Normal file
@@ -0,0 +1,29 @@
|
||||
output "instance_name" {
|
||||
description = "The name of the database instance"
|
||||
value = "${module.mysql.instance_name}"
|
||||
}
|
||||
|
||||
output "public_ip" {
|
||||
description = "The IPv4 address of the master database instance"
|
||||
value = "${module.mysql.public_ip}"
|
||||
}
|
||||
|
||||
output "instance_self_link" {
|
||||
description = "Self link to the master instance"
|
||||
value = "${module.mysql.instance_self_link}"
|
||||
}
|
||||
|
||||
output "db_name" {
|
||||
description = "Name of the default database"
|
||||
value = "${module.mysql.db_name}"
|
||||
}
|
||||
|
||||
output "proxy_connection" {
|
||||
value = "${module.mysql.proxy_connection}"
|
||||
}
|
||||
|
||||
output "db_self_link" {
|
||||
description = "Self link to the default database"
|
||||
value = "${module.mysql.db_self_link}"
|
||||
}
|
||||
|
||||
46
examples/cloud-sql-mysql/variables.tf
Normal file
46
examples/cloud-sql-mysql/variables.tf
Normal file
@@ -0,0 +1,46 @@
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
# REQUIRED PARAMETERS
|
||||
# These variables are expected to be passed in by the operator
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
variable "project" {
|
||||
description = "The project ID to host the database in."
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
description = "The region to host the database in."
|
||||
}
|
||||
|
||||
# Note, after a name is used, it cannot be reused for up to one week.
|
||||
variable "name" {
|
||||
description = "The name of the database instance. Use lowercase letters, numbers, and hyphens. Start with a letter."
|
||||
}
|
||||
|
||||
variable "master_username" {
|
||||
description = "The username for the master user."
|
||||
}
|
||||
|
||||
variable "master_password" {
|
||||
description = "The password for the master user."
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
# OPTIONAL PARAMETERS
|
||||
# Generally, these values won't need to be changed.
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
variable "publicly_accessible" {
|
||||
default = "true"
|
||||
}
|
||||
|
||||
variable "mysql_version" {
|
||||
description = "The engine version of the database, e.g. `MYSQL_5_6` or `MYSQL_5_7`."
|
||||
default = "MYSQL_5_7"
|
||||
}
|
||||
|
||||
variable "machine_type" {
|
||||
default = "db-f1-micro"
|
||||
}
|
||||
|
||||
variable "db_name" {
|
||||
default = "default"
|
||||
}
|
||||
Reference in New Issue
Block a user