简体   繁体   English

预配 Azure 应用程序网关实例时如何引用子资源

[英]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.

相关问题 使用Azure作为媒体资源(CDN)时,如何纠正WPF应用程序中的错误? - How can I correct error in my WPF Application when using Azure as a media resource (CDN)? 如何检查另一个应用程序实例是否正在使用相同的资源运行 - How to check another instance of application is running using the same resource 如何从C#向Web资源添加标签-Web应用程序 - How to Add Tags to Azure Resource from a C# - Web Application 单实例窗口形成应用程序以及如何获取它的参考? - Single instance windows forms application and how to get reference on it? Azure应用程序网关斜杠重写错误 - Azure Application Gateway Slash Rewrite Error 如何引用资源? - How to reference a resource? 如何通过REST API创建Azure Application Insights的新实例 - How to create a new instance of Azure Application Insights through the REST API 如何创建 TelemetryClient 的 static 实例,用于在 Azure 功能中记录应用程序洞察 - How to create a static instance of TelemetryClient for application insights logging in Azure Functions Azure Function App对本地资源的访问权限(网关?) - Azure Function App access to on-prem resource (Gateway?) 尝试将特定图像上传到 Azure 存储帐户时出现 403 Forbidden - Microsoft-Azure-Application-Gateway/v2 - Getting 403 Forbidden - Microsoft-Azure-Application-Gateway/v2 when trying to upload particular image to the Azure storage account
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM