Skip to content

Commit

Permalink
azurerm: support notify-keyspace-events configuration on Redis
Browse files Browse the repository at this point in the history
  • Loading branch information
bailantaotao committed Mar 7, 2018
1 parent 3cd42a1 commit ab68ea8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
9 changes: 9 additions & 0 deletions azurerm/resource_arm_redis_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ func resourceArmRedisCache() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"notify_keyspace_events": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down
52 changes: 50 additions & 2 deletions azurerm/resource_arm_redis_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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}"
Expand All @@ -578,11 +597,40 @@ resource "azurerm_redis_cache" "test" {
maxmemory_delta = 2
maxmemory_policy = "allkeys-lru"
}
patch_schedule {
day_of_week = "Tuesday"
start_hour_utc = 8
}
}
`, 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)
}
1 change: 1 addition & 0 deletions website/docs/r/redis_cache.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ab68ea8

Please sign in to comment.