Skip to content

Commit

Permalink
azurerm_redis_cache : fix incorrect ssl values for `redis_primary_c…
Browse files Browse the repository at this point in the history
…onnection_string` and `secondary_connection_string` (#23575)

* fix issue 23490

* update code

* update code

* update code
  • Loading branch information
sinbai authored Oct 18, 2023
1 parent 7574d90 commit f8a3e41
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 28 deletions.
5 changes: 2 additions & 3 deletions internal/services/redis/redis_cache_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
25 changes: 0 additions & 25 deletions internal/services/redis/redis_cache_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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", true),
testCheckSSLInConnectionString(data.ResourceName, "secondary_connection_string", true),
),
},
data.ImportStep(),
Expand All @@ -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", false),
testCheckSSLInConnectionString(data.ResourceName, "secondary_connection_string", false),
),
},
data.ImportStep(),
Expand Down Expand Up @@ -1491,23 +1486,3 @@ resource "azurerm_redis_cache" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func testCheckSSLInConnectionString(resourceName string, propertyName string, requireSSL bool) 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", requireSSL)) {
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)
}
}

0 comments on commit f8a3e41

Please sign in to comment.