Skip to content

Commit

Permalink
Allow specification of engine to allow PostgreSQL (#8)
Browse files Browse the repository at this point in the history
* Allow specification of engine to allow PostgreSQL
  • Loading branch information
gh-mlfowler authored and Sam Bashton committed Feb 7, 2018
1 parent fd502dc commit 932e949
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ module "aurora_db" {
}
```

These additional parameters need specifying for a PostgreSQL instance:
```
module "aurora_db" {
...
instance_type = "db.r4.large"
engine = "aurora-postgresql"
port = 5432
db_parameter_group_name = "default.aurora-postgresql9.6"
db_cluster_parameter_group_name = "default.aurora-postgresql9.6"
...
}
```


## Inputs

Expand All @@ -63,6 +76,7 @@ module "aurora_db" {
| cw_sns_topic | An SNS topic to publish CloudWatch alarms to | string | `false` | no |
| db_cluster_parameter_group_name | The name of a DB Cluster parameter group to use | string | `default.aurora5.6` | no |
| db_parameter_group_name | The name of a DB parameter group to use | string | `default.aurora5.6` | no |
| engine | Aurora database engine type, currently aurora or aurora-postgresql | string | `aurora` | no |
| envname | Environment name (eg,test, stage or prod) | string | - | yes |
| envtype | Environment type (eg,prod or nonprod) | string | - | yes |
| final_snapshot_identifier | The name to use when creating a final snapshot on cluster destroy, appends a random 8 digits to name to ensure it's unique too. | string | `final` | no |
Expand Down
16 changes: 16 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@
* cw_sns_topic = "${aws_sns_topic.db_alarms.id}"
* }
* ```
*
* These additional parameters need specifying for a PostgreSQL instance:
* ```
* module "aurora_db" {
* ...
* instance_type = "db.r4.large"
* engine = "aurora-postgresql"
* port = 5432
* db_parameter_group_name = "default.aurora-postgresql9.6"
* db_cluster_parameter_group_name = "default.aurora-postgresql9.6"
* ...
* }
* ```
*/

// DB Subnet Group creation
Expand All @@ -65,6 +78,7 @@ resource "aws_db_subnet_group" "main" {
resource "aws_rds_cluster_instance" "cluster_instance_0" {
identifier = "${var.identifier_prefix != "" ? format("%s-node-0", var.identifier_prefix) : format("%s-aurora-node-0", var.envname)}"
cluster_identifier = "${aws_rds_cluster.default.id}"
engine = "${var.engine}"
instance_class = "${var.instance_type}"
publicly_accessible = "${var.publicly_accessible}"
db_subnet_group_name = "${aws_db_subnet_group.main.name}"
Expand All @@ -86,6 +100,7 @@ resource "aws_rds_cluster_instance" "cluster_instance_0" {
resource "aws_rds_cluster_instance" "cluster_instance_n" {
depends_on = ["aws_rds_cluster_instance.cluster_instance_0"]
count = "${var.replica_count}"
engine = "${var.engine}"
identifier = "${var.identifier_prefix != "" ? format("%s-node-%d", var.identifier_prefix, count.index + 1) : format("%s-aurora-node-%d", var.envname, count.index + 1)}"
cluster_identifier = "${aws_rds_cluster.default.id}"
instance_class = "${var.instance_type}"
Expand All @@ -109,6 +124,7 @@ resource "aws_rds_cluster_instance" "cluster_instance_n" {
resource "aws_rds_cluster" "default" {
cluster_identifier = "${var.identifier_prefix != "" ? format("%s-cluster", var.identifier_prefix) : format("%s-aurora-cluster", var.envname)}"
availability_zones = ["${var.azs}"]
engine = "${var.engine}"
master_username = "${var.username}"
master_password = "${var.password}"
final_snapshot_identifier = "${var.final_snapshot_identifier}-${random_id.server.hex}"
Expand Down
12 changes: 9 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ variable "envtype" {
}

variable "identifier_prefix" {
type = "string"
default = ""
description = "Prefix for cluster and instance identifier"
type = "string"
default = ""
description = "Prefix for cluster and instance identifier"
}

variable "azs" {
Expand Down Expand Up @@ -169,3 +169,9 @@ variable "cw_max_replica_lag" {
default = "2000"
description = "Maximum Aurora replica lag in milliseconds above which to alarm"
}

variable "engine" {
type = "string"
default = "aurora"
description = "Aurora database engine type, currently aurora or aurora-postgresql"
}

0 comments on commit 932e949

Please sign in to comment.