简体   繁体   中英

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

When using the GET Deployments endpoint of the Azure REST API, it's possible to get details of a given deployment including the outputResources which lists the actual resources created from an ARM template deployment

Unfortunately, I can't seem to find an equivalent means of accessing the outputResources when using the Azure Resource Manager Fluent SDK.

I've tried using the following:

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

but this doesn't seem to allow me to get the details of the actual resources which were deployed.

These seem to be the only accessible properties of deployment在此处输入图像描述

You can use Azure Management Libraries for .NET to get the detailed information of deployments.

  1. Install Microsoft.Azure.Management.Fluent package

  2. Create an auth file as AUTH.md

  3. Sample

    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(); }

Result:

在此处输入图像描述

Conducting a Deployment using the Azure SDK gives you back an IDeployment object, and the properties you're looking for are now nested pretty deeply.

All of the operations related to your deployment live under IDeployment.DeploymentOperations . You can call .List() to get an enumerator and step through them.

Each DeploymentOperations object has some members you'll be interested in, the most useful to me are:

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
}

And to reiterate you'll find the Id, which is probably the most important under this path

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM