Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support to use external db host #65

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [5.2.0] - 2024-11-25
### Added
- Added new variable `beekeeper_db_external_hostname` to support external DB host.

## [5.1.1] - 2024-11-07
### Added
- Kubernetes variables to adjust number replicas on deployments.
Expand Down
24 changes: 12 additions & 12 deletions config-templates.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ data "template_file" "beekeeper_scheduler_apiary_config" {
template = file("${path.module}/files/beekeeper-scheduler-apiary-config.json")

vars = {
db_endpoint = aws_db_instance.beekeeper.endpoint
db_name = aws_db_instance.beekeeper.name
db_username = aws_db_instance.beekeeper.username
db_endpoint = var.beekeeper_db_external_hostname == "" ? aws_db_instance.beekeeper[0].endpoint : "${var.beekeeper_db_external_hostname}:${var.beekeeper_db_port}"
db_name = var.beekeeper_db_name
db_username = var.db_username
queue = aws_sqs_queue.beekeeper.id
graphite_config = var.graphite_enabled == "false" ? "" : data.template_file.beekeeper_graphite_config.rendered
}
Expand All @@ -31,9 +31,9 @@ data "template_file" "beekeeper_path_cleanup_config" {
template = file("${path.module}/files/beekeeper-path-cleanup-config.json")

vars = {
db_endpoint = aws_db_instance.beekeeper.endpoint
db_name = aws_db_instance.beekeeper.name
db_username = aws_db_instance.beekeeper.username
db_endpoint = var.beekeeper_db_external_hostname == "" ? aws_db_instance.beekeeper[0].endpoint : "${var.beekeeper_db_external_hostname}:${var.beekeeper_db_port}"
db_name = var.beekeeper_db_name
db_username = var.db_username
scheduler_delay_ms = var.scheduler_delay_ms
dry_run_enabled = var.path_cleanup_dry_run_enabled
graphite_config = var.graphite_enabled == "false" ? "" : data.template_file.beekeeper_graphite_config.rendered
Expand All @@ -44,9 +44,9 @@ data "template_file" "beekeeper_metadata_cleanup_config" {
template = file("${path.module}/files/beekeeper-metadata-cleanup-config.json")

vars = {
db_endpoint = aws_db_instance.beekeeper.endpoint
db_name = aws_db_instance.beekeeper.name
db_username = aws_db_instance.beekeeper.username
db_endpoint = var.beekeeper_db_external_hostname == "" ? aws_db_instance.beekeeper[0].endpoint : "${var.beekeeper_db_external_hostname}:${var.beekeeper_db_port}"
db_name = var.beekeeper_db_name
db_username = var.db_username
scheduler_delay_ms = var.scheduler_delay_ms
dry_run_enabled = var.metadata_cleanup_dry_run_enabled
metastore_uri = var.metastore_uri
Expand All @@ -58,9 +58,9 @@ data "template_file" "beekeeper_api_config" {
template = file("${path.module}/files/beekeeper-api-config.json")

vars = {
db_endpoint = aws_db_instance.beekeeper.endpoint
db_name = aws_db_instance.beekeeper.name
db_username = aws_db_instance.beekeeper.username
db_endpoint = var.beekeeper_db_external_hostname == "" ? aws_db_instance.beekeeper[0].endpoint : "${var.beekeeper_db_external_hostname}:${var.beekeeper_db_port}"
db_name = var.beekeeper_db_name
db_username = var.db_username
scheduler_delay_ms = var.scheduler_delay_ms
metastore_uri = var.metastore_uri
graphite_config = var.graphite_enabled == "false" ? "" : data.template_file.beekeeper_graphite_config.rendered
Expand Down
9 changes: 6 additions & 3 deletions rds.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

resource "aws_db_subnet_group" "beekeeper_db_subnet_group" {
count = var.beekeeper_db_external_hostname == "" ? 1 : 0
name = "${local.instance_alias}-db-subnet-group"
subnet_ids = var.rds_subnets
description = "Beekeeper DB Subnet Group for ${local.instance_alias}"
Expand All @@ -13,6 +14,7 @@ resource "aws_db_subnet_group" "beekeeper_db_subnet_group" {
}

resource "aws_security_group" "beekeeper_db_sg" {
count = var.beekeeper_db_external_hostname == "" ? 1 : 0
name = "${local.instance_alias}-db"
vpc_id = var.vpc_id
tags = var.beekeeper_tags
Expand Down Expand Up @@ -46,9 +48,10 @@ resource "random_id" "snapshot_id" {
}

resource "aws_db_instance" "beekeeper" {
count = var.beekeeper_db_external_hostname == "" ? 1 : 0
identifier = local.instance_alias
db_subnet_group_name = aws_db_subnet_group.beekeeper_db_subnet_group.name
vpc_security_group_ids = [aws_security_group.beekeeper_db_sg.id]
db_subnet_group_name = aws_db_subnet_group.beekeeper_db_subnet_group[0].name
vpc_security_group_ids = [aws_security_group.beekeeper_db_sg[0].id]
allocated_storage = var.rds_allocated_storage
max_allocated_storage = var.rds_max_allocated_storage
storage_type = var.rds_storage_type
Expand All @@ -57,7 +60,7 @@ resource "aws_db_instance" "beekeeper" {
instance_class = var.rds_instance_class
// Don't use instance alias as part of default DB name since all the Flyway scripts expect "beekeeper" as the db name.
// No reason to parameterize the db name anyway, since we have a different RDS instance per Beekeeper instance.
db_name = "beekeeper"
db_name = var.beekeeper_db_name
username = var.db_username
password = chomp(data.aws_secretsmanager_secret_version.beekeeper_db.secret_string)
parameter_group_name = var.rds_parameter_group_name
Expand Down
23 changes: 17 additions & 6 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ variable "beekeeper_tags" {
variable "rds_subnets" {
description = "Subnets in which to provision Beekeeper RDS DB."
type = list(string)
default = []
}

variable "rds_allocated_storage" {
Expand Down Expand Up @@ -622,10 +623,20 @@ variable "beekeeper_path_cleanup_metrics" {
]
}

variable "beekeeper_perf_scheduler_apiary_metrics" {
description = "Beekeeper metrics to be sent to Datadog."
type = list(string)
default = [
"metadata_scheduled_seconds_count*"
]
variable "beekeeper_db_external_hostname" {
description = "Hostname of the background Database. When not null, RDS DB wont be created."
type = string
default = ""
}

variable "beekeeper_db_name" {
description = "Name of the beekeeper background Database"
type = string
default = "beekeeper"
}

variable "beekeeper_db_port" {
description = "Port number of the beekeeper background Database"
type = number
default = 3306
}
Loading