Skip to content

Commit d299bc1

Browse files
authored
Add Aurora MySQL (#47)
* Add `aurora-mysql` * Update `aurora-mysql`
1 parent 50ff010 commit d299bc1

File tree

2 files changed

+114
-18
lines changed

2 files changed

+114
-18
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html
2+
3+
variable "MYSQL_NAME" {
4+
type = "string"
5+
description = "Name of the application, e.g. `app` or `analytics`"
6+
default = "mysql"
7+
}
8+
9+
variable "MYSQL_ADMIN_NAME" {
10+
type = "string"
11+
description = "MySQL admin user name"
12+
}
13+
14+
variable "MYSQL_ADMIN_PASSWORD" {
15+
type = "string"
16+
description = "MySQL password for the admin user"
17+
}
18+
19+
variable "MYSQL_DB_NAME" {
20+
type = "string"
21+
description = "MySQL database name"
22+
}
23+
24+
# https://aws.amazon.com/rds/aurora/pricing
25+
variable "MYSQL_INSTANCE_TYPE" {
26+
type = "string"
27+
default = "db.t2.small"
28+
description = "EC2 instance type for Aurora MySQL cluster"
29+
}
30+
31+
variable "MYSQL_CLUSTER_SIZE" {
32+
type = "string"
33+
default = "2"
34+
description = "MySQL cluster size"
35+
}
36+
37+
variable "MYSQL_CLUSTER_ENABLED" {
38+
type = "string"
39+
default = "false"
40+
description = "Set to false to prevent the module from creating any resources"
41+
}
42+
43+
variable "MYSQL_CLUSTER_PUBLICLY_ACCESSIBLE" {
44+
default = true
45+
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"
46+
}
47+
48+
module "aurora_mysql" {
49+
source = "git::https://github.com/cloudposse/terraform-aws-rds-cluster.git?ref=tags/0.7.0"
50+
namespace = "${var.namespace}"
51+
stage = "${var.stage}"
52+
name = "${var.MYSQL_NAME}"
53+
engine = "aurora-mysql"
54+
cluster_family = "aurora-mysql5.7"
55+
instance_type = "${var.MYSQL_INSTANCE_TYPE}"
56+
cluster_size = "${var.MYSQL_CLUSTER_SIZE}"
57+
admin_user = "${var.MYSQL_ADMIN_NAME}"
58+
admin_password = "${var.MYSQL_ADMIN_PASSWORD}"
59+
db_name = "${var.MYSQL_DB_NAME}"
60+
db_port = "3306"
61+
vpc_id = "${module.vpc.vpc_id}"
62+
subnets = ["${module.subnets.public_subnet_ids}"] # Use module.subnets.private_subnet_ids if the cluster does not need to be publicly accessible
63+
zone_id = "${var.zone_id}"
64+
enabled = "${var.MYSQL_CLUSTER_ENABLED}"
65+
publicly_accessible = "${var.MYSQL_CLUSTER_PUBLICLY_ACCESSIBLE}"
66+
}
67+
68+
output "aurora_mysql_database_name" {
69+
value = "${module.aurora_mysql.name}"
70+
description = "Database name"
71+
}
72+
73+
output "aurora_mysql_master_username" {
74+
value = "${module.aurora_mysql.user}"
75+
description = "Username for the master DB user"
76+
}
77+
78+
output "aurora_mysql_master_hostname" {
79+
value = "${module.aurora_mysql.master_host}"
80+
description = "DB Master hostname"
81+
}
82+
83+
output "aurora_mysql_replicas_hostname" {
84+
value = "${module.aurora_mysql.replicas_host}"
85+
description = "Replicas hostname"
86+
}
87+
88+
output "aurora_mysql_cluster_name" {
89+
value = "${module.aurora_mysql.cluster_name}"
90+
description = "Cluster Identifier"
91+
}

aws/backing-services/aurora-postgres.tf

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
variable "POSTGRES_NAME" {
2+
type = "string"
3+
description = "Name of the application, e.g. `app` or `analytics`"
4+
default = "postgres"
5+
}
6+
17
# Don't use `admin`
28
# ("MasterUsername admin cannot be used as it is a reserved word used by the engine")
39
variable "POSTGRES_ADMIN_NAME" {
@@ -38,24 +44,23 @@ variable "POSTGRES_CLUSTER_ENABLED" {
3844
}
3945

4046
module "aurora_postgres" {
41-
source = "git::https://github.com/cloudposse/terraform-aws-rds-cluster.git?ref=tags/0.3.5"
42-
namespace = "${var.namespace}"
43-
stage = "${var.stage}"
44-
name = "postgres"
45-
engine = "aurora-postgresql"
46-
cluster_family = "aurora-postgresql9.6"
47-
instance_type = "${var.POSTGRES_INSTANCE_TYPE}"
48-
cluster_size = "${var.POSTGRES_CLUSTER_SIZE}"
49-
admin_user = "${var.POSTGRES_ADMIN_NAME}"
50-
admin_password = "${var.POSTGRES_ADMIN_PASSWORD}"
51-
db_name = "${var.POSTGRES_DB_NAME}"
52-
db_port = "5432"
53-
vpc_id = "${module.vpc.vpc_id}"
54-
availability_zones = ["${data.aws_availability_zones.available.names}"]
55-
subnets = ["${module.subnets.private_subnet_ids}"]
56-
zone_id = "${var.zone_id}"
57-
security_groups = ["${module.kops_metadata.nodes_security_group_id}"]
58-
enabled = "${var.POSTGRES_CLUSTER_ENABLED}"
47+
source = "git::https://github.com/cloudposse/terraform-aws-rds-cluster.git?ref=tags/0.7.0"
48+
namespace = "${var.namespace}"
49+
stage = "${var.stage}"
50+
name = "${var.POSTGRES_NAME}"
51+
engine = "aurora-postgresql"
52+
cluster_family = "aurora-postgresql9.6"
53+
instance_type = "${var.POSTGRES_INSTANCE_TYPE}"
54+
cluster_size = "${var.POSTGRES_CLUSTER_SIZE}"
55+
admin_user = "${var.POSTGRES_ADMIN_NAME}"
56+
admin_password = "${var.POSTGRES_ADMIN_PASSWORD}"
57+
db_name = "${var.POSTGRES_DB_NAME}"
58+
db_port = "5432"
59+
vpc_id = "${module.vpc.vpc_id}"
60+
subnets = ["${module.subnets.private_subnet_ids}"]
61+
zone_id = "${var.zone_id}"
62+
security_groups = ["${module.kops_metadata.nodes_security_group_id}"]
63+
enabled = "${var.POSTGRES_CLUSTER_ENABLED}"
5964
}
6065

6166
output "aurora_postgres_database_name" {

0 commit comments

Comments
 (0)