PULUMI -C# - 输出变量

发布于 2025-02-11 14:29:05 字数 1145 浏览 2 评论 0原文

我正在尝试通过下一类提供资源组。从堆栈类调用它,但面临输出变量的问题。

class GenerateResourceGroup
{
    public GenerateResourceGroup(Input<string> location, Input<string> rgName, Dictionary<string, string> tags)
    {
        Console.WriteLine(location);
        Console.WriteLine(rgName);
        var config = new Pulumi.Config();
        var resourceGroup = new Pulumi.AzureNative.Resources.ResourceGroup("resourceGroup", new Pulumi.AzureNative.Resources.ResourceGroupArgs
        {
            Location = location,
            ResourceGroupName = rgName,
            Tags = tags,
        });
        resourceGroupName = resourceGroup.Name;
    }
    [Output]
    public Output<string> resourceGroupName { get; }
}

错误:即使我尝试使用应用程序,但仍会出现错误。

pulumi.input 1 [System.String] Pulumi.input 1 [System.String] 不支持[输出]上的[输出]上调用[ToString]。 为了获得输出的价值作为输出考虑: 1。O.Apply(v =&gt; $“ prefix {v}后缀”) 2。output.format($“ prefix {hostName}后缀”); 参见 https://pulumi.io.io/help/outputs 有关更多详细信息。

I am trying to provision resource group with below class. Calling it from the stack class but facing some issue with the output variable.

class GenerateResourceGroup
{
    public GenerateResourceGroup(Input<string> location, Input<string> rgName, Dictionary<string, string> tags)
    {
        Console.WriteLine(location);
        Console.WriteLine(rgName);
        var config = new Pulumi.Config();
        var resourceGroup = new Pulumi.AzureNative.Resources.ResourceGroup("resourceGroup", new Pulumi.AzureNative.Resources.ResourceGroupArgs
        {
            Location = location,
            ResourceGroupName = rgName,
            Tags = tags,
        });
        resourceGroupName = resourceGroup.Name;
    }
    [Output]
    public Output<string> resourceGroupName { get; }
}

Error: Even I tried to utilize apply but still getting error.

Pulumi.Input1[System.String] Pulumi.Input1[System.String]
Calling [ToString] on an [Output] is not supported.
To get the value of an Output as an Output consider:
1. o.Apply(v => $"prefix{v}suffix")
2. Output.Format($"prefix{hostname}suffix");
See https://pulumi.io/help/outputs for more details.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半世晨晓 2025-02-18 14:29:05

这是CLI的问题。我卸载了最新版本的CLI并安装了旧版本2.33.1。这解决了问题。由于API的折旧,这都是BCOZ的基础API。

It was an issue with the cli.. i uninstalled the latest version of CLI and installed old version 2.33.1. That has solved the problem. It's all bcoz underlying api due to the depreciation of the API.. learn.microsoft.com/cli/azure/microsoft-graph-migration

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文