From 10261fab11f9a15e9cd33d565b8bb523a16d0390 Mon Sep 17 00:00:00 2001 From: "github@automatetheneedful.com" Date: Wed, 27 May 2020 22:01:15 -0700 Subject: [PATCH 1/8] adding wip --- .../eventhub_authorization_rule_resource.go | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go index 1c86a888582d..ecf8149422c7 100644 --- a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go @@ -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" @@ -102,22 +102,24 @@ 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 { - read, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name) - if err != nil { - return err - } + 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)) + } - if read.ID == nil { - return fmt.Errorf("Cannot read EventHub Authorization Rule %s (resource group %s) ID", name, resourceGroup) - } + read, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name) + if err != nil { + 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)) + } + 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 { @@ -192,10 +194,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 From 848c02dbea15f8692f31fedbf3fb3ff2711168e6 Mon Sep 17 00:00:00 2001 From: "github@automatetheneedful.com" Date: Thu, 28 May 2020 08:46:42 -0700 Subject: [PATCH 2/8] wip --- .../eventhub_namespace_authorization_rule_resource.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_resource.go index 7af663e7ad24..e75a340e7fa2 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_resource.go @@ -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"] @@ -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"] From 1e1eb3b6d9ead6bc88a6e5fc2b1322259ce9450f Mon Sep 17 00:00:00 2001 From: nickmhankins <33635424+nickmhankins@users.noreply.github.com> Date: Thu, 28 May 2020 09:03:30 -0700 Subject: [PATCH 3/8] readd http --- .../services/eventhub/eventhub_authorization_rule_resource.go | 1 + 1 file changed, 1 insertion(+) diff --git a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go index ecf8149422c7..7a06127af801 100644 --- a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go @@ -3,6 +3,7 @@ package eventhub import ( "fmt" "log" + "net/http" "time" "github.com/Azure/azure-sdk-for-go/services/eventhub/mgmt/2017-04-01/eventhub" From bb1379b23d399b092a56dafa21159501f7e22c53 Mon Sep 17 00:00:00 2001 From: "github@automatetheneedful.com" Date: Thu, 28 May 2020 09:09:26 -0700 Subject: [PATCH 4/8] readd http --- .../services/eventhub/eventhub_authorization_rule_resource.go | 1 + 1 file changed, 1 insertion(+) diff --git a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go index ecf8149422c7..126ae5676225 100644 --- a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go @@ -3,6 +3,7 @@ package eventhub import ( "fmt" "log" + "net/http" "time" "github.com/Azure/azure-sdk-for-go/services/eventhub/mgmt/2017-04-01/eventhub" From 5dab67e1648ce2672a9307ed36df9d4f540eac4c Mon Sep 17 00:00:00 2001 From: "github@automatetheneedful.com" Date: Thu, 28 May 2020 09:29:37 -0700 Subject: [PATCH 5/8] remove http import --- .../services/eventhub/eventhub_authorization_rule_resource.go | 1 - 1 file changed, 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go index 126ae5676225..ecf8149422c7 100644 --- a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go @@ -3,7 +3,6 @@ package eventhub import ( "fmt" "log" - "net/http" "time" "github.com/Azure/azure-sdk-for-go/services/eventhub/mgmt/2017-04-01/eventhub" From a6fef27e1c28a75efb53faeeac530c2114491e44 Mon Sep 17 00:00:00 2001 From: "github@automatetheneedful.com" Date: Thu, 28 May 2020 10:25:56 -0700 Subject: [PATCH 6/8] newline lint --- .../services/eventhub/eventhub_authorization_rule_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go index ecf8149422c7..accc09f4c450 100644 --- a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go @@ -103,7 +103,6 @@ func resourceArmEventHubAuthorizationRuleCreateUpdate(d *schema.ResourceData, me } 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)) } @@ -112,6 +111,7 @@ func resourceArmEventHubAuthorizationRuleCreateUpdate(d *schema.ResourceData, me if err != nil { 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)) } + 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)) } From 5cc25de118b7196616c4f97696e7dc493f5571f1 Mon Sep 17 00:00:00 2001 From: "github@automatetheneedful.com" Date: Thu, 28 May 2020 10:37:30 -0700 Subject: [PATCH 7/8] make fmt --- .../services/eventhub/eventhub_authorization_rule_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go index accc09f4c450..2769cabe1610 100644 --- a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go @@ -111,7 +111,7 @@ func resourceArmEventHubAuthorizationRuleCreateUpdate(d *schema.ResourceData, me if err != nil { 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)) } - + 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)) } From 685bcefd60718ed565b54dd91bcdc07b947bb123 Mon Sep 17 00:00:00 2001 From: "github@automatetheneedful.com" Date: Fri, 29 May 2020 15:35:00 -0700 Subject: [PATCH 8/8] only retry if 404 --- .../eventhub/eventhub_authorization_rule_resource.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go index 2769cabe1610..017dbe1bd4fc 100644 --- a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go @@ -109,7 +109,10 @@ func resourceArmEventHubAuthorizationRuleCreateUpdate(d *schema.ResourceData, me read, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name) if err != nil { - 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)) + 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 {