From 86c4b1b18e552612e6df9a37b7b82c1ce9610552 Mon Sep 17 00:00:00 2001 From: Edwin Date: Thu, 8 Mar 2018 01:03:21 +0800 Subject: [PATCH] azurerm: support notify-keyspace-events configuration on Redis --- azurerm/resource_arm_redis_cache.go | 9 ++++ azurerm/resource_arm_redis_cache_test.go | 52 +++++++++++++++++++++++- website/docs/r/redis_cache.html.markdown | 1 + 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/azurerm/resource_arm_redis_cache.go b/azurerm/resource_arm_redis_cache.go index a536a86d03d7..99d043505558 100644 --- a/azurerm/resource_arm_redis_cache.go +++ b/azurerm/resource_arm_redis_cache.go @@ -121,6 +121,10 @@ func resourceArmRedisCache() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "notify_keyspace_events": { + Type: schema.TypeString, + Optional: true, + }, }, }, }, @@ -509,6 +513,10 @@ func expandRedisConfiguration(d *schema.ResourceData) *map[string]*string { output["rdb-storage-connection-string"] = utils.String(v.(string)) } + if v, ok := d.GetOk("redis_configuration.0.notify_keyspace_events"); ok { + output["notify-keyspace-events"] = utils.String(v.(string)) + } + return &output } @@ -553,6 +561,7 @@ func flattenRedisConfiguration(configuration *map[string]*string) map[string]*st redisConfiguration["rdb_backup_frequency"] = config["rdb-backup-frequency"] redisConfiguration["rdb_backup_max_snapshot_count"] = config["rdb-backup-max-snapshot-count"] redisConfiguration["rdb_storage_connection_string"] = config["rdb-storage-connection-string"] + redisConfiguration["notify_keyspace_events"] = config["notify-keyspace-events"] return redisConfiguration } diff --git a/azurerm/resource_arm_redis_cache_test.go b/azurerm/resource_arm_redis_cache_test.go index ae345d8484ec..67cc1ca2d59b 100644 --- a/azurerm/resource_arm_redis_cache_test.go +++ b/azurerm/resource_arm_redis_cache_test.go @@ -374,6 +374,26 @@ func testCheckAzureRMRedisCacheDestroy(s *terraform.State) error { return nil } +func TestAccAzureRMRedisCache_SubscribeAllEvents(t *testing.T) { + ri := acctest.RandInt() + rs := acctest.RandString(4) + config := testAccAzureRMRedisCacheSubscribeAllEvents(ri, rs, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMRedisCacheDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMRedisCacheExists("azurerm_redis_cache.test"), + ), + }, + }, + }) +} + func testAccAzureRMRedisCache_basic(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { @@ -563,7 +583,6 @@ resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" } - resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" location = "${azurerm_resource_group.test.location}" @@ -578,7 +597,6 @@ resource "azurerm_redis_cache" "test" { maxmemory_delta = 2 maxmemory_policy = "allkeys-lru" } - patch_schedule { day_of_week = "Tuesday" start_hour_utc = 8 @@ -586,3 +604,33 @@ resource "azurerm_redis_cache" "test" { } `, rInt, location, rInt) } + +func testAccAzureRMRedisCacheSubscribeAllEvents(rInt int, rString string, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} +resource "azurerm_storage_account" "test" { + name = "unlikely23exst2acct%s" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + account_type = "Standard_GRS" + tags { + environment = "staging" + } +} +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 + redis_configuration { + notify_keyspace_events = "KAE" + } +} +`, rInt, location, rString, rInt) +} diff --git a/website/docs/r/redis_cache.html.markdown b/website/docs/r/redis_cache.html.markdown index 7e53a18895ae..7fb4d856cc1e 100644 --- a/website/docs/r/redis_cache.html.markdown +++ b/website/docs/r/redis_cache.html.markdown @@ -182,6 +182,7 @@ The pricing group for the Redis Family - either "C" or "P" at present. * `rdb_backup_frequency` - (Optional) The Backup Frequency in Minutes. Only supported on Premium SKU's. Possible values are: `15`, `30`, `60`, `360`, `720` and `1440`. * `rdb_backup_max_snapshot_count` - (Optional) The maximum number of snapshots to create as a backup. Only supported for Premium SKU's. * `rdb_storage_connection_string` - (Optional) The Connection String to the Storage Account. Only supported for Premium SKU's. In the format: `DefaultEndpointsProtocol=https;BlobEndpoint=${azurerm_storage_account.test.primary_blob_endpoint};AccountName=${azurerm_storage_account.test.name};AccountKey=${azurerm_storage_account.test.primary_access_key}`. +* `notify_keyspace_events` - (Optional) Keyspace notifications allows clients to subscribe to Pub/Sub channels in order to receive events affecting the Redis data set in some way. [Reference](https://redis.io/topics/notifications#configuration) ```hcl redis_configuration {