From e6592eafa0a132d51f58ffc9d77622fd05611b1b Mon Sep 17 00:00:00 2001 From: "Elena Xin (Centific Technologies Inc)" Date: Mon, 16 Oct 2023 16:42:37 +0800 Subject: [PATCH 1/4] fix issue 23490 --- internal/services/redis/redis_cache_resource.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/services/redis/redis_cache_resource.go b/internal/services/redis/redis_cache_resource.go index ca6538e790eb..0dffb2b669d2 100644 --- a/internal/services/redis/redis_cache_resource.go +++ b/internal/services/redis/redis_cache_resource.go @@ -720,9 +720,8 @@ func resourceRedisCacheRead(d *pluginsdk.ResourceData, meta interface{}) error { return fmt.Errorf("setting `redis_configuration`: %+v", err) } - enableSslPort := !*props.EnableNonSslPort - d.Set("primary_connection_string", getRedisConnectionString(*props.HostName, *props.SslPort, *keysResp.Model.PrimaryKey, enableSslPort)) - d.Set("secondary_connection_string", getRedisConnectionString(*props.HostName, *props.SslPort, *keysResp.Model.SecondaryKey, enableSslPort)) + d.Set("primary_connection_string", getRedisConnectionString(*props.HostName, *props.SslPort, *keysResp.Model.PrimaryKey, true)) + d.Set("secondary_connection_string", getRedisConnectionString(*props.HostName, *props.SslPort, *keysResp.Model.SecondaryKey, true)) d.Set("primary_access_key", keysResp.Model.PrimaryKey) d.Set("secondary_access_key", keysResp.Model.SecondaryKey) From 9c2d47c3eb7355dfd90c284c2b0b7bcda8675b78 Mon Sep 17 00:00:00 2001 From: "Elena Xin (Centific Technologies Inc)" Date: Tue, 17 Oct 2023 10:47:26 +0800 Subject: [PATCH 2/4] update code --- internal/services/redis/redis_cache_resource_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/services/redis/redis_cache_resource_test.go b/internal/services/redis/redis_cache_resource_test.go index fc3ca9daa6d3..a4c1d2c79831 100644 --- a/internal/services/redis/redis_cache_resource_test.go +++ b/internal/services/redis/redis_cache_resource_test.go @@ -48,8 +48,8 @@ func TestAccRedisCache_withoutSSL(t *testing.T) { Config: r.basic(data, false), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - testCheckSSLInConnectionString(data.ResourceName, "primary_connection_string", false), - testCheckSSLInConnectionString(data.ResourceName, "secondary_connection_string", false), + testCheckSSLInConnectionString(data.ResourceName, "primary_connection_string", true), + testCheckSSLInConnectionString(data.ResourceName, "secondary_connection_string", true), ), }, data.ImportStep(), From 4a4bc11624a67c71fb8baa18f67d63823804932a Mon Sep 17 00:00:00 2001 From: "Elena Xin (Centific Technologies Inc)" Date: Tue, 17 Oct 2023 11:54:59 +0800 Subject: [PATCH 3/4] update code --- .../services/redis/redis_cache_resource_test.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/internal/services/redis/redis_cache_resource_test.go b/internal/services/redis/redis_cache_resource_test.go index a4c1d2c79831..d1ccc40eff1c 100644 --- a/internal/services/redis/redis_cache_resource_test.go +++ b/internal/services/redis/redis_cache_resource_test.go @@ -31,8 +31,8 @@ func TestAccRedisCache_basic(t *testing.T) { check.That(data.ResourceName).Key("minimum_tls_version").Exists(), check.That(data.ResourceName).Key("primary_connection_string").Exists(), check.That(data.ResourceName).Key("secondary_connection_string").Exists(), - testCheckSSLInConnectionString(data.ResourceName, "primary_connection_string", true), - testCheckSSLInConnectionString(data.ResourceName, "secondary_connection_string", true), + testCheckSSLInConnectionString(data.ResourceName, "primary_connection_string"), + testCheckSSLInConnectionString(data.ResourceName, "secondary_connection_string"), ), }, data.ImportStep(), @@ -48,8 +48,8 @@ func TestAccRedisCache_withoutSSL(t *testing.T) { Config: r.basic(data, false), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - testCheckSSLInConnectionString(data.ResourceName, "primary_connection_string", true), - testCheckSSLInConnectionString(data.ResourceName, "secondary_connection_string", true), + testCheckSSLInConnectionString(data.ResourceName, "primary_connection_string"), + testCheckSSLInConnectionString(data.ResourceName, "secondary_connection_string"), ), }, data.ImportStep(), @@ -1492,7 +1492,7 @@ resource "azurerm_redis_cache" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testCheckSSLInConnectionString(resourceName string, propertyName string, requireSSL bool) acceptance.TestCheckFunc { +func testCheckSSLInConnectionString(resourceName string, propertyName string) acceptance.TestCheckFunc { return func(s *acceptance.State) error { // Ensure we have enough information in state to look up in API rs, ok := s.RootModule().Resources[resourceName] @@ -1501,12 +1501,9 @@ func testCheckSSLInConnectionString(resourceName string, propertyName string, re } connectionString := rs.Primary.Attributes[propertyName] - if strings.Contains(connectionString, fmt.Sprintf("ssl=%t", requireSSL)) { + if strings.Contains(connectionString, fmt.Sprintf("ssl=%t", true)) { return nil } - if strings.Contains(connectionString, fmt.Sprintf("ssl=%t", !requireSSL)) { - return fmt.Errorf("Bad: wrong SSL setting in connection string: %s", propertyName) - } return fmt.Errorf("Bad: missing SSL setting in connection string: %s", propertyName) } From 436870b9724c26b59cd69de44f186f2a2542b0ec Mon Sep 17 00:00:00 2001 From: Elena Xin Date: Wed, 18 Oct 2023 11:10:33 +0800 Subject: [PATCH 4/4] update code --- .../redis/redis_cache_resource_test.go | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/internal/services/redis/redis_cache_resource_test.go b/internal/services/redis/redis_cache_resource_test.go index d1ccc40eff1c..d5bd281fd20d 100644 --- a/internal/services/redis/redis_cache_resource_test.go +++ b/internal/services/redis/redis_cache_resource_test.go @@ -6,7 +6,6 @@ package redis_test import ( "context" "fmt" - "strings" "testing" "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2023-04-01/redis" @@ -31,8 +30,6 @@ func TestAccRedisCache_basic(t *testing.T) { check.That(data.ResourceName).Key("minimum_tls_version").Exists(), check.That(data.ResourceName).Key("primary_connection_string").Exists(), check.That(data.ResourceName).Key("secondary_connection_string").Exists(), - testCheckSSLInConnectionString(data.ResourceName, "primary_connection_string"), - testCheckSSLInConnectionString(data.ResourceName, "secondary_connection_string"), ), }, data.ImportStep(), @@ -48,8 +45,6 @@ func TestAccRedisCache_withoutSSL(t *testing.T) { Config: r.basic(data, false), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - testCheckSSLInConnectionString(data.ResourceName, "primary_connection_string"), - testCheckSSLInConnectionString(data.ResourceName, "secondary_connection_string"), ), }, data.ImportStep(), @@ -1491,20 +1486,3 @@ resource "azurerm_redis_cache" "test" { } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } - -func testCheckSSLInConnectionString(resourceName string, propertyName string) acceptance.TestCheckFunc { - return func(s *acceptance.State) error { - // Ensure we have enough information in state to look up in API - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", resourceName) - } - - connectionString := rs.Primary.Attributes[propertyName] - if strings.Contains(connectionString, fmt.Sprintf("ssl=%t", true)) { - return nil - } - - return fmt.Errorf("Bad: missing SSL setting in connection string: %s", propertyName) - } -}