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 3 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
15 changes: 6 additions & 9 deletions internal/services/redis/redis_cache_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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"),
testCheckSSLInConnectionString(data.ResourceName, "secondary_connection_string"),
),
},
data.ImportStep(),
Expand Down Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that the connection string is now specifically set to be true now, we probably don't need to have this check in the tests at all anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, fixed. Thanks.

return func(s *acceptance.State) error {
// Ensure we have enough information in state to look up in API
rs, ok := s.RootModule().Resources[resourceName]
Expand All @@ -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)
}
Expand Down