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 support for notify-keyspace-events #949

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in running the tests I noticed this field needs to be split into the two sub-fields - I'll push a commit to fix this :)

account_tier             = "Standard"
account_replication_type = "GRS"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh...thanks for your help :D

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