[英]How to reference sub resource when provisioning Azure Application Gateway instance
When I try to provision Azure Application Gateway instance with the following code it ends up with an error saying that fronted port appgwfp80
can't be found.当我尝试使用以下代码配置 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",
},
});
To my understanding, it's because when Pulumi provision resources it appends suffix to the end for these purposes and because I reference fronted port id with resourceGroup.Id.Apply(id => $"{id}/providers/Microsoft.Network/applicationGateways/{appGWName}/frontendPorts/appgwfp80")
where I pass agw-pt-dev-uks-001
as appGWName
it can't be found because Application Gateway name was set to something like agw-pt-dev-uks-001d7c2fa0
.据我了解,这是因为当 Pulumi 提供资源时,它会出于这些目的将后缀附加到末尾,并且因为我使用
resourceGroup.Id.Apply(id => $"{id}/providers/Microsoft.Network/applicationGateways/{appGWName}/frontendPorts/appgwfp80")
在我将agw-pt-dev-uks-001
作为appGWName
它,因为应用程序网关名称设置为类似agw-pt-dev-uks-001d7c2fa0
。
The problem goes away when I explicitly set ApplicationGatewayName = "agw-pt-dev-uks-001"
.当我明确设置
ApplicationGatewayName = "agw-pt-dev-uks-001"
时,问题就消失了。
I would like to follow one naming convention for all of my resources but now Application Gateway is provisioned without suffix in the name when other resources have this suffix in place.我想为我的所有资源遵循一种命名约定,但现在当其他资源具有此后缀时,应用程序网关的名称没有后缀。
Is there any other way to reference subresource id so for instance I can somehow get the Application Gateway name generated by Pulumi?有没有其他方法可以引用子资源 ID,例如我可以以某种方式获取 Pulumi 生成的应用程序网关名称? Or do I just need to pass a fixed name for all of my resources and just mark them with
DeleteBeforeReplace
so in case of changes Pulumi can apply changes by removing provisioned resources?或者我是否只需要为我的所有资源传递一个固定名称,并用
DeleteBeforeReplace
标记它们,以便在发生更改时 Pulumi 可以通过删除配置的资源来应用更改?
Thanks for all of your suggestions.感谢您的所有建议。
There's no other way to build the ID at the moment, and you need to set ApplicationGatewayName
explicitly.目前没有其他方法可以构建 ID,您需要显式设置
ApplicationGatewayName
。 If you want a random suffix, you could generate it yourself如果你想要一个随机后缀,你可以自己生成
//using Pulumi.Random;
var suffix = new RandomString("name", new RandomStringArgs
{
Length = 8,
Special = false,
Upper = false
});
var resourceName = Output.Format($"appgw-{suffix.Result}");
var applicationGateway = new ApplicationGateway(appGWName, new ApplicationGatewayArgs
{
ApplicationGatewayName = resourceName,
// ... use the same technique to build IDs
});
A potential improvement is tracked in this issue .在此问题中跟踪了潜在的改进。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.