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

[IVYNET-102] Add backups & HA #8

Merged
merged 4 commits into from
Oct 17, 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 postgres/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Overview

This module provides a DB (Postgres) mostly for backend.
By default it enables backup, but not HA.

# Versions
- postgres-2 - add HA and backup switch
- postgres-1 - basic module for backend

# TF Docs
Expand Down Expand Up @@ -36,6 +38,8 @@ No modules.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_availability"></a> [availability](#input\_availability) | Type of availability (normal=ZONAL, HA=REGIONAL) | `string` | `"ZONAL"` | no |
| <a name="input_backup"></a> [backup](#input\_backup) | Switch to enable backups | `bool` | `true` | no |
| <a name="input_db-size"></a> [db-size](#input\_db-size) | DB size/type | `string` | `"db-f1-micro"` | no |
| <a name="input_db-version"></a> [db-version](#input\_db-version) | DB type and version (e.g. POSTGRES\_14) | `string` | `"POSTGRES_14"` | no |
| <a name="input_deletion-protection"></a> [deletion-protection](#input\_deletion-protection) | Delete protection of DB | `bool` | `true` | no |
Expand Down
8 changes: 8 additions & 0 deletions postgres/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ resource "google_sql_database_instance" "this" {
private_network = var.network-id
}
}
dynamic "backup_configuration" {
for_each = var.backup ? [1] : []
content {
enabled = true
point_in_time_recovery_enabled = true
}
}
availability_type = var.availability
}
depends_on = [google_service_networking_connection.this]
}
Expand Down
8 changes: 4 additions & 4 deletions postgres/tests/main.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ run "setup" {
run "plan_not_net" {
command = plan
variables {
name = "test"
name = run.setup.name1
network-id = run.setup.net-id
network-name = run.setup.net-name
private-network = false
Expand All @@ -27,7 +27,7 @@ run "plan_not_net" {
run "plan_full" {
command = plan
variables {
name = "test"
name = run.setup.name2
network-id = run.setup.net-id
network-name = run.setup.net-name
}
Expand All @@ -36,7 +36,7 @@ run "plan_full" {
run "apply_simple" {
command = apply
variables {
name = "test"
name = run.setup.name1
deletion-protection = false
db-size = "db-g1-small"
db-version = "POSTGRES_15"
Expand All @@ -49,7 +49,7 @@ run "apply_simple" {
run "apply_private" {
command = apply
variables {
name = "test2"
name = run.setup.name2
deletion-protection = false
network-id = run.setup.net-id
network-name = run.setup.net-name
Expand Down
27 changes: 25 additions & 2 deletions postgres/tests/setup/main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
terraform {
required_providers {
random = {
source = "hashicorp/random"
version = "3.5.1"
}
}
}

resource "random_pet" "name1" {
}

resource "random_pet" "name2" {
}

module "network" {
source = "../../../network"
name = "test44"
name = random_pet.name1.id
}

module "vm" {
source = "../../../backend"
name = "test44"
name = random_pet.name1.id
network-id = module.network.network-id
network-subnet-id = module.network.subnet-id-backend
network-proxy-cidr = module.network.subnet-cidr-proxy
Expand All @@ -30,3 +45,11 @@ output "net-name" {
output "net-link" {
value = module.network.network-link
}

output "name1" {
value = random_pet.name1.id
}

output "name2" {
value = random_pet.name2.id
}
16 changes: 16 additions & 0 deletions postgres/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
variable "availability" {
default = "ZONAL"
description = "Type of availability (normal=ZONAL, HA=REGIONAL)"
type = string
validation {
condition = contains(["ZONAL", "REGIONAL"], var.availability)
error_message = "It has to be 'ZONAL' or 'REGIONAL'"
}
}

variable "backup" {
default = true
description = "Switch to enable backups"
type = bool
}

variable "db-size" {
default = "db-f1-micro"
description = "DB size/type"
Expand Down