Last active
October 13, 2023 09:57
-
-
Save joonvena/576b918e70b958d2be16ad4d9bf40204 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aiven_pg" "main" { | |
project = var.aiven_project | |
service_name = var.database_name | |
cloud_name = "aws-eu-north-1" | |
plan = "free-1-5gb" | |
pg_user_config { | |
pg_version = var.pg_version | |
ip_filter_string = var.allowed_ips | |
} | |
} | |
resource "aiven_pg_database" "main" { | |
project = aiven_pg.main.project | |
service_name = aiven_pg.main.service_name | |
database_name = var.database_name | |
} | |
resource "aiven_pg_user" "main" { | |
project = aiven_pg.main.project | |
service_name = aiven_pg.main.service_name | |
username = var.database_name | |
} | |
data "aiven_pg_user" "main" { | |
project = aiven_pg.main.project | |
service_name = aiven_pg.main.service_name | |
username = aiven_pg_user.main.username | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variables { | |
aiven_project = "testing" | |
database_name = "testing" | |
pg_version = "13" | |
} | |
provider "aiven" {} | |
run "unit_test" { | |
command = plan | |
assert { | |
condition = aiven_pg.main.pg_user_config[0].pg_version == var.pg_version | |
error_message = "PostgreSQL version was ${aiven_pg.main.pg_user_config[0].pg_version} expected ${var.pg_version}" | |
} | |
assert { | |
condition = aiven_pg_database.main.database_name == var.database_name | |
error_message = "Database name was ${aiven_pg_database.main.database_name} expected ${var.database_name}" | |
} | |
assert { | |
condition = aiven_pg_user.main.username == var.database_name | |
error_message = "Database user was ${aiven_pg_user.main.username} expected ${var.database_name}" | |
} | |
assert { | |
condition = aiven_pg.main.pg_user_config[0].ip_filter_string[0] == "0.0.0.0/0" | |
error_message = "Allowed IPs should have default value of 0.0.0.0/0" | |
} | |
} | |
run "input_validation" { | |
command = plan | |
variables { | |
pg_version = "11" | |
} | |
expect_failures = [ | |
var.pg_version | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "aiven_project" { | |
description = "Aiven project name" | |
type = string | |
} | |
variable "database_name" { | |
description = "Name of the database" | |
type = string | |
} | |
variable "pg_version" { | |
description = "PostgreSQL version" | |
type = string | |
validation { | |
condition = can(regex("^(12|13|14|15)$", var.pg_version)) | |
error_message = "Invalid PostgreSQL version" | |
} | |
} | |
variable "allowed_ips" { | |
description = "List of allowed IPs" | |
type = list(string) | |
default = ["0.0.0.0/0"] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment