English 中文(简体)
蚊帐双管齐下模板问题
原标题:Issue with bicep template for subnet

我在RG1中有一个现有的网和路面表。 所有其他资源都在增长趋势。

我正在制作一个子网双管,称为模块,必须与网和路面表挂钩。

蚊帐

//parameters
//variables

resource vnetRef  Microsoft.Network/virtualNetworks@2023-09-01  = {
  name: vnetId
}

resource subnet  Microsoft.Network/virtualNetworks/subnets@2023-09-01  = {
  name: subnetName
  parent: vnetRef
  properties: {
    addressPrefix: subnetPrefix
    routeTable: {
      id: routeTableId
    }          
  }
}

output subnetId string = subnet.id

主编

resource vnet  Microsoft.Network/virtualNetworks@2023-09-01  existing = {
  name:  ${appAcronym}-${subscriptionName}-vnet 
  scope: resourceGroup(sharedScopeRG)
}

resource routeTable  Microsoft.Network/routeTables@2023-09-01  existing = {
  name: routeTableName
  scope: resourceGroup(sharedScopeRG)
}

module subnetModule  ../AnotherRepo/subnet.bicep  = {
  name:  subnetModule 
  scope: resourceGroup(rgName)
  params: {
    name: subnetName
    subnetPrefix: subnetAddressSpace
    vnetId: vnet.id
    routeTableId: routeTable.id
    //other params for 蚊帐
  }
}

模板资源/订阅/补贴/资源小组/RG1/providers/Microsoft.Network/virtualNetwork/myVnet用于Microsoft。 网络/虚拟 第1行和第1739栏的网络长度不正确。 专用资源类别必须具有与资源名称相同的部分。 根基资源类型必须比其资源名称更长。 详情请见。 。

I then passed vnet.name instead of vnet.id when calling 蚊帐 and then get the following error: Resource myVnet was disallowed by policy. Error Type: PolicyViolation, Policy Definition Name : Allowed locations, Policy Assignment Name : .

这意味着,当子网模块被称作时,它正试图创建网。 我曾尝试过多种方式来提出这些问题,但没有一项努力。

最佳回答

First thing, you should deploy the subnets inside the vnet resource. Otherwise if you rerun the vnet module, the existing subnets not defined in the vnet module will be destroy (see related post).

在您的子网模块中,你需要使用<代码>现有的关键词,以提及现有的网状:

// subnet.bicep
param vnetName string
param subnetName string
param subnetPrefix string
param routeTableId string

resource vnetRef  Microsoft.Network/virtualNetworks@2023-09-01  existing = {
  name: vnetName
}

resource subnet  Microsoft.Network/virtualNetworks/subnets@2023-09-01  = {
  parent: vnetRef
  name: subnetName  
  properties: {
    addressPrefix: subnetPrefix
    routeTable: {
      id: routeTableId
    }   
  }
}

output subnetId string = subnet.id

在从你的主要档案中援引子网模块时,该模块的范围必须是网络资源小组的范围:

param appAcronym string
param subscriptionName string
param sharedScopeRG string
param routeTableName string
param subnetName string
param subnetAddressSpace string

resource vnet  Microsoft.Network/virtualNetworks@2023-09-01  existing = {
  name:  ${appAcronym}-${subscriptionName}-vnet 
  scope: resourceGroup(sharedScopeRG)
}

resource routeTable  Microsoft.Network/routeTables@2023-09-01  existing = {
  name: routeTableName
  scope: resourceGroup(sharedScopeRG)
}

module subnetModule  subnet.bicep  = {
  name:  subnetModule 
  scope: resourceGroup(sharedScopeRG) // scope should be the scope of the vnet resource group
  params: {
    subnetName: subnetName
    vnetName: vnet.name
    subnetPrefix: subnetAddressSpace
    routeTableId: routeTable.id
  }
}
问题回答
resource vnet  Microsoft.Network/virtualNetworks@2023-09-01  existing = {
  name:  ${appAcronym}-${subscriptionName}-vnet 
  scope: resourceGroup(myRG)
}

module subnetModule  /subnet.bicep  = {
  name:  ${prefixRName}-snetModule 
  scope: resourceGroup(myRG)
  params: {
    name: 
    subnetPrefix: 
    vnetName: vnet.name
  }
}
param name string
param vnetName string

var subnetName =  ${vnetName}/${name} 

resource subnet  Microsoft.Network/virtualNetworks/subnets@2023-09-01  = {
  name: subnetName
  properties: {
    addressPrefix: //param for address            
  }
}

output subnetId string = subnet.id

如果你不想在子网自行车上再次提电网,你可以做如下工作:

http://www.un.org/Depts/DGACM/index_french.htm

param vnetName string

resource subnet  Microsoft.Network/virtualNetworks/subnets@2023-09-01  = {
  name:  ${vnetName}/wbsubnet1 
  properties: {
    addressPrefix:  10.0.1.0/24 
  }
}

<代码>main.bicep

resource vnet  Microsoft.Network/virtualNetworks@2023-09-01  existing = {
  name:  wbvnet1 
}

module subnetModule  subnet.bicep  = {
  name:  wbsubnettest 
  params: {
    vnetName:  wb-vNet 
  }
}

在外部部署儿童资源时,通常有两种方式:

  • using parent keywords, you do in this way. docs
  • using full resource name. such as my sample code. docs

为了只关注子网问题,我忽略了这里的可用渠道资源。





相关问题
Windows Azure WorkerRole response

I am working on an Azure demo to run Powershell in a worker role. In my web role I add the name of the Powershell script which is to be run to a CloudQueue object. I can print the script output to ...

Windows Azure WebRole stuck in a deployment loop

I ve been struggling with this one for a couple of days now. My current Windows Azure WebRole is stuck in a loop where the status keeps changing between Initializing, Busy, Stopping and Stopped. It ...

Getting a token for Windows Azure

We are looking at Windows Azure, but getting a token appears to be hard now, at least that s what I m seeing in web searches. Anyone tried it or know how to accelerate that process? Any idea how long ...

Developing Azure .Net 4.0 Applications

Presently .Net 4.0 is not supported on Azure. This thread indicates that you will not be able to use .Net 4.0 with VS 2010 until it is supported in the cloud. http://social.msdn.microsoft.com I d ...

.NET 4.0 on Windows Azure?

My google-fu is failing me on this one. As a possible solution to Unit Testing .NET 3.5 projects using MStest in VS2010 (but I ve put this in a seperate question because it s kind of unrelated): Is ...

热门标签