From 7020c0c2912316ffdf8d61ec3466c2563a96e9ca Mon Sep 17 00:00:00 2001 From: Octavian Ionescu Date: Thu, 24 Oct 2019 20:22:58 +0300 Subject: [PATCH] added template validation Signed-off-by: Octavian Ionescu --- azurerm/resource_arm_template_deployment.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/azurerm/resource_arm_template_deployment.go b/azurerm/resource_arm_template_deployment.go index 37f83cb7aedb..e5a814d33765 100644 --- a/azurerm/resource_arm_template_deployment.go +++ b/azurerm/resource_arm_template_deployment.go @@ -152,6 +152,27 @@ func resourceArmTemplateDeploymentCreateUpdate(d *schema.ResourceData, meta inte Properties: &properties, } + deploymentValidateResponse, err := client.Validate(ctx, resourceGroup, name, deployment) + + if !d.IsNewResource() { + d.Partial(true) + } + + if err != nil { + return fmt.Errorf("Error requesting Validation for Template Deployment %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + if deploymentValidateResponse.Error != nil { + if deploymentValidateResponse.Error.Message != nil { + return fmt.Errorf("Error validating Template for Deployment %q (Resource Group %q): %+v", name, resourceGroup, *deploymentValidateResponse.Error.Message) + } + return fmt.Errorf("Error validating Template for Deployment %q (Resource Group %q): %+v", name, resourceGroup, *deploymentValidateResponse.Error) + } + + if !d.IsNewResource() { + d.Partial(false) + } + future, err := client.CreateOrUpdate(ctx, resourceGroup, name, deployment) if err != nil { return fmt.Errorf("Error creating deployment: %+v", err)