Hello everybody, this is my first post in this community and also fairly new to Terrafrom. Please correct or disregard deviation from community guidelines.
I currently have a directory structure as below and I am trying to output db_endpoint from cosmosdb module and use it in environments/dev/keyvault.tf to pass it as a secret
├── environments
│ └── dev
│ ├── cosmosdb.tf
│ ├── keyvault.tf
│ ├── variables.tf
├── modules
│ ├── cosmosdb
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ ├── keyvault
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
Here is my output from cosmosdb module. modules/cosmosdb/output.tf
output “db_endpoint” {
value = azurerm_cosmosdb_account.example.endpoint
description = “Database endpint url”
}
Below is what I have in environments/dev/keyvault.tf (tried using data source, but it still comes back with same error)
/data “azurerm_cosmosdb_account” “dbconnectionurl” {
name = module.cosmosdb.name
resource_group_name = var.resourcegroupname
endpoint = module.cosmosdb.db_endpoint
}/
module “keyvault-dev” {
source = “…/…/modules/keyvault”
secrets = {
“dbConnectionUrl” = module.cosmosdb.db_endpoint
}
}
When I run plan, it errors out with a message “Reference to undeclared module”
Error: Reference to undeclared module
on keyvault.tf line 21, in module “keyvault-dev”:
21: “dbConnectionUrl” = module.cosmosdb.db_endpoint
No module call named “cosmosdb” is declared in the root module.
Can someone please help on how i can achieve this? Please let me know if you need more information.