使用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
相关产品推荐
相关产品推荐

