如何使用 Fluent Resource Manager SDK 获取部署的输出资源?

How to get the outputResources of a deployment using the fluent Resource Manager SDK?

使用 Azure REST GET Deployments endpoint API 时,可以获得给定部署的详细信息,包括 outputResources,它列出了从 ARM 模板部署创建的实际资源

不幸的是,在使用 Azure Resource Manager Fluent SDK 时,我似乎找不到访问 outputResources 的等效方法。

我试过使用以下方法:

var deployments = ResourceManager.Authenticate(credentials)
.WithSubscription(subscriptionId)
.Deployments.ListByResourceGroup(resourceGroup)
.Where(x => x.Name == deploymentName)
.OrderByDescending(x => x.Timestamp)
.First();

但这似乎不允许我获取已部署的实际资源的详细信息。

这些似乎是 deployment 的唯一可访问属性

您可以使用Azure Management Libraries for .NET获取部署的详细信息。

  1. 安装Microsoft.Azure.Management.Fluent包

  2. 创建一个授权文件 AUTH.md

  3. 样本

    static void Main(string[] args)
    {
        IAzure azure = Azure.Authenticate("C:\Users\v-linjji\my.azureauth").WithDefaultSubscription();
        var deployments = azure.Deployments.ListByResourceGroup("JackWebApp");
        foreach(var deployment in deployments)
        {
            Console.WriteLine(deployment.Timestamp + " -> " + deployment.Name);
    
            foreach(var dependency in deployment.Dependencies)
            {
                Console.WriteLine(dependency.Id);
            }
    
            foreach(var operation in deployment.DeploymentOperations.List())
            {
                Console.WriteLine(operation.OperationId + " -> " + operation.StatusCode);
            }
    
            Console.WriteLine("Outputs:" + deployment.Outputs);
    
            Console.WriteLine();
        }
    
        Console.ReadLine();
    }
    

结果:

使用 Azure SDK 执行部署会返回一个 IDeployment 对象,并且您正在寻找的属性现在嵌套得非常深。

与您的部署相关的所有操作都在 IDeployment.DeploymentOperations 下。您可以调用 .List() 获取枚举器并逐步执行它们。

每个 DeploymentOperations 对象都有一些您会感兴趣的成员,对我最有用的是:

foreach(IDeploymentOperation op in deployment.DeploymentOperations.List())
{
    op.ProvisioningState // Completed, In Progress, Error
    op.StatusMessage // OK, Failed, etc
    op.TargetResource.Id // the fully qualified resource Id of your deployment
    op.TargetResource.ResourceName // the name of the new item
    op.TargetResource.ResourceType // the type of the new item, StorageAccount, Networking, etc
}

重申一下,您会找到 Id,这可能是该路径下最重要的

op.TargetResource.Id // the fully qualified resource Id of your deployment
/subscriptions/abc123/resourcegroup/MycoolGroup123/storageAccount/abc123efg