From 00b62fd67468a8083c5c7316084fae15eeddf710 Mon Sep 17 00:00:00 2001 From: Dubnik Date: Wed, 26 Jun 2019 11:07:26 +0100 Subject: [PATCH 1/2] fix to allow parallel rule setup --- azurerm/resource_arm_redis_firewall_rule.go | 28 ++++++++++++--------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/azurerm/resource_arm_redis_firewall_rule.go b/azurerm/resource_arm_redis_firewall_rule.go index aac42ccfd2cd..42d0dfae19b9 100644 --- a/azurerm/resource_arm_redis_firewall_rule.go +++ b/azurerm/resource_arm_redis_firewall_rule.go @@ -10,6 +10,7 @@ import ( "regexp" "github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2018-03-01/redis" + "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -84,21 +85,24 @@ func resourceArmRedisFirewallRuleCreateUpdate(d *schema.ResourceData, meta inter }, } - if _, err := client.CreateOrUpdate(ctx, resourceGroup, cacheName, name, parameters); err != nil { - return err - } + return resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { - read, err := client.Get(ctx, resourceGroup, cacheName, name) - if err != nil { - return err - } - if read.ID == nil { - return fmt.Errorf("Cannot read Redis Firewall Rule %q (cache %q / resource group %q) ID", name, cacheName, resourceGroup) - } + if _, err := client.CreateOrUpdate(ctx, resourceGroup, cacheName, name, parameters); err != nil { + return resource.NonRetryableError(fmt.Errorf("Error creating the rule: %s", err)) + } + + read, err := client.Get(ctx, resourceGroup, cacheName, name) + if err != nil { + return resource.RetryableError(fmt.Errorf("Expected instance to be created but was in non existent state, retrying")) + } + if read.ID == nil { + return resource.NonRetryableError(fmt.Errorf("Cannot read Redis Firewall Rule %q (cache %q / resource group %q) ID", name, cacheName, resourceGroup)) + } - d.SetId(*read.ID) + d.SetId(*read.ID) - return resourceArmRedisFirewallRuleRead(d, meta) + return resource.NonRetryableError(resourceArmRedisFirewallRuleRead(d, meta)) + }) } func resourceArmRedisFirewallRuleRead(d *schema.ResourceData, meta interface{}) error { From 368bf5eba050d3686f8a57a4e1a3e309d49ee897 Mon Sep 17 00:00:00 2001 From: Dubnik Date: Wed, 26 Jun 2019 21:17:03 +0100 Subject: [PATCH 2/2] added tests --- .../resource_arm_redis_firewall_rule_test.go | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/azurerm/resource_arm_redis_firewall_rule_test.go b/azurerm/resource_arm_redis_firewall_rule_test.go index 8b73010e5468..10e6ef6610f1 100644 --- a/azurerm/resource_arm_redis_firewall_rule_test.go +++ b/azurerm/resource_arm_redis_firewall_rule_test.go @@ -75,6 +75,37 @@ func TestAccAzureRMRedisFirewallRule_basic(t *testing.T) { }) } +func TestAccAzureRMRedisFirewallRule_multi(t *testing.T) { + ruleOne := "azurerm_redis_firewall_rule.test" + ruleTwo := "azurerm_redis_firewall_rule.double" + ri := tf.AccRandTimeInt() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMRedisFirewallRuleDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMRedisFirewallRule_multi(ri, testLocation()), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMRedisFirewallRuleExists(ruleOne), + testCheckAzureRMRedisFirewallRuleExists(ruleTwo), + ), + }, + { + ResourceName: ruleOne, + ImportState: true, + ImportStateVerify: true, + }, + { + ResourceName: ruleTwo, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAzureRMRedisFirewallRule_requiresImport(t *testing.T) { if !requireResourcesToBeImported { t.Skip("Skipping since resources aren't required to be imported") @@ -213,6 +244,20 @@ resource "azurerm_redis_firewall_rule" "test" { `, rInt, location, rInt, rInt) } +func testAccAzureRMRedisFirewallRule_multi(rInt int, location string) string { + return fmt.Sprintf(` +%s + +resource "azurerm_redis_firewall_rule" "double" { + name = "fwruletwo%d" + redis_cache_name = "${azurerm_redis_cache.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + start_ip = "4.5.6.7" + end_ip = "8.9.0.1" + } +`, testAccAzureRMRedisFirewallRule_basic(rInt, location), rInt) +} + func testAccAzureRMRedisFirewallRule_requiresImport(rInt int, location string) string { return fmt.Sprintf(` %s