2

先决条件:

  • 在应用服务上配置的同一应用服务计划中不能有重复的应用服务混合连接

使用他们网站(https://www.pulumi.com/docs/reference/pkg/azure/appservice/hybridconnection/)提供的示例:

using Pulumi;
using Azure = Pulumi.Azure;
using Pulumi.AzureNextGen; 

class MyStack : Stack
{
    public MyStack()
    {
        var exampleResourceGroup = new Azure.Core.ResourceGroup("exampleResourceGroup", new Azure.Core.ResourceGroupArgs
        {
            Location = "West Europe",
        });
        var examplePlan = new Azure.AppService.Plan("examplePlan", new Azure.AppService.PlanArgs
        {
            Location = exampleResourceGroup.Location,
            ResourceGroupName = exampleResourceGroup.Name,
            Sku = new Azure.AppService.Inputs.PlanSkuArgs
            {
                Tier = "Standard",
                Size = "S1",
            },
        });
        var exampleAppService = new Azure.AppService.AppService("exampleAppService", new Azure.AppService.AppServiceArgs
        {
            Location = exampleResourceGroup.Location,
            ResourceGroupName = exampleResourceGroup.Name,
            AppServicePlanId = examplePlan.Id,
        });
        var exampleNamespace = new Azure.Relay.Namespace("exampleNamespace", new Azure.Relay.NamespaceArgs
        {
            Location = exampleResourceGroup.Location,
            ResourceGroupName = exampleResourceGroup.Name,
            SkuName = "Standard",
        });
        var exampleHybridConnection = new Azure.Relay.HybridConnection("exampleHybridConnection", new Azure.Relay.HybridConnectionArgs
        {
            ResourceGroupName = exampleResourceGroup.Name,
            RelayNamespaceName = exampleNamespace.Name,
            UserMetadata = "examplemetadata",
        });
        var exampleAppservice_hybridConnectionHybridConnection = new Azure.AppService.HybridConnection("exampleAppservice/hybridConnectionHybridConnection", new Azure.AppService.HybridConnectionArgs
        {
            AppServiceName = exampleAppService.Name,
            ResourceGroupName = exampleResourceGroup.Name,
            RelayId = exampleHybridConnection.Id,
            Hostname = "testhostname.example",
            Port = 8080,
            SendKeyName = "RootManageSharedAccessKey",
        });
    }

}

我收到以下错误:

错误:无法列出命名空间“XXX”(资源组“XXX”)的访问密钥:relay.NamespacesClient#ListKeys:响应请求失败:StatusCode=404 - 原始错误:autorest/azure:无法解析错误响应:“ “请求的资源 defaultSender 不存在。”“错误:json:无法将字符串解组为 azure.RequestError 类型的 Go 值

为了解决这个问题,我必须添加一个中继命名空间授权规则:

using Pulumi;
using Azure = Pulumi.Azure;
using Pulumi.AzureNextGen;

class MyStack : Stack
{
    public MyStack()
    {
        var exampleResourceGroup = new Azure.Core.ResourceGroup("exampleResourceGroup", new Azure.Core.ResourceGroupArgs
        {
            Location = "West Europe",
        });
        var examplePlan = new Azure.AppService.Plan("examplePlan", new Azure.AppService.PlanArgs
        {
            Location = exampleResourceGroup.Location,
            ResourceGroupName = exampleResourceGroup.Name,
            Sku = new Azure.AppService.Inputs.PlanSkuArgs
            {
                Tier = "Standard",
                Size = "S1",
            },
        });
        var exampleAppService = new Azure.AppService.AppService("exampleAppService", new Azure.AppService.AppServiceArgs
        {
            Location = exampleResourceGroup.Location,
            ResourceGroupName = exampleResourceGroup.Name,
            AppServicePlanId = examplePlan.Id,
        });
        var exampleNamespace = new Azure.Relay.Namespace("exampleNamespace", new Azure.Relay.NamespaceArgs
        {
            Location = exampleResourceGroup.Location,
            ResourceGroupName = exampleResourceGroup.Name,
            SkuName = "Standard",
        });

var defaultSenderAuthorizationRule = new Pulumi.AzureNextGen.Relay.Latest.NamespaceAuthorizationRule("defaultSenderAuthorizationRule",
                new AzureProviderNextGen.Relay.Latest.NamespaceAuthorizationRuleArgs
                {
                    AuthorizationRuleName = "defaultSender",
                    NamespaceName = exampleNamespace .Name,
                    ResourceGroupName = exampleNamespace .ResourceGroupName,
                    Rights =
                    {
                        "Manage",
                        "Listen",
                        "Send",
                    },
                });


        var exampleHybridConnection = new Azure.Relay.HybridConnection("exampleHybridConnection", new Azure.Relay.HybridConnectionArgs
        {
            ResourceGroupName = exampleResourceGroup.Name,
            RelayNamespaceName = exampleNamespace.Name,
            UserMetadata = "examplemetadata",
        });
        var exampleAppservice_hybridConnectionHybridConnection = new Azure.AppService.HybridConnection("exampleAppservice/hybridConnectionHybridConnection", new Azure.AppService.HybridConnectionArgs
        {
            AppServiceName = exampleAppService.Name,
            ResourceGroupName = exampleResourceGroup.Name,
            RelayId = exampleHybridConnection.Id,
            Hostname = "testhostname.example",
            Port = 8080,
            SendKeyName = "RootManageSharedAccessKey",
        });
    }

}

在此之后,它工作正常,堆栈完成,说我的 Appservice:HybridConnection 已创建。然而,当我导航到应用服务网络/HybridConnection 设置时,它不存在。

预期行为:

成功创建 AppService.HybridConnection 后,它应该出现在 Azure 门户中应用服务的混合连接列表中。

实际行为:

AppService.HybridConnection 创建成功但未出现在 App Service\Hybrid Connection 列表中

4

1 回答 1

1

在查看 Azure 活动日志时,似乎资源被创建,然后立即被删除。

解决方案是..

  1. 更新 Relay.HybridConnection 中的 UserMetadata,使其包含带有主机名和端口的 Endpoint 键
var exampleHybridConnection = new Azure.Relay.HybridConnection("exampleHybridConnection", new Azure.Relay.HybridConnectionArgs
        {
            ResourceGroupName = exampleResourceGroup.Name,
            RelayNamespaceName = exampleNamespace.Name,
            UserMetadata = "[{\"key\":\"endpoint\",\"value\":\"testhostname.example:8080\"}]",
        });
  1. 将授权规则添加到 Relay.HybridConnection。
var defaultListenerRule = new Pulumi.AzureNextGen.Relay.Latest.HybridConnectionAuthorizationRule("defaultListener",
                new Pulumi.AzureNextGen.Relay.Latest.HybridConnectionAuthorizationRuleArgs
                {
                    AuthorizationRuleName = "defaultListener",
                    HybridConnectionName = exampleHybridConnection.Name,
                    NamespaceName = exampleHybridConnection.RelayNamespaceName,
                    ResourceGroupName = exampleHybridConnection.ResourceGroupName,
                    Rights =
                    {
                        "Listen",
                    },
                });

            var defaultSenderRule = new Pulumi.AzureNextGen.Relay.Latest.HybridConnectionAuthorizationRule("defaultSender",
                new Pulumi.AzureNextGen.Relay.Latest.HybridConnectionAuthorizationRuleArgs
                {
                    AuthorizationRuleName = "defaultSender",
                    HybridConnectionName = exampleHybridConnection.Name,
                    NamespaceName = exampleHybridConnection.RelayNamespaceName,
                    ResourceGroupName = exampleHybridConnection.ResourceGroupName,
                    Rights =
                    {
                        "Send",
                    },
                });
  1. 然后在 AppService.HybridConnection 上添加一个 CustomResourceOptions 参数“DeleteBeforeReplace = true”。
var exampleAppservice_hybridConnectionHybridConnection = new Azure.AppService.HybridConnection("exampleAppservice/hybridConnectionHybridConnection", new Azure.AppService.HybridConnectionArgs
            {
                AppServiceName = exampleAppService.Name,
                ResourceGroupName = exampleResourceGroup.Name,
                RelayId = exampleHybridConnection.Id,
                Hostname = "testhostname.example",
                Port = 8080,
                SendKeyName = "exampleSharedAccessKey",
            }, new CustomResourceOptions { DeleteBeforeReplace = true });

创建后,所有内容都将链接并显示在混合连接管理器和 Azure 的门户中。

于 2021-01-12T22:19:25.423 回答