|
| 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 | +} |
0 commit comments