Skip to content

Commit

Permalink
[Bug Fix ] azurerm_redis_cache - Support for unsetting `data_persis…
Browse files Browse the repository at this point in the history
…tence_authentication_method` (hashicorp#27932)

* support for unsetting  data_persistence_authentication_method

* optimize data_persistence_authentication_method settings
  • Loading branch information
xuzhang3 authored and NotTheEvilOne committed Jan 20, 2025
1 parent f052a43 commit 746b30c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
14 changes: 6 additions & 8 deletions internal/services/redis/redis_cache_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,30 +861,28 @@ func expandRedisConfiguration(d *pluginsdk.ResourceData) (*redis.RedisCommonProp
skuName := d.Get("sku_name").(string)

if v := raw["maxclients"].(int); v > 0 {
output.Maxclients = utils.String(strconv.Itoa(v))
output.Maxclients = pointer.To(strconv.Itoa(v))
}

if d.Get("sku_name").(string) != string(redis.SkuNameBasic) {
if v := raw["maxmemory_delta"].(int); v > 0 {
output.MaxmemoryDelta = utils.String(strconv.Itoa(v))
output.MaxmemoryDelta = pointer.To(strconv.Itoa(v))
}

if v := raw["maxmemory_reserved"].(int); v > 0 {
output.MaxmemoryReserved = utils.String(strconv.Itoa(v))
output.MaxmemoryReserved = pointer.To(strconv.Itoa(v))
}

if v := raw["maxfragmentationmemory_reserved"].(int); v > 0 {
output.MaxfragmentationmemoryReserved = utils.String(strconv.Itoa(v))
output.MaxfragmentationmemoryReserved = pointer.To(strconv.Itoa(v))
}
}

if v := raw["maxmemory_policy"].(string); v != "" {
output.MaxmemoryPolicy = utils.String(v)
output.MaxmemoryPolicy = pointer.To(v)
}

if v := raw["data_persistence_authentication_method"].(string); v != "" {
output.PreferredDataPersistenceAuthMethod = utils.String(v)
}
output.PreferredDataPersistenceAuthMethod = pointer.To(raw["data_persistence_authentication_method"].(string))

// AAD/Entra support
// nolint : staticcheck
Expand Down
56 changes: 56 additions & 0 deletions internal/services/redis/redis_cache_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,36 @@ func TestAccRedisCache_managedIdentityAuth(t *testing.T) {
})
}

func TestAccRedisCache_managedIdentityAuthDisable(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test")
r := RedisCacheResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.managedIdentityAuth(data, true),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
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(),
check.That(data.ResourceName).Key("redis_configuration.0.data_persistence_authentication_method").HasValue("ManagedIdentity"),
),
},
data.ImportStep(),
{
Config: r.managedIdentityAuthDisable(data, true),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
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(),
check.That(data.ResourceName).Key("redis_configuration.0.data_persistence_authentication_method").HasValue(""),
),
},
data.ImportStep(),
})
}

func TestAccRedisCache_withoutSSL(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test")
r := RedisCacheResource{}
Expand Down Expand Up @@ -614,6 +644,32 @@ resource "azurerm_redis_cache" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, !requireSSL)
}

func (RedisCacheResource) managedIdentityAuthDisable(data acceptance.TestData, requireSSL bool) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_redis_cache" "test" {
name = "acctestRedis-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
capacity = 1
family = "C"
sku_name = "Basic"
non_ssl_port_enabled = %t
minimum_tls_version = "1.2"
redis_configuration {}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, !requireSSL)
}

func (RedisCacheResource) requiresImport(data acceptance.TestData) string {
template := RedisCacheResource{}.basic(data, true)
return fmt.Sprintf(`
Expand Down

0 comments on commit 746b30c

Please sign in to comment.