gpt4 book ai didi

azure - 如何使用另一个二头肌模块文件中的 keyvault

转载 作者:行者123 更新时间:2023-12-03 06:31:01 26 4
gpt4 key购买 nike

我正在创建一个二头肌文件,用于部署 key 保管库和一些存储帐户。但这些资源位于不同的模块文件中。当我尝试将存储帐户连接字符串添加到 key 保管库时,我似乎可以引用 key 保管库。

ma​​in.bicep

module resourceKeyVaultModule './modules/keyvault.bicep' = {
name: 'resourceKeyVaultModuleDeployment'
params: {
application: application
location: location
environment: environment
severity: severity
}
scope: resourceGroup
}

module resourceStorageAccountModule './modules/storage.bicep' = {
name: 'resourceStorageAccountModuleDeployment'
params: {
application: application
location: location
environment: environment
severity: severity
keyVault: resourceKeyVaultModule.outputs.name
}
scope: resourceGroup
}

keyvault.bicep

// == Key Vault
resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' = {
name: nameKeyVault
location: location
tags: {
location: location
environment: environment
severity: severity
}
properties: {
accessPolicies: [
{
objectId: ''
permissions: {
certificates: [
'all'
]
keys: [
'all'
]
secrets: [
'all'
]
storage: [
'all'
]
}
tenantId: ''
}
]
sku: {
family: 'A'
name: 'standard'
}
tenantId: ''
}
}

output name string = keyVault.name

存储.bicep

param keyVault string

// == Storage Account
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-05-01' = {
name: nameStorageAccount
location: location
tags: {
location: location
environment: environment
severity: severity
}
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
properties: {
minimumTlsVersion: 'TLS1_2'
}
}

resource secretConnectionString 'Microsoft.KeyVault/vaults/secrets@2022-07-01' = {
name: 'connectionString-storageAccount'
dependsOn: [keyVault]
tags: {
location: location
environment: environment
severity: severity
}
properties: {
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};AccountKey=${listKeys(storageAccount.id, storageAccount.apiVersion).keys[0].value};EndpointSuffix=${az.environment().suffixes.storage}'
}
}

取决于:[keyVault]错误:封闭数组需要“module[] | (resource | module) | resources[]”类型的项目,但提供的项目类型为“string”.bicep(BCP034)

最佳答案

我认为您正在寻找现有关键字。

To reference an existing resource that isn't deployed in your current Bicep file, declare the resource with the existing keyword. Use the existing keyword when you're deploying a resource that needs to get a value from an existing resource. You access the existing resource's properties through its symbolic name.

The resource isn't redeployed when referenced with the existing keyword.

来源:Existing resources in Bicep

关于azure - 如何使用另一个二头肌模块文件中的 keyvault,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75233514/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com