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: Add active_directory_authentication_enabled argument #23976

Merged
merged 7 commits into from
Nov 28, 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
33 changes: 30 additions & 3 deletions internal/services/redis/redis_cache_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ func resourceRedisCache() *pluginsdk.Resource {
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"active_directory_authentication_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
},
"maxclients": {
Type: pluginsdk.TypeInt,
Computed: true,
Expand Down Expand Up @@ -466,7 +470,7 @@ func resourceRedisCacheCreate(d *pluginsdk.ResourceData, meta interface{}) error
return fmt.Errorf("internal-error: context had no deadline")
}
stateConf := &pluginsdk.StateChangeConf{
Pending: []string{"Scaling", "Updating", "Creating"},
Pending: []string{"Scaling", "Updating", "Creating", "ConfiguringAAD"},
Target: []string{"Succeeded"},
Refresh: redisStateRefreshFunc(ctx, client, id),
MinTimeout: 15 * time.Second,
Expand Down Expand Up @@ -570,7 +574,7 @@ func resourceRedisCacheUpdate(d *pluginsdk.ResourceData, meta interface{}) error

log.Printf("[DEBUG] Waiting for %s to become available", *id)
stateConf := &pluginsdk.StateChangeConf{
Pending: []string{"Scaling", "Updating", "Creating", "UpgradingRedisServerVersion"},
Pending: []string{"Scaling", "Updating", "Creating", "UpgradingRedisServerVersion", "ConfiguringAAD"},
Target: []string{"Succeeded"},
Refresh: redisStateRefreshFunc(ctx, client, *id),
MinTimeout: 15 * time.Second,
Expand Down Expand Up @@ -821,9 +825,24 @@ func expandRedisConfiguration(d *pluginsdk.ResourceData) (*redis.RedisCommonProp
output.MaxmemoryPolicy = utils.String(v)
}

// AAD/Entra support
// nolint : staticcheck
v, valExists := d.GetOkExists("redis_configuration.0.active_directory_authentication_enabled")
if valExists {
entraEnabled := v.(bool)

// active_directory_authentication_enabled is available when SKU is Premium
if strings.EqualFold(skuName, string(redis.SkuNamePremium)) {

output.AadEnabled = utils.String(strconv.FormatBool(entraEnabled))
} else if entraEnabled && !strings.EqualFold(skuName, string(redis.SkuNamePremium)) {
return nil, fmt.Errorf("The `active_directory_authentication_enabled` property requires a `Premium` sku to be set")
}
}

// RDB Backup
// nolint : staticcheck
v, valExists := d.GetOkExists("redis_configuration.0.rdb_backup_enabled")
v, valExists = d.GetOkExists("redis_configuration.0.rdb_backup_enabled")
if valExists {
rdbBackupEnabled := v.(bool)

Expand Down Expand Up @@ -939,6 +958,14 @@ func flattenTenantSettings(input *map[string]string) map[string]string {
func flattenRedisConfiguration(input *redis.RedisCommonPropertiesRedisConfiguration) ([]interface{}, error) {
outputs := make(map[string]interface{})

if input.AadEnabled != nil {
a, err := strconv.ParseBool(*input.AadEnabled)
if err != nil {
return nil, fmt.Errorf("parsing `aad-enabled` %q: %+v", *input.AadEnabled, err)
}
outputs["active_directory_authentication_enabled"] = a
}

if input.Maxclients != nil {
i, err := strconv.Atoi(*input.Maxclients)
if err != nil {
Expand Down
43 changes: 43 additions & 0 deletions internal/services/redis/redis_cache_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ func TestAccRedisCache_premiumShardedScaling(t *testing.T) {
})
}

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

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.aadEnabled(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("redis_configuration.0.rdb_storage_connection_string"),
})
}

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

func (RedisCacheResource) aadEnabled(data acceptance.TestData) 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 = 3
family = "P"
sku_name = "Premium"
enable_non_ssl_port = false
public_network_access_enabled = false

redis_configuration {
active_directory_authentication_enabled = true
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (RedisCacheResource) backupDisabled(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/redis_cache.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ redis_configuration {

-> **NOTE:** `enable_authentication` can only be set to `false` if a `subnet_id` is specified; and only works if there aren't existing instances within the subnet with `enable_authentication` set to `true`.

* `active_directory_authentication_enabled` - (Optional) Enable Microsoft Entra (AAD) authentication. Defaults to `false`.

* `maxmemory_reserved` - (Optional) Value in megabytes reserved for non-cache usage e.g. failover. Defaults are shown below.
* `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`.
Expand Down
Loading