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

使用Terraform修剪Service Bus队列连接字符串并存储至Key Vault

解决Terraform存储Azure Service Bus连接字符串到Key Vault时去除EntityPath的问题

问题核心:你在replace函数里把Terraform资源属性用双引号括起来了,导致它被当作普通字符串存储,而不是读取实际的连接字符串值。

正确的Terraform代码

resource "azurerm_key_vault_secret" "que-referee-sr-lr-connectionstring" {
  name         = lower(format("%s-%s", azurerm_servicebus_queue_authorization_rule.que-referee-sr-lr.name, "primary-connection-string"))
  value        = replace(azurerm_servicebus_queue_authorization_rule.que-referee-sr-lr.primary_connection_string, "/;EntityPath.*/", "")
  key_vault_id = data.azurerm_key_vault.PlatformKV.id
}

关键修改说明

  • 移除replace第一个参数的双引号:azurerm_servicebus_queue_authorization_rule.que-referee-sr-lr.primary_connection_string是Terraform的资源属性引用,不需要用引号包裹,否则会被当作字面字符串处理。
  • 正则表达式/;EntityPath.*/会匹配从;EntityPath开始到字符串末尾的所有内容,替换为空字符串后就能得到你需要的不带EntityPath的连接字符串。

内容的提问来源于stack exchange,提问作者nitesh malik

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 16:50:37