gpt4 book ai didi

azure - 如何在二头肌中输出资源id

转载 作者:行者123 更新时间:2023-12-02 22:53:15 26 4
gpt4 key购买 nike

如何在二头肌中输出资源id,在创建子网时我们如何获取输出字符串,虚拟网络语法如下所示

resource virtualNetwork 'Microsoft.Network/virtualNetworks@2019-11-01' = {
name: vnetName
location: resourceGroup().location
properties: {
addressSpace: {
addressPrefixes: [
'10.0.0.0/16'
]
}
subnets: [
{
name: 'subnetpoc-1'
properties: {
addressPrefix: '10.0.3.0/24'
}
}
{
name: 'subnetnetpoc-2'
properties: {
addressPrefix: '10.0.4.0/24'
}
}
]
}
}

// output subnet string = ""

最佳答案

您可以使用 resourceId 函数来实现:

param vnetName string

resource virtualNetwork 'Microsoft.Network/virtualNetworks@2019-11-01' = {
name: vnetName
...
}

// Return the 1st subnet id
output subnetId1 string = resourceId('Microsoft.Network/VirtualNetworks/subnets', vnetName, 'subnetpoc-1')

// Return the 2nd subnet id
output subnetId2 string = resourceId('Microsoft.Network/VirtualNetworks/subnets', vnetName, 'subnetpoc-2')

// Return as array
output subnetIdsArray array = [
resourceId('Microsoft.Network/VirtualNetworks/subnets', vnetName, 'subnetpoc-1')
resourceId('Microsoft.Network/VirtualNetworks/subnets', vnetName, 'subnetpoc-2')
]

// Return as object
output subnetIdsObject object = {
subnetId1: resourceId('Microsoft.Network/VirtualNetworks/subnets', vnetName, 'subnetpoc-1')
subnetId2: resourceId('Microsoft.Network/VirtualNetworks/subnets', vnetName, 'subnetpoc-2')
}



关于azure - 如何在二头肌中输出资源id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69654443/

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