【发布时间】:2021-12-04 18:51:30
【问题描述】:
当我尝试使用以下代码预配 Azure 应用程序网关实例时,最终会出现错误,提示找不到前端端口 appgwfp80。
var appGWName = "agw-pt-dev-uks-001";
var applicationGateway = new ApplicationGateway(appGWName, new ApplicationGatewayArgs
{
ResourceGroupName = resourceGroup.Name,
BackendAddressPools = new ApplicationGatewayBackendAddressPoolArgs[]
{
new ()
{
Name = "appgwpool",
BackendAddresses = new ApplicationGatewayBackendAddressArgs[] { new () { Fqdn = appService.DefaultSiteHostname }}
}
},
BackendHttpSettingsCollection = ..,
GatewayIPConfigurations = ..,
FrontendPorts =
{
new ApplicationGatewayFrontendPortArgs
{
Name = "appgwfp80",
Port = 80,
},
},
FrontendIPConfigurations = ..,
HttpListeners = new ApplicationGatewayHttpListenerArgs[]
{
new ()
{
Name = "appgwhl",
FrontendIPConfiguration = new SubResourceArgs
{
Id = resourceGroup.Id.Apply(id => $"{id}/providers/Microsoft.Network/applicationGateways/{appGWName}/frontendIPConfigurations/publicIp")
},
FrontendPort = new SubResourceArgs
{
Id = resourceGroup.Id.Apply(id => $"{id}/providers/Microsoft.Network/applicationGateways/{appGWName}/frontendPorts/appgwfp80")
}
}
},
RequestRoutingRules = ..,
Sku = new ApplicationGatewaySkuArgs
{
Capacity = 1,
Name = "Standard_v2",
Tier = "Standard_v2",
},
});
据我了解,这是因为当 Pulumi 提供资源时,它会将后缀附加到 these purposes 的末尾,并且因为我使用 resourceGroup.Id.Apply(id => $"{id}/providers/Microsoft.Network/applicationGateways/{appGWName}/frontendPorts/appgwfp80") 引用前端端口 ID,我将 agw-pt-dev-uks-001 传递为 appGWName 它无法找到因为应用程序网关名称设置为agw-pt-dev-uks-001d7c2fa0。
当我明确设置ApplicationGatewayName = "agw-pt-dev-uks-001" 时问题就消失了。
我想为我的所有资源遵循一种命名约定,但现在应用程序网关在名称中没有后缀,而其他资源具有此后缀。
还有其他方法可以引用子资源 ID,例如我可以通过某种方式获取 Pulumi 生成的应用程序网关名称吗?或者我是否只需要为我的所有资源传递一个固定名称并用DeleteBeforeReplace 标记它们,以便在发生更改时 Pulumi 可以通过删除配置的资源来应用更改?
感谢您的所有建议。
【问题讨论】:
标签: c# azure-application-gateway pulumi