forked from claranet/terraform-azurerm-db-postgresql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
r-users.tf
22 lines (16 loc) · 1.06 KB
/
r-users.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
resource "random_password" "db_passwords" {
for_each = var.create_databases_users ? toset(var.databases_names) : toset([])
special = "false"
length = 32
}
resource "null_resource" "db_users" {
for_each = var.create_databases_users ? toset(var.databases_names) : toset([])
provisioner "local-exec" {
command = "ansible-playbook --extra-vars '{\"database_name\": ${each.value}, \"server_fqdn\": ${azurerm_postgresql_server.postgresql_server.fqdn}, \"administrator_user\": ${var.administrator_login}@${replace(azurerm_postgresql_server.postgresql_server.fqdn, ".postgres.database.azure.com", "")}, \"administrator_password\": ${var.administrator_password}, \"database_user_password\": ${random_password.db_passwords[each.value].result} }' --connection=local -i 127.0.0.1, main.yml"
working_dir = "${path.module}/playbook-ansible"
}
triggers = {
database = azurerm_postgresql_database.postgresql_db[each.value].id
}
depends_on = [azurerm_postgresql_server.postgresql_server, azurerm_postgresql_database.postgresql_db, random_password.db_passwords]
}