Azure sdk .net 如何使用fluent Resource Manager SDK获取部署的输出资源?
使用Azure REST API时,可以获取给定部署的详细信息,包括outputResources,其中列出了从ARM模板部署创建的实际资源 不幸的是,在使用Azure资源管理器Fluent SDK时,我似乎找不到访问outputResources的等效方法 我尝试使用以下方法:Azure sdk .net 如何使用fluent Resource Manager SDK获取部署的输出资源?,azure-sdk-.net,azure-sdk,azure-fluent-api,Azure Sdk .net,Azure Sdk,Azure Fluent Api,使用Azure REST API时,可以获取给定部署的详细信息,包括outputResources,其中列出了从ARM模板部署创建的实际资源 不幸的是,在使用Azure资源管理器Fluent SDK时,我似乎找不到访问outputResources的等效方法 我尝试使用以下方法: var deployments = ResourceManager.Authenticate(credentials) .WithSubscription(subscriptionId) .Deployments.Li
var deployments = ResourceManager.Authenticate(credentials)
.WithSubscription(subscriptionId)
.Deployments.ListByResourceGroup(resourceGroup)
.Where(x => x.Name == deploymentName)
.OrderByDescending(x => x.Timestamp)
.First();
但这似乎不允许我获得部署的实际资源的详细信息
这些似乎是部署的唯一可访问属性
您可以使用获取部署的详细信息
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
这个字段,
Outputs
不是他所说的同一个属性<只有在ARM模板中指定可选的Outputs
节点时,才会填写code>Outputs。同时,outPutResources字段包含所有生成的资源URI的列表,与Arm部署后在控制台中看到的内容类似。