【问题标题】:Add Azure Traffic Manager endpoints in main bicep template as child resource在主二头肌模板中添加 Azure 流量管理器端点作为子资源
【发布时间】:2021-11-24 20:04:15
【问题描述】:

我正在尝试通过在我的main.bicep 文件中调用的Network/trafficManagerProfiles.bicep 模块添加新的流量管理器配置文件。
这很好用。

main.bicep 文件正在使用它们自己的小模块创建多个功能应用程序,调用方式类似这样

module functionAppModule 'Web/functions.bicep' = {
  dependsOn: [
    appServicePlanModule
    webApiStorageAccount
  ]
  name: 'functionAppModule'
  params: {
    environmentName: environmentName
    systemName: systemName
    azureRegion: azureRegion
    appServicePlanId: appServicePlanModule.outputs.id
  }
}

现在我正在尝试将我的 Web 应用程序 (Azure Functions) 的必要端点添加到流量管理器配置文件中,using the endpoints property 也可以这样做。

但是,这意味着我需要向此文件添加一个参数,以接受包含有关我的应用服务的所有信息的对象数组,或者我需要在此处解决它们(通过使用 existing 关键字检索实例)。这听起来不像是实现它的方式,因为所有这些资源都已在 main.bicep 文件中可用/引用。

流量管理器配置文件模块现在如下所示:

param systemName string
@allowed([
  'dev'
  'test'
  'acc'
  'prod'
])
param environmentName string
param relativeLiveEndpoint string = '/api/Live'

var trafficManagerProfileName = '${systemName}${environmentName}'

resource trafficManagerProfile 'Microsoft.Network/trafficmanagerprofiles@2018-08-01' = {
  name: trafficManagerProfileName
  location: 'global'
  properties: {
    allowedEndpointRecordTypes: [
      'DomainName'
    ]
    dnsConfig: {
      relativeName: trafficManagerProfileName
      ttl: 60
    }
    profileStatus: 'Enabled'
    trafficRoutingMethod: 'Performance'
    monitorConfig: {
      profileMonitorStatus: 'Online'
      protocol: 'HTTPS'
      port: 443
      path: relativeLiveEndpoint
      timeoutInSeconds: 10
      intervalInSeconds: 30
      toleratedNumberOfFailures: 3
    }
    endpoints: [
      {
        id: 'the resource id'
        name: 'the resource name'
        type: 'the resource type'
        properties: {
          endpointStatus: 'Enabled'
          endpointMonitorStatus: 'Online'
          targetResourceId: 'the resource id'
          target: 'mysite.azurewebsites.net'
          endpointLocation: 'West Europe'
          weight: 1
          priority: 1
        }
      }
      // All other app services
    ]
  }
}

根据 Stack Overflow 上的一些答案,endpoints 也可以通过 ARM 模板中的子资源创建(类似于 Microsoft.Network/trafficmanagerprofiles/endpoints),但是,这在 Bicep 中似乎不可用(或者只是在自动完成中不可用)。

我想要在我的main.bicep 文件中做类似的事情,因为这样我可以引用我想要添加的所有应用服务。

var trafficManagerProfileEndpoints 'Microsoft.Network/trafficmanagerprofiles/endpoints@2050-01-01` = {
  name: '${trafficManagerProfile.Name}/endpoints'
  endpoints: [ 
    // All of my endpoints
  ]
}

与通过Microsoft.Web/sites/config@2020-12-01 获得的应用服务中的配置设置有些相似。

对此有什么想法吗?

【问题讨论】:

    标签: azure azure-resource-manager azure-traffic-manager azure-bicep


    【解决方案1】:

    我刚刚以闪电般的速度解决了您的问题,如果我不完全理解它,请原谅我,但看起来您需要再次将您的网络应用声明为资源,但作为现有资源。这使您可以从应用服务中访问所需的所有道具。

    此博客解释如何在 Bicep 中使用现有资源:https://hexmaster.nl/posts/bicep-existing/

    【讨论】:

    • 谢谢,这确实让我想到了(我在答案中添加了一个内联评论),但并不“感觉”像实现这个的方式。
    【解决方案2】:

    这可以通过 Bicep ARM 实现,但 Microsoft.Network/trafficManagerProfiles api 没有可用于端点的类型,因此即使部署工作正常,它也会生成警告。

    如果您定义的流量管理器配置文件没有 endpoints 属性:

    resource trafficManager 'Microsoft.Network/trafficmanagerprofiles@2018-08-01' = {
      name: '<name>'
      location: 'global'
      properties: {
        profileStatus: 'Enabled'
        trafficRoutingMethod: '<trafficRoutingMethod>'
        dnsConfig: {
          ...
        }
        monitorConfig: {
          ...
        }    
      }
    }
    

    然后您可以像这样添加端点:

    // Azure endpoints: cloud service, app service, app service slots, public ip
    resource trafficManagerAzureEndpoint 'Microsoft.Network/trafficManagerProfiles/azureEndpoints@2018-08-01' = {
      name: '${trafficManagerName}/${name}'
      properties: {
        ...
      }
    }
    
    // External endpoint
    resource trafficManagerExternalEndpoint 'Microsoft.Network/trafficManagerProfiles/externalEndpoints@2018-08-01' = {
      name: '${trafficManagerName}/${name}'
      properties: {
        ...
      }
    }
    
    // Nested endpoints
    resource trafficManagerNestedEndpoint 'Microsoft.Network/trafficManagerProfiles/nestedEndpoints@2018-08-01' = {
      name: '${trafficManagerName}/${name}'
      properties: {
        ...
      }
    }
    
    

    【讨论】:

    • 这看起来正是我想要的!将在本周晚些时候试用。
    • 正如你所建议的,这就像一个魅力。谢谢!
    猜你喜欢
    • 2021-10-11
    • 2021-11-29
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多