You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Terraform输出Cosmos DB主/次连接字符串报错,求解决

问题解决:Terraform输出Cosmos DB连接字符串报错

错误原因

你使用的data.azurerm_cosmosdb_account数据源并未导出connection_strings这个属性,Terraform找不到该属性所以报错。Azurerm Provider中,Cosmos DB账户的数据源是将各类连接字符串作为单独属性导出的,而非集合形式的connection_strings。

解决方案

根据你的需求(给Azure Data Factory MongoApi链接服务提供连接字符串),直接输出对应主/次连接字符串即可:

输出主连接字符串

output "cosmosdb_primary_connection_string" {
  value       = data.azurerm_cosmosdb_account.example.primary_connection_string
  sensitive   = true
}

输出次连接字符串

output "cosmosdb_secondary_connection_string" {
  value       = data.azurerm_cosmosdb_account.example.secondary_connection_string
  sensitive   = true
}

输出所有类型的连接字符串(可选)

如果需要一次性获取所有连接字符串(含只读),可以手动组合成列表:

output "cosmosdb_all_connection_strings" {
  value = [
    data.azurerm_cosmosdb_account.example.primary_connection_string,
    data.azurerm_cosmosdb_account.example.secondary_connection_string,
    data.azurerm_cosmosdb_account.example.primary_readonly_connection_string,
    data.azurerm_cosmosdb_account.example.secondary_readonly_connection_string
  ]
  sensitive = true
}

内容的提问来源于stack exchange,提问作者Mohan Kumar G

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 19:25:28