使用Azure REST API的GET Deployments endpoint时,可以获取给定部署的详细信息,包括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();
但是这似乎不允许我获取已部署的实际资源的详细信息。
答案 0 :(得分:1)
您可以使用Azure Management Libraries for .NET来获取部署的详细信息。
安装Microsoft.Azure.Management.Fluent软件包
样品
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();
}
结果:
答案 1 :(得分:1)
使用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