Skip to content

Commit 79b8625

Browse files
committed
[engine-type] allow to use different db engine type
1 parent 2a6486b commit 79b8625

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

modules/datastore/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ To read more, see [the Metaflow docs](https://docs.metaflow.org/metaflow-on-aws/
1919

2020
| Name | Description | Type | Default | Required |
2121
|------|-------------|------|---------|:--------:|
22+
| <a name="input_db_engine"></a> [db\_engine](#input\_db\_engine) | n/a | `string` | `"postgresql"` | no |
23+
| <a name="input_db_engine_version"></a> [db\_engine\_version](#input\_db\_engine\_version) | n/a | `string` | `"11"` | no |
2224
| <a name="input_db_instance_type"></a> [db\_instance\_type](#input\_db\_instance\_type) | RDS instance type to launch for PostgresQL database. | `string` | `"db.t2.small"` | no |
2325
| <a name="input_db_name"></a> [db\_name](#input\_db\_name) | Name of PostgresQL database for Metaflow service. | `string` | `"metaflow"` | no |
2426
| <a name="input_db_username"></a> [db\_username](#input\_db\_username) | PostgresQL username; defaults to 'metaflow' | `string` | `"metaflow"` | no |

modules/datastore/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ output "datastore_s3_bucket_kms_key_arn" {
2929
}
3030

3131
output "rds_master_instance_endpoint" {
32-
value = aws_db_instance.this.endpoint
32+
value = local.use_aurora ? aws_rds_cluster.this[0].endpoint : aws_db_instance.this[0].endpoint
3333
description = "The database connection endpoint in address:port format"
3434
}
3535

modules/datastore/rds.tf

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,57 @@ resource "random_password" "this" {
5353

5454
resource "random_pet" "final_snapshot_id" {}
5555

56+
locals {
57+
use_aurora = length(regexall("^aurora-", var.db_engine)) > 0
58+
}
59+
60+
resource "aws_rds_cluster" "this" {
61+
count = local.use_aurora ? 1 : 0
62+
cluster_identifier = "${var.resource_prefix}${var.db_name}${var.resource_suffix}"
63+
kms_key_id = aws_kms_key.rds.arn
64+
engine = var.db_engine
65+
66+
database_name = var.db_name
67+
master_username = var.db_username
68+
master_password = random_password.this.result
69+
db_subnet_group_name = aws_db_subnet_group.this.id
70+
71+
engine_version = var.db_engine_version
72+
storage_encrypted = true
73+
74+
final_snapshot_identifier = "${var.resource_prefix}${var.db_name}-final-snapshot${var.resource_suffix}-${random_pet.final_snapshot_id.id}" # Snapshot upon delete
75+
vpc_security_group_ids = [aws_security_group.rds_security_group.id]
76+
77+
tags = merge(
78+
var.standard_tags,
79+
{
80+
Name = "${var.resource_prefix}${var.db_name}${var.resource_suffix}"
81+
Metaflow = "true"
82+
}
83+
)
84+
}
85+
86+
resource "aws_rds_cluster_instance" "cluster_instances" {
87+
count = local.use_aurora ? 1 : 0
88+
identifier = "${var.resource_prefix}${var.db_name}${var.resource_suffix}-${count.index}"
89+
cluster_identifier = aws_rds_cluster.this[0].id
90+
instance_class = var.db_instance_type
91+
engine = aws_rds_cluster.this[0].engine
92+
engine_version = aws_rds_cluster.this[0].engine_version
93+
}
94+
5695
/*
5796
Define rds db instance.
5897
*/
5998
resource "aws_db_instance" "this" {
99+
count = local.use_aurora ? 0 : 1
60100
publicly_accessible = false
61101
allocated_storage = 20 # Allocate 20GB
62102
storage_type = "gp2" # general purpose SSD
63103
storage_encrypted = true
64104
kms_key_id = aws_kms_key.rds.arn
65-
engine = "postgres"
66-
engine_version = "11"
105+
engine = var.db_engine
106+
engine_version = var.db_engine_version
67107
instance_class = var.db_instance_type # Hardware configuration
68108
identifier = "${var.resource_prefix}${var.db_name}${var.resource_suffix}" # used for dns hostname needs to be customer unique in region
69109
name = var.db_name # unique id for CLI commands (name of DB table which is why we're not adding the prefix as no conflicts will occur and the API expects this table name)

modules/datastore/variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ variable "db_instance_type" {
44
default = "db.t2.small"
55
}
66

7+
variable "db_engine" {
8+
type = string
9+
default = "postgresql"
10+
}
11+
12+
variable "db_engine_version" {
13+
type = string
14+
default = "11"
15+
}
16+
717
variable "db_name" {
818
type = string
919
description = "Name of PostgresQL database for Metaflow service."

0 commit comments

Comments
 (0)