2

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 enter image description here

abatishchev
  • 98,240
  • 88
  • 296
  • 433
chivano
  • 603
  • 1
  • 5
  • 13

2 Answers2

2

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:

enter image description here

Jack Jia
  • 5,268
  • 1
  • 12
  • 14
  • This field, `Outputs` is not the same property he is talking about. `Outputs` are only filled in if you specify the optional `Outputs` node in an ARM template. The outPutResources field, meanwhile, has a list of all of the generated Resource URIs and is similar to what you see in the console after an Arm Deployment. – FoxDeploy Jul 16 '20 at 20:46
1

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
FoxDeploy
  • 12,569
  • 2
  • 33
  • 48