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

#24317: Support preferred_data_persistence_auth_method for azurerm_redis_cache resource #24370

Merged
merged 5 commits into from Feb 16, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/services/redis/redis_cache_data_source.go
Expand Up @@ -162,6 +162,10 @@ func dataSourceRedisCache() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Computed: true,
},
"data_persistence_authentication_method": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
},
Expand Down
18 changes: 18 additions & 0 deletions internal/services/redis/redis_cache_resource.go
Expand Up @@ -179,6 +179,16 @@ func resourceRedisCache() *pluginsdk.Resource {
Computed: true,
},

"data_persistence_authentication_method": {
Type: pluginsdk.TypeString,
Optional: true,
Default: "SAS",
ValidateFunc: validation.StringInSlice([]string{
"SAS",
"ManagedIdentity",
}, false),
},

"rdb_backup_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Expand Down Expand Up @@ -830,6 +840,10 @@ func expandRedisConfiguration(d *pluginsdk.ResourceData) (*redis.RedisCommonProp
output.MaxmemoryPolicy = utils.String(v)
}

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

// AAD/Entra support
// nolint : staticcheck
v, valExists := d.GetOkExists("redis_configuration.0.active_directory_authentication_enabled")
Expand Down Expand Up @@ -1000,6 +1014,10 @@ func flattenRedisConfiguration(input *redis.RedisCommonPropertiesRedisConfigurat
outputs["maxmemory_policy"] = *input.MaxmemoryPolicy
}

if input.PreferredDataPersistenceAuthMethod != nil {
outputs["data_persistence_authentication_method"] = *input.PreferredDataPersistenceAuthMethod
}

if input.MaxfragmentationmemoryReserved != nil {
i, err := strconv.Atoi(*input.MaxfragmentationmemoryReserved)
if err != nil {
Expand Down
47 changes: 47 additions & 0 deletions internal/services/redis/redis_cache_resource_test.go
Expand Up @@ -36,6 +36,25 @@ func TestAccRedisCache_basic(t *testing.T) {
})
}

func TestAccRedisCache_managedIdentityAuth(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(),
})
}

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

func (RedisCacheResource) managedIdentityAuth(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"
enable_non_ssl_port = %t
minimum_tls_version = "1.2"

redis_configuration {
data_persistence_authentication_method = "ManagedIdentity"
}
}
`, 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
2 changes: 2 additions & 0 deletions website/docs/r/redis_cache.html.markdown
Expand Up @@ -146,6 +146,8 @@ redis_configuration {
* `maxmemory_delta` - (Optional) The max-memory delta for this Redis instance. Defaults are shown below.
* `maxmemory_policy` - (Optional) How Redis will select what to remove when `maxmemory` is reached. Defaults to `volatile-lru`.

* `data_persistence_authentication_method` - (Optional) Preferred auth method to communicate to storage account used for data persistence. Possible values are `SAS` and `ManagedIdentity`. Defaults to `SAS`.

* `maxfragmentationmemory_reserved` - (Optional) Value in megabytes reserved to accommodate for memory fragmentation. Defaults are shown below.

* `rdb_backup_enabled` - (Optional) Is Backup Enabled? Only supported on Premium SKUs. Defaults to `false`.
Expand Down