Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_eventhub_authorization_rule - Fix intermittent 404 errors #7122

Merged
merged 9 commits into from Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -3,10 +3,10 @@ package eventhub
import (
"fmt"
"log"
"net/http"
"time"

"github.com/Azure/azure-sdk-for-go/services/eventhub/mgmt/2017-04-01/eventhub"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
Expand Down Expand Up @@ -102,22 +102,27 @@ func resourceArmEventHubAuthorizationRuleCreateUpdate(d *schema.ResourceData, me
},
}

if _, err := client.CreateOrUpdateAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name, parameters); err != nil {
return fmt.Errorf("Error creating/updating EventHub Authorization Rule %q (EventHub %q / Namespace %q / Resource Group %q): %s", name, eventHubName, namespaceName, resourceGroup, err)
}
return resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
if _, err := client.CreateOrUpdateAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name, parameters); err != nil {
return resource.NonRetryableError(fmt.Errorf("Error creating Authorization Rule %q (event Hub %q / Namespace %q / Resource Group %q): %+v", name, eventHubName, namespaceName, resourceGroup, err))
}

read, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name)
if err != nil {
return err
}
read, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name)
if err != nil {
if utils.ResponseWasNotFound(read.Response) {
return resource.RetryableError(fmt.Errorf("Expected instance of the Authorization Rule %q (event Hub %q / Namespace %q / Resource Group %q) to be created but was in non existent state, retrying", name, eventHubName, namespaceName, resourceGroup))
}
return resource.NonRetryableError(fmt.Errorf("Expected instance of Authorization Rule %q (event Hub %q / Namespace %q / Resource Group %q) could not be found", name, eventHubName, namespaceName, resourceGroup))
}

if read.ID == nil {
return fmt.Errorf("Cannot read EventHub Authorization Rule %s (resource group %s) ID", name, resourceGroup)
}
if read.ID == nil {
return resource.NonRetryableError(fmt.Errorf("Cannot read Authorization Rule %q (event Hub %q / Namespace %q / Resource Group %q) ID", name, eventHubName, namespaceName, resourceGroup))
}

d.SetId(*read.ID)
d.SetId(*read.ID)

return resourceArmEventHubAuthorizationRuleRead(d, meta)
return resource.NonRetryableError(resourceArmEventHubAuthorizationRuleRead(d, meta))
})
}

func resourceArmEventHubAuthorizationRuleRead(d *schema.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -192,10 +197,10 @@ func resourceArmEventHubAuthorizationRuleDelete(d *schema.ResourceData, meta int
locks.ByName(namespaceName, eventHubNamespaceResourceName)
defer locks.UnlockByName(namespaceName, eventHubNamespaceResourceName)

resp, err := eventhubClient.DeleteAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name)

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("Error issuing Azure ARM delete request of EventHub Authorization Rule '%s': %+v", name, err)
if resp, err := eventhubClient.DeleteAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name); err != nil {
if !utils.ResponseWasNotFound(resp) {
return fmt.Errorf("Error issuing Azure ARM delete request of EventHub Authorization Rule '%s': %+v", name, err)
}
}

return nil
Expand Down
Expand Up @@ -119,7 +119,7 @@ func resourceArmEventHubNamespaceAuthorizationRuleRead(d *schema.ResourceData, m
return err
}

name := id.Path["AuthorizationRules"] // this is different then eventhub where its authorizationRules
name := id.Path["authorizationRules"]
resourceGroup := id.ResourceGroup
namespaceName := id.Path["namespaces"]

Expand Down Expand Up @@ -168,7 +168,7 @@ func resourceArmEventHubNamespaceAuthorizationRuleDelete(d *schema.ResourceData,
return err
}

name := id.Path["AuthorizationRules"] // this is different then eventhub where its authorizationRules
name := id.Path["authorizationRules"]
resourceGroup := id.ResourceGroup
namespaceName := id.Path["namespaces"]

Expand Down