簡體   English   中英

How to validate ARM Template using azure .net SDK or Fluent API?

[英]How to validate ARM Template using azure .net SDK or Fluent API?

How to validate uploaded ARM Template using azure .net SDK or Fluent API? I want to validate my uploaded ARM template like azure portal do using azure .net SDK or Fluent API? For reference please see below image azure is showing message if ARM template not valid so same thing i want to implement using any .net API or REST API.

在此處輸入圖像描述

@Jim 我收到以下錯誤:

在此處輸入圖像描述

如果您想驗證您的 arm 模板,請參考以下步驟

  1. 創建服務主體並將 Contributor 角色分配給 sp
az ad sp create-for-rbac -n "MyApp"
  1. 安裝 Package
Install-Package Microsoft.Azure.Management.ResourceManager.Fluent -Version 1.34.0
  1. 代碼
 string clientId = "23****9c";
            string clientSecret = "?s****/k";
            string tenantDomain = "";
            string subscription = "";
            var creds= SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientId, clientSecret, tenantDomain, AzureEnvironment.AzureGlobalCloud);
            var restClient = RestClient.Configure()
                .WithEnvironment(AzureEnvironment.AzureGlobalCloud)
                .WithCredentials(creds)
                .WithLogLevel(HttpLoggingDelegatingHandler.Level.BodyAndHeaders)
                .Build();


            ResourceManagementClient managementClient = new ResourceManagementClient(restClient);
            managementClient.SubscriptionId = subscription;

            //Validates whether the specified template is syntactically correct and will be accepted by Azure Resource Manager..
            DeploymentValidateResultInner res = await managementClient.Deployments.ValidateAsync("<groupName>", "<deployName>", new DeploymentInner()
            {
                Location = "",
                Properties = new DeploymentProperties()
                {
                    ParametersLink = new ParametersLink("uri"),
                    TemplateLink = new TemplateLink("")
                }
            });

            Console.WriteLine(res.Error.Message);

            // get changes that will be made by the deployment if executed at the scope of resource group
            WhatIfOperationResultInner res1 = await  managementClient.Deployments.WhatIfAsync("<groupName>", "<deployName>", new DeploymentWhatIf() { 
                  Location="",
                   Properties= new DeploymentWhatIfProperties() {
                       ParametersLink = new ParametersLink("uri"),
                       TemplateLink = new TemplateLink("")
                   }
            });

            foreach (var change in res1.Changes) {
               // 
            }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM