gpt4 book ai didi

c# - 创建Pulumi.AzureNative.OperationalInsights.Workspace后如何获取WorkspaceKey?

转载 作者:行者123 更新时间:2023-12-02 22:59:42 27 4
gpt4 key购买 nike

我使用以下内容创建 Pulumi.AzureNative.OperationalInsights.Workspace:

    name = "workspace";
var workspace =
new Workspace
(
name,
new WorkspaceArgs
{
Location = resourceGroup.Location,
ResourceGroupName = resourceGroup.Name,
RetentionInDays = 30,
Sku = new WorkspaceSkuArgs
{
Name = WorkspaceSkuNameEnum.PerGB2018,
},
Tags =
{
{ "tag1", "val1" },
},
WorkspaceName = name,
}
);

稍后我想将我的 ContainerGroup 连接到此工作区,并需要 WorkspaceIdWorkspaceKey

我从哪里可以获得这些值?

最佳答案

WorkspaceId 派生自 workspace.CustomerId

WorkspaceKey 不是由工作区直接返回的,您需要使用 GetSharedKeys 检索它。

这是一个为我成功配置的完整工作示例

using Pulumi;
using Pulumi.AzureNative.ContainerInstance;
using Pulumi.AzureNative.ContainerInstance.Inputs;
using Pulumi.AzureNative.Resources;
using Pulumi.AzureNative.OperationalInsights;
using Pulumi.AzureNative.OperationalInsights.Inputs;

class MyStack : Stack
{
public MyStack()
{
// Create an Azure Resource Group
var resourceGroup = new ResourceGroup("example");

// create the operational insights workspace
var workspace =
new Workspace
(
"example",
new WorkspaceArgs
{
Location = resourceGroup.Location,
ResourceGroupName = resourceGroup.Name,
RetentionInDays = 30,
Sku = new WorkspaceSkuArgs
{
Name = WorkspaceSkuNameEnum.PerGB2018,
},
WorkspaceName = "example",
}
);

// retrieve the workspace shared key
// you may want to make this a secret
var workspaceSharedKeys = Output.Tuple(resourceGroup.Name, workspace.Name).Apply(items =>
GetSharedKeys.InvokeAsync(new GetSharedKeysArgs
{
ResourceGroupName = items.Item1,
WorkspaceName = items.Item2,
}));

// provision the containergroup
var containerGroup = new ContainerGroup("example", new ContainerGroupArgs
{
ContainerGroupName = "example",
Containers =
{
new ContainerArgs
{
Image = "nginx",
Name = "example",
Ports =
{
new ContainerPortArgs
{
Port = 80,
},
},
Resources = new ResourceRequirementsArgs
{
Requests = new ResourceRequestsArgs
{
Cpu = 1,
MemoryInGB = 1.5,
},
},
},
},
Diagnostics = new ContainerGroupDiagnosticsArgs
{
LogAnalytics = new LogAnalyticsArgs
{
LogType = "ContainerInsights",

WorkspaceId = workspace.CustomerId,
WorkspaceKey = workspaceSharedKeys.Apply(key => key.PrimarySharedKey!),
},
},
Location = "WestUS",
OsType = "Linux",
ResourceGroupName = resourceGroup.Name,
});
}
}

关于c# - 创建Pulumi.AzureNative.OperationalInsights.Workspace后如何获取WorkspaceKey?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71306263/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com