配置Azure Application Gateway时如何引用其子资源?
解决方案
你遇到的问题核心是手动拼接资源ID时用了静态的预设名称,没有使用Pulumi生成的实际资源名,有两种可行的处理方式,均不需要强制关闭所有资源的自动命名特性:
方式1:使用Application Gateway实例的输出生成ID
你创建的applicationGateway资源实例自带Name输出属性,返回Pulumi最终生成的带随机后缀的实际资源名,替换掉你代码里静态的appGWName变量拼接即可,修改后的HttpListeners配置参考:
HttpListeners = new ApplicationGatewayHttpListenerArgs[] { new () { Name = "appgwhl", FrontendIPConfiguration = new SubResourceArgs { Id = Output.All(resourceGroup.Id, applicationGateway.Name).Apply(values => { var rgId = values[0]; var actualAppGwName = values[1]; return $"{rgId}/providers/Microsoft.Network/applicationGateways/{actualAppGwName}/frontendIPConfigurations/publicIp"; }) }, FrontendPort = new SubResourceArgs { Id = Output.All(resourceGroup.Id, applicationGateway.Name).Apply(values => { var rgId = values[0]; var actualAppGwName = values[1]; return $"{rgId}/providers/Microsoft.Network/applicationGateways/{actualAppGwName}/frontendPorts/appgwfp80"; }) } } },
方式2:固定资源名+DeleteBeforeReplace
如果团队有统一的固定资源命名要求,可以显式设置ApplicationGatewayName为固定值,同时给Application Gateway资源加上DeleteBeforeReplace = true的配置,这样Pulumi在需要替换资源时会先删除旧资源再创建新资源,避免同名冲突,这种方式适合对资源命名规范有强要求的场景。
内容的提问来源于stack exchange,提问作者Rob
相关产品推荐
相关产品推荐

