Hello, quick recap of the dependency issue
I have a TF module which creates a database role
module userorrole
resource "postgresql_role" "app_login_user" {
provider = postgresql
name = var.app_username
login = var.login
search_path = var.search_path
roles = var.roles != "" ? var.roles : null
}
In my main module I invoke the above module as follows based on the supplied input variable by consumers.
Input variable from module consumers
*************************
schema_to_applogin_mapping = {
apple= {
app_login_user = "apple _user"
enable_password_rotation = false
}}
module "create_std_schema_read_role" {
for_each = var.schema_to_applogin_mapping
source = "./modules/userorrole"
app_username = "${each.key}_role_r"
login = false
providers = {
postgresql = postgresql.appusrprov
}
}
outputs.tf
*********
output "ret_rl_name" {
value = var.app_username
description = "Created Role name"
}
Based on the above code snippet and input variable I am just creating a database role called (apple_role_r).
Now the consumer is going to supply another input variable as shown below to create some additional logins and requesting to grant the above read only role(apple_role_r)
additional_logins_mapping = {
grant_read_on_apple = {
schema_to_grant = "apple"
privileges = "r"
rotate_password = false
}
}
I have another module which invokes the same userorrole module as follows
module "add_additional_logins" {
for_each = var.addtional_logins_mapping
source = "./modules/userorrole"
app_username = each.key
search_path = ["public", each.value["schema_to_grant"]]
roles = ["${each.value.schema_to_grant}_role_${each.value.privileges}"]
}
Issue
Terraform is executing the add_additional_logins ahead of time before completing the execution of the create_std_schema_read_role module.
I can add depends_on = [create_std_schema_read_role ] clause for add_additional_logins module , but every TF apply some security group related resources is getting recreated, so I won’t be able to use the module level dependency.
Ask
How else I can enforce a dependency between
add_additional_logins module and create_std_schema_read_role so that add_additional_logins module waits until completion of create_std_schema_read_role ?
Regards
RK