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_redis_cache : fix incorrect ssl values for redis_primary_connection_string and secondary_connection_string #23575

Merged
merged 4 commits into from
Oct 18, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
Loading