dafine list for user and db in postgbres module
This commit is contained in:
parent
3318babf7c
commit
9539b43f7d
2 changed files with 20 additions and 26 deletions
|
|
@ -12,18 +12,24 @@ resource "stackit_postgresflex_instance" "this" {
|
||||||
|
|
||||||
// Postgres User
|
// Postgres User
|
||||||
resource "stackit_postgresflex_user" "this" {
|
resource "stackit_postgresflex_user" "this" {
|
||||||
|
for_each = {
|
||||||
|
for db in var.postgres_databases : db.user_name => db
|
||||||
|
}
|
||||||
depends_on = [ stackit_postgresflex_instance.this ]
|
depends_on = [ stackit_postgresflex_instance.this ]
|
||||||
project_id = var.stackit_project_id
|
project_id = var.stackit_project_id
|
||||||
instance_id = stackit_postgresflex_instance.this.instance_id
|
instance_id = stackit_postgresflex_instance.this.instance_id
|
||||||
username = var.postgres_db_user_name
|
username = each.value.user_name
|
||||||
roles = var.postgres_db_user_roles
|
roles = each.value.user_roles
|
||||||
}
|
}
|
||||||
|
|
||||||
// Postgres Database
|
// Postgres Database
|
||||||
resource "stackit_postgresflex_database" "this" {
|
resource "stackit_postgresflex_database" "this" {
|
||||||
depends_on = [ stackit_postgresflex_user.this ]
|
for_each = {
|
||||||
|
for db in var.postgres_databases : db.db_name => db
|
||||||
|
}
|
||||||
|
depends_on = [stackit_postgresflex_user.this]
|
||||||
project_id = var.stackit_project_id
|
project_id = var.stackit_project_id
|
||||||
instance_id = stackit_postgresflex_instance.this.instance_id
|
instance_id = stackit_postgresflex_instance.this.instance_id
|
||||||
name = var.postgres_db_name
|
name = each.value.db_name
|
||||||
owner = var.postgres_db_user_name
|
owner = each.value.user_name
|
||||||
}
|
}
|
||||||
|
|
@ -10,11 +10,6 @@ variable "postgres_instance_name" {
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
# variable "postegres_instance_id" {
|
|
||||||
# description = "postgres instance id"
|
|
||||||
# type = string
|
|
||||||
# }
|
|
||||||
|
|
||||||
variable "postgres_instance_replicas" {
|
variable "postgres_instance_replicas" {
|
||||||
description = "number of replicas for postgres instance"
|
description = "number of replicas for postgres instance"
|
||||||
type = number
|
type = number
|
||||||
|
|
@ -58,19 +53,12 @@ variable "postgres_instance_region" {
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
# Postgres User Configs
|
# Postgres User and DB Configs
|
||||||
variable "postgres_db_user_name" {
|
variable "postgres_databases" {
|
||||||
description = "username and owner for postgres db"
|
description = "list of users and databases"
|
||||||
type = string
|
type = list(object({
|
||||||
}
|
db_name = string # db name inside the instance
|
||||||
|
user_name = string # username and owner for postgres db
|
||||||
variable "postgres_db_user_roles" {
|
user_roles = list(string) # List of database access levels for the user. Supported values are: login, createdb.
|
||||||
description = "List of database access levels for the user. Supported values are: login, createdb."
|
}))
|
||||||
type = list(string)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Postgres Database Configs
|
|
||||||
variable "postgres_db_name" {
|
|
||||||
description = "db name inside the instance"
|
|
||||||
type = string
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue