Skip to content

Commit e3e134b

Browse files
Porting to M162: Adding validation before deployment for ARG Tasks (#12096)
* Adding validation before deployment for ARG Tasks (#11979) * Adding validation before deployment for ARG Tasks * Review comments, try-catch * Bug fix * Updating task version * Fixing merge conflicts * Bug fix * Review comments * Merge conflicts * Review comments * Brackets
1 parent 1346edd commit e3e134b

File tree

8 files changed

+25
-9
lines changed

8 files changed

+25
-9
lines changed

Tasks/AzureResourceGroupDeploymentV2/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,5 +195,6 @@
195195
"loc.messages.ServicePrincipalRoleAssignmentDetails": "Please make sure the Service Principal with name %s is assigned the right roles for the Resource Group %s. Follow the link for more details: https://docs.microsoft.com/en-us/azure/role-based-access-control/role-assignments-portal",
196196
"loc.messages.ServicePrincipalFetchFailed": "Error while fetching Service Principal details: %s",
197197
"loc.messages.FindMoreDeploymentDetailsAzurePortal": "Task successfully created an Azure Resource Manager deployment, but the deployment failed. Please see more detailed Azure resource manager deployment logs at: (Please Copy-Paste the link) %s",
198+
"loc.messages.TemplateValidationFailure": "Validation errors were found in the Azure Resource Manager template. This can potentially cause template deployment to fail. %s. Please follow https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-syntax",
198199
"loc.messages.ManagedServiceIdentityDetails": "Please make sure the Managed Service Identity used for deployment is assigned the right roles for the Resource Group %s. Follow the link for more details: https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/howto-assign-access-portal"
199200
}

Tasks/AzureResourceGroupDeploymentV2/operations/ResourceGroup.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,11 @@ export class ResourceGroup {
534534
if (deployment.properties["mode"] === "Validation") {
535535
return this.validateDeployment(armClient, deployment);
536536
} else {
537+
try {
538+
await this.validateDeployment(armClient, deployment);
539+
} catch (error) {
540+
tl.warning(tl.loc("TemplateValidationFailure", error));
541+
}
537542
console.log(tl.loc("StartingDeployment"));
538543
return new Promise<void>((resolve, reject) => {
539544
this.taskParameters.deploymentName = this.taskParameters.deploymentName || this.createDeploymentName();
@@ -544,7 +549,7 @@ export class ResourceGroup {
544549
return this.waitAndPerformAzureDeployment(armClient, deployment, retryCount);
545550
}
546551
this.writeDeploymentErrors(error);
547-
this.checkAndPrintPortalDeploymentURL(result.error);
552+
this.checkAndPrintPortalDeploymentURL((!!result && !!result.error) ? result.error : error);
548553
this.printServicePrincipalRoleAssignmentError(error);
549554
return reject(tl.loc("CreateTemplateDeploymentFailed"));
550555
}

Tasks/AzureResourceGroupDeploymentV2/task.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"version": {
1616
"Major": 2,
1717
"Minor": 162,
18-
"Patch": 4
18+
"Patch": 5
1919
},
2020
"demands": [],
2121
"minimumAgentVersion": "2.119.1",
@@ -484,6 +484,7 @@
484484
"ServicePrincipalRoleAssignmentDetails": "Please make sure the Service Principal with name %s is assigned the right roles for the Resource Group %s. Follow the link for more details: https://docs.microsoft.com/en-us/azure/role-based-access-control/role-assignments-portal",
485485
"ServicePrincipalFetchFailed": "Error while fetching Service Principal details: %s",
486486
"FindMoreDeploymentDetailsAzurePortal": "Task successfully created an Azure Resource Manager deployment, but the deployment failed. Please see more detailed Azure resource manager deployment logs at: (Please Copy-Paste the link) %s",
487+
"TemplateValidationFailure": "Validation errors were found in the Azure Resource Manager template. This can potentially cause template deployment to fail. %s. Please follow https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-syntax",
487488
"ManagedServiceIdentityDetails": "Please make sure the Managed Service Identity used for deployment is assigned the right roles for the Resource Group %s. Follow the link for more details: https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/howto-assign-access-portal"
488489
}
489490
}

Tasks/AzureResourceGroupDeploymentV2/task.loc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"version": {
1616
"Major": 2,
1717
"Minor": 162,
18-
"Patch": 4
18+
"Patch": 5
1919
},
2020
"demands": [],
2121
"minimumAgentVersion": "2.119.1",
@@ -484,6 +484,7 @@
484484
"ServicePrincipalRoleAssignmentDetails": "ms-resource:loc.messages.ServicePrincipalRoleAssignmentDetails",
485485
"ServicePrincipalFetchFailed": "ms-resource:loc.messages.ServicePrincipalFetchFailed",
486486
"FindMoreDeploymentDetailsAzurePortal": "ms-resource:loc.messages.FindMoreDeploymentDetailsAzurePortal",
487+
"TemplateValidationFailure": "ms-resource:loc.messages.TemplateValidationFailure",
487488
"ManagedServiceIdentityDetails": "ms-resource:loc.messages.ManagedServiceIdentityDetails"
488489
}
489490
}

