diff --git a/builtin/providers/azurerm/resource_arm_template_deployment.go b/builtin/providers/azurerm/resource_arm_template_deployment.go index 79f400715d..5eb37cd70e 100644 --- a/builtin/providers/azurerm/resource_arm_template_deployment.go +++ b/builtin/providers/azurerm/resource_arm_template_deployment.go @@ -101,7 +101,7 @@ func resourceArmTemplateDeploymentCreate(d *schema.ResourceData, meta interface{ _, err := deployClient.CreateOrUpdate(resGroup, name, deployment, make(chan struct{})) if err != nil { - return nil + return fmt.Errorf("Error creating deployment: %s", err) } read, err := deployClient.Get(resGroup, name) diff --git a/builtin/providers/azurerm/resource_arm_template_deployment_test.go b/builtin/providers/azurerm/resource_arm_template_deployment_test.go index 99314628bf..efb64ce0c5 100644 --- a/builtin/providers/azurerm/resource_arm_template_deployment_test.go +++ b/builtin/providers/azurerm/resource_arm_template_deployment_test.go @@ -3,6 +3,7 @@ package azurerm import ( "fmt" "net/http" + "regexp" "testing" "github.com/hashicorp/terraform/helper/acctest" @@ -47,6 +48,22 @@ func TestAccAzureRMTemplateDeployment_withParams(t *testing.T) { }) } +func TestAccAzureRMTemplateDeployment_withError(t *testing.T) { + ri := acctest.RandInt() + config := fmt.Sprintf(testAccAzureRMTemplateDeployment_withError, ri, ri) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMTemplateDeploymentDestroy, + Steps: []resource.TestStep{ + { + Config: config, + ExpectError: regexp.MustCompile("The deployment operation failed"), + }, + }, + }) +} + func testCheckAzureRMTemplateDeploymentExists(name string) resource.TestCheckFunc { return func(s *terraform.State) error { // Ensure we have enough information in state to look up in API @@ -249,3 +266,66 @@ DEPLOY } ` + +// StorageAccount name is too long, forces error +var testAccAzureRMTemplateDeployment_withError = ` + resource "azurerm_resource_group" "test" { + name = "acctestrg-%d" + location = "West US" + } + + output "test" { + value = "${azurerm_template_deployment.test.outputs.testOutput}" + } + + resource "azurerm_template_deployment" "test" { + name = "acctesttemplate-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + template_body = <