Skip to content

Commit

Permalink
Add Aurora MySQL (#47)
Browse files Browse the repository at this point in the history
* Add `aurora-mysql`

* Update `aurora-mysql`
  • Loading branch information
aknysh committed Nov 6, 2018
1 parent 50ff010 commit d299bc1
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 18 deletions.
91 changes: 91 additions & 0 deletions aws/backing-services/aurora-mysql.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html

variable "MYSQL_NAME" {
type = "string"
description = "Name of the application, e.g. `app` or `analytics`"
default = "mysql"
}

variable "MYSQL_ADMIN_NAME" {
type = "string"
description = "MySQL admin user name"
}

variable "MYSQL_ADMIN_PASSWORD" {
type = "string"
description = "MySQL password for the admin user"
}

variable "MYSQL_DB_NAME" {
type = "string"
description = "MySQL database name"
}

# https://aws.amazon.com/rds/aurora/pricing
variable "MYSQL_INSTANCE_TYPE" {
type = "string"
default = "db.t2.small"
description = "EC2 instance type for Aurora MySQL cluster"
}

variable "MYSQL_CLUSTER_SIZE" {
type = "string"
default = "2"
description = "MySQL cluster size"
}

variable "MYSQL_CLUSTER_ENABLED" {
type = "string"
default = "false"
description = "Set to false to prevent the module from creating any resources"
}

variable "MYSQL_CLUSTER_PUBLICLY_ACCESSIBLE" {
default = true
description = "Specifies the accessibility options for the DB instance. A value of true specifies an Internet-facing instance with a publicly resolvable DNS name, which resolves to a public IP address. A value of false specifies an internal instance with a DNS name that resolves to a private IP address"
}

module "aurora_mysql" {
source = "git::https://github.com/cloudposse/terraform-aws-rds-cluster.git?ref=tags/0.7.0"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "${var.MYSQL_NAME}"
engine = "aurora-mysql"
cluster_family = "aurora-mysql5.7"
instance_type = "${var.MYSQL_INSTANCE_TYPE}"
cluster_size = "${var.MYSQL_CLUSTER_SIZE}"
admin_user = "${var.MYSQL_ADMIN_NAME}"
admin_password = "${var.MYSQL_ADMIN_PASSWORD}"
db_name = "${var.MYSQL_DB_NAME}"
db_port = "3306"
vpc_id = "${module.vpc.vpc_id}"
subnets = ["${module.subnets.public_subnet_ids}"] # Use module.subnets.private_subnet_ids if the cluster does not need to be publicly accessible
zone_id = "${var.zone_id}"
enabled = "${var.MYSQL_CLUSTER_ENABLED}"
publicly_accessible = "${var.MYSQL_CLUSTER_PUBLICLY_ACCESSIBLE}"
}

output "aurora_mysql_database_name" {
value = "${module.aurora_mysql.name}"
description = "Database name"
}

output "aurora_mysql_master_username" {
value = "${module.aurora_mysql.user}"
description = "Username for the master DB user"
}

output "aurora_mysql_master_hostname" {
value = "${module.aurora_mysql.master_host}"
description = "DB Master hostname"
}

output "aurora_mysql_replicas_hostname" {
value = "${module.aurora_mysql.replicas_host}"
description = "Replicas hostname"
}

output "aurora_mysql_cluster_name" {
value = "${module.aurora_mysql.cluster_name}"
description = "Cluster Identifier"
}
41 changes: 23 additions & 18 deletions aws/backing-services/aurora-postgres.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
variable "POSTGRES_NAME" {
type = "string"
description = "Name of the application, e.g. `app` or `analytics`"
default = "postgres"
}

# Don't use `admin`
# ("MasterUsername admin cannot be used as it is a reserved word used by the engine")
variable "POSTGRES_ADMIN_NAME" {
Expand Down Expand Up @@ -38,24 +44,23 @@ variable "POSTGRES_CLUSTER_ENABLED" {
}

module "aurora_postgres" {
source = "git::https://github.com/cloudposse/terraform-aws-rds-cluster.git?ref=tags/0.3.5"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "postgres"
engine = "aurora-postgresql"
cluster_family = "aurora-postgresql9.6"
instance_type = "${var.POSTGRES_INSTANCE_TYPE}"
cluster_size = "${var.POSTGRES_CLUSTER_SIZE}"
admin_user = "${var.POSTGRES_ADMIN_NAME}"
admin_password = "${var.POSTGRES_ADMIN_PASSWORD}"
db_name = "${var.POSTGRES_DB_NAME}"
db_port = "5432"
vpc_id = "${module.vpc.vpc_id}"
availability_zones = ["${data.aws_availability_zones.available.names}"]
subnets = ["${module.subnets.private_subnet_ids}"]
zone_id = "${var.zone_id}"
security_groups = ["${module.kops_metadata.nodes_security_group_id}"]
enabled = "${var.POSTGRES_CLUSTER_ENABLED}"
source = "git::https://github.com/cloudposse/terraform-aws-rds-cluster.git?ref=tags/0.7.0"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "${var.POSTGRES_NAME}"
engine = "aurora-postgresql"
cluster_family = "aurora-postgresql9.6"
instance_type = "${var.POSTGRES_INSTANCE_TYPE}"
cluster_size = "${var.POSTGRES_CLUSTER_SIZE}"
admin_user = "${var.POSTGRES_ADMIN_NAME}"
admin_password = "${var.POSTGRES_ADMIN_PASSWORD}"
db_name = "${var.POSTGRES_DB_NAME}"
db_port = "5432"
vpc_id = "${module.vpc.vpc_id}"
subnets = ["${module.subnets.private_subnet_ids}"]
zone_id = "${var.zone_id}"
security_groups = ["${module.kops_metadata.nodes_security_group_id}"]
enabled = "${var.POSTGRES_CLUSTER_ENABLED}"
}

output "aurora_postgres_database_name" {
Expand Down

0 comments on commit d299bc1

Please sign in to comment.