Skip to content

Commit

Permalink
Merge pull request #31 from Ontotext-AD/GDB-9997_toggle_on_off_backup
Browse files Browse the repository at this point in the history
GDB-9997 toggle on off backup
  • Loading branch information
viktor-ribchev authored Apr 3, 2024
2 parents 4e04795 + 1bcfc88 commit 5f2b92e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
5 changes: 4 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module "vpc" {
module "backup" {
source = "./modules/backup"

count = var.deploy_backup ? 1 : 0

resource_name_prefix = var.resource_name_prefix
iam_role_id = module.graphdb.iam_role_id
}
Expand Down Expand Up @@ -109,9 +111,10 @@ module "graphdb" {

# Backup Configuration

deploy_backup = var.deploy_backup
backup_schedule = var.backup_schedule
backup_retention_count = var.backup_retention_count
backup_bucket_name = module.backup.bucket_name
backup_bucket_name = var.deploy_backup == false ? "" : module.backup[0].bucket_name

# VM Image

Expand Down
12 changes: 8 additions & 4 deletions modules/graphdb/templates/04_gdb_backup_conf.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ echo "#################################################"
echo "# Configuring the GraphDB backup cron job #"
echo "#################################################"

cat <<-EOF > /usr/bin/graphdb_backup
if [ ${deploy_backup} == "true" ]; then
cat <<-EOF >/usr/bin/graphdb_backup
#!/bin/bash
set -euxo pipefail
Expand Down Expand Up @@ -64,7 +65,10 @@ rotate_backups
EOF

chmod +x /usr/bin/graphdb_backup
echo "${backup_schedule} graphdb /usr/bin/graphdb_backup" > /etc/cron.d/graphdb_backup
chmod +x /usr/bin/graphdb_backup
echo "${backup_schedule} graphdb /usr/bin/graphdb_backup" > /etc/cron.d/graphdb_backup

echo "Cron job created"
echo "Cron job created"
else
echo "Backup module is not deployed, skipping provisioning..."
fi
1 change: 1 addition & 0 deletions modules/graphdb/user_data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ data "cloudinit_config" "graphdb_user_data" {
backup_schedule : var.backup_schedule
backup_retention_count : var.backup_retention_count
backup_bucket_name : var.backup_bucket_name
deploy_backup : var.deploy_backup
})
}

Expand Down
8 changes: 6 additions & 2 deletions modules/graphdb/variables.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Common parameters

variable "resource_name_prefix" {
Expand Down Expand Up @@ -109,6 +108,11 @@ variable "lb_subnets" {

# Backup Parameters

variable "deploy_backup" {
description = "Deploy backup module"
type = bool
}

variable "backup_schedule" {
description = "Cron expression for the backup job."
type = string
Expand All @@ -119,7 +123,7 @@ variable "backup_bucket_name" {
type = string

validation {
condition = can(regex("^[a-z0-9_-]+$", var.backup_bucket_name))
condition = var.backup_bucket_name == "" || can(regex("^[a-z0-9_-]+$", var.backup_bucket_name))
error_message = "Bucket name can only contain lowercase letters, numbers, hyphens, and underscores."
}
}
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ variable "aws_region" {
}

# Backup configurations
variable "deploy_backup" {
description = "Deploy backup module"
type = bool
default = true
}

variable "backup_schedule" {
description = "Cron expression for the backup job."
Expand Down

0 comments on commit 5f2b92e

Please sign in to comment.