Tasks/AzureResourceManagerTemplateDeploymentV3/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,6 @@
8686
"loc.messages.ServicePrincipalRoleAssignmentDetails": "Please make sure the Service Principal with name %s is assigned the right roles for the entity %s. Follow the link for more details: https://docs.microsoft.com/en-us/azure/role-based-access-control/role-assignments-portal",
8787
"loc.messages.ServicePrincipalFetchFailed": "Error while fetching Service Principal details: %s",
8888
"loc.messages.FindMoreDeploymentDetailsAzurePortal": "Task successfully created an Azure Resource Manager deployment, but the deployment failed. Please see more detailed Azure resource manager deployment logs at: (Please Copy-Paste the link) %s",
89-
"loc.messages.ManagedServiceIdentityDetails": "Please make sure the Managed Service Identity used for deployment is assigned the right roles for the Resource Group %s. Follow the link for more details: https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/howto-assign-access-portal"
89+
"loc.messages.ManagedServiceIdentityDetails": "Please make sure the Managed Service Identity used for deployment is assigned the right roles for the Resource Group %s. Follow the link for more details: https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/howto-assign-access-portal",
90+
"loc.messages.TemplateValidationFailure": "Validation errors were found in the Azure Resource Manager template. This can potentially cause template deployment to fail. %s. Please follow https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-syntax"
9091
}

Tasks/AzureResourceManagerTemplateDeploymentV3/operations/DeploymentScopeBase.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export class DeploymentScopeBase {
5050
if (this.deploymentParameters.properties["mode"] === "Validation") {
5151
return this.validateDeployment();
5252
} else {
53+
try {
54+
await this.validateDeployment();
55+
} catch (error) {
56+
tl.warning(tl.loc("TemplateValidationFailure", error));
57+
}
5358
console.log(tl.loc("StartingDeployment"));
5459
return new Promise<void>((resolve, reject) => {
5560
this.taskParameters.deploymentName = this.taskParameters.deploymentName || utils.createDeploymentName(this.taskParameters);
@@ -60,7 +65,7 @@ export class DeploymentScopeBase {
6065
return this.waitAndPerformAzureDeployment(retryCount);
6166
}
6267
utils.writeDeploymentErrors(this.taskParameters, error);
63-
this.checkAndPrintPortalDeploymentURL(error);
68+
this.checkAndPrintPortalDeploymentURL((!!result && !!result.error) ? result.error : error);
6469
this.printServicePrincipalRoleAssignmentError(error);
6570
return reject(tl.loc("CreateTemplateDeploymentFailed"));
6671
}

Tasks/AzureResourceManagerTemplateDeploymentV3/task.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"version": {
1616
"Major": 3,
1717
"Minor": 1,
18-
"Patch": 13
18+
"Patch": 14
1919
},
2020
"preview": "true",
2121
"demands": [],
@@ -305,6 +305,7 @@
305305
"ServicePrincipalRoleAssignmentDetails": "Please make sure the Service Principal with name %s is assigned the right roles for the entity %s. Follow the link for more details: https://docs.microsoft.com/en-us/azure/role-based-access-control/role-assignments-portal",
306306
"ServicePrincipalFetchFailed": "Error while fetching Service Principal details: %s",
307307
"FindMoreDeploymentDetailsAzurePortal": "Task successfully created an Azure Resource Manager deployment, but the deployment failed. Please see more detailed Azure resource manager deployment logs at: (Please Copy-Paste the link) %s",
308-
"ManagedServiceIdentityDetails": "Please make sure the Managed Service Identity used for deployment is assigned the right roles for the Resource Group %s. Follow the link for more details: https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/howto-assign-access-portal"
308+
"ManagedServiceIdentityDetails": "Please make sure the Managed Service Identity used for deployment is assigned the right roles for the Resource Group %s. Follow the link for more details: https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/howto-assign-access-portal",
309+
"TemplateValidationFailure": "Validation errors were found in the Azure Resource Manager template. This can potentially cause template deployment to fail. %s. Please follow https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-syntax"
309310
}
310311
}

Tasks/AzureResourceManagerTemplateDeploymentV3/task.loc.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"version": {
1616
"Major": 3,
1717
"Minor": 1,
18-
"Patch": 13
18+
"Patch": 14
1919
},
2020
"preview": "true",
2121
"demands": [],
@@ -305,6 +305,7 @@
305305
"ServicePrincipalRoleAssignmentDetails": "ms-resource:loc.messages.ServicePrincipalRoleAssignmentDetails",
306306
"ServicePrincipalFetchFailed": "ms-resource:loc.messages.ServicePrincipalFetchFailed",
307307
"FindMoreDeploymentDetailsAzurePortal": "ms-resource:loc.messages.FindMoreDeploymentDetailsAzurePortal",
308-
"ManagedServiceIdentityDetails": "ms-resource:loc.messages.ManagedServiceIdentityDetails"
308+
"ManagedServiceIdentityDetails": "ms-resource:loc.messages.ManagedServiceIdentityDetails",
309+
"TemplateValidationFailure": "ms-resource:loc.messages.TemplateValidationFailure"
309310
}
310311
}

0 commit comments

Comments
 (0)