mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-07 14:44:11 -06:00
provider/azurerm: catch azurerm_template_deployment errors (#7644)
The error was ignored causing Terraform to report that the deployments was successful rather than in a bad state. This commit cause the apply operation to report the error. Added a test which attempts to create a storage account with a name longer than the maximum permitted length to force a failure. ``` TF_ACC=1 go test ./builtin/providers/azurerm -v -run TestAccAzureRMTemplateDeployment_ -timeout 120m === RUN TestAccAzureRMTemplateDeployment_basic --- PASS: TestAccAzureRMTemplateDeployment_basic (377.78s) === RUN TestAccAzureRMTemplateDeployment_withParams --- PASS: TestAccAzureRMTemplateDeployment_withParams (327.89s) === RUN TestAccAzureRMTemplateDeployment_withError --- PASS: TestAccAzureRMTemplateDeployment_withError (226.64s) PASS ok github.com/hashicorp/terraform/builtin/providers/azurerm 932.440s ```
This commit is contained in:
parent
324e78020d
commit
0fde61b9ab
@ -101,7 +101,7 @@ func resourceArmTemplateDeploymentCreate(d *schema.ResourceData, meta interface{
|
|||||||
|
|
||||||
_, err := deployClient.CreateOrUpdate(resGroup, name, deployment, make(chan struct{}))
|
_, err := deployClient.CreateOrUpdate(resGroup, name, deployment, make(chan struct{}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return fmt.Errorf("Error creating deployment: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
read, err := deployClient.Get(resGroup, name)
|
read, err := deployClient.Get(resGroup, name)
|
||||||
|
@ -3,6 +3,7 @@ package azurerm
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"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 {
|
func testCheckAzureRMTemplateDeploymentExists(name string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
// Ensure we have enough information in state to look up in API
|
// 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 = <<DEPLOY
|
||||||
|
{
|
||||||
|
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
|
||||||
|
"contentVersion": "1.0.0.0",
|
||||||
|
"parameters": {
|
||||||
|
"storageAccountType": {
|
||||||
|
"type": "string",
|
||||||
|
"defaultValue": "Standard_LRS",
|
||||||
|
"allowedValues": [
|
||||||
|
"Standard_LRS",
|
||||||
|
"Standard_GRS",
|
||||||
|
"Standard_ZRS"
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"description": "Storage Account type"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"variables": {
|
||||||
|
"location": "[resourceGroup().location]",
|
||||||
|
"storageAccountName": "badStorageAccountNameTooLong",
|
||||||
|
"apiVersion": "2015-06-15"
|
||||||
|
},
|
||||||
|
"resources": [
|
||||||
|
{
|
||||||
|
"type": "Microsoft.Storage/storageAccounts",
|
||||||
|
"name": "[variables('storageAccountName')]",
|
||||||
|
"apiVersion": "[variables('apiVersion')]",
|
||||||
|
"location": "[variables('location')]",
|
||||||
|
"properties": {
|
||||||
|
"accountType": "[parameters('storageAccountType')]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputs": {
|
||||||
|
"testOutput": {
|
||||||
|
"type": "string",
|
||||||
|
"value": "Output Value"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DEPLOY
|
||||||
|
parameters {
|
||||||
|
storageAccountType = "Standard_GRS"
|
||||||
|
}
|
||||||
|
deployment_mode = "Complete"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
Loading…
Reference in New Issue
Block a user