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 82ed4e0 commit ea2b9df
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 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 @@ -119,6 +119,10 @@ func resourceArmRedisCache() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"notify_keyspace_events": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -423,6 +427,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 All @@ -439,6 +447,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: 52 additions & 0 deletions azurerm/resource_arm_redis_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,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 @@ -504,3 +524,35 @@ resource "azurerm_redis_cache" "test" {
}
`, rInt, location, rString, 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 @@ -153,6 +153,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 ea2b9df

Please sign in to comment.